aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-10-15 10:59:01 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2017-10-15 11:03:20 +0200
commitc7b1d3054f9e87cf7ae7b10df5fbf5a97f6448f4 (patch)
tree08886f4fabb29cac0b0ba7cb341477ab8f28a757 /components/script/dom
parent8b366a7441a7a4febcb5e2047807f9ad447c7adb (diff)
downloadservo-c7b1d3054f9e87cf7ae7b10df5fbf5a97f6448f4.tar.gz
servo-c7b1d3054f9e87cf7ae7b10df5fbf5a97f6448f4.zip
Change AttrValue::Url to AttrValue::ResolvedUrl
There is actually only one attribute that can use that, the one for <body background>.
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/element.rs28
-rw-r--r--components/script/dom/htmlbodyelement.rs23
-rw-r--r--components/script/dom/htmliframeelement.rs3
-rw-r--r--components/script/dom/htmlimageelement.rs3
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs3
-rw-r--r--components/script/dom/htmllinkelement.rs3
-rw-r--r--components/script/dom/htmlmediaelement.rs10
-rw-r--r--components/script/dom/htmlscriptelement.rs10
8 files changed, 27 insertions, 56 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index f6e5357df10..2287dcedb9a 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -1306,26 +1306,13 @@ impl Element {
Some(attr) => attr,
None => return DOMString::new(),
};
- let value = attr.value();
- match *value {
- AttrValue::Url(ref value, _) => {
- // XXXManishearth this doesn't handle `javascript:` urls properly
- let base = document_from_node(self).base_url();
- let value = base.join(value)
- .map(|parsed| parsed.into_string())
- .unwrap_or_else(|_| value.clone());
- DOMString::from(value)
- },
- _ => panic!("attribute value should be AttrValue::Url(..)"),
- }
- }
-
- pub fn set_url_attribute(&self, local_name: &LocalName, value: DOMString) {
- let value = AttrValue::from_url(
- document_from_node(self).base_url(),
- value.into(),
- );
- self.set_attribute(local_name, value);
+ let value = &**attr.value();
+ // XXXManishearth this doesn't handle `javascript:` urls properly
+ let base = document_from_node(self).base_url();
+ let value = base.join(value)
+ .map(|parsed| parsed.into_string())
+ .unwrap_or_else(|_| value.to_owned());
+ DOMString::from(value)
}
pub fn get_string_attribute(&self, local_name: &LocalName) -> DOMString {
@@ -1334,6 +1321,7 @@ impl Element {
None => DOMString::new(),
}
}
+
pub fn set_string_attribute(&self, local_name: &LocalName, value: DOMString) {
assert!(*local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::String(value.into()));
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index 580dc0a8808..69d56b31b95 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -4,7 +4,6 @@
use cssparser::RGBA;
use dom::attr::Attr;
-use dom::bindings::codegen::Bindings::AttrBinding::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::inheritance::Castable;
@@ -74,15 +73,16 @@ impl HTMLBodyElementMethods for HTMLBodyElement {
make_legacy_color_setter!(SetText, "text");
// https://html.spec.whatwg.org/multipage/#dom-body-background
- fn Background(&self) -> DOMString {
- self.upcast::<Element>()
- .get_attribute(&ns!(), &local_name!("background"))
- .map(|attr| attr.Value())
- .unwrap_or_default()
- }
+ make_getter!(Background, "background");
// https://html.spec.whatwg.org/multipage/#dom-body-background
- make_url_setter!(SetBackground, "background");
+ fn SetBackground(&self, input: DOMString) {
+ let value = AttrValue::from_resolved_url(
+ &document_from_node(self).base_url(),
+ input.into(),
+ );
+ self.upcast::<Element>().set_attribute(&local_name!("background"), value);
+ }
// https://html.spec.whatwg.org/multipage/#windoweventhandlers
window_event_handlers!(ForwardToWindow);
@@ -120,7 +120,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutDom<HTMLBodyElement> {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &local_name!("background"))
- .and_then(AttrValue::as_url)
+ .and_then(AttrValue::as_resolved_url)
.cloned()
}
}
@@ -160,7 +160,10 @@ impl VirtualMethods for HTMLBodyElement {
local_name!("bgcolor") |
local_name!("text") => AttrValue::from_legacy_color(value.into()),
local_name!("background") => {
- AttrValue::from_url(document_from_node(self).base_url(), value.into())
+ AttrValue::from_resolved_url(
+ &document_from_node(self).base_url(),
+ value.into(),
+ )
},
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs
index 2346358aabd..61828e4b404 100644
--- a/components/script/dom/htmliframeelement.rs
+++ b/components/script/dom/htmliframeelement.rs
@@ -571,7 +571,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
make_url_getter!(Src, "src");
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
- make_url_setter!(SetSrc, "src");
+ make_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
fn Sandbox(&self) -> DomRoot<DOMTokenList> {
@@ -761,7 +761,6 @@ impl VirtualMethods for HTMLIFrameElement {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
- &local_name!("src") => AttrValue::from_url(document_from_node(self).base_url(), value.into()),
&local_name!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("width") => AttrValue::from_dimension(value.into()),
&local_name!("height") => AttrValue::from_dimension(value.into()),
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index a9b2f01e283..1eb01956350 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -826,7 +826,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
make_url_getter!(Src, "src");
// https://html.spec.whatwg.org/multipage/#dom-img-src
- make_url_setter!(SetSrc, "src");
+ make_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-img-crossOrigin
fn GetCrossOrigin(&self) -> Option<DOMString> {
@@ -981,7 +981,6 @@ impl VirtualMethods for HTMLImageElement {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
- &local_name!("src") => AttrValue::from_url(document_from_node(self).base_url(), value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("width") | &local_name!("height") => AttrValue::from_dimension(value.into()),
&local_name!("hspace") | &local_name!("vspace") => AttrValue::from_u32(value.into(), 0),
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 7260ec7bc50..08ea8a57653 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -530,7 +530,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
make_url_getter!(Src, "src");
// https://html.spec.whatwg.org/multipage/#dom-input-src
- make_url_setter!(SetSrc, "src");
+ make_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-input-step
make_getter!(Step, "step");
@@ -1056,7 +1056,6 @@ impl VirtualMethods for HTMLInputElement {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
- &local_name!("src") => AttrValue::from_url(document_from_node(self).base_url(), value.into()),
&local_name!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE),
diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs
index 9bf1ba73991..320b425331b 100644
--- a/components/script/dom/htmllinkelement.rs
+++ b/components/script/dom/htmllinkelement.rs
@@ -208,7 +208,6 @@ impl VirtualMethods for HTMLLinkElement {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
- &local_name!("href") => AttrValue::from_url(document_from_node(self).base_url(), value.into()),
&local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
@@ -374,7 +373,7 @@ impl HTMLLinkElementMethods for HTMLLinkElement {
make_url_getter!(Href, "href");
// https://html.spec.whatwg.org/multipage/#dom-link-href
- make_url_setter!(SetHref, "href");
+ make_setter!(SetHref, "href");
// https://html.spec.whatwg.org/multipage/#dom-link-rel
make_getter!(Rel, "rel");
diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs
index 965dd83cee4..d5c3748bd0c 100644
--- a/components/script/dom/htmlmediaelement.rs
+++ b/components/script/dom/htmlmediaelement.rs
@@ -46,7 +46,6 @@ use std::collections::VecDeque;
use std::mem;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
-use style::attr::AttrValue;
use task_source::TaskSource;
use time::{self, Timespec, Duration};
@@ -840,7 +839,7 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
make_url_getter!(Src, "src");
// https://html.spec.whatwg.org/multipage/#dom-media-src
- make_url_setter!(SetSrc, "src");
+ make_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-media-srcobject
fn GetSrcObject(&self) -> Option<DomRoot<Blob>> {
@@ -915,13 +914,6 @@ impl VirtualMethods for HTMLMediaElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
- fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
- match name {
- &local_name!("src") => AttrValue::from_url(document_from_node(self).base_url(), value.into()),
- _ => self.super_type().unwrap().parse_plain_attribute(name, value),
- }
- }
-
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs
index 5ad655ce659..5c85aa30899 100644
--- a/components/script/dom/htmlscriptelement.rs
+++ b/components/script/dom/htmlscriptelement.rs
@@ -42,7 +42,6 @@ use std::io::{Read, Write};
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex};
-use style::attr::AttrValue;
use style::str::{HTML_SPACE_CHARACTERS, StaticStringVec};
use uuid::Uuid;
@@ -654,13 +653,6 @@ impl VirtualMethods for HTMLScriptElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
- fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
- match name {
- &local_name!("src") => AttrValue::from_url(document_from_node(self).base_url(), value.into()),
- _ => self.super_type().unwrap().parse_plain_attribute(name, value),
- }
- }
-
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match *attr.local_name() {
@@ -712,7 +704,7 @@ impl HTMLScriptElementMethods for HTMLScriptElement {
make_url_getter!(Src, "src");
// https://html.spec.whatwg.org/multipage/#dom-script-src
- make_url_setter!(SetSrc, "src");
+ make_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-script-type
make_getter!(Type, "type");