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 RECOLLECT_BOX_TREE_CHILDREN = 0b0111_1111_1111 << 4;
16 const RECOMPUTE_INLINE_CONTENT_SIZES = 0b1000_0000_0000 << 4;
18 const REBUILD_BOX = 0b1111_1111_1111 << 4;
21 }
22}
23
24impl LayoutDamage {
25 pub fn recollect_box_tree_children() -> RestyleDamage {
26 RestyleDamage::from_bits_retain(LayoutDamage::RECOLLECT_BOX_TREE_CHILDREN.bits())
27 }
28
29 pub fn recompute_inline_content_sizes() -> RestyleDamage {
30 RestyleDamage::from_bits_retain(LayoutDamage::RECOMPUTE_INLINE_CONTENT_SIZES.bits())
31 }
32
33 pub fn rebuild_box_tree() -> RestyleDamage {
34 RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits())
35 }
36
37 pub fn has_box_damage(&self) -> bool {
38 self.intersects(Self::REBUILD_BOX)
39 }
40}
41
42impl From<RestyleDamage> for LayoutDamage {
43 fn from(restyle_damage: RestyleDamage) -> Self {
44 LayoutDamage::from_bits_retain(restyle_damage.bits())
45 }
46}
47
48impl From<LayoutDamage> for RestyleDamage {
49 fn from(layout_damage: LayoutDamage) -> Self {
50 RestyleDamage::from_bits_retain(layout_damage.bits())
51 }
52}
53
54impl std::fmt::Debug for LayoutDamage {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 if self.contains(Self::REBUILD_BOX) {
57 f.write_str("REBUILD_BOX")
58 } else if self.contains(Self::RECOLLECT_BOX_TREE_CHILDREN) {
59 f.write_str("RECOLLECT_BOX_TREE_CHILDREN")
60 } else {
61 f.write_str("EMPTY")
62 }
63 }
64}