소스 검색

LibWeb: Simplify final line box width computation

The width of a line box is the distance from the left edge of the first
fragment to the right edge of the last fragment. We don't have to loop
over all the fragments to figure this out. :^)
Andreas Kling 4 년 전
부모
커밋
70de5fd056
1개의 변경된 파일3개의 추가작업 그리고 4개의 파일을 삭제
  1. 3 4
      Libraries/LibWeb/Layout/InlineFormattingContext.cpp

+ 3 - 4
Libraries/LibWeb/Layout/InlineFormattingContext.cpp

@@ -181,11 +181,10 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode)
             if (is<Box>(fragment.layout_node()))
                 dimension_box_on_line(downcast<Box>(fragment.layout_node()), layout_mode);
 
-            float final_line_box_width = 0;
-            for (auto& fragment : line_box.fragments())
-                final_line_box_width += fragment.width();
+            float left_edge = line_box.fragments().first().offset().x();
+            float right_edge = line_box.fragments().last().offset().x() + line_box.fragments().last().width();
+            float final_line_box_width = right_edge - left_edge;
             line_box.m_width = final_line_box_width;
-
             max_linebox_width = max(max_linebox_width, final_line_box_width);
         }