diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index d2636820362..50f571452b6 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -85,19 +85,28 @@ use util::str::{DOMString, LengthOrPercentageOrAuto}; bitflags! { #[doc = "Element Event States."] #[derive(JSTraceable, HeapSizeOf)] - flags EventState: u8 { + flags EventState: u16 { #[doc = "The mouse is down on this element. \ (https://html.spec.whatwg.org/multipage/#selector-active). \ FIXME(#7333): set/unset this when appropriate"] const IN_ACTIVE_STATE = 0x01, - #[doc = "This element has focus."] + #[doc = "This element has focus. + https://html.spec.whatwg.org/multipage/scripting.html#selector-focus"] const IN_FOCUS_STATE = 0x02, - #[doc = "The mouse is hovering over this element."] + #[doc = "The mouse is hovering over this element. \ + https://html.spec.whatwg.org/multipage/scripting.html#selector-hover"] const IN_HOVER_STATE = 0x04, - #[doc = "Content is enabled (and can be disabled)."] + #[doc = "Content is enabled (and can be disabled). \ + http://www.whatwg.org/html/#selector-enabled"] const IN_ENABLED_STATE = 0x08, - #[doc = "Content is disabled."] + #[doc = "Content is disabled. \ + http://www.whatwg.org/html/#selector-disabled"] const IN_DISABLED_STATE = 0x10, + #[doc = "Content is checked. \ + https://html.spec.whatwg.org/multipage/scripting.html#selector-checked"] + const IN_CHECKED_STATE = 0x20, + #[doc = "https://html.spec.whatwg.org/multipage/scripting.html#selector-indeterminate"] + const IN_INDETERMINATE_STATE = 0x40, } } @@ -1834,7 +1843,11 @@ impl Element { self.set_click_in_progress(false); } - fn set_state(&self, which: EventState, value: bool) { + pub fn get_state(&self) -> EventState { + self.event_state.get() + } + + pub fn set_state(&self, which: EventState, value: bool) { let mut state = self.event_state.get(); if state.contains(which) == value { return diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index b82f96aed63..baaa2db012d 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -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, - checked: Cell, checked_changed: Cell, placeholder: DOMRefCell, - indeterminate: Cell, value_changed: Cell, size: Cell, #[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::().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::().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::().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::().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