Implements the :checked pseudo-class for inputs

Relevant spec:
https://html.spec.whatwg.org/multipage/scripting.html#selector-checked

Also modifies HTMLInputElement::SetChecked to no longer modify its
checked content value, instead making use of its internal checkedness
state now that we can match `:checked` properly.
This commit is contained in:
Matthew Rasmus 2014-12-02 17:06:30 -08:00
parent 9ac817523c
commit 1b84bd22b8
7 changed files with 47 additions and 4 deletions

View file

@ -45,6 +45,7 @@ pub trait TElement<'a> : Copy {
fn get_id(self) -> Option<Atom>;
fn get_disabled_state(self) -> bool;
fn get_enabled_state(self) -> bool;
fn get_checked_state(self) -> bool;
fn has_class(self, name: &Atom) -> bool;
// Ordinarily I wouldn't use callbacks like this, but the alternative is

View file

@ -997,6 +997,12 @@ pub fn matches_simple_selector<'a,E,N>(selector: &SimpleSelector,
let elem = element.as_element();
elem.get_enabled_state()
},
// https://html.spec.whatwg.org/multipage/scripting.html#selector-checked
Checked => {
*shareable = false;
let elem = element.as_element();
elem.get_checked_state()
}
FirstChild => {
*shareable = false;
matches_first_child(element)

View file

@ -68,6 +68,7 @@ pub enum SimpleSelector {
Hover,
Disabled,
Enabled,
Checked,
FirstChild, LastChild, OnlyChild,
// Empty,
Root,
@ -226,7 +227,7 @@ fn compute_specificity(mut selector: &CompoundSelector,
| &AttrExists(..) | &AttrEqual(..) | &AttrIncludes(..) | &AttrDashMatch(..)
| &AttrPrefixMatch(..) | &AttrSubstringMatch(..) | &AttrSuffixMatch(..)
| &AnyLink | &Link | &Visited | &Hover | &Disabled | &Enabled
| &FirstChild | &LastChild | &OnlyChild | &Root
| &FirstChild | &LastChild | &OnlyChild | &Root | &Checked
// | &Empty | &Lang(*)
| &NthChild(..) | &NthLastChild(..)
| &NthOfType(..) | &NthLastOfType(..)
@ -497,6 +498,7 @@ fn parse_simple_pseudo_class(name: &str) -> Result<SimpleSelector, ()> {
"hover" => Ok(Hover),
"disabled" => Ok(Disabled),
"enabled" => Ok(Enabled),
"checked" => Ok(Checked),
"first-child" => Ok(FirstChild),
"last-child" => Ok(LastChild),
"only-child" => Ok(OnlyChild),