layout_api/
layout_damage.rs1use bitflags::bitflags;
6use style::selector_parser::RestyleDamage;
7
8bitflags! {
9 #[derive(Clone, Copy, Default, Eq, PartialEq)]
12 pub struct LayoutDamage: u16 {
13 const RECOMPUTE_INLINE_CONTENT_SIZES = 0b1000_0000_0000 << 4;
15 const DESCENDANT_HAS_BOX_DAMAGE = 0b0111_1111_1111 << 4;
19 const BOX_DAMAGE = 0b1111_1111_1111 << 4;
22 }
23}
24
25impl LayoutDamage {
26 pub fn descendant_has_box_damage() -> RestyleDamage {
27 RestyleDamage::from_bits_retain(LayoutDamage::DESCENDANT_HAS_BOX_DAMAGE.bits())
28 }
29
30 pub fn box_damage() -> RestyleDamage {
31 RestyleDamage::from_bits_retain(LayoutDamage::BOX_DAMAGE.bits())
32 }
33
34 pub fn needs_new_box(&self) -> bool {
35 self.contains(Self::DESCENDANT_HAS_BOX_DAMAGE)
36 }
37
38 pub fn recompute_inline_content_sizes() -> RestyleDamage {
39 RestyleDamage::from_bits_retain(LayoutDamage::RECOMPUTE_INLINE_CONTENT_SIZES.bits())
40 }
41}
42
43impl From<RestyleDamage> for LayoutDamage {
44 fn from(restyle_damage: RestyleDamage) -> Self {
45 LayoutDamage::from_bits_retain(restyle_damage.bits())
46 }
47}
48
49impl From<LayoutDamage> for RestyleDamage {
50 fn from(layout_damage: LayoutDamage) -> Self {
51 RestyleDamage::from_bits_retain(layout_damage.bits())
52 }
53}
54
55impl std::fmt::Debug for LayoutDamage {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 if self.contains(Self::BOX_DAMAGE) {
58 f.write_str("REBUILD_BOX")
59 } else if self.contains(Self::DESCENDANT_HAS_BOX_DAMAGE) {
60 f.write_str("RECOLLECT_BOX_TREE_CHILDREN")
61 } else {
62 f.write_str("EMPTY")
63 }
64 }
65}