tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

computed_value_flags.rs (8082B)


      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 /// Misc information about a given computed style.
      8 ///
      9 /// All flags are currently inherited for text, pseudo elements, and
     10 /// anonymous boxes, see StyleBuilder::for_inheritance and its callsites.
     11 /// If we ever want to add some flags that shouldn't inherit for them,
     12 /// we might want to add a function to handle this.
     13 #[repr(C)]
     14 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     15 #[cfg_attr(feature = "servo", derive(crate::derives::MallocSizeOf))]
     16 pub struct ComputedValueFlags(u32);
     17 
     18 bitflags! {
     19    impl ComputedValueFlags: u32 {
     20        /// Whether the style or any of the ancestors has a text-decoration-line
     21        /// property that should get propagated to descendants.
     22        ///
     23        /// text-decoration-line is a reset property, but gets propagated in the
     24        /// frame/box tree.
     25        const HAS_TEXT_DECORATION_LINES = 1 << 0;
     26 
     27        /// Whether line break inside should be suppressed.
     28        ///
     29        /// If this flag is set, the line should not be broken inside,
     30        /// which means inlines act as if nowrap is set, <br> element is
     31        /// suppressed, and blocks are inlinized.
     32        ///
     33        /// This bit is propagated to all children of line participants.
     34        /// It is currently used by ruby to make its content unbreakable.
     35        const SHOULD_SUPPRESS_LINEBREAK = 1 << 1;
     36 
     37        /// A flag used to mark text that that has text-combine-upright.
     38        ///
     39        /// This is used from Gecko's layout engine.
     40        const IS_TEXT_COMBINED = 1 << 2;
     41 
     42        /// A flag used to mark styles under a relevant link that is also
     43        /// visited.
     44        const IS_RELEVANT_LINK_VISITED = 1 << 3;
     45 
     46        /// A flag used to mark styles which are a ::first-line or under one.
     47        const IS_IN_FIRST_LINE_SUBTREE = 1 << 4;
     48 
     49        /// A flag used to mark styles which have contain:style or under one.
     50        const SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE = 1 << 5;
     51 
     52        /// Whether this style's `display` property depends on our parent style.
     53        ///
     54        /// This is important because it may affect our optimizations to avoid
     55        /// computing the style of pseudo-elements, given whether the
     56        /// pseudo-element is generated depends on the `display` value.
     57        const DISPLAY_DEPENDS_ON_INHERITED_STYLE = 1 << 6;
     58 
     59        /// Whether this style's `content` depends on our parent style.
     60        ///
     61        /// Important because of the same reason.
     62        const CONTENT_DEPENDS_ON_INHERITED_STYLE = 1 << 7;
     63 
     64        /// Whether the child explicitly inherits any reset property.
     65        const INHERITS_RESET_STYLE = 1 << 8;
     66 
     67        /// Whether any value on our style is font-metric-dependent on our
     68        /// primary font.
     69        const DEPENDS_ON_SELF_FONT_METRICS = 1 << 9;
     70 
     71        /// Whether any value on our style is font-metric-dependent on the
     72        /// primary font of our parent.
     73        const DEPENDS_ON_INHERITED_FONT_METRICS = 1 << 10;
     74 
     75        /// Whether the style or any of the ancestors has a multicol style.
     76        ///
     77        /// Only used in Servo.
     78        const CAN_BE_FRAGMENTED = 1 << 11;
     79 
     80        /// Whether this style is the style of the document element.
     81        const IS_ROOT_ELEMENT_STYLE = 1 << 12;
     82 
     83        /// Whether this element is inside an `opacity: 0` subtree.
     84        const IS_IN_OPACITY_ZERO_SUBTREE = 1 << 13;
     85 
     86        /// Whether there are author-specified rules for border-* properties
     87        /// (except border-image-*), background-color, or background-image.
     88        ///
     89        /// TODO(emilio): Maybe do include border-image, see:
     90        ///
     91        /// https://github.com/w3c/csswg-drafts/issues/4777#issuecomment-604424845
     92        const HAS_AUTHOR_SPECIFIED_BORDER_BACKGROUND = 1 << 14;
     93 
     94        /// Whether there are author-specified rules for `font-family`.
     95        const HAS_AUTHOR_SPECIFIED_FONT_FAMILY = 1 << 16;
     96 
     97        /// Whether there are author-specified rules for `font-synthesis-weight`.
     98        const HAS_AUTHOR_SPECIFIED_FONT_SYNTHESIS_WEIGHT = 1 << 17;
     99 
    100        /// Whether there are author-specified rules for `font-synthesis-style`.
    101        const HAS_AUTHOR_SPECIFIED_FONT_SYNTHESIS_STYLE = 1 << 18;
    102 
    103        // (There's also font-synthesis-small-caps and font-synthesis-position,
    104        // but we don't currently need to keep track of those.)
    105 
    106        /// Whether there are author-specified rules for `letter-spacing`.
    107        const HAS_AUTHOR_SPECIFIED_LETTER_SPACING = 1 << 19;
    108 
    109        /// Whether there are author-specified rules for `word-spacing`.
    110        const HAS_AUTHOR_SPECIFIED_WORD_SPACING = 1 << 20;
    111 
    112        /// Whether the style depends on viewport units.
    113        const USES_VIEWPORT_UNITS = 1 << 21;
    114 
    115        /// Whether the style depends on viewport units on container queries.
    116        ///
    117        /// This needs to be a separate flag from `USES_VIEWPORT_UNITS` because
    118        /// it causes us to re-match the style (rather than re-cascascading it,
    119        /// which is enough for other uses of viewport units).
    120        const USES_VIEWPORT_UNITS_ON_CONTAINER_QUERIES = 1 << 22;
    121 
    122        /// A flag used to mark styles which have `container-type` of `size` or
    123        /// `inline-size`, or under one.
    124        const SELF_OR_ANCESTOR_HAS_SIZE_CONTAINER_TYPE = 1 << 23;
    125        /// Whether the style uses container query units, in which case the style depends on the
    126        /// container's size and we can't reuse it across cousins (without double-checking the
    127        /// container at least).
    128        const USES_CONTAINER_UNITS = 1 << 24;
    129 
    130        /// Whether there are author-specific rules for text `color`.
    131        const HAS_AUTHOR_SPECIFIED_TEXT_COLOR = 1 << 25;
    132 
    133        /// Whether this style considered a scope style rule.
    134        const CONSIDERED_NONTRIVIAL_SCOPED_STYLE = 1 << 26;
    135 
    136        /// Whether this style is that of a `display: contents` element that is either a direct
    137        /// child of an item container or another `display: contents` element, the style of which
    138        /// has this flag set, marked in order to cascade beyond them to the descendants of the
    139        /// the item container that do generate a box.
    140        const DIPLAY_CONTENTS_IN_ITEM_CONTAINER = 1 << 27;
    141    }
    142 }
    143 
    144 impl Default for ComputedValueFlags {
    145    #[inline]
    146    fn default() -> Self {
    147        Self::empty()
    148    }
    149 }
    150 
    151 impl ComputedValueFlags {
    152    /// Flags that are unconditionally propagated to descendants.
    153    #[inline]
    154    fn inherited_flags() -> Self {
    155        Self::IS_RELEVANT_LINK_VISITED
    156            | Self::CAN_BE_FRAGMENTED
    157            | Self::IS_IN_FIRST_LINE_SUBTREE
    158            | Self::HAS_TEXT_DECORATION_LINES
    159            | Self::IS_IN_OPACITY_ZERO_SUBTREE
    160            | Self::SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE
    161            | Self::SELF_OR_ANCESTOR_HAS_SIZE_CONTAINER_TYPE
    162    }
    163 
    164    /// Flags that may be propagated to descendants.
    165    #[inline]
    166    fn maybe_inherited_flags() -> Self {
    167        Self::inherited_flags()
    168            | Self::SHOULD_SUPPRESS_LINEBREAK
    169            | Self::DIPLAY_CONTENTS_IN_ITEM_CONTAINER
    170    }
    171 
    172    /// Flags that are an input to the cascade.
    173    #[inline]
    174    fn cascade_input_flags() -> Self {
    175        Self::USES_VIEWPORT_UNITS_ON_CONTAINER_QUERIES | Self::CONSIDERED_NONTRIVIAL_SCOPED_STYLE
    176    }
    177 
    178    /// Returns the flags that are always propagated to descendants.
    179    ///
    180    /// See StyleAdjuster::set_bits and StyleBuilder.
    181    #[inline]
    182    pub fn inherited(self) -> Self {
    183        self & Self::inherited_flags()
    184    }
    185 
    186    /// Flags that are conditionally propagated to descendants, just to handle
    187    /// properly style invalidation.
    188    #[inline]
    189    pub fn maybe_inherited(self) -> Self {
    190        self & Self::maybe_inherited_flags()
    191    }
    192 
    193    /// Flags that are an input to the cascade.
    194    #[inline]
    195    pub fn for_cascade_inputs(self) -> Self {
    196        self & Self::cascade_input_flags()
    197    }
    198 }