script/dom/css/
cssstylevalue.rs1use cssparser::{Parser, ParserInput};
6use dom_struct::dom_struct;
7use js::context::JSContext;
8use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
9use servo_url::ServoUrl;
10
11use crate::dom::bindings::codegen::Bindings::CSSStyleValueBinding::CSSStyleValueMethods;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::bindings::str::DOMString;
14use crate::dom::globalscope::GlobalScope;
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 cx: &mut JSContext,
32 global: &GlobalScope,
33 value: String,
34 ) -> DomRoot<CSSStyleValue> {
35 reflect_dom_object_with_cx(Box::new(CSSStyleValue::new_inherited(value)), global, cx)
36 }
37}
38
39impl CSSStyleValueMethods<crate::DomTypeHolder> for CSSStyleValue {
40 fn Stringifier(&self) -> DOMString {
42 DOMString::from(&*self.value)
43 }
44}
45
46impl CSSStyleValue {
47 pub(crate) fn get_url(&self, base_url: ServoUrl) -> Option<ServoUrl> {
52 let mut input = ParserInput::new(&self.value);
53 let mut parser = Parser::new(&mut input);
54 parser
55 .expect_url()
56 .ok()
57 .and_then(|string| base_url.join(&string).ok())
58 }
59}