2001-12-12 10:59:31 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
#include "mozilla/dom/SVGDocument.h"
|
2014-05-25 00:37:48 +04:00
|
|
|
|
|
|
|
#include "mozilla/css/Loader.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsIStyleSheetService.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2014-05-24 23:29:11 +04:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2014-05-25 00:37:48 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2002-03-21 04:43:51 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsLiteralString.h"
|
2013-02-08 23:55:07 +04:00
|
|
|
#include "nsIDOMSVGElement.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-03-20 20:22:26 +04:00
|
|
|
#include "nsSVGElement.h"
|
|
|
|
#include "mozilla/dom/SVGDocumentBinding.h"
|
2010-04-30 17:12:05 +04:00
|
|
|
|
2014-05-25 00:37:48 +04:00
|
|
|
using namespace mozilla::css;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
2004-11-19 02:32:06 +03:00
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2004-11-19 02:32:06 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods:
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
void
|
|
|
|
SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv)
|
2004-11-19 02:32:06 +03:00
|
|
|
{
|
|
|
|
SetDOMStringToNull(aDomain);
|
2003-06-21 04:26:28 +04:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
if (mDocumentURI) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString domain;
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = mDocumentURI->GetHost(domain);
|
2013-03-20 20:22:26 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (domain.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2004-11-19 02:32:06 +03:00
|
|
|
CopyUTF8toUTF16(domain, aDomain);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
nsSVGElement*
|
|
|
|
SVGDocument::GetRootElement(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Element* root = nsDocument::GetRootElement();
|
|
|
|
if (!root) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!root->IsSVGElement()) {
|
2013-03-20 20:22:26 +04:00
|
|
|
aRv.Throw(NS_NOINTERFACE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return static_cast<nsSVGElement*>(root);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 04:01:39 +04:00
|
|
|
nsresult
|
|
|
|
SVGDocument::InsertChildAt(nsIContent* aKid, uint32_t aIndex, bool aNotify)
|
|
|
|
{
|
|
|
|
nsresult rv = XMLDocument::InsertChildAt(aKid, aIndex, aNotify);
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && aKid->IsElement() && !aKid->IsSVGElement()) {
|
2014-06-05 04:01:39 +04:00
|
|
|
// 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-11 07:02:13 +03:00
|
|
|
nsresult
|
2014-06-20 06:01:40 +04:00
|
|
|
SVGDocument::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2009-12-11 07:02:13 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
nsRefPtr<SVGDocument> clone = new SVGDocument();
|
2009-12-11 07:02:13 +03:00
|
|
|
nsresult rv = CloneDocHelper(clone.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CallQueryInterface(clone.get(), aResult);
|
|
|
|
}
|
|
|
|
|
2014-05-24 23:29:11 +04:00
|
|
|
void
|
|
|
|
SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
|
|
|
|
{
|
|
|
|
if (mHasLoadedNonSVGUserAgentStyleSheets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mHasLoadedNonSVGUserAgentStyleSheets = true;
|
|
|
|
|
2014-05-25 00:37:48 +04: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) {
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet;
|
2014-05-25 00:37:48 +04:00
|
|
|
cssLoader->LoadSheetSync(uri, true, true, getter_AddRefs(cssSheet));
|
|
|
|
if (cssSheet) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(cssSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet* sheet = nsLayoutStylesheetCache::NumberControlSheet();
|
2014-05-28 17:28:34 +04:00
|
|
|
if (sheet) {
|
|
|
|
// number-control.css can be behind a pref
|
|
|
|
EnsureOnDemandBuiltInUASheet(sheet);
|
|
|
|
}
|
2014-05-24 23:29:11 +04:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet());
|
2014-06-12 05:12:00 +04:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet());
|
2014-05-24 23:29:11 +04:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet());
|
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet());
|
|
|
|
}
|
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:17 +04:00
|
|
|
SVGDocument::WrapNode(JSContext *aCx)
|
2013-03-20 20:22:26 +04: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-09 02:27:17 +04:00
|
|
|
return SVGDocumentBinding::Wrap(aCx, this);
|
2013-03-20 20:22:26 +04:00
|
|
|
}
|
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2004-11-19 02:32:06 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Exported creation functions
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
2001-12-12 10:59:31 +03:00
|
|
|
NS_NewSVGDocument(nsIDocument** aInstancePtrResult)
|
|
|
|
{
|
2013-03-20 20:22:26 +04:00
|
|
|
nsRefPtr<SVGDocument> doc = new SVGDocument();
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-04-13 11:08:49 +04:00
|
|
|
doc.forget(aInstancePtrResult);
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
return rv;
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|