layout: Correctly marking box damage when text-related style changed (#38059)

This change aims to supplement the missing incremental box tree
construction when text-related styles change. Since certain text style
adjustments can alter visible text content and typography. Therefore,
the parent nodes of such text are marked as needing to re-collect their
box tree children to ensure the correct display of text.

Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This commit is contained in:
JoeDow 2025-07-26 19:50:13 +08:00 committed by GitHub
parent d678901122
commit 9ef4d0c9d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 92 additions and 0 deletions

View file

@ -658,8 +658,33 @@ impl<'dom> style::dom::TElement for ServoLayoutElement<'dom> {
false
};
let text_shaping_needs_recollect = || {
if old.clone_direction() != new.clone_direction() ||
old.clone_unicode_bidi() != new.clone_unicode_bidi()
{
return true;
}
let old_text = old.get_inherited_text().clone();
let new_text = new.get_inherited_text().clone();
if old_text.white_space_collapse != new_text.white_space_collapse ||
old_text.text_transform != new_text.text_transform ||
old_text.word_break != new_text.word_break ||
old_text.overflow_wrap != new_text.overflow_wrap ||
old_text.letter_spacing != new_text.letter_spacing ||
old_text.word_spacing != new_text.word_spacing ||
old_text.text_rendering != new_text.text_rendering
{
return true;
}
false
};
if box_tree_needs_rebuild() {
RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits())
} else if text_shaping_needs_recollect() {
RestyleDamage::from_bits_retain(LayoutDamage::RECOLLECT_BOX_TREE_CHILDREN.bits())
} else {
// This element needs to be laid out again, but does not have any damage to
// its box. In the future, we will distinguish between types of damage to the