Diff
Modified: trunk/LayoutTests/ChangeLog (133576 => 133577)
--- trunk/LayoutTests/ChangeLog 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/LayoutTests/ChangeLog 2012-11-06 10:43:46 UTC (rev 133577)
@@ -1,5 +1,16 @@
2012-11-06 Shinya Kawanaka <shin...@chromium.org>
+ [Shadow] Using isUnknownPseudoElement() for shadow pseudo id seems confusing
+ https://bugs.webkit.org/show_bug.cgi?id=100826
+
+ Reviewed by Hajime Morita.
+
+ * fast/dom/shadow/shadow-nested-pseudo-id.html: Fixed a testcase so that shadowPseudoId starts with 'x-'.
+ * fast/dom/shadow/shadow-pseudo-id-expected.html: Added.
+ * fast/dom/shadow/shadow-pseudo-id.html: Added.
+
+2012-11-06 Shinya Kawanaka <shin...@chromium.org>
+
[Shadow] ShadowRoot should know the existence of elements having ElementShadow.
https://bugs.webkit.org/show_bug.cgi?id=100922
Modified: trunk/LayoutTests/fast/dom/shadow/shadow-nested-pseudo-id.html (133576 => 133577)
--- trunk/LayoutTests/fast/dom/shadow/shadow-nested-pseudo-id.html 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-nested-pseudo-id.html 2012-11-06 10:43:46 UTC (rev 133577)
@@ -4,15 +4,15 @@
<script src=""
<style>
-p::-shadow-child {
+p::x-shadow-child {
color: red;
}
-a::-nested-shadow-child {
+a::x-nested-shadow-child {
color: blue;
}
-p::-shadow-child::-nested-shadow-child {
+p::x-shadow-child::x-nested-shadow-child {
background-color: green;
}
@@ -39,9 +39,9 @@
fail("You need window.internals to run this test");
var host = document.getElementById("host");
-var tuple = buildShadowWithOneChild(host, "a", "-shadow-child");
+var tuple = buildShadowWithOneChild(host, "a", "x-shadow-child");
shouldBe("window.getComputedStyle(tuple.shadowChild).color", "'rgb(255, 0, 0)'");
-var shadowTuple = buildShadowWithOneChild(tuple.shadowChild, "b", "-nested-shadow-child");
+var shadowTuple = buildShadowWithOneChild(tuple.shadowChild, "b", "x-nested-shadow-child");
shouldBe("window.getComputedStyle(shadowTuple.shadowChild).color", "'rgb(0, 0, 255)'");
shouldBe("window.getComputedStyle(shadowTuple.shadowChild).backgroundColor", "'rgb(0, 128, 0)'");
Added: trunk/LayoutTests/fast/dom/shadow/shadow-pseudo-id-expected.html (0 => 133577)
--- trunk/LayoutTests/fast/dom/shadow/shadow-pseudo-id-expected.html (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-pseudo-id-expected.html 2012-11-06 10:43:46 UTC (rev 133577)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+
+<p>This test checks a custom pseudo element selector is valid only if it starts with 'x-'</p>
+
+<div id="console"></div>
+<div id="host1"><div style="color:red">pseudo is x-shadow: This should be red.</div></div>
+<div id="host2"><div>pseudo is -test: This should not be red.</div></div>
+<div id="host2"><div>pseudo is foobar: This should not be red.</div></div>
+
+</body>
+</html>
Added: trunk/LayoutTests/fast/dom/shadow/shadow-pseudo-id.html (0 => 133577)
--- trunk/LayoutTests/fast/dom/shadow/shadow-pseudo-id.html (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-pseudo-id.html 2012-11-06 10:43:46 UTC (rev 133577)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+div::x-shadow {
+ color: red;
+}
+
+div::-test {
+ color: red;
+}
+
+div::foobar {
+ color: red;
+}
+</style>
+</head>
+<body>
+
+<p>This test checks a custom pseudo element selector is valid only if it starts with 'x-'</p>
+
+<div id="console"></div>
+<div id="host1"></div>
+<div id="host2"></div>
+<div id="host3"></div>
+
+<script>
+var shadowRoot1 = new WebKitShadowRoot(host1);
+var div1 = document.createElement('div');
+div1.innerHTML = "pseudo is x-shadow: This should be red.";
+div1.pseudo = "x-shadow";
+shadowRoot1.appendChild(div1);
+
+var shadowRoot2 = new WebKitShadowRoot(host2);
+var div2 = document.createElement('div');
+div2.innerHTML = "pseudo is -test: This should not be red.";
+div2.pseudo = "-test";
+shadowRoot2.appendChild(div2);
+
+var shadowRoot3 = new WebKitShadowRoot(host3);
+var div3 = document.createElement('div');
+div3.innerHTML = "pseudo is foobar: This should not be red.";
+div3.pseudo = "foobar";
+shadowRoot3.appendChild(div3);
+</script>
+
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (133576 => 133577)
--- trunk/Source/WebCore/ChangeLog 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/ChangeLog 2012-11-06 10:43:46 UTC (rev 133577)
@@ -1,5 +1,53 @@
2012-11-06 Shinya Kawanaka <shin...@chromium.org>
+ [Shadow] Using isUnknownPseudoElement() for shadow pseudo id seems confusing
+ https://bugs.webkit.org/show_bug.cgi?id=100826
+
+ Reviewed by Hajime Morita.
+
+ We used isUnknownPseudoElement() for these 3 meanings: 1) the element is a custom pseudo-element (starting with 'x-'),
+ 2) the element is a webkit custom pseudo-element (starting with '-webkit-'), and 3) the element has an unknown type.
+ We would like to distinguish them when parsing CSSSelector types. Also, we disable using (3) type for using
+ shadowPseudoId.
+
+ In this patch, we allow using WebKitCustomPseudoElement in AuthorShadowRoot, and CustomPseudoElement in
+ UAShadowRoot. However, we will disable them later.
+
+ Test: fast/dom/shadow/shadow-pseudo-id.html
+
+ * css/CSSGrammar.y.in: Now we can discard UNKNOWN type. It should not match anything.
+ * css/CSSParser.cpp:
+ (WebCore::CSSParser::updateSpecifiersWithElementName):
+ (WebCore::CSSParser::updateSpecifiers):
+ * css/CSSParserValues.h:
+ (WebCore::CSSParserSelector::isCustomPseudoElement):
+ (CSSParserSelector):
+ * css/CSSSelector.cpp:
+ (WebCore::CSSSelector::pseudoId):
+ (WebCore::CSSSelector::parsePseudoType):
+ (WebCore::CSSSelector::isCustomPseudoType): Returns true if the type is PseudoUserAgentCustomElement or PseudoWebKitCustomElement.
+ (WebCore::CSSSelector::extractPseudoType):
+ * css/CSSSelector.h:
+ (CSSSelector):
+ (WebCore::CSSSelector::isCustomPseudoElement):
+ (WebCore):
+ * css/CSSSelectorList.cpp:
+ (WebCore::SelectorHasInvalidSelectorFunctor::operator()): We will reject all selectors which were judged as
+ UNKNOWN before. i.e. It contians all three types for now.
+ (WebCore::CSSSelectorList::hasInvalidSelector): Renamed.
+ * css/CSSSelectorList.h:
+ (CSSSelectorList):
+ * css/RuleSet.cpp:
+ (WebCore::RuleSet::addRule):
+ * css/SelectorChecker.cpp:
+ (WebCore::SelectorChecker::checkSelector):
+ * dom/Element.cpp:
+ (WebCore::Element::setShadowPseudoId):
+ * dom/SelectorQuery.cpp:
+ (WebCore::SelectorQueryCache::add):
+
+2012-11-06 Shinya Kawanaka <shin...@chromium.org>
+
[Shadow] ShadowRoot should know the existence of elements having ElementShadow.
https://bugs.webkit.org/show_bug.cgi?id=100922
Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (133576 => 133577)
--- trunk/Source/WebCore/css/CSSGrammar.y.in 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in 2012-11-06 10:43:46 UTC (rev 133577)
@@ -1307,7 +1307,9 @@
$3.lower();
$$->setValue($3);
// FIXME: This call is needed to force selector to compute the pseudoType early enough.
- $$->pseudoType();
+ CSSSelector::PseudoType type = $$->pseudoType();
+ if (type == CSSSelector::PseudoUnknown)
+ $$ = 0;
}
// use by :-webkit-any.
// FIXME: should we support generic selectors here or just simple_selectors?
Modified: trunk/Source/WebCore/css/CSSParser.cpp (133576 => 133577)
--- trunk/Source/WebCore/css/CSSParser.cpp 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2012-11-06 10:43:46 UTC (rev 133577)
@@ -10257,7 +10257,7 @@
{
AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleSheet ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace;
QualifiedName tag = QualifiedName(namespacePrefix, elementName, determinedNamespace);
- if (!specifiers->isUnknownPseudoElement()) {
+ if (!specifiers->isCustomPseudoElement()) {
specifiers->setTag(tag);
return;
}
@@ -10266,7 +10266,7 @@
CSSParserSelector* history = specifiers;
while (history->tagHistory()) {
history = history->tagHistory();
- if (history->isUnknownPseudoElement() || history->hasShadowDescendant())
+ if (history->isCustomPseudoElement() || history->hasShadowDescendant())
lastShadowDescendant = history;
}
@@ -10285,12 +10285,12 @@
CSSParserSelector* CSSParser::updateSpecifiers(CSSParserSelector* specifiers, CSSParserSelector* newSpecifier)
{
- if (newSpecifier->isUnknownPseudoElement()) {
+ if (newSpecifier->isCustomPseudoElement()) {
// Unknown pseudo element always goes at the top of selector chain.
newSpecifier->appendTagHistory(CSSSelector::ShadowDescendant, sinkFloatingSelector(specifiers));
return newSpecifier;
}
- if (specifiers->isUnknownPseudoElement()) {
+ if (specifiers->isCustomPseudoElement()) {
// Specifiers for unknown pseudo element go right behind it in the chain.
specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier), CSSSelector::ShadowDescendant);
return specifiers;
Modified: trunk/Source/WebCore/css/CSSParserValues.h (133576 => 133577)
--- trunk/Source/WebCore/css/CSSParserValues.h 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/CSSParserValues.h 2012-11-06 10:43:46 UTC (rev 133577)
@@ -191,7 +191,8 @@
void adoptSelectorVector(CSSSelectorVector&);
CSSSelector::PseudoType pseudoType() const { return m_selector->pseudoType(); }
- bool isUnknownPseudoElement() const { return m_selector->isUnknownPseudoElement(); }
+ bool isCustomPseudoElement() const { return m_selector->isCustomPseudoElement(); }
+
bool isSimple() const { return !m_tagHistory && m_selector->isSimple(); }
bool hasShadowDescendant() const;
Modified: trunk/Source/WebCore/css/CSSSelector.cpp (133576 => 133577)
--- trunk/Source/WebCore/css/CSSSelector.cpp 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/CSSSelector.cpp 2012-11-06 10:43:46 UTC (rev 133577)
@@ -218,6 +218,8 @@
case PseudoRightPage:
case PseudoInRange:
case PseudoOutOfRange:
+ case PseudoUserAgentCustomElement:
+ case PseudoWebKitCustomElement:
return NOPSEUDO;
case PseudoNotParsed:
ASSERT_NOT_REACHED();
@@ -387,12 +389,22 @@
return PseudoUnknown;
HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoType = nameToPseudoTypeMap();
HashMap<AtomicStringImpl*, CSSSelector::PseudoType>::iterator slot = nameToPseudoType->find(name.impl());
- return slot == nameToPseudoType->end() ? PseudoUnknown : slot->value;
+
+ if (slot != nameToPseudoType->end())
+ return slot->value;
+
+ if (name.startsWith("-webkit-"))
+ return PseudoWebKitCustomElement;
+ if (name.startsWith("x-"))
+ return PseudoUserAgentCustomElement;
+
+ return PseudoUnknown;
}
-bool CSSSelector::isUnknownPseudoType(const AtomicString& name)
+bool CSSSelector::isCustomPseudoType(const AtomicString& name)
{
- return parsePseudoType(name) == PseudoUnknown;
+ CSSSelector::PseudoType type = parsePseudoType(name);
+ return type == PseudoUserAgentCustomElement || type == PseudoWebKitCustomElement;
}
void CSSSelector::extractPseudoType() const
@@ -420,6 +432,8 @@
case PseudoScrollbarTrack:
case PseudoScrollbarTrackPiece:
case PseudoSelection:
+ case PseudoUserAgentCustomElement:
+ case PseudoWebKitCustomElement:
element = true;
break;
case PseudoUnknown:
Modified: trunk/Source/WebCore/css/CSSSelector.h (133576 => 133577)
--- trunk/Source/WebCore/css/CSSSelector.h 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/CSSSelector.h 2012-11-06 10:43:46 UTC (rev 133577)
@@ -154,6 +154,8 @@
#endif
PseudoInRange,
PseudoOutOfRange,
+ PseudoUserAgentCustomElement,
+ PseudoWebKitCustomElement,
};
enum MarginBoxType {
@@ -183,7 +185,7 @@
}
static PseudoType parsePseudoType(const AtomicString&);
- static bool isUnknownPseudoType(const AtomicString&);
+ static bool isCustomPseudoType(const AtomicString&);
static PseudoId pseudoId(PseudoType);
// Selectors are kept in an array by CSSSelectorList. The next component of the selector is
@@ -211,6 +213,7 @@
bool matchesPseudoElement() const;
bool isUnknownPseudoElement() const;
+ bool isCustomPseudoElement() const;
bool isSiblingSelector() const;
bool isAttributeSelector() const;
@@ -291,6 +294,11 @@
return m_match == PseudoElement && m_pseudoType == PseudoUnknown;
}
+inline bool CSSSelector::isCustomPseudoElement() const
+{
+ return m_match == PseudoElement && (m_pseudoType == PseudoUserAgentCustomElement || m_pseudoType == PseudoWebKitCustomElement);
+}
+
inline bool CSSSelector::isSiblingSelector() const
{
PseudoType type = pseudoType();
Modified: trunk/Source/WebCore/css/CSSSelectorList.cpp (133576 => 133577)
--- trunk/Source/WebCore/css/CSSSelectorList.cpp 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/CSSSelectorList.cpp 2012-11-06 10:43:46 UTC (rev 133577)
@@ -197,17 +197,17 @@
return forEachSelector(functor, this);
}
-class SelectorHasUnknownPseudoElementFunctor {
+class SelectorHasInvalidSelectorFunctor {
public:
bool operator()(CSSSelector* selector)
{
- return selector->isUnknownPseudoElement();
+ return selector->isUnknownPseudoElement() || selector->isCustomPseudoElement();
}
};
-bool CSSSelectorList::hasUnknownPseudoElements() const
+bool CSSSelectorList::hasInvalidSelector() const
{
- SelectorHasUnknownPseudoElementFunctor functor;
+ SelectorHasInvalidSelectorFunctor functor;
return forEachSelector(functor, this);
}
Modified: trunk/Source/WebCore/css/CSSSelectorList.h (133576 => 133577)
--- trunk/Source/WebCore/css/CSSSelectorList.h 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/CSSSelectorList.h 2012-11-06 10:43:46 UTC (rev 133577)
@@ -59,7 +59,7 @@
}
bool selectorsNeedNamespaceResolution();
- bool hasUnknownPseudoElements() const;
+ bool hasInvalidSelector() const;
String selectorsText() const;
Modified: trunk/Source/WebCore/css/RuleSet.cpp (133576 => 133577)
--- trunk/Source/WebCore/css/RuleSet.cpp 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/RuleSet.cpp 2012-11-06 10:43:46 UTC (rev 133577)
@@ -229,7 +229,7 @@
addToRuleSet(selector->value().impl(), m_classRules, ruleData);
return;
}
- if (selector->isUnknownPseudoElement()) {
+ if (selector->isCustomPseudoElement()) {
addToRuleSet(selector->value().impl(), m_shadowPseudoElementRules, ruleData);
return;
}
Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (133576 => 133577)
--- trunk/Source/WebCore/css/SelectorChecker.cpp 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp 2012-11-06 10:43:46 UTC (rev 133577)
@@ -446,7 +446,7 @@
return SelectorFailsLocally;
if (context.selector->m_match == CSSSelector::PseudoElement) {
- if (context.selector->isUnknownPseudoElement()) {
+ if (context.selector->isCustomPseudoElement()) {
if (context.element->shadowPseudoId() != context.selector->value())
return SelectorFailsLocally;
} else {
Modified: trunk/Source/WebCore/dom/Element.cpp (133576 => 133577)
--- trunk/Source/WebCore/dom/Element.cpp 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/dom/Element.cpp 2012-11-06 10:43:46 UTC (rev 133577)
@@ -1359,7 +1359,7 @@
void Element::setShadowPseudoId(const AtomicString& id, ExceptionCode& ec)
{
- if (!CSSSelector::isUnknownPseudoType(id)) {
+ if (!CSSSelector::isCustomPseudoType(id)) {
ec = SYNTAX_ERR;
return;
}
Modified: trunk/Source/WebCore/dom/SelectorQuery.cpp (133576 => 133577)
--- trunk/Source/WebCore/dom/SelectorQuery.cpp 2012-11-06 10:26:08 UTC (rev 133576)
+++ trunk/Source/WebCore/dom/SelectorQuery.cpp 2012-11-06 10:43:46 UTC (rev 133577)
@@ -180,7 +180,7 @@
CSSSelectorList selectorList;
parser.parseSelector(selectors, selectorList);
- if (!selectorList.first() || selectorList.hasUnknownPseudoElements()) {
+ if (!selectorList.first() || selectorList.hasInvalidSelector()) {
ec = SYNTAX_ERR;
return 0;
}