Commit 65b8a51a authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

custom-elements: Do not distinguish V0 custom elements and V1 custom elements...

custom-elements: Do not distinguish V0 custom elements and V1 custom elements in :unresolved and :defined matching.

This CL changed the behavior of :unresolved selector for V1-defined
custom elements, and the behavior of :defined selector for V0-defined
custom elements.

The following table shows the current behavior:

		:unresolved	:not(:defined)	:defined
Built-in	false		false		true
Not-defined	true		true		false
V0-defined	false		true		false
V1-defined	true		false		true

After this CL, the behavior is:

		:unresolved	:not(:defined)	:defined
Built-in	false		false		true
Not-defined	true		true		false
V0-defined	false		false*		true*
V1-defined	false*		false		true

V0 custom elements specification defined ':unresolved' and V1 custom
elements specification defines ':defined', but we don't need to
distinguish V0-defined elements and V1-defined elements for these
selectors. The current behavior makes it difficult to migrate V0 custom
elements to V1 custom elements gradually.

Bug: 889336
Change-Id: I48ecced042fe78314b42da4ea65baddb720e38fc
Reviewed-on: https://chromium-review.googlesource.com/1248061Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594582}
parent 4ddc2ce8
...@@ -54,4 +54,28 @@ test_with_window((w) => { ...@@ -54,4 +54,28 @@ test_with_window((w) => {
assert_true(w.document.createElement('div', 'b-b') instanceof w.HTMLDivElement, assert_true(w.document.createElement('div', 'b-b') instanceof w.HTMLDivElement,
'V0 createElement syntax does not work with V1 defined element'); 'V0 createElement syntax does not work with V1 defined element');
}, 'V0 and V1 definition and createElement cannot be used together'); }, 'V0 and V1 definition and createElement cannot be used together');
test_with_window((w) => {
const element = w.document.createElement('my-element');
assert_true(element.matches(':unresolved'), 'Undefined element should be matched to :unresolved');
assert_false(element.matches(':defined'), 'Undefined element should not be matched to :defined');
class MyElement extends w.HTMLElement {};
w.document.registerElement('my-element', {prototype: MyElement.prototype});
assert_true(element instanceof MyElement, 'Make sure V0-upgraded');
assert_false(element.matches(':unresolved'), 'V0-defined element should not be matched to :unresolved');
assert_true(element.matches(':defined'), 'V0-defined element should be matched to :defined');
const element1 = w.document.createElement('my-element1');
w.customElements.define('my-element1', MyElement);
w.customElements.upgrade(element1);
assert_true(element1 instanceof MyElement, 'Make sure V1-upgraded');
assert_false(element1.matches(':unresolved'), 'V1-defined element should not be matched to :unresolved');
assert_true(element1.matches(':defined'), 'V1-defined element should be matched to :defined');
const builtin = w.document.createElement('span');
assert_false(builtin.matches(':unresolved'), 'Built-in element should not be matched to :unresolved');
assert_true(builtin.matches(':defined'), 'Built-in element should be matched to :defined');
}, ':unresolved and :defined work with both of V0 and V1 custom elements');
</script> </script>
...@@ -1071,9 +1071,9 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context, ...@@ -1071,9 +1071,9 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context,
return element == ToShadowRoot(context.scope)->host(); return element == ToShadowRoot(context.scope)->host();
return context.scope == &element; return context.scope == &element;
case CSSSelector::kPseudoUnresolved: case CSSSelector::kPseudoUnresolved:
return element.IsUnresolvedV0CustomElement(); return !element.IsDefined() && element.IsUnresolvedV0CustomElement();
case CSSSelector::kPseudoDefined: case CSSSelector::kPseudoDefined:
return element.IsDefined(); return element.IsDefined() || element.IsUpgradedV0CustomElement();
case CSSSelector::kPseudoHost: case CSSSelector::kPseudoHost:
case CSSSelector::kPseudoHostContext: case CSSSelector::kPseudoHostContext:
return CheckPseudoHost(context, result); return CheckPseudoHost(context, result);
......
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