Commit 98dd4e48 authored by tasak@google.com's avatar tasak@google.com

Rename :ancestor to :host-context.

The :host-context() functional pseudo-class tests whether there is an ancestor, outside the shadow tree,
which matches a particular selector. Its syntax is:

   :host-context( <compound-selector> )

Spec link: http://drafts.csswg.org/css-scoping/#host-selector

BUG=354287
TEST=no new tests because just renaming.

Review URL: https://codereview.chromium.org/210813003

git-svn-id: svn://svn.chromium.org/blink/trunk@170016 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 096eaf88
......@@ -17,7 +17,7 @@ PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
:host in a shadow tree should match its shadow host.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
:host with :ancestor in a shadow tree should match its shadow host.
:host with :host-context in a shadow tree should match its shadow host.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
:host takes simple selectors and matches when one of the simple selectors matches.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
......
......@@ -127,13 +127,13 @@ backgroundColorShouldBe('host', 'rgb(0, 128, 0)');
cleanUp();
debug(':host with :ancestor in a shadow tree should match its shadow host.');
debug(':host with :host-context in a shadow tree should match its shadow host.');
sandbox.appendChild(
createDOM('div', {'id': 'host', 'class': 'foobar'},
createShadowRoot(
createDOM('style', {},
document.createTextNode(':host(:ancestor(body.mytheme)) { background-color: green; }')),
document.createTextNode(':host(:host-context(body.mytheme)) { background-color: green; }')),
createDOM('div', {},
document.createTextNode('Hello')))));
......
Test that :ancestor(:first-child) is re-evaluated when :first-child changes.
Test that :host-context(:first-child) is re-evaluated when :first-child changes.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......
......@@ -7,7 +7,7 @@
</div>
<script>
description("Test that :ancestor(:first-child) is re-evaluated when :first-child changes.");
description("Test that :host-context(:first-child) is re-evaluated when :first-child changes.");
var test = document.getElementById("test");
var first = document.getElementById("first");
......@@ -16,7 +16,7 @@ first.appendChild(
createDOM("div", {"id": "host"},
createShadowRoot(
createDOM('style', {},
document.createTextNode(":ancestor(#first:first-child) { background-color: red; }")),
document.createTextNode(":host-context(#first:first-child) { background-color: red; }")),
createDOM('div', {},
document.createTextNode("You should see no red.")))));
......
Test whether :ancestor matches a shadow host correctly.
Test whether :host-context matches a shadow host correctly.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
:ancestor out of shadow tree should not match any shadow hosts.
:host-context out of shadow tree should not match any shadow hosts.
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
:ancestor with * should not match any shadow hosts.
:host-context with * should not match any shadow hosts.
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
:ancestor with tag selector should not match any shadow hosts.
:host-context with tag selector should not match any shadow hosts.
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
:ancestor with class selector should not match any shadow hosts.
:host-context with class selector should not match any shadow hosts.
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
:ancestor with id selector should not match any shadow hosts.
:host-context with id selector should not match any shadow hosts.
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
:ancestor with attribute selector should not match any shadow hosts.
:host-context with attribute selector should not match any shadow hosts.
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
:ancestor in a shadow tree should match its shadow host.
:host-context in a shadow tree should match its shadow host.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
:ancestor with :host in a shadow tree should match its shadow host.
:host-context with :host in a shadow tree should match its shadow host.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
:ancestor takes simple selectors and matches when one of the simple selectors matches.
:host-context takes simple selectors and matches when one of the simple selectors matches.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
:ancestor matches a shadow host in just a nested shadow tree, not all enclosing shadow trees.
:host-context matches a shadow host in just a nested shadow tree, not all enclosing shadow trees.
PASS backgroundColorOf('host1') is "rgba(0, 0, 0, 0)"
PASS backgroundColorOf('host1/host2') is "rgb(0, 128, 0)"
:ancestor matches based on a composed tree.
:host-context matches based on a composed tree.
PASS backgroundColorOf('host/target') is "rgb(0, 128, 0)"
:ancestor matches based on a composed tree when having multiple shadow roots.
:host-context matches based on a composed tree when having multiple shadow roots.
PASS backgroundColorOf('host/targetA') is "rgba(0, 0, 0, 0)"
PASS backgroundColorOf('host/targetB') is "rgb(0, 128, 0)"
PASS backgroundColorOf('host/targetC') is "rgb(0, 128, 0)"
:ancestor is updated when its matched ancestor changes className or id.
:host-context is updated when its matched ancestor changes className or id.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
PASS backgroundColorOf('host') is "rgba(0, 0, 0, 0)"
Compare :ancestor with :ancestor.
Compare :host-context with :host-context.
PASS backgroundColorOf('host') is "rgb(0, 128, 0)"
PASS backgroundColorOf('host') is "rgb(255, 0, 0)"
PASS backgroundColorOf('host/target') is "rgb(0, 128, 0)"
......
......@@ -24,10 +24,10 @@ PASS fooShadowRoot.querySelectorAll(":host(div#foo-host) /shadow/ span").length
PASS fooShadowRoot.querySelectorAll(":host(div#foo-host) /shadow/ span")[0].id is "not-top"
PASS fooShadowRoot.querySelectorAll(":host(div#foo-host) /shadow/ span")[1].id is "top"
PASS fooShadowRoot.querySelectorAll(":host(div#foo-host) /shadow/ span")[2].id is "inner-host"
PASS fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span").length is 3
PASS fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span")[0].id is "not-top"
PASS fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span")[1].id is "top"
PASS fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span")[2].id is "inner-host"
PASS fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span").length is 3
PASS fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span")[0].id is "not-top"
PASS fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span")[1].id is "top"
PASS fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span")[2].id is "inner-host"
PASS barHost.querySelectorAll("#bar-host /shadow/ span").length is 1
PASS barHost.querySelectorAll("#bar-host /shadow/ span")[0].id is "nested"
PASS barHost.querySelectorAll(":host :scope span").length is 1
......@@ -40,10 +40,10 @@ PASS barShadowRoot.querySelectorAll(":host(div#bar-host) /shadow/ span").length
PASS barShadowRoot.querySelectorAll(":host(div#bar-host) /shadow/ span")[0].id is "nested"
PASS barShadowRoot.querySelectorAll(":host(div#bar-host) /deep/ span").length is 1
PASS barShadowRoot.querySelectorAll(":host(div#bar-host) /deep/ span")[0].id is "nested"
PASS barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /shadow/ span").length is 1
PASS barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /shadow/ span")[0].id is "nested"
PASS barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /deep/ span").length is 1
PASS barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /deep/ span")[0].id is "nested"
PASS barShadowRoot.querySelectorAll(":host-context(div#foo-host) /shadow/ span").length is 1
PASS barShadowRoot.querySelectorAll(":host-context(div#foo-host) /shadow/ span")[0].id is "nested"
PASS barShadowRoot.querySelectorAll(":host-context(div#foo-host) /deep/ span").length is 1
PASS barShadowRoot.querySelectorAll(":host-context(div#foo-host) /deep/ span")[0].id is "nested"
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -55,11 +55,11 @@ shouldBe('fooShadowRoot.querySelectorAll(":host(div#foo-host) /shadow/ span")[0]
shouldBe('fooShadowRoot.querySelectorAll(":host(div#foo-host) /shadow/ span")[1].id', '"top"');
shouldBe('fooShadowRoot.querySelectorAll(":host(div#foo-host) /shadow/ span")[2].id', '"inner-host"');
// :ancestor in foo's shadow tree can match div#foo-host.
shouldBe('fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span").length', '3');
shouldBe('fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span")[0].id', '"not-top"');
shouldBe('fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span")[1].id', '"top"');
shouldBe('fooShadowRoot.querySelectorAll(":ancestor(body) /shadow/ span")[2].id', '"inner-host"');
// :host-context in foo's shadow tree can match div#foo-host.
shouldBe('fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span").length', '3');
shouldBe('fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span")[0].id', '"not-top"');
shouldBe('fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span")[1].id', '"top"');
shouldBe('fooShadowRoot.querySelectorAll(":host-context(body) /shadow/ span")[2].id', '"inner-host"');
var barHost = fooShadowRoot.getElementById('bar-host');
shouldBe('barHost.querySelectorAll("#bar-host /shadow/ span").length', '1');
......@@ -78,10 +78,10 @@ shouldBe('barShadowRoot.querySelectorAll(":host(div#bar-host) /shadow/ span")[0]
shouldBe('barShadowRoot.querySelectorAll(":host(div#bar-host) /deep/ span").length', '1');
shouldBe('barShadowRoot.querySelectorAll(":host(div#bar-host) /deep/ span")[0].id', '"nested"');
shouldBe('barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /shadow/ span").length', '1');
shouldBe('barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /shadow/ span")[0].id', '"nested"');
shouldBe('barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /deep/ span").length', '1');
shouldBe('barShadowRoot.querySelectorAll(":ancestor(div#foo-host) /deep/ span")[0].id', '"nested"');
shouldBe('barShadowRoot.querySelectorAll(":host-context(div#foo-host) /shadow/ span").length', '1');
shouldBe('barShadowRoot.querySelectorAll(":host-context(div#foo-host) /shadow/ span")[0].id', '"nested"');
shouldBe('barShadowRoot.querySelectorAll(":host-context(div#foo-host) /deep/ span").length', '1');
shouldBe('barShadowRoot.querySelectorAll(":host-context(div#foo-host) /deep/ span")[0].id', '"nested"');
</script>
</html>
......@@ -116,7 +116,7 @@ static inline bool isCSSTokenAString(int yytype)
case FUNCTION:
case ANYFUNCTION:
case HOSTFUNCTION:
case ANCESTORFUNCTION:
case HOSTCONTEXTFUNCTION:
case NOTFUNCTION:
case CALCFUNCTION:
case MINFUNCTION:
......@@ -267,7 +267,7 @@ inline static CSSParserValue makeIdentValue(CSSParserString string)
%token <string> MINFUNCTION
%token <string> MAXFUNCTION
%token <string> HOSTFUNCTION
%token <string> ANCESTORFUNCTION
%token <string> HOSTCONTEXTFUNCTION
%token <string> UNICODERANGE
......@@ -1481,27 +1481,27 @@ pseudo:
| ':' HOSTFUNCTION selector_recovery closing_parenthesis {
YYERROR;
}
| ':' ANCESTORFUNCTION maybe_space simple_selector_list maybe_space closing_parenthesis {
// used by :host-context()
| ':' HOSTCONTEXTFUNCTION maybe_space simple_selector_list maybe_space closing_parenthesis {
$$ = parser->createFloatingSelector();
$$->setMatch(CSSSelector::PseudoClass);
$$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4));
parser->tokenToLowerCase($2);
$$->setValue($2);
CSSSelector::PseudoType type = $$->pseudoType();
if (type != CSSSelector::PseudoAncestor)
if (type != CSSSelector::PseudoHostContext)
YYERROR;
}
// used by :ancestor()
| ':' ANCESTORFUNCTION maybe_space closing_parenthesis {
| ':' HOSTCONTEXTFUNCTION maybe_space closing_parenthesis {
$$ = parser->createFloatingSelector();
$$->setMatch(CSSSelector::PseudoClass);
parser->tokenToLowerCase($2);
$$->setValue($2.atomicSubstring(0, $2.length() - 1));
CSSSelector::PseudoType type = $$->pseudoType();
if (type != CSSSelector::PseudoAncestor)
if (type != CSSSelector::PseudoHostContext)
YYERROR;
}
| ':' ANCESTORFUNCTION selector_recovery closing_parenthesis {
| ':' HOSTCONTEXTFUNCTION selector_recovery closing_parenthesis {
YYERROR;
}
;
......
......@@ -261,7 +261,7 @@ bool CSSParserSelector::hasHostPseudoSelector() const
{
CSSParserSelector* selector = const_cast<CSSParserSelector*>(this);
do {
if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseudoType() == CSSSelector::PseudoAncestor)
if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseudoType() == CSSSelector::PseudoHostContext)
return true;
} while ((selector = selector->tagHistory()));
return false;
......
......@@ -100,7 +100,7 @@ inline unsigned CSSSelector::specificityForOneSelector() const
case Id:
return 0x10000;
case PseudoClass:
if (pseudoType() == PseudoHost || pseudoType() == PseudoAncestor)
if (pseudoType() == PseudoHost || pseudoType() == PseudoHostContext)
return 0;
// fall through.
case Exact:
......@@ -254,7 +254,7 @@ PseudoId CSSSelector::pseudoId(PseudoType type)
case PseudoUnresolved:
case PseudoContent:
case PseudoHost:
case PseudoAncestor:
case PseudoHostContext:
case PseudoFullScreen:
case PseudoFullScreenDocument:
case PseudoFullScreenAncestor:
......@@ -354,8 +354,8 @@ const static NameToPseudoStruct pseudoTypeMap[] = {
{"unresolved", CSSSelector::PseudoUnresolved},
{"host", CSSSelector::PseudoHost},
{"host(", CSSSelector::PseudoHost},
{"ancestor", CSSSelector::PseudoAncestor},
{"ancestor(", CSSSelector::PseudoAncestor},
{"host-context", CSSSelector::PseudoHostContext},
{"host-context(", CSSSelector::PseudoHostContext},
{"content", CSSSelector::PseudoContent},
};
......@@ -520,7 +520,7 @@ void CSSSelector::extractPseudoType() const
case PseudoFutureCue:
case PseudoPastCue:
case PseudoHost:
case PseudoAncestor:
case PseudoHostContext:
case PseudoUnresolved:
break;
case PseudoFirstPage:
......@@ -621,7 +621,7 @@ String CSSSelector::selectorText(const String& rightSide) const
break;
}
case PseudoHost:
case PseudoAncestor: {
case PseudoHostContext: {
if (cs->selectorList()) {
const CSSSelector* firstSubSelector = cs->selectorList()->first();
for (const CSSSelector* subSelector = firstSubSelector; subSelector; subSelector = CSSSelectorList::next(*subSelector)) {
......@@ -773,7 +773,7 @@ static bool validateSubSelector(const CSSSelector* selector)
case CSSSelector::PseudoLastOfType:
case CSSSelector::PseudoOnlyOfType:
case CSSSelector::PseudoHost:
case CSSSelector::PseudoAncestor:
case CSSSelector::PseudoHostContext:
return true;
default:
return false;
......
......@@ -218,7 +218,7 @@ namespace WebCore {
PseudoUnresolved,
PseudoContent,
PseudoHost,
PseudoAncestor
PseudoHostContext
};
enum OptionalPseudoTypeRequirements {
......@@ -387,7 +387,7 @@ inline bool CSSSelector::isCustomPseudoElement() const
inline bool CSSSelector::isHostPseudoClass() const
{
return m_match == PseudoClass && (m_pseudoType == PseudoHost || m_pseudoType == PseudoAncestor);
return m_match == PseudoClass && (m_pseudoType == PseudoHost || m_pseudoType == PseudoHostContext);
}
inline bool CSSSelector::isSiblingSelector() const
......
......@@ -727,8 +727,8 @@ inline bool CSSTokenizer::detectFunctionTypeToken(int length)
m_token = HOSTFUNCTION;
return true;
}
CASE("ancestor") {
m_token = ANCESTORFUNCTION;
CASE("host-context") {
m_token = HOSTCONTEXTFUNCTION;
return true;
}
CASE("nth-child") {
......
......@@ -872,7 +872,7 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context, const Sib
break;
case CSSSelector::PseudoHost:
case CSSSelector::PseudoAncestor:
case CSSSelector::PseudoHostContext:
{
// :host only matches a shadow host when :host is in a shadow tree of the shadow host.
if (!context.scope)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment