Hoist checked and indeterminate state into EventState.

This is necessary for those selectors to take advantage of restyle hints.
This commit is contained in:
Bobby Holley 2015-10-22 12:56:18 -07:00
parent 7512aa69c0
commit f7f27a8146
2 changed files with 27 additions and 18 deletions

View file

@ -15,7 +15,7 @@ use dom::bindings::conversions::Castable;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, LayoutJS, Root, RootedReference};
use dom::document::Document;
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE, RawLayoutElementHelpers};
use dom::element::{AttributeMutation, Element, IN_CHECKED_STATE, IN_ENABLED_STATE, IN_INDETERMINATE_STATE, RawLayoutElementHelpers};
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
@ -57,10 +57,8 @@ enum InputType {
pub struct HTMLInputElement {
htmlelement: HTMLElement,
input_type: Cell<InputType>,
checked: Cell<bool>,
checked_changed: Cell<bool>,
placeholder: DOMRefCell<DOMString>,
indeterminate: Cell<bool>,
value_changed: Cell<bool>,
size: Cell<u32>,
#[ignore_heap_size_of = "#7193"]
@ -111,9 +109,7 @@ impl HTMLInputElement {
HTMLElement::new_inherited_with_state(IN_ENABLED_STATE,
localName, prefix, document),
input_type: Cell::new(InputType::InputText),
checked: Cell::new(false),
placeholder: DOMRefCell::new("".to_owned()),
indeterminate: Cell::new(false),
checked_changed: Cell::new(false),
value_changed: Cell::new(false),
size: Cell::new(DEFAULT_INPUT_SIZE),
@ -204,13 +200,13 @@ impl RawLayoutHTMLInputElementHelpers for HTMLInputElement {
#[allow(unrooted_must_root)]
#[allow(unsafe_code)]
unsafe fn get_checked_state_for_layout(&self) -> bool {
self.checked.get()
self.Checked()
}
#[allow(unrooted_must_root)]
#[allow(unsafe_code)]
unsafe fn get_indeterminate_state_for_layout(&self) -> bool {
self.indeterminate.get()
self.Indeterminate()
}
#[allow(unrooted_must_root)]
@ -240,7 +236,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-input-checked
fn Checked(&self) -> bool {
self.checked.get()
self.upcast::<Element>().get_state().contains(IN_CHECKED_STATE)
}
// https://html.spec.whatwg.org/multipage/#dom-input-checked
@ -329,12 +325,12 @@ impl HTMLInputElementMethods for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-input-indeterminate
fn Indeterminate(&self) -> bool {
self.indeterminate.get()
self.upcast::<Element>().get_state().contains(IN_INDETERMINATE_STATE)
}
// https://html.spec.whatwg.org/multipage/#dom-input-indeterminate
fn SetIndeterminate(&self, val: bool) {
self.indeterminate.set(val)
self.upcast::<Element>().set_state(IN_INDETERMINATE_STATE, val)
}
}
@ -443,7 +439,7 @@ impl HTMLInputElement {
}
fn update_checked_state(&self, checked: bool, dirty: bool) {
self.checked.set(checked);
self.upcast::<Element>().set_state(IN_CHECKED_STATE, checked);
if dirty {
self.checked_changed.set(true);
@ -459,7 +455,7 @@ impl HTMLInputElement {
}
pub fn get_indeterminate_state(&self) -> bool {
self.indeterminate.get()
self.Indeterminate()
}
// https://html.spec.whatwg.org/multipage/#concept-fe-mutable