mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
parent
9ac817523c
commit
1b84bd22b8
7 changed files with 47 additions and 4 deletions
|
@ -13,6 +13,7 @@ use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
|
|||
use dom::bindings::codegen::Bindings::ElementBinding;
|
||||
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
||||
use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{ElementDerived, HTMLInputElementDerived, HTMLTableCellElementDerived};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, NodeCast, EventTargetCast, ElementCast};
|
||||
|
@ -198,6 +199,7 @@ pub trait RawLayoutElementHelpers {
|
|||
-> LengthOrPercentageOrAuto;
|
||||
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute)
|
||||
-> Option<i32>;
|
||||
unsafe fn get_checked_state_for_layout(&self) -> bool;
|
||||
fn local_name<'a>(&'a self) -> &'a Atom;
|
||||
fn namespace<'a>(&'a self) -> &'a Namespace;
|
||||
fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>>;
|
||||
|
@ -313,6 +315,17 @@ impl RawLayoutElementHelpers for Element {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unrooted_must_root)]
|
||||
unsafe fn get_checked_state_for_layout(&self) -> bool {
|
||||
// TODO option and menuitem can also have a checked state.
|
||||
if !self.is_htmlinputelement() {
|
||||
return false
|
||||
}
|
||||
let this: &HTMLInputElement = mem::transmute(self);
|
||||
this.get_checked_state_for_layout()
|
||||
}
|
||||
|
||||
// Getters used in components/layout/wrapper.rs
|
||||
|
||||
fn local_name<'a>(&'a self) -> &'a Atom {
|
||||
|
@ -1156,6 +1169,12 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
|
|||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
node.get_enabled_state()
|
||||
}
|
||||
fn get_checked_state(self) -> bool {
|
||||
match HTMLInputElementCast::to_ref(self) {
|
||||
Some(input) => input.Checked(),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
fn has_class(self, name: &Atom) -> bool {
|
||||
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
|
||||
// of disambiguating methods.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue