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 @@
#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_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/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
......@@ -963,27 +964,25 @@ static std::pair<LayoutUnit, LayoutUnit> SelectionTopAndBottom(
: nullptr;
if (fragmentainer) {
// Step 1: Find the line box containing |layout_replaced|.
const NGPaintFragment* inline_fragment =
*NGPaintFragment::InlineFragmentsFor(&layout_replaced).begin();
if (!inline_fragment)
NGInlineCursor line_box;
line_box.MoveTo(layout_replaced);
if (!line_box)
return fallback;
const NGPaintFragment* line_box_container =
inline_fragment->ContainerLineBox();
if (!line_box_container)
line_box.MoveToContainingLine();
if (!line_box)
return fallback;
// 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
// 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 TextDirection text_direction = line_style.Direction();
const PhysicalOffset line_box_offset =
line_box_container->InlineOffsetToContainerBox();
const PhysicalSize line_box_size = line_box_container->Size();
const PhysicalOffset line_box_offset = line_box.CurrentOffset();
const PhysicalSize line_box_size = line_box.CurrentSize();
const LogicalOffset logical_offset = line_box_offset.ConvertToLogical(
writing_mode, text_direction, fragmentainer->Size(),
line_box_container->Size());
line_box.CurrentSize());
const LogicalSize logical_size =
line_box_size.ConvertToLogical(writing_mode);
return {logical_offset.block_offset,
......@@ -1039,15 +1038,14 @@ PhysicalRect LayoutReplaced::LocalSelectionVisualRect() const {
return PhysicalRect();
}
if (IsInline()) {
const auto fragments = NGPaintFragment::InlineFragmentsFor(this);
if (fragments.IsInLayoutNGInlineFormattingContext()) {
if (IsInline() && IsInLayoutNGInlineFormattingContext()) {
PhysicalRect rect;
for (const NGPaintFragment* fragment : fragments)
rect.Unite(fragment->ComputeLocalSelectionRectForReplaced());
NGInlineCursor cursor;
cursor.MoveTo(*this);
for (; cursor; cursor.MoveToNextForSameLayoutObject())
rect.Unite(ComputeLocalSelectionRectForReplaced(cursor));
return rect;
}
}
if (!InlineBoxWrapper()) {
// We're a block-level replaced element. Just return our own dimensions.
......
......@@ -134,20 +134,6 @@ LogicalRect ExpandSelectionRectToLineHeight(
{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,
const NGInlineCursor& cursor) {
NGInlineCursor line(cursor);
......@@ -1013,14 +999,17 @@ PhysicalRect ComputeLocalSelectionRectForText(
return physical_rect;
}
PhysicalRect NGPaintFragment::ComputeLocalSelectionRectForReplaced() const {
DCHECK(GetLayoutObject()->IsLayoutReplaced());
const PhysicalRect selection_rect = PhysicalFragment().LocalRect();
LogicalRect logical_rect = ComputeLogicalRectFor(selection_rect, *this);
// TODO(yosin): We should move |ComputeLocalSelectionRectForReplaced()| to
// "ng_selection_painter.cc".
PhysicalRect ComputeLocalSelectionRectForReplaced(
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 =
ExpandSelectionRectToLineHeight(logical_rect, *this);
ExpandSelectionRectToLineHeight(logical_rect, cursor);
const PhysicalRect physical_rect =
ComputePhysicalRectFor(line_height_expanded_rect, *this);
ComputePhysicalRectFor(line_height_expanded_rect, cursor);
return physical_rect;
}
......
......@@ -181,8 +181,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
IntRect VisualRect() const override;
IntRect PartialInvalidationVisualRect() const override;
PhysicalRect ComputeLocalSelectionRectForReplaced() const;
// Set ShouldDoFullPaintInvalidation flag in the corresponding LayoutObject.
void SetShouldDoFullPaintInvalidation();
......@@ -420,6 +418,8 @@ PhysicalRect ComputeLocalSelectionRectForText(
const NGInlineCursor& cursor,
const LayoutSelectionStatus& selection_status);
PhysicalRect ComputeLocalSelectionRectForReplaced(const NGInlineCursor& cursor);
} // namespace blink
#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