aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2014-12-08 12:01:51 -0700
committerbors-servo <metajack+bors@gmail.com>2014-12-08 12:01:51 -0700
commitf18c18371d2bb5edde9d64e46b74bf01411afab3 (patch)
tree1e3968b0c73bdff6704134babad2d23d538131e1 /components/script/dom
parent0b486b12109ab765ecee4cbcc684e5d99e8ad5ad (diff)
parent1b84bd22b8d44a0c9d79458702db7bb465bde685 (diff)
downloadservo-f18c18371d2bb5edde9d64e46b74bf01411afab3.tar.gz
servo-f18c18371d2bb5edde9d64e46b74bf01411afab3.zip
auto merge of #4190 : mttr/servo/checked_pseudo_class, r=Manishearth
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.
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/element.rs19
-rw-r--r--components/script/dom/htmlinputelement.rs10
2 files changed, 28 insertions, 1 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 51a3d095007..5b5c7176430 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -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.
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index a736a7a8f3d..1fee2c82627 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -125,6 +125,7 @@ pub trait LayoutHTMLInputElementHelpers {
}
pub trait RawLayoutHTMLInputElementHelpers {
+ unsafe fn get_checked_state_for_layout(&self) -> bool;
unsafe fn get_size_for_layout(&self) -> u32;
}
@@ -163,6 +164,11 @@ impl LayoutHTMLInputElementHelpers for JS<HTMLInputElement> {
impl RawLayoutHTMLInputElementHelpers for HTMLInputElement {
#[allow(unrooted_must_root)]
+ unsafe fn get_checked_state_for_layout(&self) -> bool {
+ self.checked.get()
+ }
+
+ #[allow(unrooted_must_root)]
unsafe fn get_size_for_layout(&self) -> u32 {
self.size.get()
}
@@ -181,7 +187,9 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> {
}
// https://html.spec.whatwg.org/multipage/forms.html#dom-input-checked
- make_bool_setter!(SetChecked, "checked")
+ fn SetChecked(self, checked: bool) {
+ self.update_checked_state(checked);
+ }
// https://html.spec.whatwg.org/multipage/forms.html#dom-input-readonly
make_bool_getter!(ReadOnly)