script/dom/css/
cssstyleproperties.rs1use dom_struct::dom_struct;
6use js::context::{JSContext, NoGC};
7use script_bindings::reflector::reflect_dom_object;
8use style::properties::{LonghandId, PropertyId, ShorthandId};
9use style::selector_parser::PseudoElement;
10
11use crate::dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
12use crate::dom::bindings::codegen::Bindings::CSSStylePropertiesBinding::CSSStylePropertiesMethods;
13use crate::dom::bindings::error::ErrorResult;
14use crate::dom::bindings::root::DomRoot;
15use crate::dom::bindings::str::DOMString;
16use crate::dom::css::cssstyledeclaration::{
17 CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner,
18};
19use crate::dom::window::Window;
20
21#[dom_struct]
23pub(crate) struct CSSStyleProperties {
24 style_declaration: CSSStyleDeclaration,
25}
26
27macro_rules! css_properties(
28 ( $([$getter:ident, $setter:ident, $id:expr],)* ) => (
29 $(
30 fn $getter(&self, no_gc: &NoGC) -> DOMString {
31 debug_assert!(
32 $id.enabled_for_all_content(),
33 "Someone forgot a #[Pref] annotation"
34 );
35 self.style_declaration.get_property_value(no_gc, $id)
36 }
37 fn $setter(&self, cx: &mut JSContext, value: DOMString) -> ErrorResult {
38 debug_assert!(
39 $id.enabled_for_all_content(),
40 "Someone forgot a #[Pref] annotation"
41 );
42 self.style_declaration.set_property(cx, $id, value, DOMString::new())
43 }
44 )*
45 );
46);
47
48impl CSSStyleProperties {
49 #[cfg_attr(crown, expect(crown::unrooted_must_root))]
50 pub(crate) fn new(
51 cx: &mut JSContext,
52 global: &Window,
53 owner: CSSStyleOwner,
54 pseudo: Option<PseudoElement>,
55 modification_access: CSSModificationAccess,
56 ) -> DomRoot<CSSStyleProperties> {
57 reflect_dom_object(
58 cx,
59 Box::new(CSSStyleProperties {
60 style_declaration: CSSStyleDeclaration::new_inherited(
61 owner,
62 pseudo,
63 modification_access,
64 ),
65 }),
66 global,
67 )
68 }
69}
70
71impl CSSStylePropertiesMethods<crate::DomTypeHolder> for CSSStyleProperties {
72 fn CssFloat(&self, no_gc: &NoGC) -> DOMString {
74 self.style_declaration
75 .get_property_value(no_gc, PropertyId::NonCustom(LonghandId::Float.into()))
76 }
77
78 fn SetCssFloat(&self, cx: &mut JSContext, value: DOMString) -> ErrorResult {
80 self.style_declaration.set_property(
81 cx,
82 PropertyId::NonCustom(LonghandId::Float.into()),
83 value,
84 DOMString::new(),
85 )
86 }
87
88 fn IndexedGetter(&self, no_gc: &NoGC, index: u32) -> Option<DOMString> {
89 self.style_declaration.IndexedGetter(no_gc, index)
90 }
91
92 fn Length(&self, cx: &JSContext) -> u32 {
93 self.style_declaration.Length(cx.no_gc())
94 }
95
96 style::css_properties_accessors!(css_properties);
98}