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/. */
|
2007-08-06 19:27:19 +04:00
|
|
|
|
|
|
|
#include "nsStyledElement.h"
|
2017-04-01 05:54:41 +03:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2007-08-06 19:27:19 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsAttrValue.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2013-10-03 00:09:18 +04:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2018-02-09 19:17:10 +03:00
|
|
|
#include "mozilla/dom/MutationEventBinding.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2018-05-22 09:34:23 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2007-08-06 19:27:19 +04:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2009-04-09 00:52:37 +04:00
|
|
|
#include "nsDOMCSSAttrDeclaration.h"
|
2007-08-06 19:27:19 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIDocument.h"
|
2018-05-30 19:15:25 +03:00
|
|
|
#include "mozilla/DeclarationBlock.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
2010-08-06 01:59:36 +04:00
|
|
|
#include "nsXULElement.h"
|
2011-07-15 14:31:34 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-08-30 21:58:24 +04:00
|
|
|
#include "nsStyleUtil.h"
|
2007-08-06 19:27:19 +04:00
|
|
|
|
2013-11-19 23:49:52 +04:00
|
|
|
using namespace mozilla;
|
2012-11-15 02:10:08 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-03-11 05:48:57 +03:00
|
|
|
|
2017-08-17 00:31:40 +03:00
|
|
|
// Use the CC variant of this, even though this class does not define
|
|
|
|
// a new CC participant, to make QIing to the CC interfaces faster.
|
|
|
|
NS_IMPL_QUERY_INTERFACE_CYCLE_COLLECTION_INHERITED(nsStyledElement,
|
|
|
|
nsStyledElementBase,
|
|
|
|
nsStyledElement)
|
2016-08-02 21:05:38 +03:00
|
|
|
|
2007-08-06 19:27:19 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2016-08-02 21:05:38 +03:00
|
|
|
nsStyledElement::ParseAttribute(int32_t aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2016-08-02 21:05:38 +03:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2016-08-02 21:05:38 +03:00
|
|
|
nsAttrValue& aResult)
|
2007-08-06 19:27:19 +04:00
|
|
|
{
|
2014-05-30 11:36:53 +04:00
|
|
|
if (aAttribute == nsGkAtoms::style && aNamespaceID == kNameSpaceID_None) {
|
2017-11-02 23:36:14 +03:00
|
|
|
ParseStyleAttribute(aValue, aMaybeScriptedPrincipal, aResult, false);
|
2014-05-30 11:36:53 +04:00
|
|
|
return true;
|
2007-08-06 19:27:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsStyledElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2007-08-06 19:27:19 +04:00
|
|
|
}
|
|
|
|
|
2017-06-07 20:28:20 +03:00
|
|
|
nsresult
|
2017-10-03 01:05:19 +03:00
|
|
|
nsStyledElement::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 20:28:20 +03:00
|
|
|
const nsAttrValueOrString* aValue, bool aNotify)
|
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::style) {
|
|
|
|
if (aValue) {
|
|
|
|
SetMayHaveStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsStyledElementBase::BeforeSetAttr(aNamespaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
|
|
|
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
void
|
|
|
|
nsStyledElement::InlineStyleDeclarationWillChange(MutationClosureData& aData)
|
2007-08-06 19:27:19 +04:00
|
|
|
{
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
MOZ_ASSERT(OwnerDoc()->UpdateNestingLevel() > 0,
|
|
|
|
"Should be inside document update!");
|
2011-09-29 10:19:26 +04:00
|
|
|
bool modification = false;
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
if (MayHaveStyle()) {
|
|
|
|
bool needsOldValue =
|
|
|
|
!StaticPrefs::dom_mutation_events_cssom_disabled() &&
|
|
|
|
nsContentUtils::HasMutationListeners(this,
|
|
|
|
NS_EVENT_BITS_MUTATION_ATTRMODIFIED,
|
|
|
|
this);
|
|
|
|
|
|
|
|
if (!needsOldValue) {
|
|
|
|
CustomElementDefinition* definition = GetCustomElementDefinition();
|
|
|
|
if (definition && definition->IsInObservedAttributeList(nsGkAtoms::style)) {
|
|
|
|
needsOldValue = true;
|
|
|
|
}
|
|
|
|
}
|
2007-08-06 19:27:19 +04:00
|
|
|
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
if (needsOldValue) {
|
|
|
|
nsAutoString oldValueStr;
|
|
|
|
modification = GetAttr(kNameSpaceID_None, nsGkAtoms::style,
|
|
|
|
oldValueStr);
|
|
|
|
if (modification) {
|
|
|
|
aData.mOldValue.emplace();
|
|
|
|
aData.mOldValue->SetTo(oldValueStr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
modification = HasAttr(kNameSpaceID_None, nsGkAtoms::style);
|
2012-02-14 06:00:56 +04:00
|
|
|
}
|
2007-08-06 19:27:19 +04:00
|
|
|
}
|
|
|
|
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
aData.mModType = modification ?
|
2018-06-26 00:20:54 +03:00
|
|
|
static_cast<uint8_t>(MutationEvent_Binding::MODIFICATION) :
|
|
|
|
static_cast<uint8_t>(MutationEvent_Binding::ADDITION);
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
nsNodeUtils::AttributeWillChange(this, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::style,
|
|
|
|
aData.mModType, nullptr);
|
|
|
|
|
|
|
|
//XXXsmaug In order to make attribute handling more consistent, consider to
|
|
|
|
// call BeforeSetAttr and pass kCallAfterSetAttr to
|
|
|
|
// SetAttrAndNotify in SetInlineStyleDeclaration.
|
|
|
|
// Handling of mozAutoDocUpdate may require changes in that case.
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStyledElement::SetInlineStyleDeclaration(DeclarationBlock& aDeclaration,
|
|
|
|
MutationClosureData& aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OwnerDoc()->UpdateNestingLevel(),
|
|
|
|
"Should be inside document update!");
|
|
|
|
|
|
|
|
bool hasListeners =
|
|
|
|
!StaticPrefs::dom_mutation_events_cssom_disabled() &&
|
|
|
|
nsContentUtils::HasMutationListeners(this,
|
|
|
|
NS_EVENT_BITS_MUTATION_ATTRMODIFIED,
|
|
|
|
this);
|
|
|
|
|
|
|
|
nsAttrValue attrValue(do_AddRef(&aDeclaration), nullptr);
|
|
|
|
SetMayHaveStyle();
|
2010-02-24 07:37:47 +03:00
|
|
|
|
2017-04-01 05:54:41 +03:00
|
|
|
nsIDocument* document = GetComposedDoc();
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
mozAutoDocUpdate updateBatch(document, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nullptr,
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
aData.mOldValue.isSome() ?
|
|
|
|
aData.mOldValue.ptr() : nullptr,
|
|
|
|
attrValue, nullptr, aData.mModType,
|
|
|
|
hasListeners, true, kDontCallAfterSetAttr,
|
2017-05-19 00:09:01 +03:00
|
|
|
document, updateBatch);
|
2007-08-06 19:27:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// Others and helpers
|
|
|
|
|
2012-11-11 03:30:15 +04:00
|
|
|
nsICSSDeclaration*
|
2016-08-02 21:05:38 +03:00
|
|
|
nsStyledElement::Style()
|
2007-08-06 19:27:19 +04:00
|
|
|
{
|
2012-11-15 02:10:08 +04:00
|
|
|
Element::nsDOMSlots *slots = DOMSlots();
|
2007-08-06 19:27:19 +04:00
|
|
|
|
|
|
|
if (!slots->mStyle) {
|
|
|
|
// Just in case...
|
2017-03-25 01:28:19 +03:00
|
|
|
ReparseStyleAttribute(true, false);
|
2007-08-06 19:27:19 +04:00
|
|
|
|
2011-11-05 14:32:52 +04:00
|
|
|
slots->mStyle = new nsDOMCSSAttributeDeclaration(this, false);
|
2011-04-08 06:29:50 +04:00
|
|
|
SetMayHaveStyle();
|
2007-08-06 19:27:19 +04:00
|
|
|
}
|
|
|
|
|
2010-08-06 01:59:36 +04:00
|
|
|
return slots->mStyle;
|
2007-08-06 19:27:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-03-25 01:28:19 +03:00
|
|
|
nsStyledElement::ReparseStyleAttribute(bool aForceInDataDoc, bool aForceIfAlreadyParsed)
|
2007-08-06 19:27:19 +04:00
|
|
|
{
|
2011-04-08 06:29:50 +04:00
|
|
|
if (!MayHaveStyle()) {
|
2007-09-18 12:38:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-08-06 19:27:19 +04:00
|
|
|
const nsAttrValue* oldVal = mAttrsAndChildren.GetAttr(nsGkAtoms::style);
|
2017-03-25 01:28:19 +03:00
|
|
|
if (oldVal && (aForceIfAlreadyParsed || oldVal->Type() != nsAttrValue::eCSSDeclaration)) {
|
2007-08-06 19:27:19 +04:00
|
|
|
nsAttrValue attrValue;
|
|
|
|
nsAutoString stringValue;
|
|
|
|
oldVal->ToString(stringValue);
|
2017-11-02 23:36:14 +03:00
|
|
|
ParseStyleAttribute(stringValue, nullptr, attrValue, aForceInDataDoc);
|
2015-11-09 10:57:16 +03:00
|
|
|
// Don't bother going through SetInlineStyleDeclaration; we don't
|
|
|
|
// want to fire off mutation events or document notifications anyway
|
2017-05-19 00:09:01 +03:00
|
|
|
bool oldValueSet;
|
|
|
|
nsresult rv = mAttrsAndChildren.SetAndSwapAttr(nsGkAtoms::style, attrValue,
|
|
|
|
&oldValueSet);
|
2007-08-06 19:27:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2007-08-06 19:27:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-25 01:28:19 +03:00
|
|
|
void
|
|
|
|
nsStyledElement::NodeInfoChanged(nsIDocument* aOldDoc)
|
|
|
|
{
|
|
|
|
nsStyledElementBase::NodeInfoChanged(aOldDoc);
|
|
|
|
}
|
|
|
|
|
2016-08-08 13:29:11 +03:00
|
|
|
nsICSSDeclaration*
|
|
|
|
nsStyledElement::GetExistingStyle()
|
|
|
|
{
|
|
|
|
Element::nsDOMSlots* slots = GetExistingDOMSlots();
|
|
|
|
if (!slots) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return slots->mStyle;
|
|
|
|
}
|
|
|
|
|
2007-08-06 19:27:19 +04:00
|
|
|
void
|
2016-08-02 21:05:38 +03:00
|
|
|
nsStyledElement::ParseStyleAttribute(const nsAString& aValue,
|
2017-11-02 23:36:14 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2016-08-02 21:05:38 +03:00
|
|
|
nsAttrValue& aResult,
|
|
|
|
bool aForceInDataDoc)
|
2007-08-06 19:27:19 +04:00
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
2015-08-21 19:09:06 +03:00
|
|
|
bool isNativeAnon = IsInNativeAnonymousSubtree();
|
2007-08-06 19:27:19 +04:00
|
|
|
|
2015-08-21 19:09:06 +03:00
|
|
|
if (!isNativeAnon &&
|
|
|
|
!nsStyleUtil::CSPAllowsInlineStyle(nullptr, NodePrincipal(),
|
2017-11-05 23:19:34 +03:00
|
|
|
aMaybeScriptedPrincipal,
|
2018-07-05 09:21:04 +03:00
|
|
|
doc->GetDocumentURI(), 0, 0, aValue,
|
2012-08-30 21:58:24 +04:00
|
|
|
nullptr))
|
|
|
|
return;
|
|
|
|
|
2011-10-18 15:19:44 +04:00
|
|
|
if (aForceInDataDoc ||
|
|
|
|
!doc->IsLoadedAsData() ||
|
2016-08-08 13:29:11 +03:00
|
|
|
GetExistingStyle() ||
|
2011-10-18 15:19:44 +04:00
|
|
|
doc->IsStaticDocument()) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isCSS = true; // assume CSS until proven otherwise
|
2007-08-06 19:27:19 +04:00
|
|
|
|
2015-08-21 19:09:06 +03:00
|
|
|
if (!isNativeAnon) { // native anonymous content always assumes CSS
|
2007-08-06 19:27:19 +04:00
|
|
|
nsAutoString styleType;
|
|
|
|
doc->GetHeaderData(nsGkAtoms::headerContentStyleType, styleType);
|
|
|
|
if (!styleType.IsEmpty()) {
|
|
|
|
static const char textCssStr[] = "text/css";
|
|
|
|
isCSS = (styleType.EqualsIgnoreCase(textCssStr, sizeof(textCssStr) - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 23:36:14 +03:00
|
|
|
if (isCSS && aResult.ParseStyleAttribute(aValue, aMaybeScriptedPrincipal,
|
|
|
|
this)) {
|
2012-09-30 20:40:24 +04:00
|
|
|
return;
|
2007-08-06 19:27:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.SetTo(aValue);
|
|
|
|
}
|