From 2c2d741b1fbfdcf61c7b72501d1b0ec68d941bd2 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Nov 2014 10:35:45 +0530 Subject: [PATCH 01/19] Split up the InputButton variant --- components/script/dom/htmlinputelement.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 20227cd397e..378952d4da3 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -41,7 +41,9 @@ const DEFAULT_RESET_VALUE: &'static str = "Reset"; #[deriving(PartialEq)] #[allow(dead_code)] enum InputType { - InputButton(Option<&'static str>), + InputSubmit, + InputReset, + InputButton, InputText, InputFile, InputImage, @@ -110,9 +112,9 @@ impl LayoutHTMLInputElementHelpers for JS { match (*self.unsafe_get()).input_type.get() { InputCheckbox | InputRadio => "".to_string(), InputFile | InputImage => "".to_string(), - InputButton(ref default) => get_raw_attr_value(self) - .or_else(|| default.map(|v| v.to_string())) - .unwrap_or_else(|| "".to_string()), + InputButton => get_raw_attr_value(self).unwrap_or_else(|| "".to_string()), + InputSubmit => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_SUBMIT_VALUE.to_string()), + InputReset => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_RESET_VALUE.to_string()), InputPassword => { let raw = get_raw_textinput_value(self); String::from_char(raw.char_len(), '●') @@ -305,9 +307,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { &atom!("type") => { let value = attr.value(); self.input_type.set(match value.as_slice() { - "button" => InputButton(None), - "submit" => InputButton(Some(DEFAULT_SUBMIT_VALUE)), - "reset" => InputButton(Some(DEFAULT_RESET_VALUE)), + "button" => InputButton, + "submit" => InputSubmit, + "reset" => InputReset, "file" => InputFile, "radio" => InputRadio, "checkbox" => InputCheckbox, @@ -421,7 +423,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { match self.input_type.get() { InputCheckbox => self.SetChecked(!self.checked.get()), InputRadio => self.SetChecked(true), - InputButton(Some(DEFAULT_SUBMIT_VALUE)) => { + InputSubmit => { self.form_owner().map(|o| { o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone())) }); From 7d51a543d8d04f9603ceb00d21faa298dda8b6c4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Nov 2014 11:18:10 +0530 Subject: [PATCH 02/19] Implement form control mutability, rename FormOwner -> FormControl --- components/script/dom/htmlformelement.rs | 4 +++- components/script/dom/htmlinputelement.rs | 17 +++++++++++++++-- .../script/dom/webidls/HTMLInputElement.webidl | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index a8461618db9..3ac799fdc04 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -410,7 +410,7 @@ impl<'a> FormSubmitter<'a> { } } -pub trait FormOwner<'a> : Copy { +pub trait FormControl<'a> : Copy { fn form_owner(self) -> Option>; fn get_form_attribute(self, attr: &Atom, @@ -423,4 +423,6 @@ pub trait FormOwner<'a> : Copy { } } fn to_element(self) -> JSRef<'a, Element>; + // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable + fn mutable(self) -> bool; } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 378952d4da3..30b4dcaa820 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -23,7 +23,7 @@ use dom::event::Event; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::keyboardevent::KeyboardEvent; -use dom::htmlformelement::{InputElement, FormOwner, HTMLFormElement, HTMLFormElementHelpers, NotFromFormSubmitMethod}; +use dom::htmlformelement::{InputElement, FormControl, HTMLFormElement, HTMLFormElementHelpers, NotFromFormSubmitMethod}; use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; use textinput::{Single, TextInput, TriggerDefaultAction, DispatchInput, Nothing}; @@ -151,6 +151,12 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/forms.html#dom-input-checked make_bool_setter!(SetChecked, "checked") + // https://html.spec.whatwg.org/multipage/forms.html#dom-input-readonly + make_bool_getter!(ReadOnly) + + // https://html.spec.whatwg.org/multipage/forms.html#dom-input-readonly + make_bool_setter!(SetReadOnly, "readonly") + // https://html.spec.whatwg.org/multipage/forms.html#dom-input-size make_uint_getter!(Size) @@ -457,7 +463,7 @@ impl Reflectable for HTMLInputElement { } } -impl<'a> FormOwner<'a> for JSRef<'a, HTMLInputElement> { +impl<'a> FormControl<'a> for JSRef<'a, HTMLInputElement> { // FIXME: This is wrong (https://github.com/servo/servo/issues/3553) // but we need html5ever to do it correctly fn form_owner(self) -> Option> { @@ -485,4 +491,11 @@ impl<'a> FormOwner<'a> for JSRef<'a, HTMLInputElement> { fn to_element(self) -> JSRef<'a, Element> { ElementCast::from_ref(self) } + + // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable + fn mutable(self) -> bool { + // https://html.spec.whatwg.org/multipage/forms.html#the-input-element:concept-fe-mutable + // https://html.spec.whatwg.org/multipage/forms.html#the-readonly-attribute:concept-fe-mutable + !(self.Disabled() || self.ReadOnly()) + } } diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl index b69d8fcf4ff..32b4f04261b 100644 --- a/components/script/dom/webidls/HTMLInputElement.webidl +++ b/components/script/dom/webidls/HTMLInputElement.webidl @@ -32,7 +32,7 @@ interface HTMLInputElement : HTMLElement { attribute DOMString name; // attribute DOMString pattern; // attribute DOMString placeholder; - // attribute boolean readOnly; + attribute boolean readOnly; // attribute boolean required; attribute unsigned long size; // attribute DOMString src; From e2376a64bfc9e381871bfe569e259c0e22a81a0a Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 16 Nov 2014 03:17:54 +0530 Subject: [PATCH 03/19] Add stub Activatable trait --- components/script/dom/activation.rs | 27 +++++++++++++++++++++++++++ components/script/lib.rs | 1 + 2 files changed, 28 insertions(+) create mode 100644 components/script/dom/activation.rs diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs new file mode 100644 index 00000000000..cb803d67ba1 --- /dev/null +++ b/components/script/dom/activation.rs @@ -0,0 +1,27 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::InheritTypes::HTMLInputElementCast; +use dom::bindings::js::JSRef; +use dom::element::HTMLInputElementTypeId; +use dom::htmlinputelement::HTMLInputElement; +use dom::node::{ElementNodeTypeId, Node, NodeHelpers}; + +pub trait Activatable {} + + +/// Obtain an Activatable instance for a given Node-derived object, +/// if it is activatable +pub fn activation_vtable_for<'a>(node: &'a JSRef<'a, Node>) -> Option<&'a Activatable + 'a> { + match node.type_id() { + ElementNodeTypeId(HTMLInputElementTypeId) => { + let _element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(node).unwrap(); + // Some(element as &'a VirtualMethods + 'a) + None + }, + _ => { + None + } + } +} diff --git a/components/script/lib.rs b/components/script/lib.rs index 6edcb72ae45..de1ddbe5987 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -82,6 +82,7 @@ pub mod dom { #[path="bindings/codegen/InterfaceTypes.rs"] pub mod types; + pub mod activation; pub mod attr; pub mod blob; pub mod browsercontext; From c3fdd60adcdc54e5a17399b4b5b56972b96bc010 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 16 Nov 2014 03:45:44 +0530 Subject: [PATCH 04/19] Add trusted setter to Event --- components/script/dom/event.rs | 10 ++++++++++ components/script/dom/htmlformelement.rs | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index 637bd259035..6d7ce64bf5e 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -245,3 +245,13 @@ impl Reflectable for Event { &self.reflector_ } } + +pub trait EventHelpers { + fn set_trusted(self, trusted: bool); +} + +impl<'a> EventHelpers for JSRef<'a, Event> { + fn set_trusted(self, trusted: bool) { + self.trusted.set(trusted); + } +} diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 3ac799fdc04..1d12bdebf39 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -15,7 +15,7 @@ use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::{Document, DocumentHelpers}; use dom::element::{Element, AttributeHandlers, HTMLFormElementTypeId, HTMLTextAreaElementTypeId, HTMLDataListElementTypeId}; use dom::element::{HTMLInputElementTypeId, HTMLButtonElementTypeId, HTMLObjectElementTypeId, HTMLSelectElementTypeId}; -use dom::event::{Event, Bubbles, Cancelable}; +use dom::event::{Event, EventHelpers, Bubbles, Cancelable}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlinputelement::HTMLInputElement; @@ -142,6 +142,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> { let event = Event::new(Window(*win), "submit".to_string(), Bubbles, Cancelable).root(); + event.set_trusted(true); let target: JSRef = EventTargetCast::from_ref(self); target.DispatchEvent(*event).ok(); if event.DefaultPrevented() { From ddfa0c7de74d707959704f0c035b46df451549fc Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 16 Nov 2014 03:45:51 +0530 Subject: [PATCH 05/19] Implement basic (unhooked) framework for element activation --- components/script/dom/activation.rs | 70 ++++++++++++++++++------- components/script/dom/element.rs | 81 +++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 22 deletions(-) diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index cb803d67ba1..98e8d435c12 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -2,26 +2,60 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::bindings::codegen::InheritTypes::HTMLInputElementCast; -use dom::bindings::js::JSRef; -use dom::element::HTMLInputElementTypeId; -use dom::htmlinputelement::HTMLInputElement; -use dom::node::{ElementNodeTypeId, Node, NodeHelpers}; - -pub trait Activatable {} +use dom::bindings::codegen::Bindings::EventBinding::EventMethods; +use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast}; +use dom::bindings::js::{JSRef, Temporary, OptionalRootable}; +use dom::element::{Element, ActivationElementHelpers}; +use dom::event::{Event, EventHelpers}; +use dom::eventtarget::{EventTarget, EventTargetHelpers}; +use dom::mouseevent::MouseEvent; +use dom::node::window_from_node; -/// Obtain an Activatable instance for a given Node-derived object, -/// if it is activatable -pub fn activation_vtable_for<'a>(node: &'a JSRef<'a, Node>) -> Option<&'a Activatable + 'a> { - match node.type_id() { - ElementNodeTypeId(HTMLInputElementTypeId) => { - let _element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(node).unwrap(); - // Some(element as &'a VirtualMethods + 'a) - None - }, - _ => { - None +/// Trait for elements with defined activation behavior +pub trait Activatable : Copy { + fn as_element(&self) -> Temporary; + + // https://html.spec.whatwg.org/multipage/interaction.html#run-pre-click-activation-steps + fn pre_click_activation(&self); + + // https://html.spec.whatwg.org/multipage/interaction.html#run-canceled-activation-steps + fn canceled_activation(&self); + + // https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps + fn post_click_activation(&self); + + // https://html.spec.whatwg.org/multipage/interaction.html#run-synthetic-click-activation-steps + fn synthetic_click_activation(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { + let element = self.as_element().root(); + // Step 1 + if element.click_in_progress() { + return; } + // Step 2 + element.set_click_in_progress(true); + // Step 3 + self.pre_click_activation(); + + // Step 4 + // https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-mouse-event + let win = window_from_node(*element).root(); + let target: JSRef = EventTargetCast::from_ref(*element); + let mouse = MouseEvent::new(*win, "click".to_string(), false, false, Some(*win), 1, + 0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey, + 0, None).root(); + let event: JSRef = EventCast::from_ref(*mouse); + event.set_trusted(true); + target.dispatch_event_with_target(None, event).ok(); + + // Step 5 + if event.DefaultPrevented() { + self.canceled_activation(); + } else { + self.post_click_activation(); + } + + // Step 6 + element.set_click_in_progress(false); } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index d3b5b1946aa..ca12d6f2afd 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -4,16 +4,18 @@ //! Element nodes. +use dom::activation::Activatable; use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrHelpers, AttrHelpersForLayout}; use dom::attr::{AttrValue, StringAttrValue, UIntAttrValue, AtomAttrValue}; use dom::namednodemap::NamedNodeMap; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; +use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::ElementBinding; use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; -use dom::bindings::codegen::InheritTypes::{ElementDerived, HTMLInputElementDerived}; -use dom::bindings::codegen::InheritTypes::{HTMLTableCellElementDerived, NodeCast}; +use dom::bindings::codegen::InheritTypes::{ElementDerived, HTMLInputElementDerived, HTMLTableCellElementDerived}; +use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, NodeCast, EventTargetCast, ElementCast}; use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable}; use dom::bindings::js::{OptionalSettable, OptionalRootable, Root}; use dom::bindings::utils::{Reflectable, Reflector}; @@ -24,7 +26,8 @@ use dom::domrect::DOMRect; use dom::domrectlist::DOMRectList; use dom::document::{Document, DocumentHelpers, LayoutDocumentHelpers}; use dom::domtokenlist::DOMTokenList; -use dom::eventtarget::{EventTarget, NodeTargetTypeId}; +use dom::event::Event; +use dom::eventtarget::{EventTarget, NodeTargetTypeId, EventTargetHelpers}; use dom::htmlcollection::HTMLCollection; use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers}; use dom::htmlserializer::serialize; @@ -41,7 +44,7 @@ use servo_util::namespace; use servo_util::str::{DOMString, LengthOrPercentageOrAuto}; use std::ascii::AsciiExt; -use std::cell::{Ref, RefMut}; +use std::cell::{Cell, Ref, RefMut}; use std::default::Default; use std::mem; use string_cache::{Atom, Namespace, QualName}; @@ -57,6 +60,7 @@ pub struct Element { style_attribute: DOMRefCell>, attr_list: MutNullableJS, class_list: MutNullableJS, + click_in_progress: Cell, } impl ElementDerived for EventTarget { @@ -175,6 +179,7 @@ impl Element { attr_list: Default::default(), class_list: Default::default(), style_attribute: DOMRefCell::new(None), + click_in_progress: Cell::new(false), } } @@ -1183,3 +1188,71 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { } } } + +pub trait ActivationElementHelpers<'a> { + fn as_maybe_activatable(&'a self) -> Option<&'a Activatable + 'a>; + fn click_in_progress(self) -> bool; + fn set_click_in_progress(self, click: bool); + fn nearest_activable_element(self) -> Option>; + fn authentic_click_activation<'b>(self, event: JSRef<'b, Event>); +} + +impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { + fn as_maybe_activatable(&'a self) -> Option<&'a Activatable + 'a> { + let node: JSRef = NodeCast::from_ref(*self); + match node.type_id() { + ElementNodeTypeId(HTMLInputElementTypeId) => { + let _element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(self).unwrap(); + // Some(element as &'a Activatable + 'a) + None + }, + _ => { + None + } + } + } + + fn click_in_progress(self) -> bool { + self.click_in_progress.get() + } + + fn set_click_in_progress(self, click: bool) { + self.click_in_progress.set(click) + } + + // https://html.spec.whatwg.org/multipage/interaction.html#nearest-activatable-element + fn nearest_activable_element(self) -> Option> { + let node: JSRef = NodeCast::from_ref(self); + node.ancestors() + .filter_map(|node| ElementCast::to_ref(node)) + .filter(|e| e.as_maybe_activatable().is_some()).next() + } + + // https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps + fn authentic_click_activation<'b>(self, event: JSRef<'b, Event>) { + let target: JSRef = EventTargetCast::from_ref(self); + // Step 2 (requires canvas support) + // Step 3 + self.set_click_in_progress(true); + // Step 4 + let e = self.nearest_activable_element(); + // Step 5 + e.map(|a| a.as_maybe_activatable().map(|el| el.pre_click_activation())); + // Step 6 + target.dispatch_event_with_target(None, event).ok(); + e.map(|el| { + if NodeCast::from_ref(el).is_in_doc() { + return; // XXXManishearth do we need this check? + } + el.as_maybe_activatable().map(|a| { + if event.DefaultPrevented() { + a.post_click_activation(); + } else { + a.canceled_activation(); + } + }); + }); + // Step 7 + self.set_click_in_progress(false); + } +} From 03207dea81fc4500c9df047de90083cf9af378c1 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 16 Nov 2014 07:41:22 +0530 Subject: [PATCH 06/19] Hook up authentic click activation to the script task --- components/script/script_task.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/script/script_task.rs b/components/script/script_task.rs index fdd4795ab25..acbd2cfbab3 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -18,8 +18,8 @@ use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap}; use dom::document::{Document, HTMLDocument, DocumentHelpers, FromParser}; use dom::element::{Element, HTMLButtonElementTypeId, HTMLInputElementTypeId}; -use dom::element::{HTMLSelectElementTypeId, HTMLTextAreaElementTypeId, HTMLOptionElementTypeId}; -use dom::event::{Event, Bubbles, DoesNotBubble, Cancelable, NotCancelable}; +use dom::element::{HTMLSelectElementTypeId, HTMLTextAreaElementTypeId, HTMLOptionElementTypeId, ActivationElementHelpers}; +use dom::event::{Event, EventHelpers, Bubbles, DoesNotBubble, Cancelable, NotCancelable}; use dom::uievent::UIEvent; use dom::eventtarget::{EventTarget, EventTargetHelpers}; use dom::keyboardevent::KeyboardEvent; @@ -1018,8 +1018,11 @@ impl ScriptTask { Event::new(global::Window(*window), "click".to_string(), Bubbles, Cancelable).root(); - let eventtarget: JSRef = EventTargetCast::from_ref(node); - let _ = eventtarget.dispatch_event_with_target(None, *event); + // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#trusted-events + event.set_trusted(true); + // https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps + let el = ElementCast::to_ref(node).unwrap(); // is_element() check already exists above + el.authentic_click_activation(*event); doc.commit_focus_transaction(); window.flush_layout(); From 2ed9626f1aca8a327a34d3819c1d854c115435e3 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 23 Nov 2014 08:28:05 +0530 Subject: [PATCH 07/19] Some reorganization of activation code: - Make method name apply to trait implementor better (When a user agent is to run post-click activation steps on an element, it must run the activation behavior defined for that element) - Mention invariants and conditions on authentic_click_activation --- components/script/dom/activation.rs | 5 +++-- components/script/dom/element.rs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index 98e8d435c12..267ca5d58a1 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -23,7 +23,7 @@ pub trait Activatable : Copy { fn canceled_activation(&self); // https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps - fn post_click_activation(&self); + fn activation_behavior(&self); // https://html.spec.whatwg.org/multipage/interaction.html#run-synthetic-click-activation-steps fn synthetic_click_activation(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { @@ -52,7 +52,8 @@ pub trait Activatable : Copy { if event.DefaultPrevented() { self.canceled_activation(); } else { - self.post_click_activation(); + // post click activation + self.activation_behavior(); } // Step 6 diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ca12d6f2afd..31e5358393f 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1228,8 +1228,19 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { .filter(|e| e.as_maybe_activatable().is_some()).next() } - // https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps + /// Please call this method *only* for real click events + /// + /// https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps + /// + /// Use an element's synthetic click activation (or handle_event) for any script-triggered clicks. + /// If the spec says otherwise, check with Manishearth first fn authentic_click_activation<'b>(self, event: JSRef<'b, Event>) { + // Not explicitly part of the spec, however this helps enforce the invariants + // required to save state between pre-activation and post-activation + // Since we cannot nest authentic clicks (unlike synthetic click activation, where + // the script can generate more click events from the handler) + assert!(!self.click_in_progress()); + let target: JSRef = EventTargetCast::from_ref(self); // Step 2 (requires canvas support) // Step 3 @@ -1246,7 +1257,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { } el.as_maybe_activatable().map(|a| { if event.DefaultPrevented() { - a.post_click_activation(); + // post click activation + a.activation_behavior(); } else { a.canceled_activation(); } From d1547e3a7c7ebc1b870b65793d6387ef7f12af5f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 24 Nov 2014 06:04:04 +0530 Subject: [PATCH 08/19] Move InputSubmit to Activatable --- components/script/dom/element.rs | 23 +++++------ components/script/dom/htmlinputelement.rs | 47 ++++++++++++++++++++--- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 31e5358393f..2708e0def6c 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1202,9 +1202,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { let node: JSRef = NodeCast::from_ref(*self); match node.type_id() { ElementNodeTypeId(HTMLInputElementTypeId) => { - let _element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(self).unwrap(); - // Some(element as &'a Activatable + 'a) - None + let element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(self).unwrap(); + Some(element as &'a Activatable + 'a) }, _ => { None @@ -1222,10 +1221,15 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { // https://html.spec.whatwg.org/multipage/interaction.html#nearest-activatable-element fn nearest_activable_element(self) -> Option> { - let node: JSRef = NodeCast::from_ref(self); - node.ancestors() - .filter_map(|node| ElementCast::to_ref(node)) - .filter(|e| e.as_maybe_activatable().is_some()).next() + match self.as_maybe_activatable() { + Some(el) => Some(*el.as_element().root()), + None => { + let node: JSRef = NodeCast::from_ref(self); + node.ancestors() + .filter_map(|node| ElementCast::to_ref(node)) + .filter(|e| e.as_maybe_activatable().is_some()).next() + } + } } /// Please call this method *only* for real click events @@ -1252,11 +1256,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { // Step 6 target.dispatch_event_with_target(None, event).ok(); e.map(|el| { - if NodeCast::from_ref(el).is_in_doc() { - return; // XXXManishearth do we need this check? - } el.as_maybe_activatable().map(|a| { - if event.DefaultPrevented() { + if !event.DefaultPrevented() { // post click activation a.activation_behavior(); } else { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 30b4dcaa820..148beb08cab 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::activation::Activatable; use dom::attr::{Attr, AttrValue, UIntAttrValue}; use dom::attr::AttrHelpers; use dom::bindings::cell::DOMRefCell; @@ -429,11 +430,6 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { match self.input_type.get() { InputCheckbox => self.SetChecked(!self.checked.get()), InputRadio => self.SetChecked(true), - InputSubmit => { - self.form_owner().map(|o| { - o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone())) - }); - } _ => {} } @@ -499,3 +495,44 @@ impl<'a> FormControl<'a> for JSRef<'a, HTMLInputElement> { !(self.Disabled() || self.ReadOnly()) } } + + +impl<'a> Activatable for JSRef<'a, HTMLInputElement> { + fn as_element(&self) -> Temporary { + Temporary::from_rooted(ElementCast::from_ref(*self)) + } + + // https://html.spec.whatwg.org/multipage/interaction.html#run-pre-click-activation-steps + fn pre_click_activation(&self) { + match self.input_type.get() { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + // InputSubmit => (), // No behavior defined + _ => () + } + } + + // https://html.spec.whatwg.org/multipage/interaction.html#run-canceled-activation-steps + fn canceled_activation(&self) { + match self.input_type.get() { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + // InputSubmit => (), // No behavior defined + _ => () + } + } + + // https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps + fn activation_behavior(&self) { + match self.input_type.get() { + InputSubmit => { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + // FIXME (Manishearth): + if self.mutable() /* and document owner is fully active */ { + self.form_owner().map(|o| { + o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone())) + }); + } + }, + _ => () + } + } +} From 14a6e54371a96736b4a211108e12494fae50e6bf Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 24 Nov 2014 06:41:54 +0530 Subject: [PATCH 09/19] Move InputCheckbox to Activatable --- components/script/dom/htmlinputelement.rs | 77 +++++++++++++++++-- .../dom/webidls/HTMLInputElement.webidl | 2 +- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 148beb08cab..ff8d553b246 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -8,19 +8,21 @@ use dom::attr::AttrHelpers; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; +use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLFormElementCast, HTMLInputElementCast, NodeCast}; -use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSetElementDerived}; +use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSetElementDerived, EventTargetCast}; use dom::bindings::codegen::InheritTypes::KeyboardEventCast; +use dom::bindings::global::Window; use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, ResultRootable}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, Element, HTMLInputElementTypeId}; use dom::element::RawLayoutElementHelpers; -use dom::event::Event; +use dom::event::{Event, Bubbles, NotCancelable, EventHelpers}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::keyboardevent::KeyboardEvent; @@ -34,6 +36,7 @@ use string_cache::Atom; use std::ascii::OwnedAsciiExt; use std::cell::Cell; +use std::cell::RefCell; const DEFAULT_SUBMIT_VALUE: &'static str = "Submit"; const DEFAULT_RESET_VALUE: &'static str = "Reset"; @@ -58,8 +61,25 @@ pub struct HTMLInputElement { htmlelement: HTMLElement, input_type: Cell, checked: Cell, + indeterminate: Cell, size: Cell, textinput: DOMRefCell, + activation_state: RefCell, +} + +#[jstraceable] +struct InputActivationState { + indeterminate: bool, + checked: bool +} + +impl InputActivationState { + fn new() -> InputActivationState { + InputActivationState { + indeterminate: false, + checked: false + } + } } impl HTMLInputElementDerived for EventTarget { @@ -76,8 +96,10 @@ impl HTMLInputElement { htmlelement: HTMLElement::new_inherited(HTMLInputElementTypeId, localName, prefix, document), input_type: Cell::new(InputText), checked: Cell::new(false), + indeterminate: Cell::new(false), size: Cell::new(DEFAULT_INPUT_SIZE), textinput: DOMRefCell::new(TextInput::new(Single, "".to_string())), + activation_state: RefCell::new(InputActivationState::new()) } } @@ -203,7 +225,7 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { make_setter!(SetFormEnctype, "formenctype") // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formmethod - make_enumerated_getter!(FormMethod, "get", "post" | "dialog") + make_enumerated_getter!(FormMethod, "get", "post" | "dialog") // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formmethod make_setter!(SetFormMethod, "formmethod") @@ -213,6 +235,17 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formtarget make_setter!(SetFormTarget, "formtarget") + + // https://html.spec.whatwg.org/multipage/forms.html#dom-input-indeterminate + fn Indeterminate(self) -> bool { + self.indeterminate.get() + } + + // https://html.spec.whatwg.org/multipage/forms.html#dom-input-indeterminate + fn SetIndeterminate(self, val: bool) { + // FIXME #4079 this should change the appearance + self.indeterminate.set(val) + } } pub trait HTMLInputElementHelpers { @@ -428,7 +461,6 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { if "click" == event.Type().as_slice() && !event.DefaultPrevented() { match self.input_type.get() { - InputCheckbox => self.SetChecked(!self.checked.get()), InputRadio => self.SetChecked(true), _ => {} } @@ -507,6 +539,18 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { match self.input_type.get() { // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 // InputSubmit => (), // No behavior defined + InputCheckbox => { + // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-%28type=checkbox%29 + if self.mutable() { + // cache current values of `checked` and `indeterminate` + // we may need to restore them later + let mut cache = self.activation_state.borrow_mut(); + cache.indeterminate = self.Indeterminate(); + cache.checked = self.Checked(); + self.SetIndeterminate(false); + self.SetChecked(!cache.checked); + } + }, _ => () } } @@ -516,6 +560,12 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { match self.input_type.get() { // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 // InputSubmit => (), // No behavior defined + InputCheckbox => { + // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-%28type=checkbox%29 + let cache = self.activation_state.borrow(); + self.SetIndeterminate(cache.indeterminate); + self.SetChecked(cache.checked); + }, _ => () } } @@ -525,13 +575,30 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { match self.input_type.get() { InputSubmit => { // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 - // FIXME (Manishearth): + // FIXME (Manishearth): support document owners (needs ability to get parent browsing context) if self.mutable() /* and document owner is fully active */ { self.form_owner().map(|o| { o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone())) }); } }, + InputCheckbox => { + // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-%28type=checkbox%29 + let win = window_from_node(*self).root(); + let event = Event::new(&Window(*win), + "input".to_string(), + Bubbles, NotCancelable).root(); + event.set_trusted(true); + let target: JSRef = EventTargetCast::from_ref(*self); + target.DispatchEvent(*event).ok(); + + let event = Event::new(&Window(*win), + "change".to_string(), + Bubbles, NotCancelable).root(); + event.set_trusted(true); + let target: JSRef = EventTargetCast::from_ref(*self); + target.DispatchEvent(*event).ok(); + }, _ => () } } diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl index 32b4f04261b..434da309f21 100644 --- a/components/script/dom/webidls/HTMLInputElement.webidl +++ b/components/script/dom/webidls/HTMLInputElement.webidl @@ -21,7 +21,7 @@ interface HTMLInputElement : HTMLElement { // attribute boolean formNoValidate; attribute DOMString formTarget; // attribute unsigned long height; - // attribute boolean indeterminate; + attribute boolean indeterminate; // attribute DOMString inputMode; //readonly attribute HTMLElement? list; // attribute DOMString max; From a5180a473d1372fdb26f255e7e25f7cb60c78abe Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 24 Nov 2014 12:16:09 +0530 Subject: [PATCH 10/19] Refactor code for fetching radio siblings --- components/script/dom/htmlinputelement.rs | 58 ++++++++++++++--------- components/script/dom/nodelist.rs | 14 ++++++ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index ff8d553b246..d838465e25f 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -12,7 +12,6 @@ use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; -use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLFormElementCast, HTMLInputElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSetElementDerived, EventTargetCast}; use dom::bindings::codegen::InheritTypes::KeyboardEventCast; @@ -28,6 +27,7 @@ use dom::htmlelement::HTMLElement; use dom::keyboardevent::KeyboardEvent; use dom::htmlformelement::{InputElement, FormControl, HTMLFormElement, HTMLFormElementHelpers, NotFromFormSubmitMethod}; use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node}; +use dom::nodelist::NodeListHelpers; use dom::virtualmethods::VirtualMethods; use textinput::{Single, TextInput, TriggerDefaultAction, DispatchInput, Nothing}; @@ -251,29 +251,19 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { pub trait HTMLInputElementHelpers { fn force_relayout(self); fn radio_group_updated(self, group: Option<&str>); - fn get_radio_group(self) -> Option; + fn get_radio_group_name(self) -> Option; + fn get_radio_group_all(self, group: Option<&str>) -> Vec>; fn update_checked_state(self, checked: bool); fn get_size(&self) -> u32; } fn broadcast_radio_checked(broadcaster: JSRef, group: Option<&str>) { //TODO: if not in document, use root ancestor instead of document - let doc = document_from_node(broadcaster).root(); - let radios = doc.QuerySelectorAll("input[type=\"radio\"]".to_string()).unwrap().root(); - let mut i = 0; - while i < radios.Length() { - let node = radios.Item(i).unwrap().root(); - let radio: JSRef = HTMLInputElementCast::to_ref(*node).unwrap(); - if radio != broadcaster { - //TODO: determine form owner - let other_group = radio.get_radio_group(); - //TODO: ensure compatibility caseless match (https://html.spec.whatwg.org/multipage/infrastructure.html#compatibility-caseless) - let group_matches = other_group.as_ref().map(|group| group.as_slice()) == group.as_ref().map(|&group| &*group); - if group_matches && radio.Checked() { - radio.SetChecked(false); - } + for r in broadcaster.get_radio_group_all(group).iter().filter(|r| *r.root() != broadcaster) { + let radio = r.root(); + if radio.Checked() { + radio.SetChecked(false); } - i += 1; } } @@ -290,8 +280,8 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { } } - // https://html.spec.whatwg.org/multipage/forms.html#radio-button-group - fn get_radio_group(self) -> Option { + + fn get_radio_group_name(self) -> Option { //TODO: determine form owner let elem: JSRef = ElementCast::from_ref(self); elem.get_attribute(ns!(""), &atom!("name")) @@ -299,11 +289,32 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { .map(|name| name.Value()) } + // https://html.spec.whatwg.org/multipage/forms.html#radio-button-group + fn get_radio_group_all(self, group: Option<&str>) -> Vec> { + assert!(self.input_type.get() == InputRadio); + //TODO: if not in document, use root ancestor instead of document + let doc = document_from_node(self).root(); + // FIXME (#4082) instead of allocating a bunch of times, use a proper iterator + let radios = doc.QuerySelectorAll("input[type=\"radio\"]".to_string()).unwrap().root(); + let owner = self.form_owner(); + radios.into_vec().iter().filter_map(|t| HTMLInputElementCast::to_ref(*t.root())).filter(|r| { + r.input_type.get() == InputRadio && + // TODO Both a and b are in the same home subtree. + r.form_owner() == owner && + // TODO should be a unicode compatibility caseless match + match (r.get_radio_group_name(), group) { + (Some(ref s1), Some(s2)) if s1.as_slice() == s2 => true, + (None, None) => true, + _ => false + } + }).map(|r| Temporary::from_rooted(r)).collect() + } + fn update_checked_state(self, checked: bool) { self.checked.set(checked); if self.input_type.get() == InputRadio && checked { broadcast_radio_checked(self, - self.get_radio_group() + self.get_radio_group_name() .as_ref() .map(|group| group.as_slice())); } @@ -357,7 +368,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { _ => InputText, }); if self.input_type.get() == InputRadio { - self.radio_group_updated(self.get_radio_group() + self.radio_group_updated(self.get_radio_group_name() .as_ref() .map(|group| group.as_slice())); } @@ -400,7 +411,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { &atom!("type") => { if self.input_type.get() == InputRadio { broadcast_radio_checked(*self, - self.get_radio_group() + self.get_radio_group_name() .as_ref() .map(|group| group.as_slice())); } @@ -465,6 +476,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { _ => {} } + // TODO: Dispatch events for non activatable inputs + // https://html.spec.whatwg.org/multipage/forms.html#common-input-element-events + //TODO: set the editing position for text inputs let doc = document_from_node(*self).root(); diff --git a/components/script/dom/nodelist.rs b/components/script/dom/nodelist.rs index d30f0ffc6b3..d3eaa5936ec 100644 --- a/components/script/dom/nodelist.rs +++ b/components/script/dom/nodelist.rs @@ -81,3 +81,17 @@ impl Reflectable for NodeList { &self.reflector_ } } + +pub trait NodeListHelpers { + fn into_vec(self) -> Vec>; +} + + +impl<'a> NodeListHelpers for JSRef<'a, NodeList> { + fn into_vec(self) -> Vec> { + match self.list_type { + Simple(ref elems) => elems.iter().map(|j| Temporary::new(*j)).collect(), + Children(ref node) => vec![Temporary::new(*node)] + } + } +} From e68119f82f4b0684918a76299d115b86285be97b Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 24 Nov 2014 13:37:36 +0530 Subject: [PATCH 11/19] Move InputRadio to Activatable --- components/script/dom/htmlinputelement.rs | 149 +++++++++++++++++----- 1 file changed, 114 insertions(+), 35 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index d838465e25f..a0b02f6a3d2 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -16,7 +16,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLFor use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSetElementDerived, EventTargetCast}; use dom::bindings::codegen::InheritTypes::KeyboardEventCast; use dom::bindings::global::Window; -use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, ResultRootable}; +use dom::bindings::js::{JS, JSRef, Root, Temporary, OptionalRootable, ResultRootable, MutNullableJS}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, Element, HTMLInputElementTypeId}; @@ -37,6 +37,7 @@ use string_cache::Atom; use std::ascii::OwnedAsciiExt; use std::cell::Cell; use std::cell::RefCell; +use std::default::Default; const DEFAULT_SUBMIT_VALUE: &'static str = "Submit"; const DEFAULT_RESET_VALUE: &'static str = "Reset"; @@ -68,16 +69,25 @@ pub struct HTMLInputElement { } #[jstraceable] +#[must_root] struct InputActivationState { indeterminate: bool, - checked: bool + checked: bool, + checked_radio: MutNullableJS, + // In case mutability changed + was_mutable: bool, + // In case the type changed + old_type: InputType, } impl InputActivationState { fn new() -> InputActivationState { InputActivationState { indeterminate: false, - checked: false + checked: false, + checked_radio: Default::default(), + was_mutable: false, + old_type: InputText } } } @@ -280,7 +290,6 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { } } - fn get_radio_group_name(self) -> Option { //TODO: determine form owner let elem: JSRef = ElementCast::from_ref(self); @@ -550,45 +559,94 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/interaction.html#run-pre-click-activation-steps fn pre_click_activation(&self) { - match self.input_type.get() { - // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 - // InputSubmit => (), // No behavior defined - InputCheckbox => { - // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-%28type=checkbox%29 - if self.mutable() { + let mut cache = self.activation_state.borrow_mut(); + let ty = self.input_type.get(); + cache.old_type = ty; + if self.mutable() { + cache.was_mutable = true; + match ty { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-(type=submit):activation-behavior + // InputSubmit => (), // No behavior defined + InputCheckbox => { + // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-(type=checkbox):pre-click-activation-steps // cache current values of `checked` and `indeterminate` // we may need to restore them later - let mut cache = self.activation_state.borrow_mut(); cache.indeterminate = self.Indeterminate(); cache.checked = self.Checked(); self.SetIndeterminate(false); self.SetChecked(!cache.checked); + }, + // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):pre-click-activation-steps + InputRadio => { + cache.checked_radio.assign(self.get_radio_group_all(self.get_radio_group_name().as_ref() + .map(|s| s.as_slice())) + .into_iter().find(|r| r.root().Checked())); + self.SetChecked(true); } - }, - _ => () + _ => () + } + } else { + cache.was_mutable = false; } } // https://html.spec.whatwg.org/multipage/interaction.html#run-canceled-activation-steps fn canceled_activation(&self) { - match self.input_type.get() { - // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + let cache = self.activation_state.borrow(); + let ty = self.input_type.get(); + if cache.old_type != ty { + // Type changed, abandon ship + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27414 + return; + } + match ty { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-(type=submit):activation-behavior // InputSubmit => (), // No behavior defined + // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-(type=checkbox):canceled-activation-steps InputCheckbox => { - // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-%28type=checkbox%29 - let cache = self.activation_state.borrow(); - self.SetIndeterminate(cache.indeterminate); - self.SetChecked(cache.checked); + // We want to restore state only if the element had been changed in the first place + if cache.was_mutable { + self.SetIndeterminate(cache.indeterminate); + self.SetChecked(cache.checked); + } }, + // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):canceled-activation-steps + InputRadio => { + // We want to restore state only if the element had been changed in the first place + if cache.was_mutable { + let old_checked: Option> = cache.checked_radio.get().root(); + let name = self.get_radio_group_name(); + old_checked.map_or_else(|| self.SetChecked(false), + |o| { + // Avoiding iterating through the whole tree here, instead + // we can check if the conditions for radio group siblings apply + if name != None && // unless self no longer has a button group + name == o.get_radio_group_name() && // TODO should be compatibility caseless + self.form_owner() == o.form_owner() && + // TODO Both a and b are in the same home subtree + o.input_type.get() == InputRadio { + o.SetChecked(true); + } else { + self.SetChecked(false); + } + }); + } + } _ => () } } // https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps fn activation_behavior(&self) { - match self.input_type.get() { + let ty = self.input_type.get(); + if self.activation_state.borrow().old_type != ty { + // Type changed, abandon ship + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27414 + return; + } + match ty { InputSubmit => { - // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-(type=submit):activation-behavior // FIXME (Manishearth): support document owners (needs ability to get parent browsing context) if self.mutable() /* and document owner is fully active */ { self.form_owner().map(|o| { @@ -597,21 +655,42 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { } }, InputCheckbox => { - // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-%28type=checkbox%29 - let win = window_from_node(*self).root(); - let event = Event::new(&Window(*win), - "input".to_string(), - Bubbles, NotCancelable).root(); - event.set_trusted(true); - let target: JSRef = EventTargetCast::from_ref(*self); - target.DispatchEvent(*event).ok(); + // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-(type=checkbox):activation-behavior + if self.mutable() { + let win = window_from_node(*self).root(); + let event = Event::new(&Window(*win), + "input".to_string(), + Bubbles, NotCancelable).root(); + event.set_trusted(true); + let target: JSRef = EventTargetCast::from_ref(*self); + target.DispatchEvent(*event).ok(); - let event = Event::new(&Window(*win), - "change".to_string(), - Bubbles, NotCancelable).root(); - event.set_trusted(true); - let target: JSRef = EventTargetCast::from_ref(*self); - target.DispatchEvent(*event).ok(); + let event = Event::new(&Window(*win), + "change".to_string(), + Bubbles, NotCancelable).root(); + event.set_trusted(true); + let target: JSRef = EventTargetCast::from_ref(*self); + target.DispatchEvent(*event).ok(); + } + }, + InputRadio => { + // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):activation-behavior + if self.mutable() { + let win = window_from_node(*self).root(); + let event = Event::new(&Window(*win), + "input".to_string(), + Bubbles, NotCancelable).root(); + event.set_trusted(true); + let target: JSRef = EventTargetCast::from_ref(*self); + target.DispatchEvent(*event).ok(); + + let event = Event::new(&Window(*win), + "change".to_string(), + Bubbles, NotCancelable).root(); + event.set_trusted(true); + let target: JSRef = EventTargetCast::from_ref(*self); + target.DispatchEvent(*event).ok(); + } }, _ => () } From c89ec3910f15f3a71be66d60da5cfd9aed1b30f1 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 24 Nov 2014 20:12:17 +0530 Subject: [PATCH 12/19] Hook up synthetic click activation to script_task and <>.click() --- components/script/dom/htmlelement.rs | 16 ++++++++-- .../script/dom/webidls/HTMLElement.webidl | 2 +- components/script/script_task.rs | 19 ++++++++++-- .../html/test-synthetic-click-activation.html | 31 +++++++++++++++++++ 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 tests/html/test-synthetic-click-activation.html diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 75ad910ee2e..728f0ee573d 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -7,14 +7,15 @@ use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::HTMLElementBinding; use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; +use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFrameSetElementDerived}; -use dom::bindings::codegen::InheritTypes::EventTargetCast; +use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLInputElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLElementDerived, HTMLBodyElementDerived}; use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::Document; -use dom::element::{Element, ElementTypeId, ElementTypeId_, HTMLElementTypeId}; +use dom::element::{Element, ElementTypeId, ElementTypeId_, HTMLElementTypeId, ActivationElementHelpers}; use dom::eventtarget::{EventTarget, EventTargetHelpers, NodeTargetTypeId}; use dom::node::{Node, ElementNodeTypeId, window_from_node}; use dom::virtualmethods::VirtualMethods; @@ -91,6 +92,17 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { win.SetOnload(listener) } } + + // https://html.spec.whatwg.org/multipage/interaction.html#dom-click + fn Click(self) { + let maybe_input = HTMLInputElementCast::to_ref(self); + match maybe_input { + Some(i) if i.Disabled() => return, + _ => () + } + let element: JSRef = ElementCast::from_ref(self); + element.as_maybe_activatable().map(|a| a.synthetic_click_activation(false, false, false, false)); + } } impl<'a> VirtualMethods for JSRef<'a, HTMLElement> { diff --git a/components/script/dom/webidls/HTMLElement.webidl b/components/script/dom/webidls/HTMLElement.webidl index 10be66c62e3..359ef11f0a7 100644 --- a/components/script/dom/webidls/HTMLElement.webidl +++ b/components/script/dom/webidls/HTMLElement.webidl @@ -23,7 +23,7 @@ interface HTMLElement : Element { // user interaction attribute boolean hidden; - //void click(); + void click(); // attribute long tabIndex; //void focus(); //void blur(); diff --git a/components/script/script_task.rs b/components/script/script_task.rs index acbd2cfbab3..9ccf7653af5 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -893,9 +893,9 @@ impl ScriptTask { None, props.key_code).root(); let event = EventCast::from_ref(*keyevent); let _ = target.DispatchEvent(event); - + let mut prevented = event.DefaultPrevented(); // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys - if state != Released && props.is_printable() && !event.DefaultPrevented() { + if state != Released && props.is_printable() && !prevented { // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order let event = KeyboardEvent::new(*window, "keypress".to_string(), true, true, Some(*window), 0, props.key.to_string(), props.code.to_string(), @@ -904,9 +904,24 @@ impl ScriptTask { props.char_code, 0).root(); let _ = target.DispatchEvent(EventCast::from_ref(*event)); + let ev = EventCast::from_ref(*event); + prevented = ev.DefaultPrevented(); // TODO: if keypress event is canceled, prevent firing input events } + // This behavior is unspecced + // We are supposed to dispatch synthetic click activation for Space and/or Return, + // however *when* we do it is up to us + // I'm dispatching it after the key event so the script has a chance to cancel it + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337 + match key { + Key::KeySpace | Key::KeyEnter if !prevented && state == Released => { + // TODO handle space and enter slightly differently + let maybe_elem: Option> = ElementCast::to_ref(target); + maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.synthetic_click_activation(ctrl, alt, shift, meta))); + } + _ => () + } window.flush_layout(); } diff --git a/tests/html/test-synthetic-click-activation.html b/tests/html/test-synthetic-click-activation.html new file mode 100644 index 00000000000..011914895a7 --- /dev/null +++ b/tests/html/test-synthetic-click-activation.html @@ -0,0 +1,31 @@ + +
+
+
+
+
+
group 1 +
+
+
+
group 2 +
+
+
+
+
+Use the buttons below to shift "fake" focus and trigger click events. The first form widget is initually focused. +
+
+
+
+ + + From 6482e313d646e25368548eb734a8ed49a4dfcee7 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 24 Nov 2014 21:49:55 +0530 Subject: [PATCH 13/19] Implement implicit form submission --- components/script/dom/activation.rs | 3 +++ components/script/dom/htmlinputelement.rs | 17 ++++++++++++++++- components/script/script_task.rs | 7 +++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index 267ca5d58a1..e4a54112e58 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -25,6 +25,9 @@ pub trait Activatable : Copy { // https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps fn activation_behavior(&self); + // https://html.spec.whatwg.org/multipage/forms.html#implicit-submission + fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool); + // https://html.spec.whatwg.org/multipage/interaction.html#run-synthetic-click-activation-steps fn synthetic_click_activation(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { let element = self.as_element().root(); diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index a0b02f6a3d2..c5e103eaa48 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -20,7 +20,7 @@ use dom::bindings::js::{JS, JSRef, Root, Temporary, OptionalRootable, ResultRoot use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, Element, HTMLInputElementTypeId}; -use dom::element::RawLayoutElementHelpers; +use dom::element::{RawLayoutElementHelpers, ActivationElementHelpers}; use dom::event::{Event, Bubbles, NotCancelable, EventHelpers}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; @@ -695,4 +695,19 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { _ => () } } + + // https://html.spec.whatwg.org/multipage/forms.html#implicit-submission + fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { + let doc = document_from_node(*self).root(); + // FIXME (#4082) use a custom iterator + let submits = doc.QuerySelectorAll("input[type=submit]".to_string()).unwrap().root(); + // XXXManishearth there may be a more efficient way of doing this (#3553) + let owner = self.form_owner(); + if owner == None || ElementCast::from_ref(*self).click_in_progress() { + return; + } + submits.into_vec().iter() + .filter_map(|t| HTMLInputElementCast::to_ref(*t.root())) + .find(|r| r.form_owner() == owner).map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); + } } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 9ccf7653af5..f0352052df9 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -915,11 +915,14 @@ impl ScriptTask { // I'm dispatching it after the key event so the script has a chance to cancel it // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337 match key { - Key::KeySpace | Key::KeyEnter if !prevented && state == Released => { - // TODO handle space and enter slightly differently + Key::KeySpace if !prevented && state == Released => { let maybe_elem: Option> = ElementCast::to_ref(target); maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.synthetic_click_activation(ctrl, alt, shift, meta))); } + Key::KeyEnter if !prevented && state == Released => { + let maybe_elem: Option> = ElementCast::to_ref(target); + maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.implicit_submission(ctrl, alt, shift, meta))); + } _ => () } window.flush_layout(); From a2f7e0fbd6f13b8bd8a2e3925c7e1e76f6968879 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 26 Nov 2014 10:46:45 +0530 Subject: [PATCH 14/19] Address review comments --- components/script/dom/element.rs | 47 +++++++------ components/script/dom/htmlelement.rs | 1 + components/script/dom/htmlinputelement.rs | 80 +++++++++-------------- components/script/script_task.rs | 2 + 4 files changed, 63 insertions(+), 67 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 2708e0def6c..83dd5593d04 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -10,9 +10,9 @@ use dom::attr::{AttrValue, StringAttrValue, UIntAttrValue, AtomAttrValue}; use dom::namednodemap::NamedNodeMap; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; -use dom::bindings::codegen::Bindings::EventBinding::EventMethods; 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::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::InheritTypes::{ElementDerived, HTMLInputElementDerived, HTMLTableCellElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, NodeCast, EventTargetCast, ElementCast}; @@ -60,6 +60,9 @@ pub struct Element { style_attribute: DOMRefCell>, attr_list: MutNullableJS, class_list: MutNullableJS, + // TODO: find a better place to keep this (#4105) + // https://critic.hoppipolla.co.uk/showcomment?chain=8873 + // Perhaps using a Set in Document? click_in_progress: Cell, } @@ -1193,7 +1196,7 @@ pub trait ActivationElementHelpers<'a> { fn as_maybe_activatable(&'a self) -> Option<&'a Activatable + 'a>; fn click_in_progress(self) -> bool; fn set_click_in_progress(self, click: bool); - fn nearest_activable_element(self) -> Option>; + fn nearest_activable_element(self) -> Option>; fn authentic_click_activation<'b>(self, event: JSRef<'b, Event>); } @@ -1220,14 +1223,15 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { } // https://html.spec.whatwg.org/multipage/interaction.html#nearest-activatable-element - fn nearest_activable_element(self) -> Option> { + fn nearest_activable_element(self) -> Option> { match self.as_maybe_activatable() { - Some(el) => Some(*el.as_element().root()), + Some(el) => Some(Temporary::from_rooted(*el.as_element().root())), None => { let node: JSRef = NodeCast::from_ref(self); node.ancestors() .filter_map(|node| ElementCast::to_ref(node)) .filter(|e| e.as_maybe_activatable().is_some()).next() + .map(|r| Temporary::from_rooted(r)) } } } @@ -1241,7 +1245,7 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { fn authentic_click_activation<'b>(self, event: JSRef<'b, Event>) { // Not explicitly part of the spec, however this helps enforce the invariants // required to save state between pre-activation and post-activation - // Since we cannot nest authentic clicks (unlike synthetic click activation, where + // since we cannot nest authentic clicks (unlike synthetic click activation, where // the script can generate more click events from the handler) assert!(!self.click_in_progress()); @@ -1250,21 +1254,26 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { // Step 3 self.set_click_in_progress(true); // Step 4 - let e = self.nearest_activable_element(); - // Step 5 - e.map(|a| a.as_maybe_activatable().map(|el| el.pre_click_activation())); - // Step 6 - target.dispatch_event_with_target(None, event).ok(); - e.map(|el| { - el.as_maybe_activatable().map(|a| { - if !event.DefaultPrevented() { - // post click activation - a.activation_behavior(); - } else { - a.canceled_activation(); + let e = self.nearest_activable_element().root(); + match e { + Some (el) => match el.as_maybe_activatable() { + Some(elem) => { + // Step 5-6 + elem.pre_click_activation(); + target.dispatch_event_with_target(None, event).ok(); + if !event.DefaultPrevented() { + // post click activation + elem.activation_behavior(); + } else { + elem.canceled_activation(); + } } - }); - }); + // Step 6 + None => {target.dispatch_event_with_target(None, event).ok();} + }, + // Step 6 + None => {target.dispatch_event_with_target(None, event).ok();} + } // Step 7 self.set_click_in_progress(false); } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 728f0ee573d..7467ea56fdf 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -101,6 +101,7 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { _ => () } let element: JSRef = ElementCast::from_ref(self); + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27430 ? element.as_maybe_activatable().map(|a| a.synthetic_click_activation(false, false, false, false)); } } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index c5e103eaa48..856c51144e0 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -8,8 +8,8 @@ use dom::attr::AttrHelpers; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; -use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; +use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLFormElementCast, HTMLInputElementCast, NodeCast}; @@ -36,7 +36,6 @@ use string_cache::Atom; use std::ascii::OwnedAsciiExt; use std::cell::Cell; -use std::cell::RefCell; use std::default::Default; const DEFAULT_SUBMIT_VALUE: &'static str = "Submit"; @@ -65,7 +64,7 @@ pub struct HTMLInputElement { indeterminate: Cell, size: Cell, textinput: DOMRefCell, - activation_state: RefCell, + activation_state: DOMRefCell, } #[jstraceable] @@ -109,7 +108,7 @@ impl HTMLInputElement { indeterminate: Cell::new(false), size: Cell::new(DEFAULT_INPUT_SIZE), textinput: DOMRefCell::new(TextInput::new(Single, "".to_string())), - activation_state: RefCell::new(InputActivationState::new()) + activation_state: DOMRefCell::new(InputActivationState::new()) } } @@ -262,14 +261,14 @@ pub trait HTMLInputElementHelpers { fn force_relayout(self); fn radio_group_updated(self, group: Option<&str>); fn get_radio_group_name(self) -> Option; - fn get_radio_group_all(self, group: Option<&str>) -> Vec>; + fn get_radio_group_members(self, group: Option<&str>) -> Vec>; fn update_checked_state(self, checked: bool); fn get_size(&self) -> u32; } fn broadcast_radio_checked(broadcaster: JSRef, group: Option<&str>) { //TODO: if not in document, use root ancestor instead of document - for r in broadcaster.get_radio_group_all(group).iter().filter(|r| *r.root() != broadcaster) { + for r in broadcaster.get_radio_group_members(group).iter().filter(|r| *r.root() != broadcaster) { let radio = r.root(); if radio.Checked() { radio.SetChecked(false); @@ -299,7 +298,7 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { } // https://html.spec.whatwg.org/multipage/forms.html#radio-button-group - fn get_radio_group_all(self, group: Option<&str>) -> Vec> { + fn get_radio_group_members(self, group: Option<&str>) -> Vec> { assert!(self.input_type.get() == InputRadio); //TODO: if not in document, use root ancestor instead of document let doc = document_from_node(self).root(); @@ -312,7 +311,7 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { r.form_owner() == owner && // TODO should be a unicode compatibility caseless match match (r.get_radio_group_name(), group) { - (Some(ref s1), Some(s2)) if s1.as_slice() == s2 => true, + (Some(ref s1), Some(s2)) => s1.as_slice() == s2, (None, None) => true, _ => false } @@ -562,8 +561,8 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { let mut cache = self.activation_state.borrow_mut(); let ty = self.input_type.get(); cache.old_type = ty; - if self.mutable() { - cache.was_mutable = true; + cache.was_mutable = self.mutable(); + if cache.was_mutable { match ty { // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-(type=submit):activation-behavior // InputSubmit => (), // No behavior defined @@ -578,15 +577,14 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { }, // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):pre-click-activation-steps InputRadio => { - cache.checked_radio.assign(self.get_radio_group_all(self.get_radio_group_name().as_ref() - .map(|s| s.as_slice())) - .into_iter().find(|r| r.root().Checked())); + let members = self.get_radio_group_members(self.get_radio_group_name().as_ref() + .map(|s| s.as_slice())); + let checked_member = members.into_iter().find(|r| r.root().Checked()); + cache.checked_radio.assign(checked_member); self.SetChecked(true); } _ => () } - } else { - cache.was_mutable = false; } } @@ -616,8 +614,8 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { if cache.was_mutable { let old_checked: Option> = cache.checked_radio.get().root(); let name = self.get_radio_group_name(); - old_checked.map_or_else(|| self.SetChecked(false), - |o| { + match old_checked { + Some(o) => { // Avoiding iterating through the whole tree here, instead // we can check if the conditions for radio group siblings apply if name != None && // unless self no longer has a button group @@ -629,8 +627,10 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { } else { self.SetChecked(false); } - }); - } + }, + None => self.SetChecked(false) + }; + } } _ => () } @@ -639,7 +639,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps fn activation_behavior(&self) { let ty = self.input_type.get(); - if self.activation_state.borrow().old_type != ty { + if self.activation_state.borrow().old_type != ty { // Type changed, abandon ship // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27414 return; @@ -654,26 +654,8 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { }); } }, - InputCheckbox => { + InputCheckbox | InputRadio => { // https://html.spec.whatwg.org/multipage/forms.html#checkbox-state-(type=checkbox):activation-behavior - if self.mutable() { - let win = window_from_node(*self).root(); - let event = Event::new(&Window(*win), - "input".to_string(), - Bubbles, NotCancelable).root(); - event.set_trusted(true); - let target: JSRef = EventTargetCast::from_ref(*self); - target.DispatchEvent(*event).ok(); - - let event = Event::new(&Window(*win), - "change".to_string(), - Bubbles, NotCancelable).root(); - event.set_trusted(true); - let target: JSRef = EventTargetCast::from_ref(*self); - target.DispatchEvent(*event).ok(); - } - }, - InputRadio => { // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):activation-behavior if self.mutable() { let win = window_from_node(*self).root(); @@ -700,14 +682,16 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { let doc = document_from_node(*self).root(); // FIXME (#4082) use a custom iterator - let submits = doc.QuerySelectorAll("input[type=submit]".to_string()).unwrap().root(); - // XXXManishearth there may be a more efficient way of doing this (#3553) - let owner = self.form_owner(); - if owner == None || ElementCast::from_ref(*self).click_in_progress() { - return; - } - submits.into_vec().iter() - .filter_map(|t| HTMLInputElementCast::to_ref(*t.root())) - .find(|r| r.form_owner() == owner).map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); + doc.QuerySelectorAll("input[type=submit]".to_string()).root().map(|submits| { + // XXXManishearth there may be a more efficient way of doing this (#3553) + let owner = self.form_owner(); + if owner == None || ElementCast::from_ref(*self).click_in_progress() { + return; + } + submits.into_vec().iter() + .filter_map(|t| HTMLInputElementCast::to_ref(*t.root())) + .find(|r| r.form_owner() == owner) + .map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); + }); } } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index f0352052df9..31fa79452df 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -894,6 +894,7 @@ impl ScriptTask { let event = EventCast::from_ref(*keyevent); let _ = target.DispatchEvent(event); let mut prevented = event.DefaultPrevented(); + // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys if state != Released && props.is_printable() && !prevented { // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order @@ -925,6 +926,7 @@ impl ScriptTask { } _ => () } + window.flush_layout(); } From 3ba4bba28b0fc2da561eded0dd87465022c724e0 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 26 Nov 2014 13:18:34 +0530 Subject: [PATCH 15/19] Implement QuerySelectorIterator (fixes #4082) --- components/script/dom/node.rs | 56 ++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 2c02ebc9b1e..55b785a04db 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -50,7 +50,7 @@ use devtools_traits::NodeInfo; use script_traits::UntrustedNodeAddress; use servo_util::geometry::Au; use servo_util::str::{DOMString, null_str_as_empty}; -use style::{parse_selector_list_from_str, matches}; +use style::{parse_selector_list_from_str, matches, SelectorList}; use js::jsapi::{JSContext, JSObject, JSTracer, JSRuntime}; use js::jsfriendapi; @@ -377,6 +377,29 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { } } +pub struct QuerySelectorIterator<'a> { + selectors: SelectorList, + iterator: TreeIterator<'a>, +} + +impl<'a> QuerySelectorIterator<'a> { + unsafe fn new(iter: TreeIterator<'a>, selectors: SelectorList) -> QuerySelectorIterator<'a> { + QuerySelectorIterator { + selectors: selectors, + iterator: iter, + } + } +} + +impl<'a> Iterator> for QuerySelectorIterator<'a> { + fn next(&mut self) -> Option> { + let selectors = &self.selectors; + // TODO(cgaebel): Is it worth it to build a bloom filter here + // (instead of passing `None`)? Probably. + self.iterator.find(|node| node.is_element() && matches(selectors, node, &mut None)) + } +} + pub trait NodeHelpers<'a> { fn ancestors(self) -> AncestorIterator<'a>; fn children(self) -> NodeChildrenIterator<'a>; @@ -449,6 +472,7 @@ pub trait NodeHelpers<'a> { fn get_content_boxes(self) -> Vec>; fn query_selector(self, selectors: DOMString) -> Fallible>>; + unsafe fn query_selector_iter(self, selectors: DOMString) -> Fallible>; fn query_selector_all(self, selectors: DOMString) -> Fallible>; fn remove_self(self); @@ -719,8 +743,10 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { Ok(None) } - // http://dom.spec.whatwg.org/#dom-parentnode-queryselectorall - fn query_selector_all(self, selectors: DOMString) -> Fallible> { + /// Get an iterator over all nodes which match a set of selectors + /// Be careful not to do anything which may manipulate the DOM tree whilst iterating, otherwise + /// the iterator may be invalidated + unsafe fn query_selector_iter(self, selectors: DOMString) -> Fallible> { // Step 1. let nodes; let root = self.ancestors().last().unwrap_or(self.clone()); @@ -728,17 +754,25 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { // Step 2. Err(()) => return Err(Syntax), // Step 3. - Ok(ref selectors) => { - nodes = root.traverse_preorder().filter( - // TODO(cgaebel): Is it worth it to build a bloom filter here - // (instead of passing `None`)? Probably. - |node| node.is_element() && matches(selectors, node, &mut None)).collect() + Ok(selectors) => { + nodes = QuerySelectorIterator::new(root.traverse_preorder(), selectors); } - } - let window = window_from_node(self).root(); - Ok(NodeList::new_simple_list(*window, nodes)) + }; + Ok(nodes) } + // http://dom.spec.whatwg.org/#dom-parentnode-queryselectorall + fn query_selector_all(self, selectors: DOMString) -> Fallible> { + // Step 1. + unsafe { + self.query_selector_iter(selectors).map(|mut iter| { + let window = window_from_node(self).root(); + NodeList::new_simple_list(*window, iter.collect()) + }) + } + } + + fn ancestors(self) -> AncestorIterator<'a> { AncestorIterator { current: self.parent_node.get().map(|node| (*node.root()).clone()), From b20d7d89c10d0a5e55edc3989c2b0a855146dcb2 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 26 Nov 2014 15:41:31 +0530 Subject: [PATCH 16/19] Switch over to query_selector_iter --- components/script/dom/htmlinputelement.rs | 96 +++++++++++++---------- components/script/dom/nodelist.rs | 14 ---- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 856c51144e0..be3b52b4ae6 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -27,7 +27,6 @@ use dom::htmlelement::HTMLElement; use dom::keyboardevent::KeyboardEvent; use dom::htmlformelement::{InputElement, FormControl, HTMLFormElement, HTMLFormElementHelpers, NotFromFormSubmitMethod}; use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node}; -use dom::nodelist::NodeListHelpers; use dom::virtualmethods::VirtualMethods; use textinput::{Single, TextInput, TriggerDefaultAction, DispatchInput, Nothing}; @@ -261,17 +260,28 @@ pub trait HTMLInputElementHelpers { fn force_relayout(self); fn radio_group_updated(self, group: Option<&str>); fn get_radio_group_name(self) -> Option; - fn get_radio_group_members(self, group: Option<&str>) -> Vec>; + fn in_same_group<'a,'b>(self, other: JSRef<'a, HTMLInputElement>, + owner: Option>, + group: Option<&str>) -> bool; fn update_checked_state(self, checked: bool); fn get_size(&self) -> u32; } fn broadcast_radio_checked(broadcaster: JSRef, group: Option<&str>) { //TODO: if not in document, use root ancestor instead of document - for r in broadcaster.get_radio_group_members(group).iter().filter(|r| *r.root() != broadcaster) { - let radio = r.root(); - if radio.Checked() { - radio.SetChecked(false); + let owner = broadcaster.form_owner().root().map(|r| *r); + let doc = document_from_node(broadcaster).root(); + let doc_node: JSRef = NodeCast::from_ref(*doc); + + // There is no DOM tree manipulation here, so this is safe + let mut iter = unsafe { + doc_node.query_selector_iter("input[type=radio]".to_string()).unwrap() + .filter_map(|t| HTMLInputElementCast::to_ref(t)) + .filter(|&r| broadcaster.in_same_group(r, owner, group) && broadcaster != r) + }; + for r in iter { + if r.Checked() { + r.SetChecked(false); } } } @@ -297,25 +307,19 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { .map(|name| name.Value()) } - // https://html.spec.whatwg.org/multipage/forms.html#radio-button-group - fn get_radio_group_members(self, group: Option<&str>) -> Vec> { - assert!(self.input_type.get() == InputRadio); - //TODO: if not in document, use root ancestor instead of document - let doc = document_from_node(self).root(); - // FIXME (#4082) instead of allocating a bunch of times, use a proper iterator - let radios = doc.QuerySelectorAll("input[type=\"radio\"]".to_string()).unwrap().root(); - let owner = self.form_owner(); - radios.into_vec().iter().filter_map(|t| HTMLInputElementCast::to_ref(*t.root())).filter(|r| { - r.input_type.get() == InputRadio && - // TODO Both a and b are in the same home subtree. - r.form_owner() == owner && - // TODO should be a unicode compatibility caseless match - match (r.get_radio_group_name(), group) { - (Some(ref s1), Some(s2)) => s1.as_slice() == s2, - (None, None) => true, - _ => false - } - }).map(|r| Temporary::from_rooted(r)).collect() + fn in_same_group<'a,'b>(self, other: JSRef<'a, HTMLInputElement>, + owner: Option>, + group: Option<&str>) -> bool { + let other_owner: Option> = other.form_owner().root().map(|r| *r); + other.input_type.get() == InputRadio && + // TODO Both a and b are in the same home subtree. + other_owner == owner && + // TODO should be a unicode compatibility caseless match + match (other.get_radio_group_name(), group) { + (Some(ref s1), Some(s2)) => s1.as_slice() == s2, + (None, None) => true, + _ => false + } } fn update_checked_state(self, checked: bool) { @@ -577,9 +581,20 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { }, // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):pre-click-activation-steps InputRadio => { - let members = self.get_radio_group_members(self.get_radio_group_name().as_ref() - .map(|s| s.as_slice())); - let checked_member = members.into_iter().find(|r| r.root().Checked()); + //TODO: if not in document, use root ancestor instead of document + let owner = self.form_owner().root().map(|r| *r); + let doc = document_from_node(*self).root(); + let doc_node: JSRef = NodeCast::from_ref(*doc); + let group = self.get_radio_group_name();; + + // Safe since we only manipulate the DOM tree after finding an element + let checked_member = unsafe { + doc_node.query_selector_iter("input[type=radio]".to_string()).unwrap() + .filter_map(|t| HTMLInputElementCast::to_ref(t)) + .filter(|&r| self.in_same_group(r, owner, + group.as_ref().map(|gr| gr.as_slice()))) + .find(|r| r.Checked()) + }; cache.checked_radio.assign(checked_member); self.SetChecked(true); } @@ -681,17 +696,18 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/forms.html#implicit-submission fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { let doc = document_from_node(*self).root(); - // FIXME (#4082) use a custom iterator - doc.QuerySelectorAll("input[type=submit]".to_string()).root().map(|submits| { - // XXXManishearth there may be a more efficient way of doing this (#3553) - let owner = self.form_owner(); - if owner == None || ElementCast::from_ref(*self).click_in_progress() { - return; - } - submits.into_vec().iter() - .filter_map(|t| HTMLInputElementCast::to_ref(*t.root())) - .find(|r| r.form_owner() == owner) - .map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); - }); + let node: JSRef = NodeCast::from_ref(*doc); + let owner = self.form_owner(); + if owner.is_none() || ElementCast::from_ref(*self).click_in_progress() { + return; + } + // This is safe because we are stopping after finding the first element + // and only then performing actions which may modify the DOM tree + unsafe { + node.query_selector_iter("input[type=submit]".to_string()).unwrap() + .filter_map(|t| HTMLInputElementCast::to_ref(t)) + .find(|r| r.form_owner() == owner) + .map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); + } } } diff --git a/components/script/dom/nodelist.rs b/components/script/dom/nodelist.rs index d3eaa5936ec..d30f0ffc6b3 100644 --- a/components/script/dom/nodelist.rs +++ b/components/script/dom/nodelist.rs @@ -81,17 +81,3 @@ impl Reflectable for NodeList { &self.reflector_ } } - -pub trait NodeListHelpers { - fn into_vec(self) -> Vec>; -} - - -impl<'a> NodeListHelpers for JSRef<'a, NodeList> { - fn into_vec(self) -> Vec> { - match self.list_type { - Simple(ref elems) => elems.iter().map(|j| Temporary::new(*j)).collect(), - Children(ref node) => vec![Temporary::new(*node)] - } - } -} From e7ac792ed65bff7685a6700f1a63b893cdd57a6c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 26 Nov 2014 19:50:35 +0530 Subject: [PATCH 17/19] Switch to NodeFlags (the footprint has not changed) --- components/script/dom/element.rs | 15 ++++++--------- components/script/dom/node.rs | 10 ++++++++-- components/script/script_task.rs | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 83dd5593d04..cc5245d7537 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -32,7 +32,7 @@ use dom::htmlcollection::HTMLCollection; use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers}; use dom::htmlserializer::serialize; use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers}; -use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator, document_from_node}; +use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator, document_from_node, CLICK_IN_PROGRESS}; use dom::node::{window_from_node, LayoutNodeHelpers}; use dom::nodelist::NodeList; use dom::virtualmethods::{VirtualMethods, vtable_for}; @@ -44,7 +44,7 @@ use servo_util::namespace; use servo_util::str::{DOMString, LengthOrPercentageOrAuto}; use std::ascii::AsciiExt; -use std::cell::{Cell, Ref, RefMut}; +use std::cell::{Ref, RefMut}; use std::default::Default; use std::mem; use string_cache::{Atom, Namespace, QualName}; @@ -60,10 +60,6 @@ pub struct Element { style_attribute: DOMRefCell>, attr_list: MutNullableJS, class_list: MutNullableJS, - // TODO: find a better place to keep this (#4105) - // https://critic.hoppipolla.co.uk/showcomment?chain=8873 - // Perhaps using a Set in Document? - click_in_progress: Cell, } impl ElementDerived for EventTarget { @@ -182,7 +178,6 @@ impl Element { attr_list: Default::default(), class_list: Default::default(), style_attribute: DOMRefCell::new(None), - click_in_progress: Cell::new(false), } } @@ -1215,11 +1210,13 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { } fn click_in_progress(self) -> bool { - self.click_in_progress.get() + let node: JSRef = NodeCast::from_ref(self); + node.get_flag(CLICK_IN_PROGRESS) } fn set_click_in_progress(self, click: bool) { - self.click_in_progress.set(click) + let node: JSRef = NodeCast::from_ref(self); + node.set_flag(CLICK_IN_PROGRESS, click) } // https://html.spec.whatwg.org/multipage/interaction.html#nearest-activatable-element diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 55b785a04db..ef655cc1bc3 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -124,7 +124,7 @@ impl NodeDerived for EventTarget { bitflags! { #[doc = "Flags for node items."] #[jstraceable] - flags NodeFlags: u8 { + flags NodeFlags: u16 { #[doc = "Specifies whether this node is in a document."] const IS_IN_DOC = 0x01, #[doc = "Specifies whether this node is in hover state."] @@ -143,6 +143,12 @@ bitflags! { #[doc = "Specifies whether this node has descendants (inclusive of itself) which \ have changed since the last reflow."] const HAS_DIRTY_DESCENDANTS = 0x80, + // TODO: find a better place to keep this (#4105) + // https://critic.hoppipolla.co.uk/showcomment?chain=8873 + // Perhaps using a Set in Document? + #[doc = "Specifies whether or not there is an authentic click in progress on \ + this element."] + const CLICK_IN_PROGRESS = 0x100, } } @@ -744,7 +750,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } /// Get an iterator over all nodes which match a set of selectors - /// Be careful not to do anything which may manipulate the DOM tree whilst iterating, otherwise + /// Be careful not to do anything which may manipulate the DOM tree whilst iterating, otherwise /// the iterator may be invalidated unsafe fn query_selector_iter(self, selectors: DOMString) -> Fallible> { // Step 1. diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 31fa79452df..b826ac98047 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -926,7 +926,7 @@ impl ScriptTask { } _ => () } - + window.flush_layout(); } From e7b3caa386cfeedfd6f582a16575ba30f8ec87f2 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 26 Nov 2014 22:29:41 +0530 Subject: [PATCH 18/19] Add oninput/onchange so tests work --- components/script/dom/document.rs | 3 +- components/script/dom/htmlelement.rs | 2 +- components/script/dom/htmlinputelement.rs | 3 +- components/script/dom/macros.rs | 16 +++ .../script/dom/webidls/EventHandler.webidl | 2 + components/script/dom/window.rs | 3 +- .../wpt/metadata/html/dom/interfaces.html.ini | 48 -------- .../html/dom/reflection-forms.html.ini | 108 ------------------ .../forms/the-input-element/button.html.ini | 12 -- .../forms/the-input-element/checkbox.html.ini | 12 -- .../input-type-button.html.ini | 9 -- .../input-type-checkbox.html.ini | 3 - .../forms/the-input-element/radio.html.ini | 7 +- .../selectors/pseudo-classes/checked.html.ini | 3 + .../pseudo-classes/indeterminate.html.ini | 12 ++ 15 files changed, 43 insertions(+), 200 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index f282aa3b483..fad44638f64 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -966,7 +966,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { self.ready_state.get() } - event_handler!(click, GetOnclick, SetOnclick) - event_handler!(load, GetOnload, SetOnload) + global_event_handlers!() event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange) } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 7467ea56fdf..010946fabc4 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -75,7 +75,7 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { make_bool_getter!(Hidden) make_bool_setter!(SetHidden, "hidden") - event_handler!(click, GetOnclick, SetOnclick) + global_event_handlers!(NoOnload) fn GetOnload(self) -> Option { if self.is_body_or_frameset() { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index be3b52b4ae6..bfe686330fe 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -633,8 +633,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { Some(o) => { // Avoiding iterating through the whole tree here, instead // we can check if the conditions for radio group siblings apply - if name != None && // unless self no longer has a button group - name == o.get_radio_group_name() && // TODO should be compatibility caseless + if name == o.get_radio_group_name() && // TODO should be compatibility caseless self.form_owner() == o.form_owner() && // TODO Both a and b are in the same home subtree o.input_type.get() == InputRadio { diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 630a112c032..b98d67a090f 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -211,3 +211,19 @@ macro_rules! error_event_handler( define_event_handler!(OnErrorEventHandlerNonNull, $event_type, $getter, $setter) ) ) + +// https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers +// see webidls/EventHandler.webidl +// As more methods get added, just update them here. +macro_rules! global_event_handlers( + () => ( + event_handler!(load, GetOnload, SetOnload) + global_event_handlers!(NoOnload) + + ); + (NoOnload) => ( + event_handler!(click, GetOnclick, SetOnclick) + event_handler!(input, GetOninput, SetOninput) + event_handler!(change, GetOnchange, SetOnchange) + ) +) \ No newline at end of file diff --git a/components/script/dom/webidls/EventHandler.webidl b/components/script/dom/webidls/EventHandler.webidl index 1278d7467fd..de491455302 100644 --- a/components/script/dom/webidls/EventHandler.webidl +++ b/components/script/dom/webidls/EventHandler.webidl @@ -23,6 +23,8 @@ typedef OnErrorEventHandlerNonNull? OnErrorEventHandler; interface GlobalEventHandlers { attribute EventHandler onclick; attribute EventHandler onload; + attribute EventHandler oninput; + attribute EventHandler onchange; }; [NoInterfaceObject] diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 0e6e00ed200..da0cc228b0a 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -270,8 +270,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> { self.performance.or_init(|| Performance::new(self)) } - event_handler!(click, GetOnclick, SetOnclick) - event_handler!(load, GetOnload, SetOnload) + global_event_handlers!() event_handler!(unload, GetOnunload, SetOnunload) error_event_handler!(error, GetOnerror, SetOnerror) diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 40fc05cdb10..3a281c37b6f 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -120,9 +120,6 @@ [Document interface: attribute oncanplaythrough] expected: FAIL - [Document interface: attribute onchange] - expected: FAIL - [Document interface: attribute onclose] expected: FAIL @@ -174,9 +171,6 @@ [Document interface: attribute onfocus] expected: FAIL - [Document interface: attribute oninput] - expected: FAIL - [Document interface: attribute oninvalid] expected: FAIL @@ -984,9 +978,6 @@ [HTMLElement interface: attribute itemValue] expected: FAIL - [HTMLElement interface: operation click()] - expected: FAIL - [HTMLElement interface: attribute tabIndex] expected: FAIL @@ -1062,9 +1053,6 @@ [HTMLElement interface: attribute oncanplaythrough] expected: FAIL - [HTMLElement interface: attribute onchange] - expected: FAIL - [HTMLElement interface: attribute onclose] expected: FAIL @@ -1116,9 +1104,6 @@ [HTMLElement interface: attribute onfocus] expected: FAIL - [HTMLElement interface: attribute oninput] - expected: FAIL - [HTMLElement interface: attribute oninvalid] expected: FAIL @@ -1254,9 +1239,6 @@ [HTMLElement interface: document.createElement("noscript") must inherit property "itemValue" with the proper type (11)] expected: FAIL - [HTMLElement interface: document.createElement("noscript") must inherit property "click" with the proper type (13)] - expected: FAIL - [HTMLElement interface: document.createElement("noscript") must inherit property "tabIndex" with the proper type (14)] expected: FAIL @@ -1332,9 +1314,6 @@ [HTMLElement interface: document.createElement("noscript") must inherit property "oncanplaythrough" with the proper type (38)] expected: FAIL - [HTMLElement interface: document.createElement("noscript") must inherit property "onchange" with the proper type (39)] - expected: FAIL - [HTMLElement interface: document.createElement("noscript") must inherit property "onclose" with the proper type (41)] expected: FAIL @@ -1386,9 +1365,6 @@ [HTMLElement interface: document.createElement("noscript") must inherit property "onfocus" with the proper type (57)] expected: FAIL - [HTMLElement interface: document.createElement("noscript") must inherit property "oninput" with the proper type (58)] - expected: FAIL - [HTMLElement interface: document.createElement("noscript") must inherit property "oninvalid" with the proper type (59)] expected: FAIL @@ -4800,9 +4776,6 @@ [HTMLInputElement interface: attribute height] expected: FAIL - [HTMLInputElement interface: attribute indeterminate] - expected: FAIL - [HTMLInputElement interface: attribute inputMode] expected: FAIL @@ -4830,9 +4803,6 @@ [HTMLInputElement interface: attribute placeholder] expected: FAIL - [HTMLInputElement interface: attribute readOnly] - expected: FAIL - [HTMLInputElement interface: attribute required] expected: FAIL @@ -4944,9 +4914,6 @@ [HTMLInputElement interface: document.createElement("input") must inherit property "height" with the proper type (15)] expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "indeterminate" with the proper type (16)] - expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "inputMode" with the proper type (17)] expected: FAIL @@ -4974,9 +4941,6 @@ [HTMLInputElement interface: document.createElement("input") must inherit property "placeholder" with the proper type (26)] expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "readOnly" with the proper type (27)] - expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "required" with the proper type (28)] expected: FAIL @@ -7170,9 +7134,6 @@ [Window interface: attribute oncanplaythrough] expected: FAIL - [Window interface: attribute onchange] - expected: FAIL - [Window interface: attribute onclose] expected: FAIL @@ -7221,9 +7182,6 @@ [Window interface: attribute onfocus] expected: FAIL - [Window interface: attribute oninput] - expected: FAIL - [Window interface: attribute oninvalid] expected: FAIL @@ -7512,9 +7470,6 @@ [Window interface: window must inherit property "oncanplaythrough" with the proper type (44)] expected: FAIL - [Window interface: window must inherit property "onchange" with the proper type (45)] - expected: FAIL - [Window interface: window must inherit property "onclose" with the proper type (47)] expected: FAIL @@ -7563,9 +7518,6 @@ [Window interface: window must inherit property "onfocus" with the proper type (63)] expected: FAIL - [Window interface: window must inherit property "oninput" with the proper type (64)] - expected: FAIL - [Window interface: window must inherit property "oninvalid" with the proper type (65)] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/reflection-forms.html.ini b/tests/wpt/metadata/html/dom/reflection-forms.html.ini index 2569e501673..55375dd30d2 100644 --- a/tests/wpt/metadata/html/dom/reflection-forms.html.ini +++ b/tests/wpt/metadata/html/dom/reflection-forms.html.ini @@ -5925,114 +5925,6 @@ [input.placeholder: IDL set to object "test-valueOf" followed by IDL get] expected: FAIL - [input.readOnly: typeof IDL attribute] - expected: FAIL - - [input.readOnly: IDL get with DOM attribute unset] - expected: FAIL - - [input.readOnly: setAttribute() to "" followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to " foo " followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to undefined followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to null followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to 7 followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to 1.5 followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to true followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to false followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to object "[object Object\]" followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to NaN followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to Infinity followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to -Infinity followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to "\\0" followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to object "test-toString" followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to object "test-valueOf" followed by IDL get] - expected: FAIL - - [input.readOnly: setAttribute() to "readOnly" followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to "" followed by hasAttribute()] - expected: FAIL - - [input.readOnly: IDL set to "" followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to " foo " followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to undefined followed by hasAttribute()] - expected: FAIL - - [input.readOnly: IDL set to undefined followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to null followed by hasAttribute()] - expected: FAIL - - [input.readOnly: IDL set to null followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to 7 followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to 1.5 followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to false followed by hasAttribute()] - expected: FAIL - - [input.readOnly: IDL set to object "[object Object\]" followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to NaN followed by hasAttribute()] - expected: FAIL - - [input.readOnly: IDL set to NaN followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to Infinity followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to -Infinity followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to "\\0" followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to object "test-toString" followed by IDL get] - expected: FAIL - - [input.readOnly: IDL set to object "test-valueOf" followed by IDL get] - expected: FAIL - [input.required: typeof IDL attribute] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/forms/the-input-element/button.html.ini b/tests/wpt/metadata/html/semantics/forms/the-input-element/button.html.ini index a1bf2f8e7cd..6a64dd8cb98 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-input-element/button.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-input-element/button.html.ini @@ -1,17 +1,5 @@ [button.html] type: testharness - [clicking on button should not submit a form] - expected: FAIL - [the element is barred from constraint validation] expected: FAIL - [clicking on button should not reset other form fields] - expected: FAIL - - [clicking on button should not unchecked radio buttons] - expected: FAIL - - [clicking on button should not change its indeterminate IDL attribute] - expected: FAIL - diff --git a/tests/wpt/metadata/html/semantics/forms/the-input-element/checkbox.html.ini b/tests/wpt/metadata/html/semantics/forms/the-input-element/checkbox.html.ini index 7ec52aa8ee9..afdd08c6014 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-input-element/checkbox.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-input-element/checkbox.html.ini @@ -1,17 +1,5 @@ [checkbox.html] type: testharness - [click on mutable checkbox fires the input and change events] - expected: FAIL - - [click on non-mutable checkbox doesn\'t fire the input or change event] - expected: FAIL - - [pre-activation steps on unchecked checkbox] - expected: FAIL - - [pre-activation steps on checked checkbox] - expected: FAIL - [canceled activation steps on unchecked checkbox] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-button.html.ini b/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-button.html.ini index 0c7b5a7b06b..e0fd34f9938 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-button.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-button.html.ini @@ -1,14 +1,5 @@ [input-type-button.html] type: testharness - [default behavior] - expected: FAIL - [label value] expected: FAIL - [mutable element\'s activation behavior is to do nothing.] - expected: FAIL - - [immutable element has no activation behavior.] - expected: FAIL - diff --git a/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-checkbox.html.ini b/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-checkbox.html.ini index 3570a956f8c..50592c4b1b1 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-checkbox.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-input-element/input-type-checkbox.html.ini @@ -1,8 +1,5 @@ [input-type-checkbox.html] type: testharness - [a checkbox has an indeterminate state set to false onload] - expected: FAIL - [default/on: on getting, if the element has a value attribute, it must return that attribute\'s value; otherwise, it must return the string \'on\'] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/forms/the-input-element/radio.html.ini b/tests/wpt/metadata/html/semantics/forms/the-input-element/radio.html.ini index b99ec91c469..c27d5e5d352 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-input-element/radio.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-input-element/radio.html.ini @@ -1,3 +1,8 @@ [radio.html] type: testharness - expected: TIMEOUT + [canceled activation steps on unchecked radio] + expected: FAIL + + [radio inputs with name attributes gro\xc3\xbcp2 and gro\xc3\x9cp2 belong to the same radio button group] + expected: FAIL + diff --git a/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/checked.html.ini b/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/checked.html.ini index 751e4176f9c..ef274381edc 100644 --- a/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/checked.html.ini +++ b/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/checked.html.ini @@ -6,3 +6,6 @@ [\':checked\' should no longer match s whose type checkbox/radio has been removed] expected: FAIL + [\':checked\' matches clicked checkbox and radio buttons] + expected: FAIL + diff --git a/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/indeterminate.html.ini b/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/indeterminate.html.ini index adf31b3f868..7510b189e41 100644 --- a/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/indeterminate.html.ini +++ b/tests/wpt/metadata/html/semantics/selectors/pseudo-classes/indeterminate.html.ini @@ -6,3 +6,15 @@ [dynamically check a radio input in a radio button group] expected: FAIL + [click on radio4 which is in the indeterminate state] + expected: FAIL + + [adding a value to progress1 should put it in a determinate state] + expected: FAIL + + [removing progress2\'s value should put it in an indeterminate state] + expected: FAIL + + [\':progress\' also matches checkbox whose indeterminate IDL is set to true] + expected: FAIL + From 5511e02a78a03c1e4f9fca422641aa9203859b3e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 6 Dec 2014 02:12:24 -0800 Subject: [PATCH 19/19] Add Comparable trait to js.rs; fixups --- components/script/dom/bindings/js.rs | 21 +++++++ components/script/dom/element.rs | 2 +- components/script/dom/htmlinputelement.rs | 59 +++++++++---------- components/script/dom/macros.rs | 2 +- components/script/script_task.rs | 2 +- .../wpt/metadata/html/dom/interfaces.html.ini | 6 -- 6 files changed, 53 insertions(+), 39 deletions(-) diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index f24115a349a..c9f3e157b75 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -575,3 +575,24 @@ impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> { self.deref().reflector() } } + +/// A trait for comparing smart pointers ignoring the lifetimes +pub trait Comparable { + fn equals(&self, other: T) -> bool; +} + +impl<'a, 'b, T> Comparable> for JSRef<'b, T> { + fn equals(&self, other: JSRef<'a, T>) -> bool { + self.ptr == other.ptr + } +} + +impl<'a, 'b, T> Comparable>> for Option> { + fn equals(&self, other: Option>) -> bool { + match (*self, other) { + (Some(x), Some(y)) => x.ptr == y.ptr, + (None, None) => true, + _ => false + } + } +} diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index cc5245d7537..aa671d98cb4 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1253,7 +1253,7 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { // Step 4 let e = self.nearest_activable_element().root(); match e { - Some (el) => match el.as_maybe_activatable() { + Some(el) => match el.as_maybe_activatable() { Some(elem) => { // Step 5-6 elem.pre_click_activation(); diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index bfe686330fe..a736a7a8f3d 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -16,7 +16,8 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLFor use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSetElementDerived, EventTargetCast}; use dom::bindings::codegen::InheritTypes::KeyboardEventCast; use dom::bindings::global::Window; -use dom::bindings::js::{JS, JSRef, Root, Temporary, OptionalRootable, ResultRootable, MutNullableJS}; +use dom::bindings::js::{Comparable, JS, JSRef, Root, Temporary, OptionalRootable}; +use dom::bindings::js::{ResultRootable, RootedReference, MutNullableJS}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, Element, HTMLInputElementTypeId}; @@ -260,16 +261,13 @@ pub trait HTMLInputElementHelpers { fn force_relayout(self); fn radio_group_updated(self, group: Option<&str>); fn get_radio_group_name(self) -> Option; - fn in_same_group<'a,'b>(self, other: JSRef<'a, HTMLInputElement>, - owner: Option>, - group: Option<&str>) -> bool; fn update_checked_state(self, checked: bool); fn get_size(&self) -> u32; } fn broadcast_radio_checked(broadcaster: JSRef, group: Option<&str>) { //TODO: if not in document, use root ancestor instead of document - let owner = broadcaster.form_owner().root().map(|r| *r); + let owner = broadcaster.form_owner().root(); let doc = document_from_node(broadcaster).root(); let doc_node: JSRef = NodeCast::from_ref(*doc); @@ -277,7 +275,7 @@ fn broadcast_radio_checked(broadcaster: JSRef, group: Option<& let mut iter = unsafe { doc_node.query_selector_iter("input[type=radio]".to_string()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) - .filter(|&r| broadcaster.in_same_group(r, owner, group) && broadcaster != r) + .filter(|&r| in_same_group(r, owner.root_ref(), group) && broadcaster != r) }; for r in iter { if r.Checked() { @@ -286,6 +284,22 @@ fn broadcast_radio_checked(broadcaster: JSRef, group: Option<& } } +fn in_same_group<'a,'b>(other: JSRef<'a, HTMLInputElement>, + owner: Option>, + group: Option<&str>) -> bool { + let other_owner = other.form_owner().root(); + let other_owner = other_owner.root_ref(); + other.input_type.get() == InputRadio && + // TODO Both a and b are in the same home subtree. + other_owner.equals(owner) && + // TODO should be a unicode compatibility caseless match + match (other.get_radio_group_name(), group) { + (Some(ref s1), Some(s2)) => s1.as_slice() == s2, + (None, None) => true, + _ => false + } +} + impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { fn force_relayout(self) { let doc = document_from_node(self).root(); @@ -307,21 +321,6 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> { .map(|name| name.Value()) } - fn in_same_group<'a,'b>(self, other: JSRef<'a, HTMLInputElement>, - owner: Option>, - group: Option<&str>) -> bool { - let other_owner: Option> = other.form_owner().root().map(|r| *r); - other.input_type.get() == InputRadio && - // TODO Both a and b are in the same home subtree. - other_owner == owner && - // TODO should be a unicode compatibility caseless match - match (other.get_radio_group_name(), group) { - (Some(ref s1), Some(s2)) => s1.as_slice() == s2, - (None, None) => true, - _ => false - } - } - fn update_checked_state(self, checked: bool) { self.checked.set(checked); if self.input_type.get() == InputRadio && checked { @@ -582,7 +581,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):pre-click-activation-steps InputRadio => { //TODO: if not in document, use root ancestor instead of document - let owner = self.form_owner().root().map(|r| *r); + let owner = self.form_owner().root(); let doc = document_from_node(*self).root(); let doc_node: JSRef = NodeCast::from_ref(*doc); let group = self.get_radio_group_name();; @@ -591,8 +590,8 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { let checked_member = unsafe { doc_node.query_selector_iter("input[type=radio]".to_string()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) - .filter(|&r| self.in_same_group(r, owner, - group.as_ref().map(|gr| gr.as_slice()))) + .filter(|&r| in_same_group(r, owner.root_ref(), + group.as_ref().map(|gr| gr.as_slice()))) .find(|r| r.Checked()) }; cache.checked_radio.assign(checked_member); @@ -673,16 +672,16 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/forms.html#radio-button-state-(type=radio):activation-behavior if self.mutable() { let win = window_from_node(*self).root(); - let event = Event::new(&Window(*win), - "input".to_string(), - Bubbles, NotCancelable).root(); + let event = Event::new(Window(*win), + "input".to_string(), + Bubbles, NotCancelable).root(); event.set_trusted(true); let target: JSRef = EventTargetCast::from_ref(*self); target.DispatchEvent(*event).ok(); - let event = Event::new(&Window(*win), - "change".to_string(), - Bubbles, NotCancelable).root(); + let event = Event::new(Window(*win), + "change".to_string(), + Bubbles, NotCancelable).root(); event.set_trusted(true); let target: JSRef = EventTargetCast::from_ref(*self); target.DispatchEvent(*event).ok(); diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index b98d67a090f..a5789a5cc61 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -226,4 +226,4 @@ macro_rules! global_event_handlers( event_handler!(input, GetOninput, SetOninput) event_handler!(change, GetOnchange, SetOnchange) ) -) \ No newline at end of file +) diff --git a/components/script/script_task.rs b/components/script/script_task.rs index b826ac98047..28c7c2e8a0b 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, Documen use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast}; +use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, NodeCast, EventCast}; use dom::bindings::conversions::{FromJSValConvertible, Empty}; use dom::bindings::global; use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable}; diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 3a281c37b6f..566546e4cb7 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -9591,9 +9591,6 @@ [Document interface: document.implementation.createDocument(null, "", null) must inherit property "oncanplaythrough" with the proper type (99)] expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "onchange" with the proper type (100)] - expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "onclose" with the proper type (102)] expected: FAIL @@ -9645,9 +9642,6 @@ [Document interface: document.implementation.createDocument(null, "", null) must inherit property "onfocus" with the proper type (118)] expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "oninput" with the proper type (119)] - expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "oninvalid" with the proper type (120)] expected: FAIL