Remove Document::elementSheet()
https://bugs.webkit.org/show_bug.cgi?id=162876
Reviewed by Andreas Kling.
This is a Document owned stylesheet that exists as a context for parsing element inline style.
It never contains any rules and is generally confusing.
This patch removes the requirement for a stylesheet to be present for CSSParser to operate in
the correct context. Inline style is now parsed without stylesheet and a context object is
passed instead.
* bindings/js/JSCSSStyleDeclarationCustom.cpp:
(WebCore::root):
* bindings/js/JSCSSStyleDeclarationCustom.h:
(WebCore::root): Deleted.
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::PropertySetCSSStyleDeclaration::setCssText):
(WebCore::PropertySetCSSStyleDeclaration::setProperty):
(WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
(WebCore::PropertySetCSSStyleDeclaration::cssParserContext):
(WebCore::StyleRuleCSSStyleDeclaration::parentStyleSheet):
(WebCore::StyleRuleCSSStyleDeclaration::cssParserContext):
(WebCore::InlineCSSStyleDeclaration::parentStyleSheet):
(WebCore::InlineCSSStyleDeclaration::cssParserContext):
* css/PropertySetCSSStyleDeclaration.h:
(WebCore::PropertySetCSSStyleDeclaration::didMutate): Deleted.
* css/StyleProperties.cpp:
(WebCore::MutableStyleProperties::setProperty):
(WebCore::MutableStyleProperties::setCustomProperty):
(WebCore::MutableStyleProperties::parseDeclaration):
* css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseCustomPropertyValue):
(WebCore::CSSParser::parseInlineStyleDeclaration):
* css/parser/CSSParser.h:
* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::parseInlineStyleDeclaration):
* dom/Document.cpp:
(WebCore::Document::~Document):
(WebCore::Document::updateBaseURL):
(WebCore::Document::usesStyleBasedEditability):
(WebCore::Document::setHasElementUsingStyleBasedEditability):
(WebCore::Document::elementSheet): Deleted.
* dom/Document.h:
* dom/StyledElement.cpp:
(WebCore::StyledElement::setInlineStyleFromString):
(WebCore::StyledElement::invalidateStyleAttribute):
The usesStyleBasedEditability bit used to be set via the elementSheet. Instead check for it after inline style mutations.
(WebCore::StyledElement::setInlineStyleProperty):
(WebCore::StyledElement::addPropertyToPresentationAttributeStyle):
* dom/StyledElement.h:
(WebCore::StyledElement::invalidateStyleAttribute): Deleted.
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges):
* svg/SVGAnimateElementBase.cpp:
(WebCore::applyCSSPropertyToTarget):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@206753 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 34b9427..8cb28dc 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,65 @@
+2016-10-03 Antti Koivisto <antti@apple.com>
+
+ Remove Document::elementSheet()
+ https://bugs.webkit.org/show_bug.cgi?id=162876
+
+ Reviewed by Andreas Kling.
+
+ This is a Document owned stylesheet that exists as a context for parsing element inline style.
+ It never contains any rules and is generally confusing.
+
+ This patch removes the requirement for a stylesheet to be present for CSSParser to operate in
+ the correct context. Inline style is now parsed without stylesheet and a context object is
+ passed instead.
+
+ * bindings/js/JSCSSStyleDeclarationCustom.cpp:
+ (WebCore::root):
+ * bindings/js/JSCSSStyleDeclarationCustom.h:
+ (WebCore::root): Deleted.
+ * css/PropertySetCSSStyleDeclaration.cpp:
+ (WebCore::PropertySetCSSStyleDeclaration::setCssText):
+ (WebCore::PropertySetCSSStyleDeclaration::setProperty):
+ (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
+ (WebCore::PropertySetCSSStyleDeclaration::cssParserContext):
+ (WebCore::StyleRuleCSSStyleDeclaration::parentStyleSheet):
+ (WebCore::StyleRuleCSSStyleDeclaration::cssParserContext):
+ (WebCore::InlineCSSStyleDeclaration::parentStyleSheet):
+ (WebCore::InlineCSSStyleDeclaration::cssParserContext):
+ * css/PropertySetCSSStyleDeclaration.h:
+ (WebCore::PropertySetCSSStyleDeclaration::didMutate): Deleted.
+ * css/StyleProperties.cpp:
+ (WebCore::MutableStyleProperties::setProperty):
+ (WebCore::MutableStyleProperties::setCustomProperty):
+ (WebCore::MutableStyleProperties::parseDeclaration):
+ * css/parser/CSSParser.cpp:
+ (WebCore::CSSParser::parseValue):
+ (WebCore::CSSParser::parseCustomPropertyValue):
+ (WebCore::CSSParser::parseInlineStyleDeclaration):
+ * css/parser/CSSParser.h:
+ * css/parser/CSSParserImpl.cpp:
+ (WebCore::CSSParserImpl::parseInlineStyleDeclaration):
+ * dom/Document.cpp:
+ (WebCore::Document::~Document):
+ (WebCore::Document::updateBaseURL):
+ (WebCore::Document::usesStyleBasedEditability):
+ (WebCore::Document::setHasElementUsingStyleBasedEditability):
+ (WebCore::Document::elementSheet): Deleted.
+ * dom/Document.h:
+ * dom/StyledElement.cpp:
+ (WebCore::StyledElement::setInlineStyleFromString):
+ (WebCore::StyledElement::invalidateStyleAttribute):
+
+ The usesStyleBasedEditability bit used to be set via the elementSheet. Instead check for it after inline style mutations.
+
+ (WebCore::StyledElement::setInlineStyleProperty):
+ (WebCore::StyledElement::addPropertyToPresentationAttributeStyle):
+ * dom/StyledElement.h:
+ (WebCore::StyledElement::invalidateStyleAttribute): Deleted.
+ * inspector/InspectorStyleSheet.cpp:
+ (WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges):
+ * svg/SVGAnimateElementBase.cpp:
+ (WebCore::applyCSSPropertyToTarget):
+
2016-10-03 Brent Fulgham <bfulgham@apple.com>
Avoid null dereference when changing focus in design mode.
diff --git a/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
index 039eccf..4b7e32b 100644
--- a/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
+++ b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
@@ -29,10 +29,15 @@
#include "CSSParser.h"
#include "CSSPrimitiveValue.h"
#include "CSSPropertyNames.h"
+#include "CSSRule.h"
+#include "CSSStyleDeclaration.h"
+#include "CSSStyleSheet.h"
#include "CSSValue.h"
#include "HashTools.h"
+#include "JSCSSStyleDeclaration.h"
#include "JSCSSValue.h"
#include "JSNode.h"
+#include "JSStyleSheetCustom.h"
#include "RuntimeEnabledFeatures.h"
#include "Settings.h"
#include "StyleProperties.h"
@@ -48,6 +53,17 @@
namespace WebCore {
+void* root(CSSStyleDeclaration* style)
+{
+ if (auto* parentRule = style->parentRule())
+ return root(parentRule);
+ if (auto* styleSheet = style->parentStyleSheet())
+ return root(styleSheet);
+ if (auto* parentElement = style->parentElement())
+ return root(parentElement);
+ return style;
+}
+
void JSCSSStyleDeclaration::visitAdditionalChildren(SlotVisitor& visitor)
{
visitor.addOpaqueRoot(root(&wrapped()));
diff --git a/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h
index 6ed1fec..672f06a 100644
--- a/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h
+++ b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h
@@ -26,22 +26,11 @@
#ifndef JSCSSStyleDeclarationCustom_h
#define JSCSSStyleDeclarationCustom_h
-#include "CSSRule.h"
-#include "CSSStyleDeclaration.h"
-#include "CSSStyleSheet.h"
-#include "JSCSSStyleDeclaration.h"
-#include "JSStyleSheetCustom.h"
-
namespace WebCore {
-inline void* root(CSSStyleDeclaration* style)
-{
- if (CSSRule* parentRule = style->parentRule())
- return root(parentRule);
- if (CSSStyleSheet* styleSheet = style->parentStyleSheet())
- return root(styleSheet);
- return style;
-}
+class CSSStyleDeclaration;
+
+void* root(CSSStyleDeclaration*);
}
diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
index 354da15..99fc5dd 100644
--- a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
+++ b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
@@ -31,6 +31,7 @@
#include "MutationObserverInterestGroup.h"
#include "MutationRecord.h"
#include "StyleProperties.h"
+#include "StyleSheetContents.h"
#include "StyledElement.h"
namespace WebCore {
@@ -153,7 +154,7 @@
if (!willMutate())
return;
- bool changed = m_propertySet->parseDeclaration(text, contextStyleSheet());
+ bool changed = m_propertySet->parseDeclaration(text, cssParserContext(), contextStyleSheet());
didMutate(changed ? PropertyChanged : NoChanges);
@@ -231,7 +232,12 @@
return;
ec = 0;
- bool changed = propertyID != CSSPropertyCustom ? m_propertySet->setProperty(propertyID, value, important, contextStyleSheet()) : m_propertySet->setCustomProperty(propertyName, value, important, contextStyleSheet());
+
+ bool changed;
+ if (propertyID == CSSPropertyCustom)
+ changed = m_propertySet->setCustomProperty(propertyName, value, important, cssParserContext(), contextStyleSheet());
+ else
+ changed = m_propertySet->setProperty(propertyID, value, important, cssParserContext(), contextStyleSheet());
didMutate(changed ? PropertyChanged : NoChanges);
@@ -290,7 +296,7 @@
return false;
ec = 0;
- bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
+ bool changed = m_propertySet->setProperty(propertyID, value, important, cssParserContext(), contextStyleSheet());
didMutate(changed ? PropertyChanged : NoChanges);
@@ -321,6 +327,11 @@
return cssStyleSheet ? &cssStyleSheet->contents() : 0;
}
+CSSParserContext PropertySetCSSStyleDeclaration::cssParserContext() const
+{
+ return CSSParserContext(m_propertySet->cssParserMode());
+}
+
Ref<MutableStyleProperties> PropertySetCSSStyleDeclaration::copyProperties() const
{
return m_propertySet->mutableCopy();
@@ -373,7 +384,16 @@
CSSStyleSheet* StyleRuleCSSStyleDeclaration::parentStyleSheet() const
{
- return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
+ return m_parentRule ? m_parentRule->parentStyleSheet() : nullptr;
+}
+
+CSSParserContext StyleRuleCSSStyleDeclaration::cssParserContext() const
+{
+ auto* styleSheet = contextStyleSheet();
+ if (!styleSheet)
+ return PropertySetCSSStyleDeclaration::cssParserContext();
+
+ return styleSheet->parserContext();
}
void StyleRuleCSSStyleDeclaration::reattach(MutableStyleProperties& propertySet)
@@ -399,7 +419,17 @@
CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const
{
- return m_parentElement ? &m_parentElement->document().elementSheet() : 0;
+ return nullptr;
+}
+
+CSSParserContext InlineCSSStyleDeclaration::cssParserContext() const
+{
+ if (!m_parentElement)
+ return PropertySetCSSStyleDeclaration::cssParserContext();
+
+ CSSParserContext context(m_parentElement->document());
+ context.mode = m_propertySet->cssParserMode();
+ return context;
}
} // namespace WebCore
diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.h b/Source/WebCore/css/PropertySetCSSStyleDeclaration.h
index 732edbc..875e98d 100644
--- a/Source/WebCore/css/PropertySetCSSStyleDeclaration.h
+++ b/Source/WebCore/css/PropertySetCSSStyleDeclaration.h
@@ -26,6 +26,7 @@
#ifndef PropertySetCSSStyleDeclaration_h
#define PropertySetCSSStyleDeclaration_h
+#include "CSSParserMode.h"
#include "CSSStyleDeclaration.h"
#include <memory>
#include <wtf/HashMap.h>
@@ -75,6 +76,7 @@
enum MutationType { NoChanges, PropertyChanged };
virtual bool willMutate() WARN_UNUSED_RETURN { return true; }
virtual void didMutate(MutationType) { }
+ virtual CSSParserContext cssParserContext() const;
MutableStyleProperties* m_propertySet;
std::unique_ptr<HashMap<CSSValue*, RefPtr<CSSValue>>> m_cssomCSSValueClones;
@@ -105,6 +107,7 @@
bool willMutate() final WARN_UNUSED_RETURN;
void didMutate(MutationType) final;
+ CSSParserContext cssParserContext() const final;
unsigned m_refCount;
CSSRule* m_parentRule;
@@ -125,6 +128,7 @@
void clearParentElement() final { m_parentElement = 0; }
void didMutate(MutationType) final;
+ CSSParserContext cssParserContext() const final;
StyledElement* m_parentElement;
};
diff --git a/Source/WebCore/css/StyleProperties.cpp b/Source/WebCore/css/StyleProperties.cpp
index ecdf8f8..6dd4c5a 100644
--- a/Source/WebCore/css/StyleProperties.cpp
+++ b/Source/WebCore/css/StyleProperties.cpp
@@ -725,28 +725,37 @@
return propertyAt(foundPropertyIndex).isImplicit();
}
-bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& value, bool important, StyleSheetContents* contextStyleSheet)
+bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& value, bool important, CSSParserContext parserContext, StyleSheetContents* contextStyleSheet)
{
// Setting the value to an empty string just removes the property in both IE and Gecko.
// Setting it to null seems to produce less consistent results, but we treat it just the same.
if (value.isEmpty())
return removeProperty(propertyID);
+ parserContext.mode = cssParserMode();
+
// When replacing an existing property value, this moves the property to the end of the list.
// Firefox preserves the position, and MSIE moves the property to the beginning.
- return CSSParser::parseValue(*this, propertyID, value, important, cssParserMode(), contextStyleSheet) == CSSParser::ParseResult::Changed;
+ return CSSParser::parseValue(*this, propertyID, value, important, parserContext, contextStyleSheet) == CSSParser::ParseResult::Changed;
}
-bool MutableStyleProperties::setCustomProperty(const String& propertyName, const String& value, bool important, StyleSheetContents* contextStyleSheet)
+bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& value, bool important)
+{
+ CSSParserContext parserContext(cssParserMode());
+ return setProperty(propertyID, value, important, parserContext);
+}
+
+bool MutableStyleProperties::setCustomProperty(const String& propertyName, const String& value, bool important, CSSParserContext parserContext, StyleSheetContents* contextStyleSheet)
{
// Setting the value to an empty string just removes the property in both IE and Gecko.
// Setting it to null seems to produce less consistent results, but we treat it just the same.
if (value.isEmpty())
return removeCustomProperty(propertyName);
+ parserContext.mode = cssParserMode();
// When replacing an existing property value, this moves the property to the end of the list.
// Firefox preserves the position, and MSIE moves the property to the beginning.
- return CSSParser::parseCustomPropertyValue(*this, propertyName, value, important, cssParserMode(), contextStyleSheet) == CSSParser::ParseResult::Changed;
+ return CSSParser::parseCustomPropertyValue(*this, propertyName, value, important, parserContext, contextStyleSheet) == CSSParser::ParseResult::Changed;
}
void MutableStyleProperties::setProperty(CSSPropertyID propertyID, RefPtr<CSSValue>&& value, bool important)
@@ -798,16 +807,13 @@
return setProperty(CSSProperty(propertyID, CSSValuePool::singleton().createIdentifierValue(identifier), important));
}
-bool MutableStyleProperties::parseDeclaration(const String& styleDeclaration, StyleSheetContents* contextStyleSheet)
+bool MutableStyleProperties::parseDeclaration(const String& styleDeclaration, CSSParserContext context, StyleSheetContents* contextStyleSheet)
{
auto oldProperties = WTFMove(m_propertyVector);
m_propertyVector.clear();
- CSSParserContext context(cssParserMode());
- if (contextStyleSheet) {
- context = contextStyleSheet->parserContext();
- context.mode = cssParserMode();
- }
+ context.mode = cssParserMode();
+
CSSParser parser(context);
parser.parseDeclaration(*this, styleDeclaration, 0, contextStyleSheet);
diff --git a/Source/WebCore/css/StyleProperties.h b/Source/WebCore/css/StyleProperties.h
index 44be582..95066ba 100644
--- a/Source/WebCore/css/StyleProperties.h
+++ b/Source/WebCore/css/StyleProperties.h
@@ -199,7 +199,8 @@
bool addParsedProperty(const CSSProperty&);
// These expand shorthand properties into multiple properties.
- bool setProperty(CSSPropertyID, const String& value, bool important = false, StyleSheetContents* contextStyleSheet = 0);
+ bool setProperty(CSSPropertyID, const String& value, bool important, CSSParserContext, StyleSheetContents* = nullptr);
+ bool setProperty(CSSPropertyID, const String& value, bool important = false);
void setProperty(CSSPropertyID, RefPtr<CSSValue>&&, bool important = false);
// These do not. FIXME: This is too messy, we can do better.
@@ -214,7 +215,7 @@
void mergeAndOverrideOnConflict(const StyleProperties&);
void clear();
- bool parseDeclaration(const String& styleDeclaration, StyleSheetContents* contextStyleSheet);
+ bool parseDeclaration(const String& styleDeclaration, CSSParserContext, StyleSheetContents* = nullptr);
WEBCORE_EXPORT CSSStyleDeclaration* ensureCSSStyleDeclaration();
CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(StyledElement* parentElement);
@@ -225,7 +226,7 @@
Vector<CSSProperty, 4> m_propertyVector;
// Methods for querying and altering CSS custom properties.
- bool setCustomProperty(const String& propertyName, const String& value, bool important = false, StyleSheetContents* contextStyleSheet = 0);
+ bool setCustomProperty(const String& propertyName, const String& value, bool important, CSSParserContext, StyleSheetContents* = nullptr);
bool removeCustomProperty(const String& propertyName, String* returnText = nullptr);
private:
diff --git a/Source/WebCore/css/parser/CSSParser.cpp b/Source/WebCore/css/parser/CSSParser.cpp
index 52c11cd..bfc498f 100644
--- a/Source/WebCore/css/parser/CSSParser.cpp
+++ b/Source/WebCore/css/parser/CSSParser.cpp
@@ -1312,23 +1312,17 @@
return WTFMove(valueList);
}
-CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
+CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context, StyleSheetContents* contextStyleSheet)
{
ASSERT(!string.isEmpty());
- CSSParser::ParseResult result = parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode);
+ CSSParser::ParseResult result = parseSimpleLengthValue(declaration, propertyID, string, important, context.mode);
if (result != ParseResult::Error)
return result;
- result = parseColorValue(declaration, propertyID, string, important, cssParserMode);
+ result = parseColorValue(declaration, propertyID, string, important, context.mode);
if (result != ParseResult::Error)
return result;
- CSSParserContext context(cssParserMode);
- if (contextStyleSheet) {
- context = contextStyleSheet->parserContext();
- context.mode = cssParserMode;
- }
-
result = parseKeywordValue(declaration, propertyID, string, important, context, contextStyleSheet);
if (result != ParseResult::Error)
return result;
@@ -1341,14 +1335,8 @@
return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
}
-CSSParser::ParseResult CSSParser::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomicString& propertyName, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
+CSSParser::ParseResult CSSParser::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomicString& propertyName, const String& string, bool important, const CSSParserContext& context, StyleSheetContents* contextStyleSheet)
{
- CSSParserContext context(cssParserMode);
- if (contextStyleSheet) {
- context = contextStyleSheet->parserContext();
- context.mode = cssParserMode;
- }
-
CSSParser parser(context);
parser.setCustomPropertyName(propertyName);
return parser.parseValue(declaration, CSSPropertyCustom, string, important, contextStyleSheet);
@@ -1447,9 +1435,9 @@
Ref<ImmutableStyleProperties> CSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
{
- CSSParserContext context = element->document().elementSheet().contents().parserContext();
+ CSSParserContext context(element->document());
context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document().inQuirksMode());
- return CSSParser(context).parseDeclaration(string, &element->document().elementSheet().contents());
+ return CSSParser(context).parseDeclaration(string, nullptr);
}
Ref<ImmutableStyleProperties> CSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
diff --git a/Source/WebCore/css/parser/CSSParser.h b/Source/WebCore/css/parser/CSSParser.h
index 911aa82..d2c8803 100644
--- a/Source/WebCore/css/parser/CSSParser.h
+++ b/Source/WebCore/css/parser/CSSParser.h
@@ -131,8 +131,8 @@
RefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const String&);
bool parseSupportsCondition(const String&);
- static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, CSSParserMode, StyleSheetContents*);
- static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, CSSParserMode, StyleSheetContents* contextStyleSheet);
+ static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&, StyleSheetContents*);
+ static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&, StyleSheetContents* contextStyleSheet);
static bool parseColor(RGBA32& color, const String&, bool strict = false);
static bool isValidSystemColorValue(CSSValueID);
diff --git a/Source/WebCore/css/parser/CSSParserImpl.cpp b/Source/WebCore/css/parser/CSSParserImpl.cpp
index 445ae92..15574b9 100644
--- a/Source/WebCore/css/parser/CSSParserImpl.cpp
+++ b/Source/WebCore/css/parser/CSSParserImpl.cpp
@@ -135,14 +135,13 @@
Ref<ImmutableStyleProperties> CSSParserImpl::parseInlineStyleDeclaration(const String& string, Element* element)
{
- Document& document = element->document();
- CSSParserContext context = CSSParserContext(document.elementSheet().contents().parserContext());
- CSSParserMode mode = element->isHTMLElement() && !document.inQuirksMode() ? HTMLStandardMode : HTMLQuirksMode;
- context.mode = mode;
- CSSParserImpl parser(context, &document.elementSheet().contents());
+ CSSParserContext context(element->document());
+ context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document().inQuirksMode());
+
+ CSSParserImpl parser(context);
CSSTokenizer::Scope scope(string);
parser.consumeDeclarationList(scope.tokenRange(), StyleRule::Style);
- return createStyleProperties(parser.m_parsedProperties, mode);
+ return createStyleProperties(parser.m_parsedProperties, context.mode);
}
bool CSSParserImpl::parseDeclarationList(MutableStyleProperties* declaration, const String& string, const CSSParserContext& context)
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index 464eb38..19fc924 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -629,8 +629,6 @@
if (m_styleSheetList)
m_styleSheetList->detachFromDocument();
- if (m_elementSheet)
- m_elementSheet->detachFromDocument();
extensionStyleSheets().detachFromDocument();
clearStyleResolver(); // We need to destroy CSSFontSelector before destroying m_cachedResourceLoader.
@@ -2963,16 +2961,6 @@
if (!m_baseURL.isValid())
m_baseURL = URL();
- if (m_elementSheet) {
- // Element sheet is silly. It never contains anything.
- ASSERT(!m_elementSheet->contents().ruleCount());
- bool usesStyleBasedEditability = m_elementSheet->contents().usesStyleBasedEditability();
- m_elementSheet = CSSStyleSheet::createInline(*this, m_baseURL);
- // FIXME: So we are not really the parser. The right fix is to eliminate the element sheet completely.
- if (usesStyleBasedEditability)
- m_elementSheet->contents().parserSetUsesStyleBasedEditability();
- }
-
if (!equalIgnoringFragmentIdentifier(oldBaseURL, m_baseURL)) {
// Base URL change changes any relative visited links.
// FIXME: There are other URLs in the tree that would need to be re-evaluated on dynamic base URL change. Style should be invalidated too.
@@ -3158,16 +3146,9 @@
view()->scrollToFragment(m_url);
}
-CSSStyleSheet& Document::elementSheet()
-{
- if (!m_elementSheet)
- m_elementSheet = CSSStyleSheet::createInline(*this, m_baseURL);
- return *m_elementSheet;
-}
-
bool Document::usesStyleBasedEditability() const
{
- if (m_elementSheet && m_elementSheet->contents().usesStyleBasedEditability())
+ if (m_hasElementUsingStyleBasedEditability)
return true;
ASSERT(!m_renderView || !m_renderView->frameView().isPainting());
@@ -3178,6 +3159,11 @@
return authorSheets.usesStyleBasedEditability();
}
+void Document::setHasElementUsingStyleBasedEditability()
+{
+ m_hasElementUsingStyleBasedEditability = true;
+}
+
void Document::processHttpEquiv(const String& equiv, const String& content, bool isInDocumentHead)
{
ASSERT(!equiv.isNull());
diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h
index 570317b..c235322 100644
--- a/Source/WebCore/dom/Document.h
+++ b/Source/WebCore/dom/Document.h
@@ -648,8 +648,8 @@
bool canNavigate(Frame* targetFrame);
Frame* findUnsafeParentScrollPropagationBoundary();
- CSSStyleSheet& elementSheet();
bool usesStyleBasedEditability() const;
+ void setHasElementUsingStyleBasedEditability();
virtual Ref<DocumentParser> createParser();
DocumentParser* parser() const { return m_parser.get(); }
@@ -1446,7 +1446,7 @@
std::unique_ptr<DOMImplementation> m_implementation;
- RefPtr<CSSStyleSheet> m_elementSheet;
+ bool m_hasElementUsingStyleBasedEditability { false };
bool m_printing;
bool m_paginatedForScreen;
diff --git a/Source/WebCore/dom/StyledElement.cpp b/Source/WebCore/dom/StyledElement.cpp
index f75ef36..22deba1 100644
--- a/Source/WebCore/dom/StyledElement.cpp
+++ b/Source/WebCore/dom/StyledElement.cpp
@@ -174,7 +174,12 @@
return cssomWrapper;
}
-inline void StyledElement::setInlineStyleFromString(const AtomicString& newStyleString)
+static bool usesStyleBasedEditability(const StyleProperties& properties)
+{
+ return properties.getPropertyCSSValue(CSSPropertyWebkitUserModify);
+}
+
+void StyledElement::setInlineStyleFromString(const AtomicString& newStyleString)
{
RefPtr<StyleProperties>& inlineStyle = elementData()->m_inlineStyle;
@@ -190,7 +195,10 @@
if (!inlineStyle)
inlineStyle = CSSParser::parseInlineStyleDeclaration(newStyleString, this);
else
- downcast<MutableStyleProperties>(*inlineStyle).parseDeclaration(newStyleString, &document().elementSheet().contents());
+ downcast<MutableStyleProperties>(*inlineStyle).parseDeclaration(newStyleString, document());
+
+ if (usesStyleBasedEditability(*inlineStyle))
+ document().setHasElementUsingStyleBasedEditability();
}
void StyledElement::styleAttributeChanged(const AtomicString& newStyleString, AttributeModificationReason reason)
@@ -212,6 +220,15 @@
InspectorInstrumentation::didInvalidateStyleAttr(document(), *this);
}
+void StyledElement::invalidateStyleAttribute()
+{
+ if (usesStyleBasedEditability(*inlineStyle()))
+ document().setHasElementUsingStyleBasedEditability();
+
+ elementData()->setStyleAttributeIsDirty(true);
+ setNeedsStyleRecalc(InlineStyleChange);
+}
+
void StyledElement::inlineStyleChanged()
{
invalidateStyleAttribute();
@@ -241,7 +258,7 @@
bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, const String& value, bool important)
{
- bool changes = ensureMutableInlineStyle().setProperty(propertyID, value, important, &document().elementSheet().contents());
+ bool changes = ensureMutableInlineStyle().setProperty(propertyID, value, important, CSSParserContext(document()));
if (changes)
inlineStyleChanged();
return changes;
@@ -376,7 +393,7 @@
void StyledElement::addPropertyToPresentationAttributeStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const String& value)
{
- style.setProperty(propertyID, value, false, &document().elementSheet().contents());
+ style.setProperty(propertyID, value, false, CSSParserContext(document()));
}
}
diff --git a/Source/WebCore/dom/StyledElement.h b/Source/WebCore/dom/StyledElement.h
index 1efcdfd..189219f 100644
--- a/Source/WebCore/dom/StyledElement.h
+++ b/Source/WebCore/dom/StyledElement.h
@@ -93,13 +93,6 @@
void rebuildPresentationAttributeStyle();
};
-inline void StyledElement::invalidateStyleAttribute()
-{
- ASSERT(elementData());
- elementData()->setStyleAttributeIsDirty(true);
- setNeedsStyleRecalc(InlineStyleChange);
-}
-
inline const StyleProperties* StyledElement::presentationAttributeStyle() const
{
if (!elementData())
diff --git a/Source/WebCore/inspector/InspectorStyleSheet.cpp b/Source/WebCore/inspector/InspectorStyleSheet.cpp
index 429bae9..5a44b84 100644
--- a/Source/WebCore/inspector/InspectorStyleSheet.cpp
+++ b/Source/WebCore/inspector/InspectorStyleSheet.cpp
@@ -1366,7 +1366,7 @@
}
auto tempDeclaration = MutableStyleProperties::create();
- createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration, m_styleText, result, &m_element->document().elementSheet().contents());
+ createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration, m_styleText, result, nullptr);
return true;
}
diff --git a/Source/WebCore/svg/SVGAnimateElementBase.cpp b/Source/WebCore/svg/SVGAnimateElementBase.cpp
index fa29506..fd5f741 100644
--- a/Source/WebCore/svg/SVGAnimateElementBase.cpp
+++ b/Source/WebCore/svg/SVGAnimateElementBase.cpp
@@ -236,7 +236,7 @@
{
ASSERT(!targetElement.m_deletionHasBegun);
- if (!targetElement.ensureAnimatedSMILStyleProperties().setProperty(id, value, false, 0))
+ if (!targetElement.ensureAnimatedSMILStyleProperties().setProperty(id, value, false))
return;
targetElement.setNeedsStyleRecalc(SyntheticStyleChange);