Can't change @font-face descriptors from fontFaceRule.style.setProperty()
https://bugs.webkit.org/show_bug.cgi?id=177975
<rdar://problem/56648761>
Reviewed by Antti Koivisto.
LayoutTests/imported/w3c:
More passing subtests.
* web-platform-tests/css/css-syntax/urange-parsing-expected.txt:
Source/WebCore:
When parsing properties via PropertySetCSSStyleDeclaration::setProperty() (called from
script as rule.style.setProperty()), CSSPropertyParser::parseValue() needs to know if
we're parsing properties in a @font-face or @viewport rule, since some properties are
only allowed in these contexts.
Achieve this by adding to CSSParserContext an Optional<enclosingRuleType>, which gets set
for font-face and viewport rules. This gets set by StyleRuleCSSStyleDeclaration::cssParserContext()
based on the type of the parent rule.
Moved StyleRule::Type to its own header so CSSParserContext can use it. Added compile-time asserts
that the values match CSSRule::Type (fixing one of them).
Also fix <urange> serialization when start and end values are the same.
Test: web-platform-tests/css/css-syntax/urange-parsing.html
* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSKeyframeRule.cpp:
(WebCore::StyleRuleKeyframe::StyleRuleKeyframe):
* css/CSSKeyframesRule.cpp:
(WebCore::StyleRuleKeyframes::StyleRuleKeyframes):
* css/CSSPropertySourceData.h:
(WebCore::CSSRuleSourceData::create):
(WebCore::CSSRuleSourceData::createUnknown):
(WebCore::CSSRuleSourceData::CSSRuleSourceData):
* css/CSSRule.cpp:
* css/CSSUnicodeRangeValue.cpp:
(WebCore::CSSUnicodeRangeValue::customCSSText const):
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::StyleRuleCSSStyleDeclaration::cssParserContext const):
* css/StyleRule.cpp:
(WebCore::StyleRuleBase::destroy):
(WebCore::StyleRuleBase::copy const):
(WebCore::StyleRuleBase::createCSSOMWrapper const):
(WebCore::StyleRule::StyleRule):
(WebCore::StyleRulePage::StyleRulePage):
(WebCore::StyleRuleFontFace::StyleRuleFontFace):
(WebCore::StyleRuleGroup::StyleRuleGroup):
(WebCore::StyleRuleMedia::StyleRuleMedia):
(WebCore::StyleRuleSupports::StyleRuleSupports):
(WebCore::StyleRuleViewport::StyleRuleViewport):
(WebCore::StyleRuleCharset::StyleRuleCharset):
(WebCore::StyleRuleNamespace::StyleRuleNamespace):
* css/StyleRule.h:
(WebCore::StyleRuleBase::type const):
(WebCore::StyleRuleBase::isCharsetRule const):
(WebCore::StyleRuleBase::isFontFaceRule const):
(WebCore::StyleRuleBase::isKeyframesRule const):
(WebCore::StyleRuleBase::isKeyframeRule const):
(WebCore::StyleRuleBase::isNamespaceRule const):
(WebCore::StyleRuleBase::isMediaRule const):
(WebCore::StyleRuleBase::isPageRule const):
(WebCore::StyleRuleBase::isStyleRule const):
(WebCore::StyleRuleBase::isSupportsRule const):
(WebCore::StyleRuleBase::isViewportRule const):
(WebCore::StyleRuleBase::isImportRule const):
(WebCore::StyleRuleBase::StyleRuleBase):
* css/StyleRuleImport.cpp:
(WebCore::StyleRuleImport::StyleRuleImport):
* css/StyleRuleImport.h:
* css/StyleRuleType.h: Copied from Source/WebCore/css/CSSUnicodeRangeValue.cpp.
* css/StyleSheetContents.cpp:
(WebCore::traverseRulesInVector):
(WebCore::StyleSheetContents::traverseSubresources const):
* css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseValueWithVariableReferences):
* css/parser/CSSParserContext.h:
* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::parseValue):
(WebCore::CSSParserImpl::parseInlineStyleDeclaration):
(WebCore::CSSParserImpl::parseDeferredDeclaration):
(WebCore::CSSParserImpl::parseDeclarationList):
(WebCore::CSSParserImpl::supportsDeclaration):
(WebCore::CSSParserImpl::parseDeclarationListForInspector):
(WebCore::CSSParserImpl::consumeImportRule):
(WebCore::CSSParserImpl::consumeMediaRule):
(WebCore::CSSParserImpl::consumeSupportsRule):
(WebCore::CSSParserImpl::consumeViewportRule):
(WebCore::CSSParserImpl::consumeFontFaceRule):
(WebCore::CSSParserImpl::consumeKeyframesRule):
(WebCore::CSSParserImpl::consumePageRule):
(WebCore::CSSParserImpl::consumeKeyframeStyleRule):
(WebCore::observeSelectors):
(WebCore::CSSParserImpl::consumeStyleRule):
(WebCore::CSSParserImpl::consumeDeclarationList):
(WebCore::CSSParserImpl::consumeDeclaration):
(WebCore::CSSParserImpl::consumeDeclarationValue):
* css/parser/CSSParserImpl.h:
* css/parser/CSSParserObserver.h:
* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::parseValue):
* css/parser/CSSPropertyParser.h:
* css/parser/CSSTokenizer.cpp:
(WebCore::CSSTokenizer::letterU):
* inspector/InspectorStyleSheet.cpp:
(flattenSourceData):
(WebCore::StyleSheetHandler::startRuleHeader):
(WebCore::InspectorStyleSheetForInlineStyle::ruleSourceData const):
LayoutTests:
Fix tests for the urange serialization fix.
* fast/text/font-face-javascript-expected.txt:
* fast/text/font-face-javascript.html:
* fast/text/unicode-range-javascript-expected.txt:
* fast/text/unicode-range-javascript.html:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251655 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 2b27e56..48c98e7 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,111 @@
+2019-10-28 Simon Fraser <simon.fraser@apple.com>
+
+ Can't change @font-face descriptors from fontFaceRule.style.setProperty()
+ https://bugs.webkit.org/show_bug.cgi?id=177975
+ <rdar://problem/56648761>
+
+ Reviewed by Antti Koivisto.
+
+ When parsing properties via PropertySetCSSStyleDeclaration::setProperty() (called from
+ script as rule.style.setProperty()), CSSPropertyParser::parseValue() needs to know if
+ we're parsing properties in a @font-face or @viewport rule, since some properties are
+ only allowed in these contexts.
+
+ Achieve this by adding to CSSParserContext an Optional<enclosingRuleType>, which gets set
+ for font-face and viewport rules. This gets set by StyleRuleCSSStyleDeclaration::cssParserContext()
+ based on the type of the parent rule.
+
+ Moved StyleRule::Type to its own header so CSSParserContext can use it. Added compile-time asserts
+ that the values match CSSRule::Type (fixing one of them).
+
+ Also fix <urange> serialization when start and end values are the same.
+
+ Test: web-platform-tests/css/css-syntax/urange-parsing.html
+
+ * Headers.cmake:
+ * WebCore.xcodeproj/project.pbxproj:
+ * css/CSSKeyframeRule.cpp:
+ (WebCore::StyleRuleKeyframe::StyleRuleKeyframe):
+ * css/CSSKeyframesRule.cpp:
+ (WebCore::StyleRuleKeyframes::StyleRuleKeyframes):
+ * css/CSSPropertySourceData.h:
+ (WebCore::CSSRuleSourceData::create):
+ (WebCore::CSSRuleSourceData::createUnknown):
+ (WebCore::CSSRuleSourceData::CSSRuleSourceData):
+ * css/CSSRule.cpp:
+ * css/CSSUnicodeRangeValue.cpp:
+ (WebCore::CSSUnicodeRangeValue::customCSSText const):
+ * css/PropertySetCSSStyleDeclaration.cpp:
+ (WebCore::StyleRuleCSSStyleDeclaration::cssParserContext const):
+ * css/StyleRule.cpp:
+ (WebCore::StyleRuleBase::destroy):
+ (WebCore::StyleRuleBase::copy const):
+ (WebCore::StyleRuleBase::createCSSOMWrapper const):
+ (WebCore::StyleRule::StyleRule):
+ (WebCore::StyleRulePage::StyleRulePage):
+ (WebCore::StyleRuleFontFace::StyleRuleFontFace):
+ (WebCore::StyleRuleGroup::StyleRuleGroup):
+ (WebCore::StyleRuleMedia::StyleRuleMedia):
+ (WebCore::StyleRuleSupports::StyleRuleSupports):
+ (WebCore::StyleRuleViewport::StyleRuleViewport):
+ (WebCore::StyleRuleCharset::StyleRuleCharset):
+ (WebCore::StyleRuleNamespace::StyleRuleNamespace):
+ * css/StyleRule.h:
+ (WebCore::StyleRuleBase::type const):
+ (WebCore::StyleRuleBase::isCharsetRule const):
+ (WebCore::StyleRuleBase::isFontFaceRule const):
+ (WebCore::StyleRuleBase::isKeyframesRule const):
+ (WebCore::StyleRuleBase::isKeyframeRule const):
+ (WebCore::StyleRuleBase::isNamespaceRule const):
+ (WebCore::StyleRuleBase::isMediaRule const):
+ (WebCore::StyleRuleBase::isPageRule const):
+ (WebCore::StyleRuleBase::isStyleRule const):
+ (WebCore::StyleRuleBase::isSupportsRule const):
+ (WebCore::StyleRuleBase::isViewportRule const):
+ (WebCore::StyleRuleBase::isImportRule const):
+ (WebCore::StyleRuleBase::StyleRuleBase):
+ * css/StyleRuleImport.cpp:
+ (WebCore::StyleRuleImport::StyleRuleImport):
+ * css/StyleRuleImport.h:
+ * css/StyleRuleType.h: Copied from Source/WebCore/css/CSSUnicodeRangeValue.cpp.
+ * css/StyleSheetContents.cpp:
+ (WebCore::traverseRulesInVector):
+ (WebCore::StyleSheetContents::traverseSubresources const):
+ * css/parser/CSSParser.cpp:
+ (WebCore::CSSParser::parseValueWithVariableReferences):
+ * css/parser/CSSParserContext.h:
+ * css/parser/CSSParserImpl.cpp:
+ (WebCore::CSSParserImpl::parseValue):
+ (WebCore::CSSParserImpl::parseInlineStyleDeclaration):
+ (WebCore::CSSParserImpl::parseDeferredDeclaration):
+ (WebCore::CSSParserImpl::parseDeclarationList):
+ (WebCore::CSSParserImpl::supportsDeclaration):
+ (WebCore::CSSParserImpl::parseDeclarationListForInspector):
+ (WebCore::CSSParserImpl::consumeImportRule):
+ (WebCore::CSSParserImpl::consumeMediaRule):
+ (WebCore::CSSParserImpl::consumeSupportsRule):
+ (WebCore::CSSParserImpl::consumeViewportRule):
+ (WebCore::CSSParserImpl::consumeFontFaceRule):
+ (WebCore::CSSParserImpl::consumeKeyframesRule):
+ (WebCore::CSSParserImpl::consumePageRule):
+ (WebCore::CSSParserImpl::consumeKeyframeStyleRule):
+ (WebCore::observeSelectors):
+ (WebCore::CSSParserImpl::consumeStyleRule):
+ (WebCore::CSSParserImpl::consumeDeclarationList):
+ (WebCore::CSSParserImpl::consumeDeclaration):
+ (WebCore::CSSParserImpl::consumeDeclarationValue):
+ * css/parser/CSSParserImpl.h:
+ * css/parser/CSSParserObserver.h:
+ * css/parser/CSSPropertyParser.cpp:
+ (WebCore::CSSPropertyParser::parseValue):
+ * css/parser/CSSPropertyParser.h:
+ * css/parser/CSSTokenizer.cpp:
+ (WebCore::CSSTokenizer::letterU):
+ * inspector/InspectorStyleSheet.cpp:
+ (flattenSourceData):
+ (WebCore::StyleSheetHandler::startRuleHeader):
+ (WebCore::InspectorStyleSheetForInlineStyle::ruleSourceData const):
+
2019-10-28 Commit Queue <commit-queue@webkit.org>
Unreviewed, rolling out r251651.
diff --git a/Source/WebCore/Headers.cmake b/Source/WebCore/Headers.cmake
index d60d8f8..55c0e0b 100644
--- a/Source/WebCore/Headers.cmake
+++ b/Source/WebCore/Headers.cmake
@@ -335,6 +335,7 @@
css/Rect.h
css/StyleColor.h
css/StyleProperties.h
+ css/StyleRuleType.h
css/StyleSheet.h
css/StyleSheetContents.h
css/StyleSheetList.h
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index 2a4d3f0..37553f7 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -331,6 +331,7 @@
0F94B6492208FE3B00157014 /* ScrollingTreeStickyNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F94B6432208F70200157014 /* ScrollingTreeStickyNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F94B6522209150600157014 /* ScrollingStatePositionedNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F94B651220914FF00157014 /* ScrollingStatePositionedNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F94B655220931E400157014 /* ScrollingTreePositionedNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F94B6532209156C00157014 /* ScrollingTreePositionedNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 0F94F37E23661626003AA5C7 /* StyleRuleType.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F94F37C23661131003AA5C7 /* StyleRuleType.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F9DAA0F1FD1C66A0079C5B2 /* DOMGCOutputConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F9DAA0E1FD1C6640079C5B2 /* DOMGCOutputConstraint.h */; };
0FA24D7A162DF91900A3F4C0 /* GraphicsLayerUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */; settings = {ATTRIBUTES = (Private, ); }; };
0FB6252F18DE1B1500A07C05 /* GeometryUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB6252D18DE1B1500A07C05 /* GeometryUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -5737,6 +5738,7 @@
0F94B651220914FF00157014 /* ScrollingStatePositionedNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingStatePositionedNode.h; sourceTree = "<group>"; };
0F94B6532209156C00157014 /* ScrollingTreePositionedNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingTreePositionedNode.h; sourceTree = "<group>"; };
0F94B6542209156C00157014 /* ScrollingTreePositionedNode.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingTreePositionedNode.mm; sourceTree = "<group>"; };
+ 0F94F37C23661131003AA5C7 /* StyleRuleType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StyleRuleType.h; sourceTree = "<group>"; };
0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DisplayRefreshMonitorIOS.mm; sourceTree = "<group>"; };
0F9B547522B4A772007B5E8A /* ScrollingStateOverflowScrollProxyNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingStateOverflowScrollProxyNode.h; sourceTree = "<group>"; };
0F9B547622B4A773007B5E8A /* ScrollingStateOverflowScrollProxyNode.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingStateOverflowScrollProxyNode.cpp; sourceTree = "<group>"; };
@@ -9135,8 +9137,6 @@
65FEA86809833ADE00BED4AB /* Page.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Page.cpp; sourceTree = "<group>"; };
697101071C6BE1550018C7F1 /* AccessibilitySVGElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilitySVGElement.cpp; sourceTree = "<group>"; };
697101081C6BE1550018C7F1 /* AccessibilitySVGElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilitySVGElement.h; sourceTree = "<group>"; };
- AAD9D0B121DFA80C001B11C7 /* LazyLoadImageObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LazyLoadImageObserver.cpp; sourceTree = "<group>"; };
- AAD9D0B321DFA80E001B11C7 /* LazyLoadImageObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LazyLoadImageObserver.h; sourceTree = "<group>"; };
6A22E86F1F10418600F546C3 /* InspectorCanvas.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InspectorCanvas.h; sourceTree = "<group>"; };
6A22E8721F1042C400F546C3 /* InspectorCanvas.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCanvas.cpp; sourceTree = "<group>"; };
6A7279881F16C29B003F39B8 /* InspectorShaderProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorShaderProgram.h; sourceTree = "<group>"; };
@@ -12136,6 +12136,8 @@
AACC83D62316569E00EB6BF5 /* HTMLOrForeignElement.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = HTMLOrForeignElement.idl; sourceTree = "<group>"; };
AACC83D72316576A00EB6BF5 /* JSHTMLOrForeignElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSHTMLOrForeignElement.h; sourceTree = "<group>"; };
AACC83D82316576B00EB6BF5 /* JSHTMLOrForeignElement.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLOrForeignElement.cpp; sourceTree = "<group>"; };
+ AAD9D0B121DFA80C001B11C7 /* LazyLoadImageObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LazyLoadImageObserver.cpp; sourceTree = "<group>"; };
+ AAD9D0B321DFA80E001B11C7 /* LazyLoadImageObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LazyLoadImageObserver.h; sourceTree = "<group>"; };
AAE27B7416CBFC0D00623043 /* PlatformSpeechSynthesizerMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformSpeechSynthesizerMock.cpp; sourceTree = "<group>"; };
AAE27B7516CBFC0D00623043 /* PlatformSpeechSynthesizerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformSpeechSynthesizerMock.h; sourceTree = "<group>"; };
AAE3755D17429BCC006200C2 /* PlatformSpeechSynthesizerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformSpeechSynthesizerIOS.mm; sourceTree = "<group>"; };
@@ -27330,6 +27332,7 @@
E4BBED4B14FCDBA1003F0B98 /* StyleRule.h */,
E4946EAC156E64DD00D3297F /* StyleRuleImport.cpp */,
E4946EAD156E64DD00D3297F /* StyleRuleImport.h */,
+ 0F94F37C23661131003AA5C7 /* StyleRuleType.h */,
A8EA80050A19516E00A8EF5F /* StyleSheet.cpp */,
A8EA80040A19516E00A8EF5F /* StyleSheet.h */,
850656DC0AAB44D9002D15C0 /* StyleSheet.idl */,
@@ -32116,6 +32119,7 @@
E139866415478474001E3F65 /* StyleResolver.h in Headers */,
E4BBED4D14FCDBA1003F0B98 /* StyleRule.h in Headers */,
E4946EAF156E64DD00D3297F /* StyleRuleImport.h in Headers */,
+ 0F94F37E23661626003AA5C7 /* StyleRuleType.h in Headers */,
E461D65F1BB0C80D00CB5645 /* StyleScope.h in Headers */,
F47A5E3E195B8C8A00483100 /* StyleScrollSnapPoints.h in Headers */,
9D6380101AF173220031A15C /* StyleSelfAlignmentData.h in Headers */,
diff --git a/Source/WebCore/css/CSSKeyframeRule.cpp b/Source/WebCore/css/CSSKeyframeRule.cpp
index 9dd5938..69d24a6 100644
--- a/Source/WebCore/css/CSSKeyframeRule.cpp
+++ b/Source/WebCore/css/CSSKeyframeRule.cpp
@@ -35,13 +35,13 @@
namespace WebCore {
StyleRuleKeyframe::StyleRuleKeyframe(Ref<StyleProperties>&& properties)
- : StyleRuleBase(Keyframe)
+ : StyleRuleBase(StyleRuleType::Keyframe)
, m_properties(WTFMove(properties))
{
}
StyleRuleKeyframe::StyleRuleKeyframe(std::unique_ptr<Vector<double>> keys, Ref<StyleProperties>&& properties)
- : StyleRuleBase(Keyframe)
+ : StyleRuleBase(StyleRuleType::Keyframe)
, m_properties(WTFMove(properties))
, m_keys(*keys)
{
diff --git a/Source/WebCore/css/CSSKeyframesRule.cpp b/Source/WebCore/css/CSSKeyframesRule.cpp
index 6f1eb33..8ceebdc 100644
--- a/Source/WebCore/css/CSSKeyframesRule.cpp
+++ b/Source/WebCore/css/CSSKeyframesRule.cpp
@@ -37,13 +37,13 @@
namespace WebCore {
StyleRuleKeyframes::StyleRuleKeyframes(const AtomString& name)
- : StyleRuleBase(Keyframes)
+ : StyleRuleBase(StyleRuleType::Keyframes)
, m_name(name)
{
}
StyleRuleKeyframes::StyleRuleKeyframes(const AtomString& name, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
- : StyleRuleBase(Keyframes)
+ : StyleRuleBase(StyleRuleType::Keyframes)
, m_name(name)
, m_deferredRules(WTFMove(deferredRules))
{
diff --git a/Source/WebCore/css/CSSPropertySourceData.h b/Source/WebCore/css/CSSPropertySourceData.h
index 8c93eef8..b50d303 100644
--- a/Source/WebCore/css/CSSPropertySourceData.h
+++ b/Source/WebCore/css/CSSPropertySourceData.h
@@ -80,24 +80,24 @@
typedef Vector<SourceRange> SelectorRangeList;
struct CSSRuleSourceData : public RefCounted<CSSRuleSourceData> {
- static Ref<CSSRuleSourceData> create(StyleRule::Type type)
+ static Ref<CSSRuleSourceData> create(StyleRuleType type)
{
return adoptRef(*new CSSRuleSourceData(type));
}
static Ref<CSSRuleSourceData> createUnknown()
{
- return adoptRef(*new CSSRuleSourceData(StyleRule::Unknown));
+ return adoptRef(*new CSSRuleSourceData(StyleRuleType::Unknown));
}
- CSSRuleSourceData(StyleRule::Type type)
+ CSSRuleSourceData(StyleRuleType type)
: type(type)
{
- if (type == StyleRule::Style || type == StyleRule::FontFace || type == StyleRule::Page)
+ if (type == StyleRuleType::Style || type == StyleRuleType::FontFace || type == StyleRuleType::Page)
styleSourceData = CSSStyleSourceData::create();
}
- StyleRule::Type type;
+ StyleRuleType type;
// Range of the selector list in the enclosing source.
SourceRange ruleHeaderRange;
diff --git a/Source/WebCore/css/CSSRule.cpp b/Source/WebCore/css/CSSRule.cpp
index c4f7209..27cef09 100644
--- a/Source/WebCore/css/CSSRule.cpp
+++ b/Source/WebCore/css/CSSRule.cpp
@@ -36,8 +36,19 @@
COMPILE_ASSERT(sizeof(CSSRule) == sizeof(SameSizeAsCSSRule), CSSRule_should_stay_small);
+COMPILE_ASSERT(StyleRuleType::Unknown == static_cast<StyleRuleType>(CSSRule::Type::UNKNOWN_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Style == static_cast<StyleRuleType>(CSSRule::Type::STYLE_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Charset == static_cast<StyleRuleType>(CSSRule::Type::CHARSET_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Import == static_cast<StyleRuleType>(CSSRule::Type::IMPORT_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Media == static_cast<StyleRuleType>(CSSRule::Type::MEDIA_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::FontFace == static_cast<StyleRuleType>(CSSRule::Type::FONT_FACE_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Page == static_cast<StyleRuleType>(CSSRule::Type::PAGE_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Keyframes == static_cast<StyleRuleType>(CSSRule::Type::KEYFRAMES_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Keyframe == static_cast<StyleRuleType>(CSSRule::Type::KEYFRAME_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Namespace == static_cast<StyleRuleType>(CSSRule::Type::NAMESPACE_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleType::Supports == static_cast<StyleRuleType>(CSSRule::Type::SUPPORTS_RULE), enums_should_match);
#if ENABLE(CSS_DEVICE_ADAPTATION)
-COMPILE_ASSERT(StyleRuleBase::Viewport == static_cast<StyleRuleBase::Type>(CSSRule::WEBKIT_VIEWPORT_RULE), enums_should_match);
+COMPILE_ASSERT(StyleRuleBase::Viewport == static_cast<StyleRuleType>(CSSRule::WEBKIT_VIEWPORT_RULE), enums_should_match);
#endif
ExceptionOr<void> CSSRule::setCssText(const String&)
diff --git a/Source/WebCore/css/CSSUnicodeRangeValue.cpp b/Source/WebCore/css/CSSUnicodeRangeValue.cpp
index a37a1d68..4be7583 100644
--- a/Source/WebCore/css/CSSUnicodeRangeValue.cpp
+++ b/Source/WebCore/css/CSSUnicodeRangeValue.cpp
@@ -32,6 +32,9 @@
String CSSUnicodeRangeValue::customCSSText() const
{
+ if (m_from == m_to)
+ return makeString("U+", hex(m_from, Lowercase));
+
return makeString("U+", hex(m_from, Lowercase), '-', hex(m_to, Lowercase));
}
diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
index e1e1d72..d315211 100644
--- a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
+++ b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
@@ -412,7 +412,11 @@
if (!styleSheet)
return PropertySetCSSStyleDeclaration::cssParserContext();
- return styleSheet->parserContext();
+ auto context = styleSheet->parserContext();
+ if (m_parentRule)
+ context.enclosingRuleType = static_cast<StyleRuleType>(m_parentRule->type());
+
+ return context;
}
void StyleRuleCSSStyleDeclaration::reattach(MutableStyleProperties& propertySet)
diff --git a/Source/WebCore/css/StyleRule.cpp b/Source/WebCore/css/StyleRule.cpp
index 1df0a2a..1f99fdf 100644
--- a/Source/WebCore/css/StyleRule.cpp
+++ b/Source/WebCore/css/StyleRule.cpp
@@ -58,42 +58,42 @@
void StyleRuleBase::destroy()
{
switch (type()) {
- case Style:
+ case StyleRuleType::Style:
delete downcast<StyleRule>(this);
return;
- case Page:
+ case StyleRuleType::Page:
delete downcast<StyleRulePage>(this);
return;
- case FontFace:
+ case StyleRuleType::FontFace:
delete downcast<StyleRuleFontFace>(this);
return;
- case Media:
+ case StyleRuleType::Media:
delete downcast<StyleRuleMedia>(this);
return;
- case Supports:
+ case StyleRuleType::Supports:
delete downcast<StyleRuleSupports>(this);
return;
- case Import:
+ case StyleRuleType::Import:
delete downcast<StyleRuleImport>(this);
return;
- case Keyframes:
+ case StyleRuleType::Keyframes:
delete downcast<StyleRuleKeyframes>(this);
return;
#if ENABLE(CSS_DEVICE_ADAPTATION)
- case Viewport:
+ case StyleRuleType::Viewport:
delete downcast<StyleRuleViewport>(this);
return;
#endif
- case Namespace:
+ case StyleRuleType::Namespace:
delete downcast<StyleRuleNamespace>(this);
return;
- case Keyframe:
+ case StyleRuleType::Keyframe:
delete downcast<StyleRuleKeyframe>(this);
return;
- case Charset:
+ case StyleRuleType::Charset:
delete downcast<StyleRuleCharset>(this);
return;
- case Unknown:
+ case StyleRuleType::Unknown:
ASSERT_NOT_REACHED();
return;
}
@@ -103,29 +103,29 @@
Ref<StyleRuleBase> StyleRuleBase::copy() const
{
switch (type()) {
- case Style:
+ case StyleRuleType::Style:
return downcast<StyleRule>(*this).copy();
- case Page:
+ case StyleRuleType::Page:
return downcast<StyleRulePage>(*this).copy();
- case FontFace:
+ case StyleRuleType::FontFace:
return downcast<StyleRuleFontFace>(*this).copy();
- case Media:
+ case StyleRuleType::Media:
return downcast<StyleRuleMedia>(*this).copy();
- case Supports:
+ case StyleRuleType::Supports:
return downcast<StyleRuleSupports>(*this).copy();
- case Keyframes:
+ case StyleRuleType::Keyframes:
return downcast<StyleRuleKeyframes>(*this).copy();
#if ENABLE(CSS_DEVICE_ADAPTATION)
- case Viewport:
+ case StyleRuleType::Viewport:
return downcast<StyleRuleViewport>(*this).copy();
#endif
- case Import:
- case Namespace:
+ case StyleRuleType::Import:
+ case StyleRuleType::Namespace:
// FIXME: Copy import and namespace rules.
break;
- case Unknown:
- case Charset:
- case Keyframe:
+ case StyleRuleType::Unknown:
+ case StyleRuleType::Charset:
+ case StyleRuleType::Keyframe:
break;
}
CRASH();
@@ -136,38 +136,38 @@
RefPtr<CSSRule> rule;
StyleRuleBase& self = const_cast<StyleRuleBase&>(*this);
switch (type()) {
- case Style:
+ case StyleRuleType::Style:
rule = CSSStyleRule::create(downcast<StyleRule>(self), parentSheet);
break;
- case Page:
+ case StyleRuleType::Page:
rule = CSSPageRule::create(downcast<StyleRulePage>(self), parentSheet);
break;
- case FontFace:
+ case StyleRuleType::FontFace:
rule = CSSFontFaceRule::create(downcast<StyleRuleFontFace>(self), parentSheet);
break;
- case Media:
+ case StyleRuleType::Media:
rule = CSSMediaRule::create(downcast<StyleRuleMedia>(self), parentSheet);
break;
- case Supports:
+ case StyleRuleType::Supports:
rule = CSSSupportsRule::create(downcast<StyleRuleSupports>(self), parentSheet);
break;
- case Import:
+ case StyleRuleType::Import:
rule = CSSImportRule::create(downcast<StyleRuleImport>(self), parentSheet);
break;
- case Keyframes:
+ case StyleRuleType::Keyframes:
rule = CSSKeyframesRule::create(downcast<StyleRuleKeyframes>(self), parentSheet);
break;
#if ENABLE(CSS_DEVICE_ADAPTATION)
- case Viewport:
+ case StyleRuleType::Viewport:
rule = WebKitCSSViewportRule::create(downcast<StyleRuleViewport>(self), parentSheet);
break;
#endif
- case Namespace:
+ case StyleRuleType::Namespace:
rule = CSSNamespaceRule::create(downcast<StyleRuleNamespace>(self), parentSheet);
break;
- case Unknown:
- case Charset:
- case Keyframe:
+ case StyleRuleType::Unknown:
+ case StyleRuleType::Charset:
+ case StyleRuleType::Keyframe:
ASSERT_NOT_REACHED();
break;
}
@@ -184,7 +184,7 @@
}
StyleRule::StyleRule(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin, CSSSelectorList&& selectors)
- : StyleRuleBase(Style, hasDocumentSecurityOrigin)
+ : StyleRuleBase(StyleRuleType::Style, hasDocumentSecurityOrigin)
, m_properties(WTFMove(properties))
, m_selectorList(WTFMove(selectors))
{
@@ -250,7 +250,7 @@
}
StyleRulePage::StyleRulePage(Ref<StyleProperties>&& properties, CSSSelectorList&& selectors)
- : StyleRuleBase(Page)
+ : StyleRuleBase(StyleRuleType::Page)
, m_properties(WTFMove(properties))
, m_selectorList(WTFMove(selectors))
{
@@ -273,7 +273,7 @@
}
StyleRuleFontFace::StyleRuleFontFace(Ref<StyleProperties>&& properties)
- : StyleRuleBase(FontFace)
+ : StyleRuleBase(StyleRuleType::FontFace)
, m_properties(WTFMove(properties))
{
}
@@ -311,13 +311,13 @@
m_parser->parseKeyframeList(m_tokens, keyframesRule);
}
-StyleRuleGroup::StyleRuleGroup(Type type, Vector<RefPtr<StyleRuleBase>>& adoptRule)
+StyleRuleGroup::StyleRuleGroup(StyleRuleType type, Vector<RefPtr<StyleRuleBase>>& adoptRule)
: StyleRuleBase(type)
{
m_childRules.swap(adoptRule);
}
-StyleRuleGroup::StyleRuleGroup(Type type, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
+StyleRuleGroup::StyleRuleGroup(StyleRuleType type, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
: StyleRuleBase(type)
, m_deferredRules(WTFMove(deferredRules))
{
@@ -359,13 +359,13 @@
}
StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
- : StyleRuleGroup(Media, adoptRules)
+ : StyleRuleGroup(StyleRuleType::Media, adoptRules)
, m_mediaQueries(WTFMove(media))
{
}
StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
- : StyleRuleGroup(Media, WTFMove(deferredRules))
+ : StyleRuleGroup(StyleRuleType::Media, WTFMove(deferredRules))
, m_mediaQueries(WTFMove(media))
{
}
@@ -379,14 +379,14 @@
StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules)
- : StyleRuleGroup(Supports, adoptRules)
+ : StyleRuleGroup(StyleRuleType::Supports, adoptRules)
, m_conditionText(conditionText)
, m_conditionIsSupported(conditionIsSupported)
{
}
StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
- : StyleRuleGroup(Supports, WTFMove(deferredRules))
+ : StyleRuleGroup(StyleRuleType::Supports, WTFMove(deferredRules))
, m_conditionText(conditionText)
, m_conditionIsSupported(conditionIsSupported)
{
@@ -401,7 +401,7 @@
#if ENABLE(CSS_DEVICE_ADAPTATION)
StyleRuleViewport::StyleRuleViewport(Ref<StyleProperties>&& properties)
- : StyleRuleBase(Viewport)
+ : StyleRuleBase(StyleRuleType::Viewport)
, m_properties(WTFMove(properties))
{
}
@@ -423,7 +423,7 @@
#endif // ENABLE(CSS_DEVICE_ADAPTATION)
StyleRuleCharset::StyleRuleCharset()
- : StyleRuleBase(Charset)
+ : StyleRuleBase(StyleRuleType::Charset)
{
}
@@ -435,7 +435,7 @@
StyleRuleCharset::~StyleRuleCharset() = default;
StyleRuleNamespace::StyleRuleNamespace(AtomString prefix, AtomString uri)
- : StyleRuleBase(Namespace)
+ : StyleRuleBase(StyleRuleType::Namespace)
, m_prefix(prefix)
, m_uri(uri)
{
diff --git a/Source/WebCore/css/StyleRule.h b/Source/WebCore/css/StyleRule.h
index 9e6a96d..7fe07cc 100644
--- a/Source/WebCore/css/StyleRule.h
+++ b/Source/WebCore/css/StyleRule.h
@@ -24,6 +24,7 @@
#include "CSSSelectorList.h"
#include "CompiledSelector.h"
#include "StyleProperties.h"
+#include "StyleRuleType.h"
#include <wtf/RefPtr.h>
#include <wtf/TypeCasts.h>
#include <wtf/UniqueArray.h>
@@ -42,38 +43,21 @@
class StyleRuleBase : public WTF::RefCountedBase {
WTF_MAKE_FAST_ALLOCATED;
public:
- enum Type {
- Unknown, // Not used.
- Style,
- Charset, // Not used. These are internally strings owned by the style sheet.
- Import,
- Media,
- FontFace,
- Page,
- Keyframes,
- Keyframe, // Not used. These are internally non-rule StyleRuleKeyframe objects.
- Namespace,
- Supports = 12,
-#if ENABLE(CSS_DEVICE_ADAPTATION)
- Viewport = 15,
-#endif
- };
-
- Type type() const { return static_cast<Type>(m_type); }
+ StyleRuleType type() const { return static_cast<StyleRuleType>(m_type); }
- bool isCharsetRule() const { return type() == Charset; }
- bool isFontFaceRule() const { return type() == FontFace; }
- bool isKeyframesRule() const { return type() == Keyframes; }
- bool isKeyframeRule() const { return type() == Keyframe; }
- bool isNamespaceRule() const { return type() == Namespace; }
- bool isMediaRule() const { return type() == Media; }
- bool isPageRule() const { return type() == Page; }
- bool isStyleRule() const { return type() == Style; }
- bool isSupportsRule() const { return type() == Supports; }
+ bool isCharsetRule() const { return type() == StyleRuleType::Charset; }
+ bool isFontFaceRule() const { return type() == StyleRuleType::FontFace; }
+ bool isKeyframesRule() const { return type() == StyleRuleType::Keyframes; }
+ bool isKeyframeRule() const { return type() == StyleRuleType::Keyframe; }
+ bool isNamespaceRule() const { return type() == StyleRuleType::Namespace; }
+ bool isMediaRule() const { return type() == StyleRuleType::Media; }
+ bool isPageRule() const { return type() == StyleRuleType::Page; }
+ bool isStyleRule() const { return type() == StyleRuleType::Style; }
+ bool isSupportsRule() const { return type() == StyleRuleType::Supports; }
#if ENABLE(CSS_DEVICE_ADAPTATION)
- bool isViewportRule() const { return type() == Viewport; }
+ bool isViewportRule() const { return type() == StyleRuleType::Viewport; }
#endif
- bool isImportRule() const { return type() == Import; }
+ bool isImportRule() const { return type() == StyleRuleType::Import; }
Ref<StyleRuleBase> copy() const;
@@ -88,8 +72,8 @@
Ref<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
protected:
- StyleRuleBase(Type type, bool hasDocumentSecurityOrigin = false)
- : m_type(type)
+ StyleRuleBase(StyleRuleType type, bool hasDocumentSecurityOrigin = false)
+ : m_type(static_cast<unsigned>(type))
, m_hasDocumentSecurityOrigin(hasDocumentSecurityOrigin)
{
}
@@ -110,7 +94,7 @@
Ref<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
- unsigned m_type : 5;
+ unsigned m_type : 5; // StyleRuleType
// This is only needed to support getMatchedCSSRules.
unsigned m_hasDocumentSecurityOrigin : 1;
};
@@ -241,8 +225,8 @@
void wrapperRemoveRule(unsigned);
protected:
- StyleRuleGroup(Type, Vector<RefPtr<StyleRuleBase>>&);
- StyleRuleGroup(Type, std::unique_ptr<DeferredStyleGroupRuleList>&&);
+ StyleRuleGroup(StyleRuleType, Vector<RefPtr<StyleRuleBase>>&);
+ StyleRuleGroup(StyleRuleType, std::unique_ptr<DeferredStyleGroupRuleList>&&);
StyleRuleGroup(const StyleRuleGroup&);
private:
diff --git a/Source/WebCore/css/StyleRuleImport.cpp b/Source/WebCore/css/StyleRuleImport.cpp
index e24a425..8a1565b 100644
--- a/Source/WebCore/css/StyleRuleImport.cpp
+++ b/Source/WebCore/css/StyleRuleImport.cpp
@@ -42,13 +42,10 @@
}
StyleRuleImport::StyleRuleImport(const String& href, Ref<MediaQuerySet>&& media)
- : StyleRuleBase(Import)
- , m_parentStyleSheet(0)
+ : StyleRuleBase(StyleRuleType::Import)
, m_styleSheetClient(this)
, m_strHref(href)
, m_mediaQueries(WTFMove(media))
- , m_cachedSheet(0)
- , m_loading(false)
{
if (!m_mediaQueries)
m_mediaQueries = MediaQuerySet::create(String(), MediaQueryParserContext());
diff --git a/Source/WebCore/css/StyleRuleImport.h b/Source/WebCore/css/StyleRuleImport.h
index 1b25372..60f9d96 100644
--- a/Source/WebCore/css/StyleRuleImport.h
+++ b/Source/WebCore/css/StyleRuleImport.h
@@ -72,14 +72,14 @@
StyleRuleImport(const String& href, Ref<MediaQuerySet>&&);
- StyleSheetContents* m_parentStyleSheet;
+ StyleSheetContents* m_parentStyleSheet { nullptr };
ImportedStyleSheetClient m_styleSheetClient;
String m_strHref;
RefPtr<MediaQuerySet> m_mediaQueries;
RefPtr<StyleSheetContents> m_styleSheet;
CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
- bool m_loading;
+ bool m_loading { false };
};
} // namespace WebCore
diff --git a/Source/WebCore/css/StyleRuleType.h b/Source/WebCore/css/StyleRuleType.h
new file mode 100644
index 0000000..3444286
--- /dev/null
+++ b/Source/WebCore/css/StyleRuleType.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WebCore {
+
+enum class StyleRuleType : uint8_t {
+ Unknown, // Not used.
+ Style,
+ Charset, // Not used. These are internally strings owned by the style sheet.
+ Import,
+ Media,
+ FontFace,
+ Page,
+ Keyframes,
+ Keyframe, // Not used. These are internally non-rule StyleRuleKeyframe objects.
+ Namespace = 10,
+ Supports = 12,
+#if ENABLE(CSS_DEVICE_ADAPTATION)
+ Viewport = 15,
+#endif
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/css/StyleSheetContents.cpp b/Source/WebCore/css/StyleSheetContents.cpp
index 8e8818c..e8e3950 100644
--- a/Source/WebCore/css/StyleSheetContents.cpp
+++ b/Source/WebCore/css/StyleSheetContents.cpp
@@ -426,26 +426,26 @@
if (handler(*rule))
return true;
switch (rule->type()) {
- case StyleRuleBase::Media: {
+ case StyleRuleType::Media: {
auto* childRules = downcast<StyleRuleMedia>(*rule).childRulesWithoutDeferredParsing();
if (childRules && traverseRulesInVector(*childRules, handler))
return true;
break;
}
- case StyleRuleBase::Import:
+ case StyleRuleType::Import:
ASSERT_NOT_REACHED();
break;
- case StyleRuleBase::Style:
- case StyleRuleBase::FontFace:
- case StyleRuleBase::Page:
- case StyleRuleBase::Keyframes:
- case StyleRuleBase::Namespace:
- case StyleRuleBase::Unknown:
- case StyleRuleBase::Charset:
- case StyleRuleBase::Keyframe:
- case StyleRuleBase::Supports:
+ case StyleRuleType::Style:
+ case StyleRuleType::FontFace:
+ case StyleRuleType::Page:
+ case StyleRuleType::Keyframes:
+ case StyleRuleType::Namespace:
+ case StyleRuleType::Unknown:
+ case StyleRuleType::Charset:
+ case StyleRuleType::Keyframe:
+ case StyleRuleType::Supports:
#if ENABLE(CSS_DEVICE_ADAPTATION)
- case StyleRuleBase::Viewport:
+ case StyleRuleType::Viewport:
#endif
break;
}
@@ -469,26 +469,26 @@
{
return traverseRules([&] (const StyleRuleBase& rule) {
switch (rule.type()) {
- case StyleRuleBase::Style: {
+ case StyleRuleType::Style: {
auto* properties = downcast<StyleRule>(rule).propertiesWithoutDeferredParsing();
return properties && properties->traverseSubresources(handler);
}
- case StyleRuleBase::FontFace:
+ case StyleRuleType::FontFace:
return downcast<StyleRuleFontFace>(rule).properties().traverseSubresources(handler);
- case StyleRuleBase::Import:
+ case StyleRuleType::Import:
if (auto* cachedResource = downcast<StyleRuleImport>(rule).cachedCSSStyleSheet())
return handler(*cachedResource);
return false;
- case StyleRuleBase::Media:
- case StyleRuleBase::Page:
- case StyleRuleBase::Keyframes:
- case StyleRuleBase::Namespace:
- case StyleRuleBase::Unknown:
- case StyleRuleBase::Charset:
- case StyleRuleBase::Keyframe:
- case StyleRuleBase::Supports:
+ case StyleRuleType::Media:
+ case StyleRuleType::Page:
+ case StyleRuleType::Keyframes:
+ case StyleRuleType::Namespace:
+ case StyleRuleType::Unknown:
+ case StyleRuleType::Charset:
+ case StyleRuleType::Keyframe:
+ case StyleRuleType::Supports:
#if ENABLE(CSS_DEVICE_ADAPTATION)
- case StyleRuleBase::Viewport:
+ case StyleRuleType::Viewport:
#endif
return false;
};
diff --git a/Source/WebCore/css/parser/CSSParser.cpp b/Source/WebCore/css/parser/CSSParser.cpp
index cc9bd29..1f931bb 100644
--- a/Source/WebCore/css/parser/CSSParser.cpp
+++ b/Source/WebCore/css/parser/CSSParser.cpp
@@ -199,7 +199,7 @@
Vector<CSSParserToken> resolvedTokens = resolvedData->tokens();
ParsedPropertyVector parsedProperties;
- if (!CSSPropertyParser::parseValue(shorthandID, false, resolvedTokens, m_context, parsedProperties, StyleRule::Style))
+ if (!CSSPropertyParser::parseValue(shorthandID, false, resolvedTokens, m_context, parsedProperties, StyleRuleType::Style))
return nullptr;
for (auto& property : parsedProperties) {
diff --git a/Source/WebCore/css/parser/CSSParserContext.h b/Source/WebCore/css/parser/CSSParserContext.h
index b2886a9..86525fd 100644
--- a/Source/WebCore/css/parser/CSSParserContext.h
+++ b/Source/WebCore/css/parser/CSSParserContext.h
@@ -26,8 +26,10 @@
#pragma once
#include "CSSParserMode.h"
+#include "StyleRuleType.h"
#include "TextEncoding.h"
#include <wtf/HashFunctions.h>
+#include <wtf/Optional.h>
#include <wtf/URL.h>
#include <wtf/URLHash.h>
#include <wtf/text/StringHash.h>
@@ -39,12 +41,14 @@
struct CSSParserContext {
WTF_MAKE_FAST_ALLOCATED;
public:
+
CSSParserContext(CSSParserMode, const URL& baseURL = URL());
WEBCORE_EXPORT CSSParserContext(const Document&, const URL& baseURL = URL(), const String& charset = emptyString());
URL baseURL;
String charset;
CSSParserMode mode { HTMLStandardMode };
+ Optional<StyleRuleType> enclosingRuleType;
bool isHTMLDocument { false };
#if ENABLE(TEXT_AUTOSIZING)
bool textAutosizingEnabled { false };
diff --git a/Source/WebCore/css/parser/CSSParserImpl.cpp b/Source/WebCore/css/parser/CSSParserImpl.cpp
index d75e4fc..73ed1cc 100644
--- a/Source/WebCore/css/parser/CSSParserImpl.cpp
+++ b/Source/WebCore/css/parser/CSSParserImpl.cpp
@@ -85,11 +85,7 @@
CSSParser::ParseResult CSSParserImpl::parseValue(MutableStyleProperties* declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context)
{
CSSParserImpl parser(context, string);
- StyleRule::Type ruleType = StyleRule::Style;
-#if ENABLE(CSS_DEVICE_ADAPTATION)
- if (declaration->cssParserMode() == CSSViewportRuleMode)
- ruleType = StyleRule::Viewport;
-#endif
+ auto ruleType = context.enclosingRuleType.valueOr(StyleRuleType::Style);
parser.consumeDeclarationValue(parser.tokenizer()->tokenRange(), propertyID, important, ruleType);
if (parser.m_parsedProperties.isEmpty())
return CSSParser::ParseResult::Error;
@@ -162,7 +158,7 @@
context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document().inQuirksMode());
CSSParserImpl parser(context, string);
- parser.consumeDeclarationList(parser.tokenizer()->tokenRange(), StyleRule::Style);
+ parser.consumeDeclarationList(parser.tokenizer()->tokenRange(), StyleRuleType::Style);
return createStyleProperties(parser.m_parsedProperties, context.mode);
}
@@ -173,7 +169,7 @@
return createStyleProperties(properties, context.mode);
}
CSSParserImpl parser(context, styleSheet);
- parser.consumeDeclarationList(tokenRange, StyleRule::Style);
+ parser.consumeDeclarationList(tokenRange, StyleRuleType::Style);
return createStyleProperties(parser.m_parsedProperties, context.mode);
}
@@ -201,11 +197,7 @@
bool CSSParserImpl::parseDeclarationList(MutableStyleProperties* declaration, const String& string, const CSSParserContext& context)
{
CSSParserImpl parser(context, string);
- StyleRule::Type ruleType = StyleRule::Style;
-#if ENABLE(CSS_DEVICE_ADAPTATION)
- if (declaration->cssParserMode() == CSSViewportRuleMode)
- ruleType = StyleRule::Viewport;
-#endif
+ auto ruleType = context.enclosingRuleType.valueOr(StyleRuleType::Style);
parser.consumeDeclarationList(parser.tokenizer()->tokenRange(), ruleType);
if (parser.m_parsedProperties.isEmpty())
return false;
@@ -306,7 +298,7 @@
bool CSSParserImpl::supportsDeclaration(CSSParserTokenRange& range)
{
ASSERT(m_parsedProperties.isEmpty());
- consumeDeclaration(range, StyleRule::Style);
+ consumeDeclaration(range, StyleRuleType::Style);
bool result = !m_parsedProperties.isEmpty();
m_parsedProperties.clear();
return result;
@@ -316,9 +308,9 @@
{
CSSParserObserverWrapper wrapper(observer);
CSSParserImpl parser(context, declaration, nullptr, &wrapper);
- observer.startRuleHeader(StyleRule::Style, 0);
+ observer.startRuleHeader(StyleRuleType::Style, 0);
observer.endRuleHeader(1);
- parser.consumeDeclarationList(parser.tokenizer()->tokenRange(), StyleRule::Style);
+ parser.consumeDeclarationList(parser.tokenizer()->tokenRange(), StyleRuleType::Style);
}
void CSSParserImpl::parseStyleSheetForInspector(const String& string, const CSSParserContext& context, StyleSheetContents* styleSheet, CSSParserObserver& observer)
@@ -510,7 +502,7 @@
if (m_observerWrapper) {
unsigned endOffset = m_observerWrapper->endOffset(prelude);
- m_observerWrapper->observer().startRuleHeader(StyleRule::Import, m_observerWrapper->startOffset(prelude));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::Import, m_observerWrapper->startOffset(prelude));
m_observerWrapper->observer().endRuleHeader(endOffset);
m_observerWrapper->observer().startRuleBody(endOffset);
m_observerWrapper->observer().endRuleBody(endOffset);
@@ -540,7 +532,7 @@
Vector<RefPtr<StyleRuleBase>> rules;
if (m_observerWrapper) {
- m_observerWrapper->observer().startRuleHeader(StyleRule::Media, m_observerWrapper->startOffset(prelude));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::Media, m_observerWrapper->startOffset(prelude));
m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset(prelude));
m_observerWrapper->observer().startRuleBody(m_observerWrapper->previousTokenStartOffset(block));
}
@@ -566,7 +558,7 @@
return StyleRuleSupports::create(prelude.serialize().stripWhiteSpace(), supported, makeUnique<DeferredStyleGroupRuleList>(block, *m_deferredParser));
if (m_observerWrapper) {
- m_observerWrapper->observer().startRuleHeader(StyleRule::Supports, m_observerWrapper->startOffset(prelude));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::Supports, m_observerWrapper->startOffset(prelude));
m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset(prelude));
m_observerWrapper->observer().startRuleBody(m_observerWrapper->previousTokenStartOffset(block));
}
@@ -591,7 +583,7 @@
if (m_observerWrapper) {
unsigned endOffset = m_observerWrapper->endOffset(prelude);
- m_observerWrapper->observer().startRuleHeader(StyleRule::Viewport, m_observerWrapper->startOffset(prelude));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::Viewport, m_observerWrapper->startOffset(prelude));
m_observerWrapper->observer().endRuleHeader(endOffset);
m_observerWrapper->observer().startRuleBody(endOffset);
m_observerWrapper->observer().endRuleBody(endOffset);
@@ -609,13 +601,13 @@
if (m_observerWrapper) {
unsigned endOffset = m_observerWrapper->endOffset(prelude);
- m_observerWrapper->observer().startRuleHeader(StyleRule::FontFace, m_observerWrapper->startOffset(prelude));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::FontFace, m_observerWrapper->startOffset(prelude));
m_observerWrapper->observer().endRuleHeader(endOffset);
m_observerWrapper->observer().startRuleBody(endOffset);
m_observerWrapper->observer().endRuleBody(endOffset);
}
- consumeDeclarationList(block, StyleRule::FontFace);
+ consumeDeclarationList(block, StyleRuleType::FontFace);
return StyleRuleFontFace::create(createStyleProperties(m_parsedProperties, m_context.mode));
}
@@ -638,7 +630,7 @@
return StyleRuleKeyframes::create(name, makeUnique<DeferredStyleGroupRuleList>(block, *m_deferredParser));
if (m_observerWrapper) {
- m_observerWrapper->observer().startRuleHeader(StyleRule::Keyframes, m_observerWrapper->startOffset(rangeCopy));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::Keyframes, m_observerWrapper->startOffset(rangeCopy));
m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset(prelude));
m_observerWrapper->observer().startRuleBody(m_observerWrapper->previousTokenStartOffset(block));
m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(block));
@@ -662,11 +654,11 @@
if (m_observerWrapper) {
unsigned endOffset = m_observerWrapper->endOffset(prelude);
- m_observerWrapper->observer().startRuleHeader(StyleRule::Page, m_observerWrapper->startOffset(prelude));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::Page, m_observerWrapper->startOffset(prelude));
m_observerWrapper->observer().endRuleHeader(endOffset);
}
- consumeDeclarationList(block, StyleRule::Style);
+ consumeDeclarationList(block, StyleRuleType::Style);
return StyleRulePage::create(createStyleProperties(m_parsedProperties, m_context.mode), WTFMove(selectorList));
}
@@ -690,11 +682,11 @@
return nullptr;
if (m_observerWrapper) {
- m_observerWrapper->observer().startRuleHeader(StyleRule::Keyframe, m_observerWrapper->startOffset(prelude));
+ m_observerWrapper->observer().startRuleHeader(StyleRuleType::Keyframe, m_observerWrapper->startOffset(prelude));
m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset(prelude));
}
- consumeDeclarationList(block, StyleRule::Keyframe);
+ consumeDeclarationList(block, StyleRuleType::Keyframe);
return StyleRuleKeyframe::create(WTFMove(keyList), createStyleProperties(m_parsedProperties, m_context.mode));
}
@@ -703,7 +695,7 @@
// This is easier than hooking into the CSSSelectorParser
selectors.consumeWhitespace();
CSSParserTokenRange originalRange = selectors;
- wrapper.observer().startRuleHeader(StyleRule::Style, wrapper.startOffset(originalRange));
+ wrapper.observer().startRuleHeader(StyleRuleType::Style, wrapper.startOffset(originalRange));
while (!selectors.atEnd()) {
const CSSParserToken* selectorStart = &selectors.peek();
@@ -739,15 +731,15 @@
}
}
- consumeDeclarationList(block, StyleRule::Style);
+ consumeDeclarationList(block, StyleRuleType::Style);
return StyleRule::create(createStyleProperties(m_parsedProperties, m_context.mode), m_context.hasDocumentSecurityOrigin, WTFMove(selectorList));
}
-void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, StyleRule::Type ruleType)
+void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, StyleRuleType ruleType)
{
ASSERT(m_parsedProperties.isEmpty());
- bool useObserver = m_observerWrapper && (ruleType == StyleRule::Style || ruleType == StyleRule::Keyframe);
+ bool useObserver = m_observerWrapper && (ruleType == StyleRuleType::Style || ruleType == StyleRuleType::Keyframe);
if (useObserver) {
m_observerWrapper->observer().startRuleBody(m_observerWrapper->previousTokenStartOffset(range));
m_observerWrapper->skipCommentsBefore(range, true);
@@ -776,7 +768,7 @@
}
case AtKeywordToken: {
// FIXME-NEWPARSER: Support apply
- AllowedRulesType allowedRules = /* ruleType == StyleRule::Style && RuntimeEnabledFeatures::cssApplyAtRulesEnabled() ? ApplyRules :*/ NoRules;
+ AllowedRulesType allowedRules = /* ruleType == StyleRuleType::Style && RuntimeEnabledFeatures::cssApplyAtRulesEnabled() ? ApplyRules :*/ NoRules;
RefPtr<StyleRuleBase> rule = consumeAtRule(range, allowedRules);
ASSERT_UNUSED(rule, !rule);
break;
@@ -795,7 +787,7 @@
}
}
-void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Type ruleType)
+void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRuleType ruleType)
{
CSSParserTokenRange rangeCopy = range; // For inspector callbacks
@@ -826,13 +818,13 @@
consumeCustomPropertyValue(range.makeSubRange(&range.peek(), declarationValueEnd), variableName, important);
}
- if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule::Keyframe))
+ if (important && (ruleType == StyleRuleType::FontFace || ruleType == StyleRuleType::Keyframe))
return;
if (propertyID != CSSPropertyInvalid)
consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEnd), propertyID, important, ruleType);
- if (m_observerWrapper && (ruleType == StyleRule::Style || ruleType == StyleRule::Keyframe)) {
+ if (m_observerWrapper && (ruleType == StyleRuleType::Style || ruleType == StyleRuleType::Keyframe)) {
m_observerWrapper->observer().observeProperty(
m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOffset(rangeCopy),
important, m_parsedProperties.size() != propertiesCount);
@@ -845,7 +837,7 @@
m_parsedProperties.append(CSSProperty(CSSPropertyCustom, WTFMove(value), important));
}
-void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID propertyID, bool important, StyleRule::Type ruleType)
+void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID propertyID, bool important, StyleRuleType ruleType)
{
CSSPropertyParser::parseValue(propertyID, important, range, m_context, m_parsedProperties, ruleType);
}
diff --git a/Source/WebCore/css/parser/CSSParserImpl.h b/Source/WebCore/css/parser/CSSParserImpl.h
index 1158430..5eefb60 100644
--- a/Source/WebCore/css/parser/CSSParserImpl.h
+++ b/Source/WebCore/css/parser/CSSParserImpl.h
@@ -138,9 +138,9 @@
RefPtr<StyleRuleKeyframe> consumeKeyframeStyleRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRule> consumeStyleRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
- void consumeDeclarationList(CSSParserTokenRange, StyleRule::Type);
- void consumeDeclaration(CSSParserTokenRange, StyleRule::Type);
- void consumeDeclarationValue(CSSParserTokenRange, CSSPropertyID, bool important, StyleRule::Type);
+ void consumeDeclarationList(CSSParserTokenRange, StyleRuleType);
+ void consumeDeclaration(CSSParserTokenRange, StyleRuleType);
+ void consumeDeclarationValue(CSSParserTokenRange, CSSPropertyID, bool important, StyleRuleType);
void consumeCustomPropertyValue(CSSParserTokenRange, const AtomString& propertyName, bool important);
static std::unique_ptr<Vector<double>> consumeKeyframeKeyList(CSSParserTokenRange);
diff --git a/Source/WebCore/css/parser/CSSParserObserver.h b/Source/WebCore/css/parser/CSSParserObserver.h
index 0b78f4e..16efb83 100644
--- a/Source/WebCore/css/parser/CSSParserObserver.h
+++ b/Source/WebCore/css/parser/CSSParserObserver.h
@@ -33,7 +33,7 @@
class CSSParserObserver {
public:
virtual ~CSSParserObserver() { };
- virtual void startRuleHeader(StyleRule::Type, unsigned offset) = 0;
+ virtual void startRuleHeader(StyleRuleType, unsigned offset) = 0;
virtual void endRuleHeader(unsigned offset) = 0;
virtual void observeSelector(unsigned startOffset, unsigned endOffset) = 0;
virtual void startRuleBody(unsigned offset) = 0;
diff --git a/Source/WebCore/css/parser/CSSPropertyParser.cpp b/Source/WebCore/css/parser/CSSPropertyParser.cpp
index cc05ef0..53ee4a3 100644
--- a/Source/WebCore/css/parser/CSSPropertyParser.cpp
+++ b/Source/WebCore/css/parser/CSSPropertyParser.cpp
@@ -259,7 +259,7 @@
addProperty(longhands[i], property, value.copyRef(), important);
}
-bool CSSPropertyParser::parseValue(CSSPropertyID propertyID, bool important, const CSSParserTokenRange& range, const CSSParserContext& context, ParsedPropertyVector& parsedProperties, StyleRule::Type ruleType)
+bool CSSPropertyParser::parseValue(CSSPropertyID propertyID, bool important, const CSSParserTokenRange& range, const CSSParserContext& context, ParsedPropertyVector& parsedProperties, StyleRuleType ruleType)
{
int parsedPropertiesSize = parsedProperties.size();
@@ -267,11 +267,11 @@
bool parseSuccess;
#if ENABLE(CSS_DEVICE_ADAPTATION)
- if (ruleType == StyleRule::Viewport)
+ if (ruleType == StyleRuleType::Viewport)
parseSuccess = parser.parseViewportDescriptor(propertyID, important);
else
#endif
- if (ruleType == StyleRule::FontFace)
+ if (ruleType == StyleRuleType::FontFace)
parseSuccess = parser.parseFontFaceDescriptor(propertyID);
else
parseSuccess = parser.parseValueStart(propertyID, important);
diff --git a/Source/WebCore/css/parser/CSSPropertyParser.h b/Source/WebCore/css/parser/CSSPropertyParser.h
index 65e8605..56520d9 100644
--- a/Source/WebCore/css/parser/CSSPropertyParser.h
+++ b/Source/WebCore/css/parser/CSSPropertyParser.h
@@ -42,7 +42,7 @@
public:
static bool parseValue(CSSPropertyID, bool important,
const CSSParserTokenRange&, const CSSParserContext&,
- Vector<CSSProperty, 256>&, StyleRule::Type);
+ Vector<CSSProperty, 256>&, StyleRuleType);
// Parses a non-shorthand CSS property
static RefPtr<CSSValue> parseSingleValue(CSSPropertyID, const CSSParserTokenRange&, const CSSParserContext&);
diff --git a/Source/WebCore/css/parser/CSSTokenizer.cpp b/Source/WebCore/css/parser/CSSTokenizer.cpp
index 82931bf..ca6a18c 100644
--- a/Source/WebCore/css/parser/CSSTokenizer.cpp
+++ b/Source/WebCore/css/parser/CSSTokenizer.cpp
@@ -327,8 +327,7 @@
CSSParserToken CSSTokenizer::letterU(UChar cc)
{
if (m_input.peekWithoutReplacement(0) == '+'
- && (isASCIIHexDigit(m_input.peekWithoutReplacement(1))
- || m_input.peekWithoutReplacement(1) == '?')) {
+ && (isASCIIHexDigit(m_input.peekWithoutReplacement(1)) || m_input.peekWithoutReplacement(1) == '?')) {
m_input.advance();
return consumeUnicodeRange();
}
diff --git a/Source/WebCore/inspector/InspectorStyleSheet.cpp b/Source/WebCore/inspector/InspectorStyleSheet.cpp
index e5a8bf5..b416bb7 100644
--- a/Source/WebCore/inspector/InspectorStyleSheet.cpp
+++ b/Source/WebCore/inspector/InspectorStyleSheet.cpp
@@ -101,11 +101,11 @@
static void flattenSourceData(RuleSourceDataList& dataList, RuleSourceDataList& target)
{
for (auto& data : dataList) {
- if (data->type == WebCore::StyleRule::Style)
+ if (data->type == WebCore::StyleRuleType::Style)
target.append(data.copyRef());
- else if (data->type == WebCore::StyleRule::Media)
+ else if (data->type == WebCore::StyleRuleType::Media)
flattenSourceData(data->childRules, target);
- else if (data->type == WebCore::StyleRule::Supports)
+ else if (data->type == WebCore::StyleRuleType::Supports)
flattenSourceData(data->childRules, target);
}
}
@@ -154,7 +154,7 @@
}
private:
- void startRuleHeader(StyleRule::Type, unsigned) override;
+ void startRuleHeader(StyleRuleType, unsigned) override;
void endRuleHeader(unsigned) override;
void observeSelector(unsigned startOffset, unsigned endOffset) override;
void startRuleBody(unsigned) override;
@@ -174,7 +174,7 @@
RuleSourceDataList* m_ruleSourceDataResult { nullptr };
};
-void StyleSheetHandler::startRuleHeader(StyleRule::Type type, unsigned offset)
+void StyleSheetHandler::startRuleHeader(StyleRuleType type, unsigned offset)
{
// Pop off data for a previous invalid rule.
if (m_currentRuleData)
@@ -1568,7 +1568,7 @@
Ref<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::ruleSourceData() const
{
if (m_styleText.isEmpty()) {
- auto result = CSSRuleSourceData::create(StyleRule::Style);
+ auto result = CSSRuleSourceData::create(StyleRuleType::Style);
result->ruleBodyRange.start = 0;
result->ruleBodyRange.end = 0;
return result;