script/dom/
cssstylevalue.rs1use cssparser::{Parser, ParserInput};
6use dom_struct::dom_struct;
7use servo_url::ServoUrl;
8
9use crate::dom::bindings::codegen::Bindings::CSSStyleValueBinding::CSSStyleValueMethods;
10use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::bindings::str::DOMString;
13use crate::dom::globalscope::GlobalScope;
14use crate::script_runtime::CanGc;
15
16#[dom_struct]
17pub(crate) struct CSSStyleValue {
18 reflector: Reflector,
19 value: String,
20}
21
22impl CSSStyleValue {
23 fn new_inherited(value: String) -> CSSStyleValue {
24 CSSStyleValue {
25 reflector: Reflector::new(),
26 value,
27 }
28 }
29
30 pub(crate) fn new(
31 global: &GlobalScope,
32 value: String,
33 can_gc: CanGc,
34 ) -> DomRoot<CSSStyleValue> {
35 reflect_dom_object(
36 Box::new(CSSStyleValue::new_inherited(value)),
37 global,
38 can_gc,
39 )
40 }
41}
42
43impl CSSStyleValueMethods<crate::DomTypeHolder> for CSSStyleValue {
44 fn Stringifier(&self) -> DOMString {
46 DOMString::from(&*self.value)
47 }
48}
49
50impl CSSStyleValue {
51 pub(crate) fn get_url(&self, base_url: ServoUrl) -> Option<ServoUrl> {
56 let mut input = ParserInput::new(&self.value);
57 let mut parser = Parser::new(&mut input);
58 parser
59 .expect_url()
60 .ok()
61 .and_then(|string| base_url.join(&string).ok())
62 }
63}