diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-13 18:51:42 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-13 18:51:42 +0530 |
commit | 3ad1b9134f17803f04ac94754e640e7f876799d8 (patch) | |
tree | 52cd699eb4fe92e420a4c92784b86341fd5fffab /components/script | |
parent | 9954ee1334e6224409bf82db620d80721f56bb13 (diff) | |
parent | 4a1eb479379931d2e9c283241df011a0fdf9948e (diff) | |
download | servo-3ad1b9134f17803f04ac94754e640e7f876799d8.tar.gz servo-3ad1b9134f17803f04ac94754e640e7f876799d8.zip |
Auto merge of #10512 - KiChjang:base-element-attr, r=Ms2ger
Implement HTMLBaseElement attributes
The remaining test failure in `base_multiple.html` looks like there's a problem with the test itself (it does not have a `<base>` tag at all).
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10512)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/htmlbaseelement.rs | 30 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLBaseElement.webidl | 4 |
2 files changed, 31 insertions, 3 deletions
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/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; }; |