Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement :defined CSS selector #25627

Merged
merged 1 commit into from Jan 31, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

:defined works

  • Loading branch information
pshaughn committed Jan 30, 2020
commit 8ca4db2cd64344c874016f110922cefd9e4ebb58
@@ -955,6 +955,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
NonTSPseudoClass::Focus |
NonTSPseudoClass::Fullscreen |
NonTSPseudoClass::Hover |
NonTSPseudoClass::Defined |
NonTSPseudoClass::Enabled |
NonTSPseudoClass::Disabled |
NonTSPseudoClass::Checked |
@@ -962,6 +962,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
NonTSPseudoClass::Focus |
NonTSPseudoClass::Fullscreen |
NonTSPseudoClass::Hover |
NonTSPseudoClass::Defined |
NonTSPseudoClass::Enabled |
NonTSPseudoClass::Disabled |
NonTSPseudoClass::Checked |
@@ -200,6 +200,8 @@ fn create_html_element(
None => {
if is_valid_custom_element_name(&*name.local) {
result.set_custom_element_state(CustomElementState::Undefined);
} else {
result.set_custom_element_state(CustomElementState::Uncustomized);
}
},
};
@@ -324,14 +324,23 @@ impl Element {
}

pub fn set_custom_element_state(&self, state: CustomElementState) {
self.ensure_rare_data().custom_element_state = state;
// no need to inflate rare data for uncustomized
if state != CustomElementState::Uncustomized || self.rare_data().is_some() {
self.ensure_rare_data().custom_element_state = state;
}
// https://dom.spec.whatwg.org/#concept-element-defined
let in_defined_state = match state {
CustomElementState::Uncustomized | CustomElementState::Custom => true,
_ => false,
};
self.set_state(ElementState::IN_DEFINED_STATE, in_defined_state)
}

pub fn get_custom_element_state(&self) -> CustomElementState {
if let Some(rare_data) = self.rare_data().as_ref() {
return rare_data.custom_element_state;
}
CustomElementState::Undefined
CustomElementState::Uncustomized
}

pub fn set_custom_element_definition(&self, definition: Rc<CustomElementDefinition>) {
@@ -3039,6 +3048,7 @@ impl<'a> SelectorsElement for DomRoot<Element> {
NonTSPseudoClass::Focus |
NonTSPseudoClass::Fullscreen |
NonTSPseudoClass::Hover |
NonTSPseudoClass::Defined |
NonTSPseudoClass::Enabled |
NonTSPseudoClass::Disabled |
NonTSPseudoClass::Checked |
@@ -278,6 +278,7 @@ pub enum NonTSPseudoClass {
Active,
AnyLink,
Checked,
Defined,
Disabled,
Enabled,
Focus,
@@ -332,6 +333,7 @@ impl ToCss for NonTSPseudoClass {
Active => ":active",
AnyLink => ":any-link",
Checked => ":checked",
Defined => ":defined",
Disabled => ":disabled",
Enabled => ":enabled",
Focus => ":focus",
@@ -371,6 +373,7 @@ impl NonTSPseudoClass {
Focus => ElementState::IN_FOCUS_STATE,
Fullscreen => ElementState::IN_FULLSCREEN_STATE,
Hover => ElementState::IN_HOVER_STATE,
Defined => ElementState::IN_DEFINED_STATE,
Enabled => ElementState::IN_ENABLED_STATE,
Disabled => ElementState::IN_DISABLED_STATE,
Checked => ElementState::IN_CHECKED_STATE,
@@ -436,6 +439,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
"active" => Active,
"any-link" => AnyLink,
"checked" => Checked,
"defined" => Defined,
"disabled" => Disabled,
"enabled" => Enabled,
"focus" => Focus,
"testharness"
],
"custom-elements/pseudo-class-defined.html": [
"24cb5fe4cd392246e292d255c0858aa7f2b5dd0e",
"ed12830d5a9582dbf3ec30c74a43fe381221a139",
"testharness"
],
"custom-elements/range-and-constructors.html": [

This file was deleted.

@@ -1,8 +1,37 @@
[pseudo-class-defined.html]
expected: ERROR
[Untitled]
expected: FAIL

[pseudo-class-defined]
expected: FAIL

[createElementNS("http://www.w3.org/2000/svg", "div") should be :defined]
expected: FAIL

[Without browsing context: createElementNS("http://www.w3.org/2000/svg", "div") should be :defined]
expected: FAIL

[Without browsing context: createElementNS("http://www.w3.org/2000/svg", "p", { is: "" }) should be :defined]
expected: FAIL

[createElementNS("http://www.w3.org/2000/svg", "p", { is: "" }) should be :defined]
expected: FAIL

[Without browsing context: createElementNS("http://www.w3.org/2000/svg", "abbr", { is: "my-abbr" }) should be :defined]
expected: FAIL

[createElementNS("http://www.w3.org/2000/svg", "abbr", { is: "my-abbr" }) should be :defined]
expected: FAIL

[createElementNS("http://www.w3.org/2000/svg", "font-face") should be :defined]
expected: FAIL

[Without browsing context: createElementNS("http://www.w3.org/2000/svg", "font-face") should be :defined]
expected: FAIL

[createElementNS("http://www.w3.org/2000/svg", "a-a") should be :defined]
expected: FAIL

[Without browsing context: createElementNS("http://www.w3.org/2000/svg", "a-a") should be :defined]
expected: FAIL

@@ -16,6 +16,7 @@
const neither = 'rgb(255, 0, 0)';
const defined = 'rgb(255, 165, 0)';
const not_defined = 'rgb(0, 0, 255)';
const iframe = document.getElementById("iframe");
iframe.srcdoc = `<style>
* { color:${neither}; }
:defined { color:${defined}; }
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.