use bitflags::bitflags;
use style::selector_parser::RestyleDamage;
bitflags! {
#[derive(Clone, Copy, Default, Eq, PartialEq)]
pub struct LayoutDamage: u16 {
const RECOMPUTE_INLINE_CONTENT_SIZES = 0b1000_0000_0000 << 4;
const DESCENDANT_HAS_BOX_DAMAGE = 0b0111_1111_1111 << 4;
const BOX_DAMAGE = 0b1111_1111_1111 << 4;
}
}
impl LayoutDamage {
pub fn descendant_has_box_damage() -> RestyleDamage {
RestyleDamage::from_bits_retain(LayoutDamage::DESCENDANT_HAS_BOX_DAMAGE.bits())
}
pub fn box_damage() -> RestyleDamage {
RestyleDamage::from_bits_retain(LayoutDamage::BOX_DAMAGE.bits())
}
pub fn needs_new_box(&self) -> bool {
self.contains(Self::DESCENDANT_HAS_BOX_DAMAGE)
}
pub fn recompute_inline_content_sizes() -> RestyleDamage {
RestyleDamage::from_bits_retain(LayoutDamage::RECOMPUTE_INLINE_CONTENT_SIZES.bits())
}
}
impl From<RestyleDamage> for LayoutDamage {
fn from(restyle_damage: RestyleDamage) -> Self {
LayoutDamage::from_bits_retain(restyle_damage.bits())
}
}
impl From<LayoutDamage> for RestyleDamage {
fn from(layout_damage: LayoutDamage) -> Self {
RestyleDamage::from_bits_retain(layout_damage.bits())
}
}
impl std::fmt::Debug for LayoutDamage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.contains(Self::BOX_DAMAGE) {
f.write_str("REBUILD_BOX")
} else if self.contains(Self::DESCENDANT_HAS_BOX_DAMAGE) {
f.write_str("RECOLLECT_BOX_TREE_CHILDREN")
} else {
f.write_str("EMPTY")
}
}
}