aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/cssstylevalue.rs
diff options
context:
space:
mode:
authorAlan Jeffrey <ajeffrey@mozilla.com>2017-07-05 15:18:08 -0500
committerAlan Jeffrey <ajeffrey@mozilla.com>2017-07-21 16:39:11 -0500
commit2318caf002ab13cd9c9bf30676eaca5e7b9b0dc1 (patch)
treec40aa490c365e5d9453a62dc2c7483c8019fedc8 /components/script/dom/cssstylevalue.rs
parent992c647f76552ae3abaeffc69331375a69d34dab (diff)
downloadservo-2318caf002ab13cd9c9bf30676eaca5e7b9b0dc1.tar.gz
servo-2318caf002ab13cd9c9bf30676eaca5e7b9b0dc1.zip
Implement drawing an image from a CSS style value into a canvas.
Diffstat (limited to 'components/script/dom/cssstylevalue.rs')
-rw-r--r--components/script/dom/cssstylevalue.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/components/script/dom/cssstylevalue.rs b/components/script/dom/cssstylevalue.rs
index 7ee9d5509f0..adc70ed7972 100644
--- a/components/script/dom/cssstylevalue.rs
+++ b/components/script/dom/cssstylevalue.rs
@@ -2,6 +2,8 @@
* 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 cssparser::Parser;
+use cssparser::ParserInput;
use dom::bindings::codegen::Bindings::CSSStyleValueBinding::CSSStyleValueMethods;
use dom::bindings::codegen::Bindings::CSSStyleValueBinding::Wrap;
use dom::bindings::js::Root;
@@ -10,6 +12,7 @@ use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
+use servo_url::ServoUrl;
#[dom_struct]
pub struct CSSStyleValue {
@@ -44,3 +47,16 @@ impl CSSStyleValueMethods for CSSStyleValue {
self.Stringifier()
}
}
+
+impl CSSStyleValue {
+ /// Parse the value as a `url()`.
+ /// TODO: This should really always be an absolute URL, but we currently
+ /// return relative URLs for computed values, so we pass in a base.
+ /// https://github.com/servo/servo/issues/17625
+ pub fn get_url(&self, base_url: ServoUrl) -> Option<ServoUrl> {
+ let mut input = ParserInput::new(&*self.value);
+ let mut parser = Parser::new(&mut input);
+ parser.expect_url().ok()
+ .and_then(|string| base_url.join(&*string).ok())
+ }
+}