diff options
Diffstat (limited to 'components/script/dom')
24 files changed, 255 insertions, 41 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index a005956e02e..689587c377b 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1224,11 +1224,11 @@ class PropertyDefiner: ",\n".join(specs) + "\n" + "];\n") % (name, specType)) -# The length of a method is the maximum of the lengths of the +# The length of a method is the minimum of the lengths of the # argument lists of all its overloads. def methodLength(method): signatures = method.signatures() - return max([len(arguments) for (retType, arguments) in signatures]) + return min(len([arg for arg in arguments if not arg.optional and not arg.variadic]) for (_, arguments) in signatures) class MethodDefiner(PropertyDefiner): """ diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e08e47f85fe..19901c43796 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -23,6 +23,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLAreaElementDerived, HTMLEmbedElem use dom::bindings::codegen::InheritTypes::{HTMLFormElementDerived, HTMLImageElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived, HTMLTitleElementDerived}; use dom::bindings::codegen::UnionTypes::NodeOrString; +use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{NotSupported, InvalidCharacter, Security}; use dom::bindings::error::Error::HierarchyRequest; @@ -84,7 +85,7 @@ use html5ever::tree_builder::{QuirksMode, NoQuirks, LimitedQuirks, Quirks}; use layout_interface::{LayoutChan, Msg}; use string_cache::{Atom, QualName}; use url::Url; -use js::jsapi::JSRuntime; +use js::jsapi::{JSContext, JSObject, JSRuntime}; use num::ToPrimitive; use std::iter::FromIterator; @@ -94,6 +95,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::ascii::AsciiExt; use std::cell::{Cell, Ref, RefMut, RefCell}; use std::default::Default; +use std::ptr; use std::sync::mpsc::{Receiver, channel}; use time; @@ -1661,6 +1663,94 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { self.set_body_attribute(&atom!("bgcolor"), value) } + // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter + fn NamedGetter(self, cx: *mut JSContext, name: DOMString, found: &mut bool) + -> *mut JSObject { + #[jstraceable] + struct NamedElementFilter { + name: Atom, + } + impl CollectionFilter for NamedElementFilter { + fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool { + filter_by_name(&self.name, NodeCast::from_ref(elem)) + } + } + // https://html.spec.whatwg.org/#dom-document-nameditem-filter + fn filter_by_name(name: &Atom, node: JSRef<Node>) -> bool { + let html_elem_type = match node.type_id() { + NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_, + _ => return false, + }; + let elem = match ElementCast::to_ref(node) { + Some(elem) => elem, + None => return false, + }; + match html_elem_type { + HTMLElementTypeId::HTMLAppletElement => { + match elem.get_attribute(&ns!(""), &atom!("name")).root() { + Some(ref attr) if attr.r().value().atom() == Some(name) => true, + _ => { + match elem.get_attribute(&ns!(""), &atom!("id")).root() { + Some(ref attr) => attr.r().value().atom() == Some(name), + None => false, + } + }, + } + }, + HTMLElementTypeId::HTMLFormElement => { + match elem.get_attribute(&ns!(""), &atom!("name")).root() { + Some(ref attr) => attr.r().value().atom() == Some(name), + None => false, + } + }, + HTMLElementTypeId::HTMLImageElement => { + match elem.get_attribute(&ns!(""), &atom!("name")).root() { + Some(ref attr) => { + if attr.r().value().atom() == Some(name) { + true + } else { + match elem.get_attribute(&ns!(""), &atom!("id")).root() { + Some(ref attr) => attr.r().value().atom() == Some(name), + None => false, + } + } + }, + None => false, + } + }, + // TODO: Handle <embed>, <iframe> and <object>. + _ => false, + } + } + let name = Atom::from_slice(&name); + let root = NodeCast::from_ref(self); + { + // Step 1. + let mut elements = root.traverse_preorder().filter(|node| { + let node = node.root(); + filter_by_name(&name, node.r()) + }).peekable(); + if let Some(first) = elements.next() { + let first = first.root(); + if elements.is_empty() { + *found = true; + // TODO: Step 2. + // Step 3. + return first.to_jsval(cx).to_object(); + } + } else { + *found = false; + return ptr::null_mut(); + } + } + // Step 4. + *found = true; + let window = self.window().root(); + let filter = NamedElementFilter { name: name }; + let collection = HTMLCollection::create(window.r(), root, box filter).root(); + collection.to_jsval(cx).to_object() + } + global_event_handlers!(); event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange); } diff --git a/components/script/dom/htmlappletelement.rs b/components/script/dom/htmlappletelement.rs index 4ef0bc6cd2e..585df5d5273 100644 --- a/components/script/dom/htmlappletelement.rs +++ b/components/script/dom/htmlappletelement.rs @@ -3,13 +3,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::HTMLAppletElementBinding; +use dom::bindings::codegen::Bindings::HTMLAppletElementBinding::HTMLAppletElementMethods; + +use dom::attr::AttrValue; use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived; +use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; -use dom::element::ElementTypeId; +use dom::element::{AttributeHandlers, ElementTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; +use dom::virtualmethods::VirtualMethods; + +use string_cache::Atom; use util::str::DOMString; #[dom_struct] @@ -37,3 +44,21 @@ impl HTMLAppletElement { } } +impl<'a> HTMLAppletElementMethods for JSRef<'a, HTMLAppletElement> { + // https://html.spec.whatwg.org/#the-applet-element:dom-applet-name + make_getter!(Name); + make_atomic_setter!(SetName, "name"); +} + +impl<'a> VirtualMethods for JSRef<'a, HTMLAppletElement> { + fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> { + Some(HTMLElementCast::from_borrowed_ref(self) as &VirtualMethods) + } + + fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + match name { + &atom!("name") => AttrValue::from_atomic(value), + _ => self.super_type().unwrap().parse_plain_attribute(name, value), + } + } +} diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 817da5043f0..c716be93d39 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -19,7 +19,6 @@ use dom::virtualmethods::VirtualMethods; use dom::window::WindowHelpers; use cssparser::RGBA; -use string_cache::Atom; use util::str::{self, DOMString}; use std::borrow::ToOwned; diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 280a92c99b2..38ed9b26e74 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -26,7 +26,6 @@ use std::ascii::OwnedAsciiExt; use std::borrow::ToOwned; use util::str::DOMString; use std::cell::Cell; -use string_cache::Atom; #[jstraceable] #[derive(PartialEq, Copy, Clone)] diff --git a/components/script/dom/htmldialogelement.rs b/components/script/dom/htmldialogelement.rs index febfbc38f81..6d332530f55 100644 --- a/components/script/dom/htmldialogelement.rs +++ b/components/script/dom/htmldialogelement.rs @@ -14,7 +14,6 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; use util::str::DOMString; -use string_cache::Atom; use std::borrow::ToOwned; diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 84c6d926bb6..27feed8eb3a 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -20,7 +20,6 @@ use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; use util::str::{DOMString, StaticStringVec}; -use string_cache::Atom; #[dom_struct] pub struct HTMLFieldSetElement { diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index c5c1ae2e77a..3d6ad028ab7 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -2,14 +2,20 @@ * 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::attr::AttrValue; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLFormElementBinding; use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods; -use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLFormElementDerived, NodeCast}; -use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLTextAreaElementCast, HTMLFormElementCast}; +use dom::bindings::codegen::InheritTypes::EventTargetCast; +use dom::bindings::codegen::InheritTypes::HTMLDataListElementCast; +use dom::bindings::codegen::InheritTypes::HTMLElementCast; +use dom::bindings::codegen::InheritTypes::HTMLFormElementCast; +use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; +use dom::bindings::codegen::InheritTypes::HTMLInputElementCast; +use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementCast, NodeCast}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary}; use dom::document::{Document, DocumentHelpers}; @@ -22,6 +28,7 @@ use dom::htmlinputelement::{HTMLInputElement, HTMLInputElementHelpers}; use dom::htmlbuttonelement::{HTMLButtonElement}; use dom::htmltextareaelement::HTMLTextAreaElementHelpers; use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node}; +use dom::virtualmethods::VirtualMethods; use hyper::method::Method; use hyper::header::ContentType; use hyper::mime; @@ -106,9 +113,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { // https://html.spec.whatwg.org/multipage/#dom-form-name make_getter!(Name); - - // https://html.spec.whatwg.org/multipage/#dom-form-name - make_setter!(SetName, "name"); + make_atomic_setter!(SetName, "name"); // https://html.spec.whatwg.org/multipage/#dom-fs-novalidate make_bool_getter!(NoValidate); @@ -260,7 +265,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> { return None; } if child.r().ancestors() - .any(|a| a.root().r().type_id() == NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLDataListElement))) { + .any(|a| HTMLDataListElementCast::to_temporary(a).is_some()) { return None; } // XXXManishearth don't include it if it is a button but not the submitter @@ -558,3 +563,16 @@ pub trait FormControl<'a> : Copy + Sized { fn to_element(self) -> JSRef<'a, Element>; } + +impl<'a> VirtualMethods for JSRef<'a, HTMLFormElement> { + fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> { + Some(HTMLElementCast::from_borrowed_ref(self) as &VirtualMethods) + } + + fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + match name { + &atom!("name") => AttrValue::from_atomic(value), + _ => self.super_type().unwrap().parse_plain_attribute(name, value), + } + } +} diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 58096b18bea..685f46db48e 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -385,5 +385,32 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { self.process_the_iframe_attributes(); } } + + fn unbind_from_tree(&self, tree_in_doc: bool) { + if let Some(ref s) = self.super_type() { + s.unbind_from_tree(tree_in_doc); + } + + // https://html.spec.whatwg.org/multipage/#a-browsing-context-is-discarded + match (self.containing_page_pipeline_id(), self.subpage_id()) { + (Some(containing_pipeline_id), Some(subpage_id)) => { + let window = window_from_node(*self).root(); + let window = window.r(); + + let ConstellationChan(ref chan) = window.constellation_chan(); + let msg = ConstellationMsg::RemoveIFrame(containing_pipeline_id, + subpage_id); + chan.send(msg).unwrap(); + + // Resetting the subpage id to None is required here so that + // if this iframe is subsequently re-added to the document + // the load doesn't think that it's a navigation, but instead + // a new iframe. Without this, the constellation gets very + // confused. + self.subpage_id.set(None); + } + _ => {} + } + } } diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 760f5942aa0..a88f4b5ea7b 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -229,9 +229,9 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { image.is_some() } + // https://html.spec.whatwg.org/#dom-img-name make_getter!(Name); - - make_setter!(SetName, "name"); + make_atomic_setter!(SetName, "name"); make_getter!(Align); @@ -288,6 +288,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { match name { + &atom!("name") => AttrValue::from_atomic(value), &atom!("width") | &atom!("height") | &atom!("hspace") | &atom!("vspace") => AttrValue::from_u32(value, 0), _ => self.super_type().unwrap().parse_plain_attribute(name, value), diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 86a882dbb86..fbd12be244c 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -26,7 +26,9 @@ impl HTMLMediaElementDerived for EventTarget { } impl HTMLMediaElement { - pub fn new_inherited(type_id: HTMLMediaElementTypeId, tag_name: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLMediaElement { + pub fn new_inherited(type_id: HTMLMediaElementTypeId, tag_name: DOMString, + prefix: Option<DOMString>, document: JSRef<Document>) + -> HTMLMediaElement { HTMLMediaElement { htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLMediaElement(type_id), tag_name, prefix, document) } diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index 9b12cd20e4e..00390c615cc 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -12,7 +12,6 @@ use dom::element::ElementTypeId; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; use util::str::DOMString; -use string_cache::Atom; #[dom_struct] pub struct HTMLMetaElement { diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index bb56ee67092..df2c98ecfda 100644 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -24,7 +24,6 @@ use dom::virtualmethods::VirtualMethods; use net_traits::image::base::Image; use util::str::DOMString; use std::sync::Arc; -use string_cache::Atom; #[dom_struct] pub struct HTMLObjectElement { diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs index 4b3f3baf560..f259eccf5bc 100644 --- a/components/script/dom/htmloptgroupelement.rs +++ b/components/script/dom/htmloptgroupelement.rs @@ -18,7 +18,6 @@ use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use util::str::DOMString; -use string_cache::Atom; #[dom_struct] pub struct HTMLOptGroupElement { diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 232e5ec2dec..29ef5040641 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -22,7 +22,6 @@ use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use util::str::{DOMString, split_html_space_chars}; -use string_cache::Atom; #[dom_struct] pub struct HTMLOptionElement { diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index d66190ffada..97a8e7a74d7 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -8,8 +8,7 @@ macro_rules! make_getter( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef<Element> = ElementCast::from_ref(self); element.get_string_attribute(&Atom::from_slice($htmlname)) } @@ -25,8 +24,7 @@ macro_rules! make_bool_getter( fn $attr(self) -> bool { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef<Element> = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. element.has_attribute(&Atom::from_slice($htmlname)) @@ -43,8 +41,7 @@ macro_rules! make_uint_getter( fn $attr(self) -> u32 { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef<Element> = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. element.get_uint_attribute(&Atom::from_slice($htmlname), $default) @@ -64,8 +61,7 @@ macro_rules! make_url_getter( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef<Element> = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. element.get_url_attribute(&Atom::from_slice($htmlname)) @@ -84,8 +80,7 @@ macro_rules! make_url_or_base_getter( use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::window::WindowHelpers; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef<Element> = ElementCast::from_ref(self); let url = element.get_url_attribute(&Atom::from_slice($htmlname)); if url.is_empty() { @@ -107,8 +102,7 @@ macro_rules! make_enumerated_getter( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; use std::borrow::ToOwned; let element: JSRef<Element> = ElementCast::from_ref(self); let val = element.get_string_attribute(&Atom::from_slice($htmlname)) @@ -133,6 +127,7 @@ macro_rules! make_setter( fn $attr(self, value: DOMString) { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; let element: JSRef<Element> = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not at runtime. element.set_string_attribute(&Atom::from_slice($htmlname), value) @@ -146,6 +141,7 @@ macro_rules! make_bool_setter( fn $attr(self, value: bool) { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; let element: JSRef<Element> = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not at runtime. element.set_bool_attribute(&Atom::from_slice($htmlname), value) @@ -159,6 +155,7 @@ macro_rules! make_uint_setter( fn $attr(self, value: u32) { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; let value = if value > 2147483647 { $default } else { @@ -202,6 +199,20 @@ macro_rules! make_limited_uint_setter( }; ); +#[macro_export] +macro_rules! make_atomic_setter( + ( $attr:ident, $htmlname:expr ) => ( + fn $attr(self, value: DOMString) { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; + let element: JSRef<Element> = ElementCast::from_ref(self); + // FIXME(pcwalton): Do this at compile time, not at runtime. + element.set_atomic_attribute(&Atom::from_slice($htmlname), value) + } + ); +); + /// For use on non-jsmanaged types /// Use #[jstraceable] on JS managed types macro_rules! no_jsmanaged_fields( diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 90aaa524d05..f7401c99b11 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2234,13 +2234,18 @@ impl<'a> NodeMethods for JSRef<'a, Node> { match node.type_id() { // Step 3. - NodeTypeId::DocumentType if !is_equal_doctype(this, node) => return false, - NodeTypeId::Element(..) if !is_equal_element(this, node) => return false, - NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) if !is_equal_processinginstruction(this, node) => return false, + NodeTypeId::DocumentType + if !is_equal_doctype(this, node) => return false, + NodeTypeId::Element(..) + if !is_equal_element(this, node) => return false, + NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) + if !is_equal_processinginstruction(this, node) => return false, NodeTypeId::CharacterData(CharacterDataTypeId::Text) | - NodeTypeId::CharacterData(CharacterDataTypeId::Comment) if !is_equal_characterdata(this, node) => return false, + NodeTypeId::CharacterData(CharacterDataTypeId::Comment) + if !is_equal_characterdata(this, node) => return false, // Step 4. - NodeTypeId::Element(..) if !is_equal_element_attrs(this, node) => return false, + NodeTypeId::Element(..) + if !is_equal_element_attrs(this, node) => return false, _ => () } diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index 05bd23307a2..2147ee07c48 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -6,11 +6,13 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast; use dom::bindings::codegen::InheritTypes::HTMLAreaElementCast; +use dom::bindings::codegen::InheritTypes::HTMLAppletElementCast; use dom::bindings::codegen::InheritTypes::HTMLBodyElementCast; use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::codegen::InheritTypes::HTMLFieldSetElementCast; +use dom::bindings::codegen::InheritTypes::HTMLFormElementCast; use dom::bindings::codegen::InheritTypes::HTMLHeadElementCast; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::codegen::InheritTypes::HTMLImageElementCast; @@ -144,6 +146,9 @@ pub fn vtable_for<'a>(node: &'a JSRef<'a, Node>) -> &'a (VirtualMethods + 'a) { let element: &'a JSRef<'a, HTMLAnchorElement> = HTMLAnchorElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) } + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAppletElement)) => { + HTMLAppletElementCast::to_borrowed_ref(node).unwrap() as &'a (VirtualMethods + 'a) + } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) => { let element: &'a JSRef<'a, HTMLAreaElement> = HTMLAreaElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) @@ -164,6 +169,9 @@ pub fn vtable_for<'a>(node: &'a JSRef<'a, Node>) -> &'a (VirtualMethods + 'a) { let element: &'a JSRef<'a, HTMLFieldSetElement> = HTMLFieldSetElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) } + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFormElement)) => { + HTMLFormElementCast::to_borrowed_ref(node).unwrap() as &'a (VirtualMethods + 'a) + } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => { let element: &'a JSRef<'a, HTMLHeadElement> = HTMLHeadElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) diff --git a/components/script/dom/webidls/CSSStyleDeclaration.webidl b/components/script/dom/webidls/CSSStyleDeclaration.webidl index 8ed0805f432..57b3e9f43cc 100644 --- a/components/script/dom/webidls/CSSStyleDeclaration.webidl +++ b/components/script/dom/webidls/CSSStyleDeclaration.webidl @@ -39,6 +39,7 @@ partial interface CSSStyleDeclaration { [TreatNullAs=EmptyString] attribute DOMString backgroundImage; [TreatNullAs=EmptyString] attribute DOMString backgroundAttachment; [TreatNullAs=EmptyString] attribute DOMString backgroundSize; + [TreatNullAs=EmptyString] attribute DOMString backgroundOrigin; [TreatNullAs=EmptyString] attribute DOMString border; [TreatNullAs=EmptyString] attribute DOMString borderColor; diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl index 2f01882ddb4..581ad401f6d 100644 --- a/components/script/dom/webidls/Document.webidl +++ b/components/script/dom/webidls/Document.webidl @@ -81,7 +81,7 @@ partial /*sealed*/ interface Document { readonly attribute DocumentReadyState readyState; // DOM tree accessors - // getter object (DOMString name); + getter object (DOMString name); attribute DOMString title; [SetterThrows] attribute HTMLElement? body; diff --git a/components/script/dom/webidls/HTMLAppletElement.webidl b/components/script/dom/webidls/HTMLAppletElement.webidl index ff86973dac4..b7f6350de53 100644 --- a/components/script/dom/webidls/HTMLAppletElement.webidl +++ b/components/script/dom/webidls/HTMLAppletElement.webidl @@ -12,7 +12,7 @@ interface HTMLAppletElement : HTMLElement { // attribute DOMString codeBase; // attribute DOMString height; // attribute unsigned long hspace; - // attribute DOMString name; + attribute DOMString name; // attribute DOMString _object; // the underscore is not part of the identifier // attribute unsigned long vspace; // attribute DOMString width; diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index 08caf90004e..ae8758e3c56 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -128,6 +128,13 @@ partial interface Window { }; Window implements OnErrorEventHandlerForWindow; +// WebDriver extensions +partial interface Window { + // Shouldn't be public, but just to make things work for now + void webdriverCallback(optional any result); + void webdriverTimeout(); +}; + // https://html.spec.whatwg.org/multipage/#dom-sessionstorage [NoInterfaceObject] interface WindowSessionStorage { diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 0b7673d828b..009ca43a78b 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -156,7 +156,8 @@ impl<'a> WebSocketMethods for JSRef<'a, WebSocket> { fn Send(self, data: Option<DOMString>)-> Fallible<()>{ /*TODO: This is not up to spec see http://html.spec.whatwg.org/multipage/comms.html search for "If argument is a string" TODO: Need to buffer data - TODO: bufferedAmount attribute returns the size of the buffer in bytes - this is a required attribute defined in the websocket.webidle file + TODO: bufferedAmount attribute returns the size of the buffer in bytes - + this is a required attribute defined in the websocket.webidl file TODO: The send function needs to flag when full by using the following self.full.set(true). This needs to be done when the buffer is full */ diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index dd4a7ea67c1..2621a9498a3 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -35,8 +35,10 @@ use script_task::{TimerSource, ScriptChan, ScriptPort, NonWorkerScriptChan}; use script_task::ScriptMsg; use script_traits::ScriptControlChan; use timers::{IsInterval, TimerId, TimerManager, TimerCallback}; +use webdriver_handlers::jsval_to_webdriver; use devtools_traits::{DevtoolsControlChan, TimelineMarker, TimelineMarkerType, TracingMetadata}; +use webdriver_traits::{WebDriverJSError, WebDriverJSResult}; use msg::compositor_msg::ScriptListener; use msg::constellation_msg::{LoadData, PipelineId, SubpageId, ConstellationChan, WindowSizeData, WorkerId}; use net_traits::ResourceTask; @@ -166,6 +168,9 @@ pub struct Window { /// A counter of the number of pending reflows for this window. pending_reflow_count: Cell<u32>, + + /// A channel for communicating results of async scripts back to the webdriver server + webdriver_script_chan: RefCell<Option<Sender<WebDriverJSResult>>> } impl Window { @@ -483,6 +488,21 @@ impl<'a> WindowMethods for JSRef<'a, Window> { let doc = self.Document().root(); doc.r().cancel_animation_frame(ident); } + + fn WebdriverCallback(self, cx: *mut JSContext, val: JSVal) { + let rv = jsval_to_webdriver(cx, val); + let opt_chan = self.webdriver_script_chan.borrow_mut().take(); + if let Some(chan) = opt_chan { + chan.send(rv).unwrap(); + } + } + + fn WebdriverTimeout(self) { + let opt_chan = self.webdriver_script_chan.borrow_mut().take(); + if let Some(chan) = opt_chan { + chan.send(Err(WebDriverJSError::Timeout)).unwrap(); + } + } } pub trait WindowHelpers { @@ -523,6 +543,7 @@ pub trait WindowHelpers { fn emit_timeline_marker(self, marker: TimelineMarker); fn set_devtools_timeline_marker(self, marker: TimelineMarkerType, reply: Sender<TimelineMarker>); fn drop_devtools_timeline_markers(self); + fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>); } pub trait ScriptHelpers { @@ -880,6 +901,10 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { self.devtools_markers.borrow_mut().clear(); *self.devtools_marker_sender.borrow_mut() = None; } + + fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>) { + *self.webdriver_script_chan.borrow_mut() = chan; + } } impl Window { @@ -947,6 +972,7 @@ impl Window { devtools_marker_sender: RefCell::new(None), devtools_markers: RefCell::new(HashSet::new()), devtools_wants_updates: Cell::new(false), + webdriver_script_chan: RefCell::new(None), }; WindowBinding::Wrap(runtime.cx(), win) |