aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2015-07-28 12:02:51 +0200
committerMs2ger <Ms2ger@gmail.com>2015-08-08 11:26:33 +0200
commit7f2b21c06e521af6f921e81bd04adf49270749ee (patch)
treeae857c4fca00e71e67cad4d25671b2fdad269a6b /components/script/dom/document.rs
parent92e64e607ca4b00f92ba502f8d83149881da2df6 (diff)
downloadservo-7f2b21c06e521af6f921e81bd04adf49270749ee.tar.gz
servo-7f2b21c06e521af6f921e81bd04adf49270749ee.zip
Implement base_url and fallback_base_url methods.
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index d60545e159b..2f0787ad6e4 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::InheritTypes::ElementDerived;
+use dom::bindings::codegen::InheritTypes::HTMLBaseElementCast;
use dom::bindings::codegen::UnionTypes::NodeOrString;
use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::error::Error::{NotSupported, InvalidCharacter, Security};
@@ -45,6 +46,7 @@ use dom::element::{ElementTypeId, ActivationElementHelpers, FocusElementHelpers}
use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers};
use dom::eventtarget::{EventTarget, EventTargetTypeId, EventTargetHelpers};
use dom::htmlanchorelement::HTMLAnchorElement;
+use dom::htmlbaseelement::HTMLBaseElement;
use dom::htmlcollection::{HTMLCollection, CollectionFilter};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlheadelement::HTMLHeadElement;
@@ -231,7 +233,14 @@ pub trait DocumentHelpers<'a> {
fn encoding_name(self) -> Ref<'a, DOMString>;
fn is_html_document(self) -> bool;
fn is_fully_active(self) -> bool;
+ /// https://dom.spec.whatwg.org/#concept-document-url
fn url(self) -> Url;
+ /// https://html.spec.whatwg.org/multipage/#fallback-base-url
+ fn fallback_base_url(self) -> Url;
+ /// https://html.spec.whatwg.org/multipage/#document-base-url
+ fn base_url(self) -> Url;
+ /// Returns the first `base` element in the DOM that has an `href` attribute.
+ fn base_element(self) -> Option<Root<HTMLBaseElement>>;
fn quirks_mode(self) -> QuirksMode;
fn set_quirks_mode(self, mode: QuirksMode);
fn set_encoding_name(self, name: DOMString);
@@ -336,11 +345,38 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
true
}
- // https://dom.spec.whatwg.org/#dom-document-url
+ // https://dom.spec.whatwg.org/#concept-document-url
fn url(self) -> Url {
self.url.clone()
}
+ // https://html.spec.whatwg.org/multipage/#fallback-base-url
+ fn fallback_base_url(self) -> Url {
+ // Step 1: iframe srcdoc (#4767).
+ // Step 2: about:blank with a creator browsing context.
+ // Step 3.
+ self.url()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#document-base-url
+ fn base_url(self) -> Url {
+ match self.base_element() {
+ // Step 1.
+ None => self.fallback_base_url(),
+ // Step 2.
+ Some(base) => base.frozen_base_url(),
+ }
+ }
+
+ /// Returns the first `base` element in the DOM that has an `href` attribute.
+ fn base_element(self) -> Option<Root<HTMLBaseElement>> {
+ NodeCast::from_ref(self)
+ .traverse_preorder()
+ .filter_map(HTMLBaseElementCast::to_root)
+ .filter(|element| ElementCast::from_ref(&**element).has_attribute(&atom!("href")))
+ .next()
+ }
+
fn quirks_mode(self) -> QuirksMode {
self.quirks_mode.get()
}