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