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 `font-family`. 88 const HAS_AUTHOR_SPECIFIED_FONT_FAMILY = 1 << 16; 89 90 /// Whether there are author-specified rules for `font-synthesis`. 91 const HAS_AUTHOR_SPECIFIED_FONT_SYNTHESIS = 1 << 17; 92 93 /// Whether there are author-specified rules for `letter-spacing`. 94 const HAS_AUTHOR_SPECIFIED_LETTER_SPACING = 1 << 18; 95 96 /// Whether there are author-specified rules for `word-spacing`. 97 const HAS_AUTHOR_SPECIFIED_WORD_SPACING = 1 << 19; 98 99 /// Whether the style depends on viewport units. 100 const USES_VIEWPORT_UNITS = 1 << 20; 101 } 102 } 103 104 impl ComputedValueFlags { 105 /// Flags that are unconditionally propagated to descendants. 106 #[inline] inherited_flags() -> Self107 fn inherited_flags() -> Self { 108 Self::IS_RELEVANT_LINK_VISITED | 109 Self::CAN_BE_FRAGMENTED | 110 Self::IS_IN_PSEUDO_ELEMENT_SUBTREE | 111 Self::HAS_TEXT_DECORATION_LINES | 112 Self::IS_IN_OPACITY_ZERO_SUBTREE 113 } 114 115 /// Flags that may be propagated to descendants. 116 #[inline] maybe_inherited_flags() -> Self117 fn maybe_inherited_flags() -> Self { 118 Self::inherited_flags() | ComputedValueFlags::SHOULD_SUPPRESS_LINEBREAK 119 } 120 121 /// Returns the flags that are always propagated to descendants. 122 /// 123 /// See StyleAdjuster::set_bits and StyleBuilder. 124 #[inline] inherited(self) -> Self125 pub fn inherited(self) -> Self { 126 self & Self::inherited_flags() 127 } 128 129 /// Flags that are conditionally propagated to descendants, just to handle 130 /// properly style invalidation. 131 #[inline] maybe_inherited(self) -> Self132 pub fn maybe_inherited(self) -> Self { 133 self & Self::maybe_inherited_flags() 134 } 135 } 136