mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Implement drawing an image from a CSS style value into a canvas.
This commit is contained in:
parent
992c647f76
commit
2318caf002
8 changed files with 232 additions and 125 deletions
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue