Add CSS parser support for the highlight pseudoelement
https://bugs.webkit.org/show_bug.cgi?id=204902
Reviewed by Antti Koivisto.
Add basic CSS parsing support for ::highlight(), per
https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/highlight/explainer.md
* css/CSSSelector.cpp:
(WebCore::CSSSelector::pseudoId):
(WebCore::CSSSelector::parsePseudoElementType):
* css/CSSSelector.h:
* css/SelectorPseudoElementTypeMap.in:
* css/parser/CSSSelectorParser.cpp:
(WebCore::CSSSelectorParser::consumePseudo):
* rendering/style/RenderStyleConstants.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@253158 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 08d0f00..d110c29 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -426,6 +426,25 @@
(WebCore::hasHadRecentUserInteraction):
(WebCore::ResourceLoadStatistics::toString const):
+2019-12-05 Simon Fraser <simon.fraser@apple.com>
+
+ Add CSS parser support for the highlight pseudoelement
+ https://bugs.webkit.org/show_bug.cgi?id=204902
+
+ Reviewed by Antti Koivisto.
+
+ Add basic CSS parsing support for ::highlight(), per
+ https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/highlight/explainer.md
+
+ * css/CSSSelector.cpp:
+ (WebCore::CSSSelector::pseudoId):
+ (WebCore::CSSSelector::parsePseudoElementType):
+ * css/CSSSelector.h:
+ * css/SelectorPseudoElementTypeMap.in:
+ * css/parser/CSSSelectorParser.cpp:
+ (WebCore::CSSSelectorParser::consumePseudo):
+ * rendering/style/RenderStyleConstants.h:
+
2019-12-04 Louie Livon-Bemel <llivonbemel@apple.com>
Add exclusion rule for text manipulation SPI to exclude based on element class
diff --git a/Source/WebCore/css/CSSSelector.cpp b/Source/WebCore/css/CSSSelector.cpp
index 30af91e..ca989dd 100644
--- a/Source/WebCore/css/CSSSelector.cpp
+++ b/Source/WebCore/css/CSSSelector.cpp
@@ -275,6 +275,8 @@
return PseudoId::FirstLetter;
case PseudoElementSelection:
return PseudoId::Selection;
+ case PseudoElementHighlight:
+ return PseudoId::Highlight;
case PseudoElementMarker:
return PseudoId::Marker;
case PseudoElementBefore:
@@ -314,11 +316,16 @@
{
if (name.isNull())
return PseudoElementUnknown;
+
auto type = parsePseudoElementString(name);
if (type == PseudoElementUnknown) {
if (name.startsWith("-webkit-"))
type = PseudoElementWebKitCustom;
}
+
+ if (type == PseudoElementHighlight && !RuntimeEnabledFeatures::sharedFeatures().highlightAPIEnabled())
+ return PseudoElementUnknown;
+
if (type == PseudoElementPart && !RuntimeEnabledFeatures::sharedFeatures().cssShadowPartsEnabled())
return PseudoElementUnknown;
diff --git a/Source/WebCore/css/CSSSelector.h b/Source/WebCore/css/CSSSelector.h
index ea2c102..f4c335f 100644
--- a/Source/WebCore/css/CSSSelector.h
+++ b/Source/WebCore/css/CSSSelector.h
@@ -181,6 +181,7 @@
#endif
PseudoElementFirstLetter,
PseudoElementFirstLine,
+ PseudoElementHighlight,
PseudoElementMarker,
PseudoElementPart,
PseudoElementResizer,
diff --git a/Source/WebCore/css/SelectorPseudoElementTypeMap.in b/Source/WebCore/css/SelectorPseudoElementTypeMap.in
index c07db83..a7bcc10 100644
--- a/Source/WebCore/css/SelectorPseudoElementTypeMap.in
+++ b/Source/WebCore/css/SelectorPseudoElementTypeMap.in
@@ -5,6 +5,7 @@
#endif
first-letter
first-line
+highlight
marker
part
placeholder, PseudoElementWebKitCustom
diff --git a/Source/WebCore/css/parser/CSSSelectorParser.cpp b/Source/WebCore/css/parser/CSSSelectorParser.cpp
index 97363e6..538ff10 100644
--- a/Source/WebCore/css/parser/CSSSelectorParser.cpp
+++ b/Source/WebCore/css/parser/CSSSelectorParser.cpp
@@ -611,7 +611,6 @@
default:
break;
}
-
}
if (selector->match() == CSSSelector::PseudoElement) {
@@ -627,6 +626,17 @@
return selector;
}
#endif
+ case CSSSelector::PseudoElementHighlight: {
+ DisallowPseudoElementsScope scope(this);
+
+ auto& ident = block.consumeIncludingWhitespace();
+ if (ident.type() != IdentToken)
+ return nullptr;
+
+ auto argumentList = makeUnique<Vector<AtomString>>();
+ argumentList->append(ident.value().toAtomString());
+ return selector;
+ }
case CSSSelector::PseudoElementPart: {
auto argumentList = makeUnique<Vector<AtomString>>();
do {
diff --git a/Source/WebCore/rendering/style/RenderStyleConstants.h b/Source/WebCore/rendering/style/RenderStyleConstants.h
index aa924fe..f8d0673 100644
--- a/Source/WebCore/rendering/style/RenderStyleConstants.h
+++ b/Source/WebCore/rendering/style/RenderStyleConstants.h
@@ -82,13 +82,14 @@
};
// Static pseudo styles. Dynamic ones are produced on the fly.
-enum class PseudoId : uint8_t {
+enum class PseudoId : uint16_t {
// The order must be None, public IDs, and then internal IDs.
None,
// Public:
FirstLine,
FirstLetter,
+ Highlight,
Marker,
Before,
After,