2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-20 09:22:26 -07:00
|
|
|
#include "mozilla/dom/SVGDocument.h"
|
2014-05-24 13:37:48 -07:00
|
|
|
|
|
|
|
#include "mozilla/css/Loader.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsIStyleSheetService.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2014-05-24 12:29:11 -07:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2014-05-24 13:37:48 -07:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsLiteralString.h"
|
2013-02-08 11:55:07 -08:00
|
|
|
#include "nsIDOMSVGElement.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-03-20 09:22:26 -07:00
|
|
|
#include "nsSVGElement.h"
|
|
|
|
#include "mozilla/dom/SVGDocumentBinding.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2014-05-24 13:37:48 -07:00
|
|
|
using namespace mozilla::css;
|
2010-04-30 06:12:05 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-20 09:22:26 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods:
|
|
|
|
|
2013-03-20 09:22:26 -07:00
|
|
|
void
|
|
|
|
SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
SetDOMStringToNull(aDomain);
|
|
|
|
|
|
|
|
if (mDocumentURI) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString domain;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = mDocumentURI->GetHost(domain);
|
2013-03-20 09:22:26 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (domain.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
CopyUTF8toUTF16(domain, aDomain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 09:22:26 -07:00
|
|
|
nsSVGElement*
|
|
|
|
SVGDocument::GetRootElement(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Element* root = nsDocument::GetRootElement();
|
|
|
|
if (!root) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!root->IsSVG()) {
|
|
|
|
aRv.Throw(NS_NOINTERFACE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return static_cast<nsSVGElement*>(root);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-06-04 17:01:39 -07:00
|
|
|
nsresult
|
|
|
|
SVGDocument::InsertChildAt(nsIContent* aKid, uint32_t aIndex, bool aNotify)
|
|
|
|
{
|
|
|
|
nsresult rv = XMLDocument::InsertChildAt(aKid, aIndex, aNotify);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && aKid->IsElement() && !aKid->IsSVG()) {
|
|
|
|
// We can get here when well formed XML with a non-SVG root element is
|
|
|
|
// served with the SVG MIME type, for example. In that case we need to load
|
|
|
|
// the non-SVG UA sheets or else we can get bugs like bug 1016145.
|
|
|
|
EnsureNonSVGUserAgentStyleSheetsLoaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-12-10 20:02:13 -08:00
|
|
|
nsresult
|
2013-03-20 09:22:26 -07:00
|
|
|
SVGDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
2009-12-10 20:02:13 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
2013-03-20 09:22:26 -07:00
|
|
|
nsRefPtr<SVGDocument> clone = new SVGDocument();
|
2009-12-10 20:02:13 -08:00
|
|
|
nsresult rv = CloneDocHelper(clone.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CallQueryInterface(clone.get(), aResult);
|
|
|
|
}
|
|
|
|
|
2014-05-24 12:29:11 -07:00
|
|
|
void
|
|
|
|
SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
|
|
|
|
{
|
|
|
|
if (mHasLoadedNonSVGUserAgentStyleSheets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mHasLoadedNonSVGUserAgentStyleSheets = true;
|
|
|
|
|
2014-05-24 13:37:48 -07:00
|
|
|
if (IsBeingUsedAsImage()) {
|
|
|
|
// nsDocumentViewer::CreateStyleSet skipped loading all user-agent/user
|
|
|
|
// style sheets in this case, but we'll need B2G/Fennec/Metro's
|
|
|
|
// content.css. We could load all the sheets registered with the
|
|
|
|
// nsIStyleSheetService (and maybe we should) but most likely it isn't
|
|
|
|
// desirable or necessary for foreignObject in SVG-as-an-image. Instead we
|
|
|
|
// only load the "agent-style-sheets" that nsStyleSheetService::Init()
|
|
|
|
// pulls in from the category manager. That keeps memory use of
|
|
|
|
// SVG-as-an-image down.
|
|
|
|
//
|
|
|
|
// We do this before adding UASheet() etc. below because
|
|
|
|
// EnsureOnDemandBuiltInUASheet prepends, and B2G/Fennec/Metro's
|
|
|
|
// content.css must come after UASheet() etc.
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
if (catMan) {
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> sheets;
|
|
|
|
catMan->EnumerateCategory("agent-style-sheets", getter_AddRefs(sheets));
|
|
|
|
if (sheets) {
|
|
|
|
bool hasMore;
|
|
|
|
while (NS_SUCCEEDED(sheets->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> sheet;
|
|
|
|
if (NS_FAILED(sheets->GetNext(getter_AddRefs(sheet))))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsCString> icStr = do_QueryInterface(sheet);
|
|
|
|
MOZ_ASSERT(icStr,
|
|
|
|
"category manager entries must be nsISupportsCStrings");
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
icStr->GetData(name);
|
|
|
|
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
catMan->GetCategoryEntry("agent-style-sheets", name.get(),
|
|
|
|
getter_Copies(spec));
|
|
|
|
|
|
|
|
mozilla::css::Loader* cssLoader = CSSLoader();
|
|
|
|
if (cssLoader->GetEnabled()) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), spec);
|
|
|
|
if (uri) {
|
|
|
|
nsRefPtr<nsCSSStyleSheet> cssSheet;
|
|
|
|
cssLoader->LoadSheetSync(uri, true, true, getter_AddRefs(cssSheet));
|
|
|
|
if (cssSheet) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(cssSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 06:28:34 -07:00
|
|
|
nsCSSStyleSheet* sheet = nsLayoutStylesheetCache::NumberControlSheet();
|
|
|
|
if (sheet) {
|
|
|
|
// number-control.css can be behind a pref
|
|
|
|
EnsureOnDemandBuiltInUASheet(sheet);
|
|
|
|
}
|
2014-05-24 12:29:11 -07:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet());
|
2014-06-11 18:12:00 -07:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet());
|
2014-05-24 12:29:11 -07:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet());
|
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet());
|
|
|
|
}
|
|
|
|
|
2013-03-20 09:22:26 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
SVGDocument::WrapNode(JSContext *aCx)
|
2013-03-20 09:22:26 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return SVGDocumentBinding::Wrap(aCx, this);
|
2013-03-20 09:22:26 -07:00
|
|
|
}
|
|
|
|
|
2013-03-20 09:22:26 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Exported creation functions
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewSVGDocument(nsIDocument** aInstancePtrResult)
|
|
|
|
{
|
2013-03-20 09:22:26 -07:00
|
|
|
nsRefPtr<SVGDocument> doc = new SVGDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-04-13 00:08:49 -07:00
|
|
|
doc.forget(aInstancePtrResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|