1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 //! Misc information about a given computed style.
6 
7 bitflags! {
8     /// Misc information about a given computed style.
9     ///
10     /// All flags are currently inherited for text, pseudo elements, and
11     /// anonymous boxes, see StyleBuilder::for_inheritance and its callsites.
12     /// If we ever want to add some flags that shouldn't inherit for them,
13     /// we might want to add a function to handle this.
14     #[repr(C)]
15     pub struct ComputedValueFlags: u32 {
16         /// Whether the style or any of the ancestors has a text-decoration-line
17         /// property that should get propagated to descendants.
18         ///
19         /// text-decoration-line is a reset property, but gets propagated in the
20         /// frame/box tree.
21         const HAS_TEXT_DECORATION_LINES = 1 << 0;
22 
23         /// Whether line break inside should be suppressed.
24         ///
25         /// If this flag is set, the line should not be broken inside,
26         /// which means inlines act as if nowrap is set, <br> element is
27         /// suppressed, and blocks are inlinized.
28         ///
29         /// This bit is propagated to all children of line participants.
30         /// It is currently used by ruby to make its content unbreakable.
31         const SHOULD_SUPPRESS_LINEBREAK = 1 << 1;
32 
33         /// A flag used to mark text that that has text-combine-upright.
34         ///
35         /// This is used from Gecko's layout engine.
36         const IS_TEXT_COMBINED = 1 << 2;
37 
38         /// A flag used to mark styles under a relevant link that is also
39         /// visited.
40         const IS_RELEVANT_LINK_VISITED = 1 << 3;
41 
42         /// A flag used to mark styles which are a pseudo-element or under one.
43         const IS_IN_PSEUDO_ELEMENT_SUBTREE = 1 << 4;
44 
45         /// Whether this style's `display` property depends on our parent style.
46         ///
47         /// This is important because it may affect our optimizations to avoid
48         /// computing the style of pseudo-elements, given whether the
49         /// pseudo-element is generated depends on the `display` value.
50         const DISPLAY_DEPENDS_ON_INHERITED_STYLE = 1 << 6;
51 
52         /// Whether this style's `content` depends on our parent style.
53         ///
54         /// Important because of the same reason.
55         const CONTENT_DEPENDS_ON_INHERITED_STYLE = 1 << 7;
56 
57         /// Whether the child explicitly inherits any reset property.
58         const INHERITS_RESET_STYLE = 1 << 8;
59 
60         /// Whether any value on our style is font-metric-dependent on our
61         /// primary font.
62         const DEPENDS_ON_SELF_FONT_METRICS = 1 << 9;
63 
64         /// Whether any value on our style is font-metric-dependent on the
65         /// primary font of our parent.
66         const DEPENDS_ON_INHERITED_FONT_METRICS = 1 << 10;
67 
68         /// Whether the style or any of the ancestors has a multicol style.
69         ///
70         /// Only used in Servo.
71         const CAN_BE_FRAGMENTED = 1 << 11;
72 
73         /// Whether this style is the style of the document element.
74         const IS_ROOT_ELEMENT_STYLE = 1 << 12;
75 
76         /// Whether this element is inside an `opacity: 0` subtree.
77         const IS_IN_OPACITY_ZERO_SUBTREE = 1 << 13;
78 
79         /// Whether there are author-specified rules for border-* properties
80         /// (except border-image-*), background-color, or background-image.
81         ///
82         /// TODO(emilio): Maybe do include border-image, see:
83         ///
84         /// https://github.com/w3c/csswg-drafts/issues/4777#issuecomment-604424845
85         const HAS_AUTHOR_SPECIFIED_BORDER_BACKGROUND = 1 << 14;
86 
87         /// Whether there are author-specified rules for padding-* properties.
88         ///
89         /// FIXME(emilio): Try to merge this with BORDER_BACKGROUND, see
90         /// https://github.com/w3c/csswg-drafts/issues/4777
91         const HAS_AUTHOR_SPECIFIED_PADDING = 1 << 15;
92 
93         /// Whether there are author-specified rules for `font-family`.
94         const HAS_AUTHOR_SPECIFIED_FONT_FAMILY = 1 << 16;
95 
96         /// Whether there are author-specified rules for `font-synthesis`.
97         const HAS_AUTHOR_SPECIFIED_FONT_SYNTHESIS = 1 << 17;
98 
99         /// Whether there are author-specified rules for `letter-spacing`.
100         const HAS_AUTHOR_SPECIFIED_LETTER_SPACING = 1 << 18;
101 
102         /// Whether there are author-specified rules for `word-spacing`.
103         const HAS_AUTHOR_SPECIFIED_WORD_SPACING = 1 << 19;
104 
105         /// Whether the style depends on viewport units.
106         const USES_VIEWPORT_UNITS = 1 << 20;
107     }
108 }
109 
110 impl ComputedValueFlags {
111     /// Flags that are unconditionally propagated to descendants.
112     #[inline]
inherited_flags() -> Self113     fn inherited_flags() -> Self {
114         Self::IS_RELEVANT_LINK_VISITED |
115             Self::CAN_BE_FRAGMENTED |
116             Self::IS_IN_PSEUDO_ELEMENT_SUBTREE |
117             Self::HAS_TEXT_DECORATION_LINES |
118             Self::IS_IN_OPACITY_ZERO_SUBTREE
119     }
120 
121     /// Flags that may be propagated to descendants.
122     #[inline]
maybe_inherited_flags() -> Self123     fn maybe_inherited_flags() -> Self {
124         Self::inherited_flags() | ComputedValueFlags::SHOULD_SUPPRESS_LINEBREAK
125     }
126 
127     /// Returns the flags that are always propagated to descendants.
128     ///
129     /// See StyleAdjuster::set_bits and StyleBuilder.
130     #[inline]
inherited(self) -> Self131     pub fn inherited(self) -> Self {
132         self & Self::inherited_flags()
133     }
134 
135     /// Flags that are conditionally propagated to descendants, just to handle
136     /// properly style invalidation.
137     #[inline]
maybe_inherited(self) -> Self138     pub fn maybe_inherited(self) -> Self {
139         self & Self::maybe_inherited_flags()
140     }
141 }
142