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 LAYOUT_AFFECTED_BY_INFLOW_DESCENDANT = 0b0100_0000_0000 << 4;
19 const DESCENDANT_HAS_BOX_DAMAGE = 0b0011_1111_1111 << 4;
23 const BOX_DAMAGE = 0b1111_1111_1111 << 4;
26 }
27}
28
29impl LayoutDamage {
30 pub fn descendant_has_box_damage() -> RestyleDamage {
31 RestyleDamage::from_bits_retain(LayoutDamage::DESCENDANT_HAS_BOX_DAMAGE.bits())
32 }
33
34 pub fn box_damage() -> RestyleDamage {
35 RestyleDamage::from_bits_retain(LayoutDamage::BOX_DAMAGE.bits())
36 }
37
38 pub fn needs_new_box(&self) -> bool {
39 self.contains(Self::DESCENDANT_HAS_BOX_DAMAGE)
40 }
41
42 pub fn recompute_inline_content_sizes() -> RestyleDamage {
43 RestyleDamage::from_bits_retain(LayoutDamage::RECOMPUTE_INLINE_CONTENT_SIZES.bits())
44 }
45
46 pub fn layout_affected_by_inflow_descendant() -> RestyleDamage {
47 RestyleDamage::from_bits_retain(LayoutDamage::LAYOUT_AFFECTED_BY_INFLOW_DESCENDANT.bits())
48 }
49}
50
51impl From<RestyleDamage> for LayoutDamage {
52 fn from(restyle_damage: RestyleDamage) -> Self {
53 LayoutDamage::from_bits_retain(restyle_damage.bits())
54 }
55}
56
57impl From<LayoutDamage> for RestyleDamage {
58 fn from(layout_damage: LayoutDamage) -> Self {
59 RestyleDamage::from_bits_retain(layout_damage.bits())
60 }
61}
62
63impl std::fmt::Debug for LayoutDamage {
64 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 if self.contains(Self::BOX_DAMAGE) {
66 f.write_str("REBUILD_BOX")
67 } else if self.contains(Self::DESCENDANT_HAS_BOX_DAMAGE) {
68 f.write_str("RECOLLECT_BOX_TREE_CHILDREN")
69 } else {
70 f.write_str("EMPTY")
71 }
72 }
73}