From 601517e3aa83ff8f1c100dbaf91277cde20b7570 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 11 Apr 2025 09:35:21 -0700 Subject: [PATCH] Cleanup after #36461 (#36472) This avoids some minor code duplication. Testing: not needed (no behavior change) Signed-off-by: Oriol Brufau --- components/layout_2020/display_list/mod.rs | 8 +++----- components/layout_2020/dom_traversal.rs | 12 ++++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/components/layout_2020/display_list/mod.rs b/components/layout_2020/display_list/mod.rs index a872ac9ef17..fa313b306f4 100644 --- a/components/layout_2020/display_list/mod.rs +++ b/components/layout_2020/display_list/mod.rs @@ -1233,11 +1233,9 @@ fn glyphs_advance_by_index( let mut point = baseline_origin; let mut index = index; for run in glyph_runs { - let total_advance = run.advance_for_byte_range( - &ServoRange::new(fonts::ByteIndex(0), index.min(run.len())), - justification_adjustment, - ); - index = index - index.min(run.len()); + let range = ServoRange::new(fonts::ByteIndex(0), index.min(run.len())); + index = index - range.length(); + let total_advance = run.advance_for_byte_range(&range, justification_adjustment); point.x += total_advance; } point diff --git a/components/layout_2020/dom_traversal.rs b/components/layout_2020/dom_traversal.rs index 966cf83443a..42101e3edbc 100644 --- a/components/layout_2020/dom_traversal.rs +++ b/components/layout_2020/dom_traversal.rs @@ -211,12 +211,8 @@ fn traverse_children_of<'dom, Node>( if is_text_input_element || is_textarea_element { let info = NodeAndStyleInfo::new(parent_element, parent_element.style(context)); - - if parent_element - .to_threadsafe() - .node_text_content() - .is_empty() - { + let node_text_content = parent_element.to_threadsafe().node_text_content(); + if node_text_content.is_empty() { // The addition of zero-width space here forces the text input to have an inline formatting // context that might otherwise be trimmed if there's no text. This is important to ensure // that the input element is at least as tall as the line gap of the caret: @@ -225,9 +221,9 @@ fn traverse_children_of<'dom, Node>( // This is also used to ensure that the caret will still be rendered when the input is empty. // TODO: Is there a less hacky way to do this? handler.handle_text(&info, "\u{200B}".into()); + } else { + handler.handle_text(&info, node_text_content); } - - handler.handle_text(&info, parent_element.to_threadsafe().node_text_content()); } if !is_text_input_element && !is_textarea_element {