2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2011-05-18 18:22:59 -07:00
|
|
|
*
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* A base class which implements nsIStyleSheetLinkingElement and can
|
|
|
|
* be subclassed by various content nodes that want to load
|
|
|
|
* stylesheets (<style>, <link>, processing instructions, etc).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsStyleLinkElement.h"
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
#include "mozilla/css/Loader.h"
|
2013-01-08 15:25:47 -08:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-05-11 13:41:47 -07:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2013-01-08 15:25:47 -08:00
|
|
|
#include "nsIContent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMComment.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMStyleSheet.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsXPCOMCIDInternal.h"
|
|
|
|
#include "nsUnicharInputStream.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
2013-01-08 15:25:47 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsStyleLinkElement::nsStyleLinkElement()
|
2011-10-17 07:59:28 -07:00
|
|
|
: mDontLoadStyle(false)
|
|
|
|
, mUpdatesEnabled(true)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mLineNumber(1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleLinkElement::~nsStyleLinkElement()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-07 19:39:09 -07:00
|
|
|
void
|
|
|
|
nsStyleLinkElement::Unlink()
|
|
|
|
{
|
|
|
|
mStyleSheet = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleLinkElement::Traverse(nsCycleCollectionTraversalCallback &cb)
|
|
|
|
{
|
|
|
|
nsStyleLinkElement* tmp = this;
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheet);
|
2012-10-07 19:39:09 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleLinkElement::SetStyleSheet(nsIStyleSheet* aStyleSheet)
|
|
|
|
{
|
2010-05-11 13:41:47 -07:00
|
|
|
nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(mStyleSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (cssSheet) {
|
2012-07-30 07:20:58 -07:00
|
|
|
cssSheet->SetOwningNode(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mStyleSheet = aStyleSheet;
|
2010-05-11 13:41:47 -07:00
|
|
|
cssSheet = do_QueryObject(mStyleSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (cssSheet) {
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
CallQueryInterface(this,
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsIDOMNode**>(getter_AddRefs(node)));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (node) {
|
|
|
|
cssSheet->SetOwningNode(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleLinkElement::GetStyleSheet(nsIStyleSheet*& aStyleSheet)
|
|
|
|
{
|
|
|
|
aStyleSheet = mStyleSheet;
|
|
|
|
NS_IF_ADDREF(aStyleSheet);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsStyleLinkElement::InitStyleLinkElement(bool aDontLoadStyle)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mDontLoadStyle = aDontLoadStyle;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleLinkElement::GetSheet(nsIDOMStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aSheet);
|
2012-07-30 07:20:58 -07:00
|
|
|
*aSheet = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mStyleSheet) {
|
|
|
|
CallQueryInterface(mStyleSheet, aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always return NS_OK to avoid throwing JS exceptions if mStyleSheet
|
|
|
|
// is not a nsIDOMStyleSheet
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsStyleLinkElement::SetEnableUpdates(bool aEnableUpdates)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mUpdatesEnabled = aEnableUpdates;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleLinkElement::GetCharset(nsAString& aCharset)
|
|
|
|
{
|
|
|
|
// descendants have to implement this themselves
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsStyleLinkElement::OverrideBaseURI(nsIURI* aNewBaseURI)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Base URI can't be overriden in this implementation "
|
|
|
|
"of nsIStyleSheetLinkingElement.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsStyleLinkElement::SetLineNumber(uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mLineNumber = aLineNumber;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t ToLinkMask(const nsAString& aLink)
|
2011-11-20 03:13:40 -08:00
|
|
|
{
|
|
|
|
if (aLink.EqualsLiteral("prefetch"))
|
|
|
|
return PREFETCH;
|
|
|
|
else if (aLink.EqualsLiteral("dns-prefetch"))
|
|
|
|
return DNS_PREFETCH;
|
|
|
|
else if (aLink.EqualsLiteral("stylesheet"))
|
|
|
|
return STYLESHEET;
|
|
|
|
else if (aLink.EqualsLiteral("next"))
|
|
|
|
return NEXT;
|
|
|
|
else if (aLink.EqualsLiteral("alternate"))
|
|
|
|
return ALTERNATE;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t linkMask = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString::const_iterator start, done;
|
|
|
|
aTypes.BeginReading(start);
|
|
|
|
aTypes.EndReading(done);
|
|
|
|
if (start == done)
|
2011-11-20 03:13:40 -08:00
|
|
|
return linkMask;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAString::const_iterator current(start);
|
2011-12-03 13:50:15 -08:00
|
|
|
bool inString = !nsContentUtils::IsHTMLWhitespace(*current);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString subString;
|
2011-11-20 03:13:40 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
while (current != done) {
|
2011-12-03 13:50:15 -08:00
|
|
|
if (nsContentUtils::IsHTMLWhitespace(*current)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (inString) {
|
2012-03-09 21:50:34 -08:00
|
|
|
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
|
2011-11-20 03:13:40 -08:00
|
|
|
linkMask |= ToLinkMask(subString);
|
2011-10-17 07:59:28 -07:00
|
|
|
inString = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!inString) {
|
|
|
|
start = current;
|
2011-10-17 07:59:28 -07:00
|
|
|
inString = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++current;
|
|
|
|
}
|
|
|
|
if (inString) {
|
2012-03-09 21:50:34 -08:00
|
|
|
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
|
|
|
|
linkMask |= ToLinkMask(subString);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-11-20 03:13:40 -08:00
|
|
|
return linkMask;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-04-20 15:59:18 -07:00
|
|
|
nsStyleLinkElement::UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aWillNotify,
|
|
|
|
bool* aIsAlternate)
|
2007-04-20 15:59:18 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return DoUpdateStyleSheet(nullptr, aObserver, aWillNotify, aIsAlternate,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2007-04-20 15:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStyleLinkElement::UpdateStyleSheetInternal(nsIDocument *aOldDocument,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aForceUpdate)
|
2007-04-20 15:59:18 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool notify, alternate;
|
2012-07-30 07:20:58 -07:00
|
|
|
return DoUpdateStyleSheet(aOldDocument, nullptr, ¬ify, &alternate,
|
2007-04-20 15:59:18 -07:00
|
|
|
aForceUpdate);
|
|
|
|
}
|
|
|
|
|
2013-01-08 15:25:47 -08:00
|
|
|
static bool
|
|
|
|
IsScopedStyleElement(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
// This is quicker than, say, QIing aContent to nsStyleLinkElement
|
|
|
|
// and then calling its virtual GetStyleSheetInfo method to find out
|
|
|
|
// if it is scoped.
|
|
|
|
return aContent->IsHTML(nsGkAtoms::style) &&
|
|
|
|
aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scoped);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetIsElementInStyleScopeFlagOnSubtree(Element* aElement)
|
|
|
|
{
|
|
|
|
if (aElement->IsElementInStyleScope()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->SetIsElementInStyleScope();
|
|
|
|
|
|
|
|
nsIContent* n = aElement->GetNextNode(aElement);
|
|
|
|
while (n) {
|
|
|
|
if (n->IsElementInStyleScope()) {
|
|
|
|
n = n->GetNextNonChildNode(aElement);
|
|
|
|
} else {
|
|
|
|
if (n->IsElement()) {
|
|
|
|
n->SetIsElementInStyleScope();
|
|
|
|
}
|
|
|
|
n = n->GetNextNode(aElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
HasScopedStyleSheetChild(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
for (nsIContent* n = aContent->GetFirstChild(); n; n = n->GetNextSibling()) {
|
|
|
|
if (IsScopedStyleElement(n)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when aElement has had a <style scoped> child removed.
|
|
|
|
static void
|
|
|
|
UpdateIsElementInStyleScopeFlagOnSubtree(Element* aElement)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aElement->IsElementInStyleScope(),
|
|
|
|
"only call UpdateIsElementInStyleScopeFlagOnSubtree on a "
|
|
|
|
"subtree that has IsElementInStyleScope boolean flag set");
|
|
|
|
|
|
|
|
if (HasScopedStyleSheetChild(aElement)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->ClearIsElementInStyleScope();
|
|
|
|
|
|
|
|
nsIContent* n = aElement->GetNextNode(aElement);
|
|
|
|
while (n) {
|
|
|
|
if (HasScopedStyleSheetChild(n)) {
|
|
|
|
n = n->GetNextNonChildNode(aElement);
|
|
|
|
} else {
|
|
|
|
if (n->IsElement()) {
|
|
|
|
n->ClearIsElementInStyleScope();
|
|
|
|
}
|
|
|
|
n = n->GetNextNode(aElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Element*
|
|
|
|
GetScopeElement(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsCSSStyleSheet> cssStyleSheet = do_QueryObject(aSheet);
|
|
|
|
if (!cssStyleSheet) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cssStyleSheet->GetScopeElement();
|
|
|
|
}
|
|
|
|
|
2007-04-20 15:59:18 -07:00
|
|
|
nsresult
|
|
|
|
nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument *aOldDocument,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aWillNotify,
|
|
|
|
bool* aIsAlternate,
|
|
|
|
bool aForceUpdate)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aWillNotify = false;
|
2007-04-20 15:59:18 -07:00
|
|
|
|
2013-01-08 15:25:47 -08:00
|
|
|
nsCOMPtr<nsIContent> thisContent;
|
|
|
|
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
|
|
|
|
|
|
Element* oldScopeElement = GetScopeElement(mStyleSheet);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mStyleSheet && aOldDocument) {
|
|
|
|
// We're removing the link element from the document, unload the
|
|
|
|
// stylesheet. We want to do this even if updates are disabled, since
|
|
|
|
// otherwise a sheet with a stale linking element pointer will be hanging
|
|
|
|
// around -- not good!
|
|
|
|
aOldDocument->BeginUpdate(UPDATE_STYLE);
|
|
|
|
aOldDocument->RemoveStyleSheet(mStyleSheet);
|
|
|
|
aOldDocument->EndUpdate(UPDATE_STYLE);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
2013-01-08 15:25:47 -08:00
|
|
|
if (oldScopeElement) {
|
|
|
|
UpdateIsElementInStyleScopeFlagOnSubtree(oldScopeElement);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-05 02:10:40 -08:00
|
|
|
NS_ENSURE_TRUE(thisContent, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// When static documents are created, stylesheets are cloned manually.
|
|
|
|
if (mDontLoadStyle || !mUpdatesEnabled ||
|
|
|
|
thisContent->OwnerDoc()->IsStaticDocument()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = thisContent->GetDocument();
|
|
|
|
|
2010-03-02 13:00:53 -08:00
|
|
|
if (!doc || !doc->CSSLoader()->GetEnabled()) {
|
2007-11-20 10:50:12 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isInline;
|
2009-07-28 09:07:31 -07:00
|
|
|
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!aForceUpdate && mStyleSheet && !isInline && uri) {
|
2010-05-17 21:00:40 -07:00
|
|
|
nsIURI* oldURI = mStyleSheet->GetSheetURI();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (oldURI) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool equal;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = oldURI->Equals(uri, &equal);
|
|
|
|
if (NS_SUCCEEDED(rv) && equal) {
|
|
|
|
return NS_OK; // We already loaded this stylesheet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mStyleSheet) {
|
|
|
|
doc->BeginUpdate(UPDATE_STYLE);
|
|
|
|
doc->RemoveStyleSheet(mStyleSheet);
|
|
|
|
doc->EndUpdate(UPDATE_STYLE);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!uri && !isInline) {
|
|
|
|
return NS_OK; // If href is empty and this is not inline style then just bail
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString title, type, media;
|
2013-01-08 15:25:47 -08:00
|
|
|
bool isScoped;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAlternate;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-08 15:25:47 -08:00
|
|
|
GetStyleSheetInfo(title, type, media, &isScoped, &isAlternate);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!type.LowerCaseEqualsLiteral("text/css")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 15:25:47 -08:00
|
|
|
Element* scopeElement = isScoped ? thisContent->GetParentElement() : nullptr;
|
|
|
|
if (scopeElement) {
|
|
|
|
NS_ASSERTION(isInline, "non-inline style must not have scope element");
|
|
|
|
SetIsElementInStyleScopeFlagOnSubtree(scopeElement);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doneLoading = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (isInline) {
|
2011-05-18 18:22:59 -07:00
|
|
|
nsAutoString text;
|
2011-10-17 07:59:28 -07:00
|
|
|
nsContentUtils::GetNodeTextContent(thisContent, false, text);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-18 18:22:59 -07:00
|
|
|
// Parse the style sheet.
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = doc->CSSLoader()->
|
2011-05-18 18:22:59 -07:00
|
|
|
LoadInlineStyle(thisContent, text, mLineNumber, title, media,
|
2013-01-08 15:25:47 -08:00
|
|
|
scopeElement, aObserver, &doneLoading, &isAlternate);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-09-26 15:03:16 -07:00
|
|
|
// XXXbz clone the URI here to work around content policies modifying URIs.
|
|
|
|
nsCOMPtr<nsIURI> clonedURI;
|
|
|
|
uri->Clone(getter_AddRefs(clonedURI));
|
|
|
|
NS_ENSURE_TRUE(clonedURI, NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = doc->CSSLoader()->
|
2012-08-28 10:10:07 -07:00
|
|
|
LoadStyleLink(thisContent, clonedURI, title, media, isAlternate,
|
|
|
|
GetCORSMode(), aObserver, &isAlternate);
|
2008-09-28 12:18:04 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Don't propagate LoadStyleLink() errors further than this, since some
|
|
|
|
// consumers (e.g. nsXMLContentSink) will completely abort on innocuous
|
|
|
|
// things like a stylesheet load being blocked by the security system.
|
2011-10-17 07:59:28 -07:00
|
|
|
doneLoading = true;
|
|
|
|
isAlternate = false;
|
2008-04-02 20:56:38 -07:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-20 15:59:18 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aWillNotify = !doneLoading;
|
|
|
|
*aIsAlternate = isAlternate;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-20 15:59:18 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-01-08 15:25:48 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped)
|
|
|
|
{
|
|
|
|
if (!mStyleSheet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsCSSStyleSheet> cssStyleSheet = do_QueryObject(mStyleSheet);
|
|
|
|
NS_ASSERTION(cssStyleSheet, "should only call UpdateStyleSheetScope for "
|
|
|
|
"an nsCSSStyleSheet");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> thisContent;
|
|
|
|
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
|
|
|
|
|
|
Element* oldScopeElement = cssStyleSheet->GetScopeElement();
|
|
|
|
Element* newScopeElement = aIsNowScoped ?
|
|
|
|
thisContent->GetParentElement() :
|
|
|
|
nullptr;
|
|
|
|
|
|
|
|
if (oldScopeElement == newScopeElement) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* document = thisContent->GetOwnerDocument();
|
|
|
|
|
|
|
|
document->BeginUpdate(UPDATE_STYLE);
|
|
|
|
document->RemoveStyleSheet(mStyleSheet);
|
|
|
|
|
|
|
|
cssStyleSheet->SetScopeElement(newScopeElement);
|
|
|
|
|
|
|
|
document->AddStyleSheet(mStyleSheet);
|
|
|
|
document->EndUpdate(UPDATE_STYLE);
|
|
|
|
|
|
|
|
if (oldScopeElement) {
|
|
|
|
UpdateIsElementInStyleScopeFlagOnSubtree(oldScopeElement);
|
|
|
|
}
|
|
|
|
if (newScopeElement) {
|
|
|
|
SetIsElementInStyleScopeFlagOnSubtree(newScopeElement);
|
|
|
|
}
|
|
|
|
}
|