diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/Cargo.toml | 2 | ||||
-rw-r--r-- | components/script/dom/htmlbaseelement.rs | 30 | ||||
-rw-r--r-- | components/script/dom/htmltableelement.rs | 7 | ||||
-rw-r--r-- | components/script/dom/htmltablerowelement.rs | 31 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLBaseElement.webidl | 4 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLTableRowElement.webidl | 2 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 6 |
7 files changed, 67 insertions, 15 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index eaf86e3b39f..9fda41e036f 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -75,7 +75,7 @@ heapsize = "0.3.0" heapsize_plugin = "0.1.2" html5ever = {version = "0.5.1", features = ["heap_size", "unstable"]} hyper = { version = "0.8", features = [ "serde-serialization" ] } -image = "0.7" +image = "0.9" libc = "0.2" log = "0.3.5" num = "0.1.24" diff --git a/components/script/dom/htmlbaseelement.rs b/components/script/dom/htmlbaseelement.rs index 7f1ce7641d3..241c209c7a8 100644 --- a/components/script/dom/htmlbaseelement.rs +++ b/components/script/dom/htmlbaseelement.rs @@ -2,8 +2,9 @@ * 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::Attr; +use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLBaseElementBinding; +use dom::bindings::codegen::Bindings::HTMLBaseElementBinding::HTMLBaseElementMethods; use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; @@ -60,6 +61,33 @@ impl HTMLBaseElement { } } +impl HTMLBaseElementMethods for HTMLBaseElement { + // https://html.spec.whatwg.org/multipage/#dom-base-href + fn Href(&self) -> DOMString { + let document = document_from_node(self); + + // Step 1. + if !self.upcast::<Element>().has_attribute(&atom!("href")) { + return DOMString::from(document.base_url().serialize()); + } + + // Step 2. + let fallback_base_url = document.fallback_base_url(); + + // Step 3. + let url = self.upcast::<Element>().get_url_attribute(&atom!("href")); + + // Step 4. + let url_record = fallback_base_url.join(&*url); + + // Step 5, 6. + DOMString::from(url_record.ok().map_or("".to_owned(), |record| record.serialize())) + } + + // https://html.spec.whatwg.org/multipage/#dom-base-href + make_url_setter!(SetHref, "href"); +} + impl VirtualMethods for HTMLBaseElement { fn super_type(&self) -> Option<&VirtualMethods> { Some(self.upcast::<HTMLElement>() as &VirtualMethods) diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index efcc24f4370..4ea908675b1 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -118,13 +118,6 @@ impl HTMLTableElement { thead.upcast::<Node>().remove_self(); } } - - /// Determine the row index for the given `HTMLTableRowElement`. - pub fn row_index(&self, row_elem: &HTMLTableRowElement) -> Option<usize> { - self.Rows() - .elements_iter() - .position(|elem| (&elem as &Element) == row_elem.upcast::<Element>()) - } } impl HTMLTableElementMethods for HTMLTableElement { diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index c6d532a0323..bb83e00b0db 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -4,7 +4,9 @@ use cssparser::RGBA; use dom::attr::AttrValue; +use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods; use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods}; +use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::HTMLTableSectionElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; @@ -54,6 +56,14 @@ impl HTMLTableRowElement { document, HTMLTableRowElementBinding::Wrap) } + + /// Determine the index for this `HTMLTableRowElement` within the given + /// `HTMLCollection`. Returns `-1` if not found within collection. + fn row_index(&self, collection: Root<HTMLCollection>) -> i32 { + collection.elements_iter() + .position(|elem| (&elem as &Element) == self.upcast()) + .map_or(-1, |i| i as i32) + } } impl HTMLTableRowElementMethods for HTMLTableRowElement { @@ -97,7 +107,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement { None => return -1, }; if let Some(table) = parent.downcast::<HTMLTableElement>() { - return table.row_index(self).map_or(-1, |i| i as i32); + return self.row_index(table.Rows()); } if !parent.is::<HTMLTableSectionElement>() { return -1; @@ -107,8 +117,23 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement { None => return -1, }; grandparent.downcast::<HTMLTableElement>() - .and_then(|table| table.row_index(self)) - .map_or(-1, |i| i as i32) + .map_or(-1, |table| self.row_index(table.Rows())) + } + + // https://html.spec.whatwg.org/multipage/#dom-tr-sectionrowindex + fn SectionRowIndex(&self) -> i32 { + let parent = match self.upcast::<Node>().GetParentNode() { + Some(parent) => parent, + None => return -1, + }; + let collection = if let Some(table) = parent.downcast::<HTMLTableElement>() { + table.Rows() + } else if let Some(table_section) = parent.downcast::<HTMLTableSectionElement>() { + table_section.Rows() + } else { + return -1; + }; + self.row_index(collection) } } diff --git a/components/script/dom/webidls/HTMLBaseElement.webidl b/components/script/dom/webidls/HTMLBaseElement.webidl index 5c59c62f9be..549a6df1004 100644 --- a/components/script/dom/webidls/HTMLBaseElement.webidl +++ b/components/script/dom/webidls/HTMLBaseElement.webidl @@ -5,6 +5,6 @@ // https://html.spec.whatwg.org/multipage/#htmlbaseelement interface HTMLBaseElement : HTMLElement { - // attribute DOMString href; - // attribute DOMString target; + attribute DOMString href; +// attribute DOMString target; }; diff --git a/components/script/dom/webidls/HTMLTableRowElement.webidl b/components/script/dom/webidls/HTMLTableRowElement.webidl index 05d339aba3f..fe6c93e6be5 100644 --- a/components/script/dom/webidls/HTMLTableRowElement.webidl +++ b/components/script/dom/webidls/HTMLTableRowElement.webidl @@ -6,7 +6,7 @@ // https://html.spec.whatwg.org/multipage/#htmltablerowelement interface HTMLTableRowElement : HTMLElement { readonly attribute long rowIndex; - //readonly attribute long sectionRowIndex; + readonly attribute long sectionRowIndex; readonly attribute HTMLCollection cells; [Throws] HTMLElement insertCell(optional long index = -1); diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 1d7c2bffd34..8d6716201af 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -828,6 +828,12 @@ impl XMLHttpRequestMethods for XMLHttpRequest { // https://xhr.spec.whatwg.org/#the-responsexml-attribute fn GetResponseXML(&self) -> Fallible<Option<Root<Document>>> { + // TODO(#2823): Until [Exposed] is implemented, this attribute needs to return null + // explicitly in the worker scope. + if let GlobalRoot::Worker(_) = self.global() { + return Ok(None); + } + match self.response_type.get() { XMLHttpRequestResponseType::_empty | XMLHttpRequestResponseType::Document => { // Step 3 |