2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-03-20 20:22:26 +04:00
|
|
|
#include "nsSVGElement.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.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
|
|
|
|
2018-01-25 17:59:42 +03:00
|
|
|
nsresult
|
|
|
|
SVGDocument::InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
|
|
|
|
bool aNotify)
|
|
|
|
{
|
|
|
|
if (aKid->IsElement() && !aKid->IsSVGElement()) {
|
|
|
|
// 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. Note
|
|
|
|
// that we have to do this _before_ the XMLDocument::InsertChildBefore,
|
|
|
|
// since that can try to construct frames, and we need to have the sheets
|
|
|
|
// loaded by then.
|
|
|
|
EnsureNonSVGUserAgentStyleSheetsLoaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
return XMLDocument::InsertChildBefore(aKid, aBeforeThis, aNotify);
|
|
|
|
}
|
|
|
|
|
2014-06-05 04:01:39 +04:00
|
|
|
nsresult
|
2018-01-23 16:30:18 +03:00
|
|
|
SVGDocument::InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
|
|
|
|
bool aNotify)
|
2014-06-05 04:01:39 +04:00
|
|
|
{
|
2015-04-14 02:36:57 +03:00
|
|
|
if (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
|
2015-04-14 02:36:57 +03:00
|
|
|
// the non-SVG UA sheets or else we can get bugs like bug 1016145. Note
|
2018-01-23 16:30:18 +03:00
|
|
|
// that we have to do this _before_ the
|
|
|
|
// XMLDocument::InsertChildAt_Deprecated call, since that can try to
|
|
|
|
// construct frames, and we need to have the sheets loaded by then.
|
2014-06-05 04:01:39 +04:00
|
|
|
EnsureNonSVGUserAgentStyleSheetsLoaded();
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:30:18 +03:00
|
|
|
return XMLDocument::InsertChildAt_Deprecated(aKid, aIndex, aNotify);
|
2014-06-05 04:01:39 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
nsresult
|
2017-04-20 22:57:48 +03:00
|
|
|
SVGDocument::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
|
|
|
|
bool aPreallocateChildren) const
|
2009-12-11 07:02:13 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGDocument> clone = new SVGDocument();
|
2017-04-20 22:57:48 +03:00
|
|
|
nsresult rv = CloneDocHelper(clone.get(), aPreallocateChildren);
|
2009-12-11 07:02:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CallQueryInterface(clone.get(), aResult);
|
|
|
|
}
|
|
|
|
|
2014-05-24 23:29:11 +04:00
|
|
|
void
|
|
|
|
SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
|
|
|
|
{
|
|
|
|
if (mHasLoadedNonSVGUserAgentStyleSheets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-20 00:59:37 +03:00
|
|
|
if (IsStaticDocument()) {
|
|
|
|
// If we're a static clone of a document, then
|
|
|
|
// nsIDocument::CreateStaticClone will handle cloning the original
|
|
|
|
// document's sheets, including the on-demand non-SVG UA sheets,
|
|
|
|
// for us.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-24 23:29:11 +04:00
|
|
|
mHasLoadedNonSVGUserAgentStyleSheets = true;
|
|
|
|
|
2015-06-16 04:34:47 +03:00
|
|
|
BeginUpdate(UPDATE_STYLE);
|
|
|
|
|
2014-05-25 00:37:48 +04:00
|
|
|
if (IsBeingUsedAsImage()) {
|
|
|
|
// nsDocumentViewer::CreateStyleSet skipped loading all user-agent/user
|
2015-04-23 22:10:30 +03:00
|
|
|
// style sheets in this case, but we'll need B2G/Fennec's
|
2014-05-25 00:37:48 +04:00
|
|
|
// 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
|
2015-04-23 22:10:30 +03:00
|
|
|
// EnsureOnDemandBuiltInUASheet prepends, and B2G/Fennec's
|
2014-05-25 00:37:48 +04:00
|
|
|
// 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);
|
|
|
|
|
2017-08-16 06:58:35 +03:00
|
|
|
nsCString spec;
|
2014-05-25 00:37:48 +04:00
|
|
|
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) {
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<StyleSheet> sheet;
|
2015-10-14 00:43:16 +03:00
|
|
|
cssLoader->LoadSheetSync(uri,
|
|
|
|
mozilla::css::eAgentSheetFeatures,
|
2016-02-24 10:01:12 +03:00
|
|
|
true, &sheet);
|
|
|
|
if (sheet) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(sheet);
|
2014-05-25 00:37:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet* sheet = cache->NumberControlSheet();
|
2014-05-28 17:28:34 +04:00
|
|
|
if (sheet) {
|
|
|
|
// number-control.css can be behind a pref
|
|
|
|
EnsureOnDemandBuiltInUASheet(sheet);
|
|
|
|
}
|
2016-02-24 10:01:12 +03:00
|
|
|
EnsureOnDemandBuiltInUASheet(cache->FormsSheet());
|
|
|
|
EnsureOnDemandBuiltInUASheet(cache->CounterStylesSheet());
|
|
|
|
EnsureOnDemandBuiltInUASheet(cache->HTMLSheet());
|
2015-06-16 04:34:47 +03:00
|
|
|
if (nsLayoutUtils::ShouldUseNoFramesSheet(this)) {
|
2016-02-24 10:01:12 +03:00
|
|
|
EnsureOnDemandBuiltInUASheet(cache->NoFramesSheet());
|
2015-06-16 04:34:47 +03:00
|
|
|
}
|
2015-06-16 04:34:47 +03:00
|
|
|
if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) {
|
2016-02-24 10:01:12 +03:00
|
|
|
EnsureOnDemandBuiltInUASheet(cache->NoScriptSheet());
|
2015-06-16 04:34:47 +03:00
|
|
|
}
|
2016-02-24 10:01:12 +03:00
|
|
|
EnsureOnDemandBuiltInUASheet(cache->UASheet());
|
2015-06-16 04:34:47 +03:00
|
|
|
|
|
|
|
EndUpdate(UPDATE_STYLE);
|
2014-05-24 23:29:11 +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)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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
|
|
|
}
|