Commit 8a59abfb authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize NGInlineCursor for selection rect of LayoutReplaced

This patch changes implementation of |LayoutReplaced| to utilie |NGInlineCursor|
instead of |NGPaintFragment| for preperation of migrating |NGFragmentItem|.

Bug: 982194
Change-Id: I55de0f4c050fdd0883bd79bd4e695ee2a9e6aae0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1883452
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710690}
parent ada929a2
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/layout/layout_image.h" #include "third_party/blink/renderer/core/layout/layout_image.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h" #include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/layout_video.h" #include "third_party/blink/renderer/core/layout/layout_video.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h" #include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h" #include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/paint_info.h" #include "third_party/blink/renderer/core/paint/paint_info.h"
...@@ -963,27 +964,25 @@ static std::pair<LayoutUnit, LayoutUnit> SelectionTopAndBottom( ...@@ -963,27 +964,25 @@ static std::pair<LayoutUnit, LayoutUnit> SelectionTopAndBottom(
: nullptr; : nullptr;
if (fragmentainer) { if (fragmentainer) {
// Step 1: Find the line box containing |layout_replaced|. // Step 1: Find the line box containing |layout_replaced|.
const NGPaintFragment* inline_fragment = NGInlineCursor line_box;
*NGPaintFragment::InlineFragmentsFor(&layout_replaced).begin(); line_box.MoveTo(layout_replaced);
if (!inline_fragment) if (!line_box)
return fallback; return fallback;
const NGPaintFragment* line_box_container = line_box.MoveToContainingLine();
inline_fragment->ContainerLineBox(); if (!line_box)
if (!line_box_container)
return fallback; return fallback;
// Step 2: Return the logical top and bottom of the line box. // Step 2: Return the logical top and bottom of the line box.
// TODO(layout-dev): Use selection top & bottom instead of line's, or decide // TODO(layout-dev): Use selection top & bottom instead of line's, or decide
// if we still want to distinguish line and selection heights in NG. // if we still want to distinguish line and selection heights in NG.
const ComputedStyle& line_style = line_box_container->Style(); const ComputedStyle& line_style = line_box.CurrentStyle();
const WritingMode writing_mode = line_style.GetWritingMode(); const WritingMode writing_mode = line_style.GetWritingMode();
const TextDirection text_direction = line_style.Direction(); const TextDirection text_direction = line_style.Direction();
const PhysicalOffset line_box_offset = const PhysicalOffset line_box_offset = line_box.CurrentOffset();
line_box_container->InlineOffsetToContainerBox(); const PhysicalSize line_box_size = line_box.CurrentSize();
const PhysicalSize line_box_size = line_box_container->Size();
const LogicalOffset logical_offset = line_box_offset.ConvertToLogical( const LogicalOffset logical_offset = line_box_offset.ConvertToLogical(
writing_mode, text_direction, fragmentainer->Size(), writing_mode, text_direction, fragmentainer->Size(),
line_box_container->Size()); line_box.CurrentSize());
const LogicalSize logical_size = const LogicalSize logical_size =
line_box_size.ConvertToLogical(writing_mode); line_box_size.ConvertToLogical(writing_mode);
return {logical_offset.block_offset, return {logical_offset.block_offset,
...@@ -1039,14 +1038,13 @@ PhysicalRect LayoutReplaced::LocalSelectionVisualRect() const { ...@@ -1039,14 +1038,13 @@ PhysicalRect LayoutReplaced::LocalSelectionVisualRect() const {
return PhysicalRect(); return PhysicalRect();
} }
if (IsInline()) { if (IsInline() && IsInLayoutNGInlineFormattingContext()) {
const auto fragments = NGPaintFragment::InlineFragmentsFor(this); PhysicalRect rect;
if (fragments.IsInLayoutNGInlineFormattingContext()) { NGInlineCursor cursor;
PhysicalRect rect; cursor.MoveTo(*this);
for (const NGPaintFragment* fragment : fragments) for (; cursor; cursor.MoveToNextForSameLayoutObject())
rect.Unite(fragment->ComputeLocalSelectionRectForReplaced()); rect.Unite(ComputeLocalSelectionRectForReplaced(cursor));
return rect; return rect;
}
} }
if (!InlineBoxWrapper()) { if (!InlineBoxWrapper()) {
......
...@@ -134,20 +134,6 @@ LogicalRect ExpandSelectionRectToLineHeight( ...@@ -134,20 +134,6 @@ LogicalRect ExpandSelectionRectToLineHeight(
{rect.size.inline_size, selection_bottom - selection_top}}; {rect.size.inline_size, selection_bottom - selection_top}};
} }
LogicalRect ExpandSelectionRectToLineHeight(
const LogicalRect& rect,
const NGPaintFragment& paint_fragment) {
// Compute the rect of the containing line box relative to |paint_fragment|.
const NGPaintFragment* current_line = paint_fragment.ContainerLineBox();
DCHECK(current_line);
const PhysicalRect line_physical_rect(
current_line->InlineOffsetToContainerBox() -
paint_fragment.InlineOffsetToContainerBox(),
current_line->Size());
return ExpandSelectionRectToLineHeight(
rect, ComputeLogicalRectFor(line_physical_rect, paint_fragment));
}
LogicalRect ExpandSelectionRectToLineHeight(const LogicalRect& rect, LogicalRect ExpandSelectionRectToLineHeight(const LogicalRect& rect,
const NGInlineCursor& cursor) { const NGInlineCursor& cursor) {
NGInlineCursor line(cursor); NGInlineCursor line(cursor);
...@@ -1013,14 +999,17 @@ PhysicalRect ComputeLocalSelectionRectForText( ...@@ -1013,14 +999,17 @@ PhysicalRect ComputeLocalSelectionRectForText(
return physical_rect; return physical_rect;
} }
PhysicalRect NGPaintFragment::ComputeLocalSelectionRectForReplaced() const { // TODO(yosin): We should move |ComputeLocalSelectionRectForReplaced()| to
DCHECK(GetLayoutObject()->IsLayoutReplaced()); // "ng_selection_painter.cc".
const PhysicalRect selection_rect = PhysicalFragment().LocalRect(); PhysicalRect ComputeLocalSelectionRectForReplaced(
LogicalRect logical_rect = ComputeLogicalRectFor(selection_rect, *this); const NGInlineCursor& cursor) {
DCHECK(cursor.CurrentLayoutObject()->IsLayoutReplaced());
const PhysicalRect selection_rect = PhysicalRect({}, cursor.CurrentSize());
LogicalRect logical_rect = ComputeLogicalRectFor(selection_rect, cursor);
const LogicalRect line_height_expanded_rect = const LogicalRect line_height_expanded_rect =
ExpandSelectionRectToLineHeight(logical_rect, *this); ExpandSelectionRectToLineHeight(logical_rect, cursor);
const PhysicalRect physical_rect = const PhysicalRect physical_rect =
ComputePhysicalRectFor(line_height_expanded_rect, *this); ComputePhysicalRectFor(line_height_expanded_rect, cursor);
return physical_rect; return physical_rect;
} }
......
...@@ -181,8 +181,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -181,8 +181,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
IntRect VisualRect() const override; IntRect VisualRect() const override;
IntRect PartialInvalidationVisualRect() const override; IntRect PartialInvalidationVisualRect() const override;
PhysicalRect ComputeLocalSelectionRectForReplaced() const;
// Set ShouldDoFullPaintInvalidation flag in the corresponding LayoutObject. // Set ShouldDoFullPaintInvalidation flag in the corresponding LayoutObject.
void SetShouldDoFullPaintInvalidation(); void SetShouldDoFullPaintInvalidation();
...@@ -420,6 +418,8 @@ PhysicalRect ComputeLocalSelectionRectForText( ...@@ -420,6 +418,8 @@ PhysicalRect ComputeLocalSelectionRectForText(
const NGInlineCursor& cursor, const NGInlineCursor& cursor,
const LayoutSelectionStatus& selection_status); const LayoutSelectionStatus& selection_status);
PhysicalRect ComputeLocalSelectionRectForReplaced(const NGInlineCursor& cursor);
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_NG_NG_PAINT_FRAGMENT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_NG_NG_PAINT_FRAGMENT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment