layout_api/layout_damage.rs
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
5use bitflags::bitflags;
6use style::selector_parser::RestyleDamage;
7
8bitflags! {
9 /// Individual layout actions that may be necessary after restyling. This is an extension
10 /// of `RestyleDamage` from stylo, which only uses the 4 lower bits.
11 #[derive(Clone, Copy, Debug,Default, Eq, PartialEq)]
12 pub struct LayoutDamage: u16 {
13 // Layout Modes
14 //
15 // These should be kept in sync with the layout modes defined in Stylo's `RestyleDamage`.
16 // The entire damage machinery depends on `LayoutDamage` being a superset of `RestyleDamage`.
17 /// Repaint the node itself.
18 const Repaint = 0b0001;
19 /// Rebuilds the stacking contexts.
20 const RebuildStackingContextTree = 0b0011;
21 /// Recalculates the scrollable overflow.
22 const RecalculateOverflow = 0b0111;
23 /// Any other type of damage, which requires running layout again.
24 const Relayout = 0b1111;
25
26 // Layout-specific damage
27 /// Clear the cached inline content sizes and recompute them during the next layout.
28 const RecomputeInlineContentSizes = 0b1000_0000_0000_0000;
29 /// A descendant was collected as a layout root for fragment tree layout.
30 const DescendantCollectedAsLayoutRoot = 0b0100_0000_0000_0000;
31 /// Rebuild this box and all of its ancestors. Do not rebuild any children. This
32 /// is used when a box's content (such as text content) changes or a descendant
33 /// has box damage ([`Self::BOX_DAMAGE`]).
34 const DescendantHasBoxDamage = 0b0011_1111_1111_0000;
35 /// Rebuild this box, all of its ancestors and all of its descendants. This is the
36 /// most a box can be damaged.
37 const BoxDamage = 0b1111_1111_1111_0000;
38 }
39}
40
41impl LayoutDamage {
42 pub fn only_layout_modes(&self) -> LayoutDamage {
43 self.intersection(LayoutDamage::Relayout)
44 }
45}
46
47impl From<RestyleDamage> for LayoutDamage {
48 fn from(restyle_damage: RestyleDamage) -> Self {
49 LayoutDamage::from_bits_retain(restyle_damage.bits())
50 }
51}
52
53impl From<LayoutDamage> for RestyleDamage {
54 fn from(layout_damage: LayoutDamage) -> Self {
55 RestyleDamage::from_bits_retain(layout_damage.bits())
56 }
57}