Commit 0e89c5a8 authored by Koji Ishii's avatar Koji Ishii Committed by Chromium LUCI CQ

Move selection functions to NGInlineCursor

This patch moves selection functions that are not related with
|NGPaintFragment| to |NGInlineCursor|, in preparation of
removing |ng_paint_fragment.cc|.

Bug: 1154531
Change-Id: I6c1849ab443b04ac6c7c608c800b568a69d3b7bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595748
Auto-Submit: Koji Ishii <kojii@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837762}
parent a0c1b90e
......@@ -1034,7 +1034,7 @@ PhysicalRect LayoutReplaced::LocalSelectionVisualRect() const {
NGInlineCursor cursor;
cursor.MoveTo(*this);
for (; cursor; cursor.MoveToNextForSameLayoutObject())
rect.Unite(ComputeLocalSelectionRectForReplaced(cursor));
rect.Unite(cursor.CurrentLocalSelectionRectForReplaced());
return rect;
}
......
......@@ -2313,7 +2313,7 @@ PhysicalRect LayoutText::LocalSelectionVisualRect() const {
frame_selection.ComputeLayoutSelectionStatus(cursor);
if (status.start == status.end)
continue;
PhysicalRect item_rect = ComputeLocalSelectionRectForText(cursor, status);
PhysicalRect item_rect = cursor.CurrentLocalSelectionRectForText(status);
item_rect.offset += cursor.Current().OffsetInContainerFragment();
rect.Unite(item_rect);
}
......
......@@ -22,6 +22,52 @@ bool IsBidiControl(StringView string) {
return string.length() == 1 && Character::IsBidiControl(string[0]);
}
LogicalRect ExpandedSelectionRectForSoftLineBreakIfNeeded(
const LogicalRect& rect,
const NGInlineCursor& cursor,
const LayoutSelectionStatus& selection_status) {
// Expand paint rect if selection covers multiple lines and
// this fragment is at the end of line.
if (selection_status.line_break == SelectSoftLineBreak::kNotSelected)
return rect;
const LayoutBlockFlow* const layout_block_flow = cursor.GetLayoutBlockFlow();
if (layout_block_flow && layout_block_flow->ShouldTruncateOverflowingText())
return rect;
// Copy from InlineTextBoxPainter::PaintSelection.
const LayoutUnit space_width(cursor.Current().Style().GetFont().SpaceWidth());
return {rect.offset,
{rect.size.inline_size + space_width, rect.size.block_size}};
}
// Expands selection height so that the selection rect fills entire line.
LogicalRect ExpandSelectionRectToLineHeight(
const LogicalRect& rect,
const LogicalRect& line_logical_rect) {
// Unite the rect only in the block direction.
const LayoutUnit selection_top =
std::min(rect.offset.block_offset, line_logical_rect.offset.block_offset);
const LayoutUnit selection_bottom =
std::max(rect.BlockEndOffset(), line_logical_rect.BlockEndOffset());
return {{rect.offset.inline_offset, selection_top},
{rect.size.inline_size, selection_bottom - selection_top}};
}
LogicalRect ExpandSelectionRectToLineHeight(const LogicalRect& rect,
const NGInlineCursor& cursor) {
NGInlineCursor line(cursor);
line.MoveToContainingLine();
const PhysicalRect line_physical_rect(
line.Current().OffsetInContainerFragment() -
cursor.Current().OffsetInContainerFragment(),
line.Current().Size());
return ExpandSelectionRectToLineHeight(
rect, cursor.Current().ConvertChildToLogical(line_physical_rect));
}
bool IsLastBRInPage(const LayoutObject& layout_object) {
return layout_object.IsBR() && !layout_object.NextInPreOrder();
}
} // namespace
inline void NGInlineCursor::MoveToItem(const ItemsSpan::iterator& iter) {
......@@ -328,6 +374,43 @@ PhysicalRect NGInlineCursor::CurrentLocalRect(unsigned start_offset,
return PhysicalRect();
}
PhysicalRect NGInlineCursor::CurrentLocalSelectionRectForText(
const LayoutSelectionStatus& selection_status) const {
const PhysicalRect selection_rect =
CurrentLocalRect(selection_status.start, selection_status.end);
LogicalRect logical_rect = Current().ConvertChildToLogical(selection_rect);
// Let LocalRect for line break have a space width to paint line break
// when it is only character in a line or only selected in a line.
if (selection_status.start != selection_status.end &&
Current().IsLineBreak() &&
// This is for old compatible that old doesn't paint last br in a page.
!IsLastBRInPage(*Current().GetLayoutObject())) {
DCHECK(!logical_rect.size.inline_size);
logical_rect.size.inline_size =
LayoutUnit(Current().Style().GetFont().SpaceWidth());
}
const LogicalRect line_break_extended_rect =
Current().IsLineBreak() ? logical_rect
: ExpandedSelectionRectForSoftLineBreakIfNeeded(
logical_rect, *this, selection_status);
const LogicalRect line_height_expanded_rect =
ExpandSelectionRectToLineHeight(line_break_extended_rect, *this);
const PhysicalRect physical_rect =
Current().ConvertChildToPhysical(line_height_expanded_rect);
return physical_rect;
}
PhysicalRect NGInlineCursor::CurrentLocalSelectionRectForReplaced() const {
DCHECK(Current().GetLayoutObject()->IsLayoutReplaced());
const PhysicalRect selection_rect = PhysicalRect({}, Current().Size());
LogicalRect logical_rect = Current().ConvertChildToLogical(selection_rect);
const LogicalRect line_height_expanded_rect =
ExpandSelectionRectToLineHeight(logical_rect, *this);
const PhysicalRect physical_rect =
Current().ConvertChildToPhysical(line_height_expanded_rect);
return physical_rect;
}
PhysicalRect NGInlineCursor::CurrentRectInBlockFlow() const {
PhysicalRect rect = Current().RectInContainerFragment();
// We'll now convert the offset from being relative to the containing fragment
......
......@@ -315,6 +315,9 @@ class CORE_EXPORT NGInlineCursor {
// |CurrentTextEndOffset()|. It is error to call other than text.
PhysicalRect CurrentLocalRect(unsigned start_offset,
unsigned end_offset) const;
PhysicalRect CurrentLocalSelectionRectForText(
const LayoutSelectionStatus& selection_status) const;
PhysicalRect CurrentLocalSelectionRectForReplaced() const;
// Return a rectangle (or just an offset) relatively to containing
// LayoutBlockFlow, as if all the container fragments were stitched together
......
......@@ -43,52 +43,6 @@ struct SameSizeAsNGPaintFragment : public RefCounted<NGPaintFragment>,
ASSERT_SIZE(NGPaintFragment, SameSizeAsNGPaintFragment);
LogicalRect ExpandedSelectionRectForSoftLineBreakIfNeeded(
const LogicalRect& rect,
const NGInlineCursor& cursor,
const LayoutSelectionStatus& selection_status) {
// Expand paint rect if selection covers multiple lines and
// this fragment is at the end of line.
if (selection_status.line_break == SelectSoftLineBreak::kNotSelected)
return rect;
const LayoutBlockFlow* const layout_block_flow = cursor.GetLayoutBlockFlow();
if (layout_block_flow && layout_block_flow->ShouldTruncateOverflowingText())
return rect;
// Copy from InlineTextBoxPainter::PaintSelection.
const LayoutUnit space_width(cursor.Current().Style().GetFont().SpaceWidth());
return {rect.offset,
{rect.size.inline_size + space_width, rect.size.block_size}};
}
// Expands selection height so that the selection rect fills entire line.
LogicalRect ExpandSelectionRectToLineHeight(
const LogicalRect& rect,
const LogicalRect& line_logical_rect) {
// Unite the rect only in the block direction.
const LayoutUnit selection_top =
std::min(rect.offset.block_offset, line_logical_rect.offset.block_offset);
const LayoutUnit selection_bottom =
std::max(rect.BlockEndOffset(), line_logical_rect.BlockEndOffset());
return {{rect.offset.inline_offset, selection_top},
{rect.size.inline_size, selection_bottom - selection_top}};
}
LogicalRect ExpandSelectionRectToLineHeight(const LogicalRect& rect,
const NGInlineCursor& cursor) {
NGInlineCursor line(cursor);
line.MoveToContainingLine();
const PhysicalRect line_physical_rect(
line.Current().OffsetInContainerFragment() -
cursor.Current().OffsetInContainerFragment(),
line.Current().Size());
return ExpandSelectionRectToLineHeight(
rect, cursor.Current().ConvertChildToLogical(line_physical_rect));
}
bool IsLastBRInPage(const LayoutObject& layout_object) {
return layout_object.IsBR() && !layout_object.NextInPreOrder();
}
} // namespace
NGPaintFragment::NGPaintFragment(
......@@ -630,52 +584,6 @@ void NGPaintFragment::SetShouldDoFullPaintInvalidationForFirstLine() const {
}
}
// TODO(yosin): We should move |ComputeLocalSelectionRectForText()| to
// "ng_selection_painter.cc".
PhysicalRect ComputeLocalSelectionRectForText(
const NGInlineCursor& cursor,
const LayoutSelectionStatus& selection_status) {
const PhysicalRect selection_rect =
cursor.CurrentLocalRect(selection_status.start, selection_status.end);
LogicalRect logical_rect =
cursor.Current().ConvertChildToLogical(selection_rect);
// Let LocalRect for line break have a space width to paint line break
// when it is only character in a line or only selected in a line.
if (selection_status.start != selection_status.end &&
cursor.Current().IsLineBreak() &&
// This is for old compatible that old doesn't paint last br in a page.
!IsLastBRInPage(*cursor.Current().GetLayoutObject())) {
DCHECK(!logical_rect.size.inline_size);
logical_rect.size.inline_size =
LayoutUnit(cursor.Current().Style().GetFont().SpaceWidth());
}
const LogicalRect line_break_extended_rect =
cursor.Current().IsLineBreak()
? logical_rect
: ExpandedSelectionRectForSoftLineBreakIfNeeded(logical_rect, cursor,
selection_status);
const LogicalRect line_height_expanded_rect =
ExpandSelectionRectToLineHeight(line_break_extended_rect, cursor);
const PhysicalRect physical_rect =
cursor.Current().ConvertChildToPhysical(line_height_expanded_rect);
return physical_rect;
}
// TODO(yosin): We should move |ComputeLocalSelectionRectForReplaced()| to
// "ng_selection_painter.cc".
PhysicalRect ComputeLocalSelectionRectForReplaced(
const NGInlineCursor& cursor) {
DCHECK(cursor.Current().GetLayoutObject()->IsLayoutReplaced());
const PhysicalRect selection_rect = PhysicalRect({}, cursor.Current().Size());
LogicalRect logical_rect =
cursor.Current().ConvertChildToLogical(selection_rect);
const LogicalRect line_height_expanded_rect =
ExpandSelectionRectToLineHeight(logical_rect, cursor);
const PhysicalRect physical_rect =
cursor.Current().ConvertChildToPhysical(line_height_expanded_rect);
return physical_rect;
}
String NGPaintFragment::DebugName() const {
StringBuilder name;
......
......@@ -18,8 +18,6 @@
namespace blink {
class NGBlockBreakToken;
class NGInlineCursor;
struct LayoutSelectionStatus;
struct NGContainerInkOverflow;
enum class NGOutlineType;
......@@ -343,12 +341,6 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT
extern template class CORE_EXTERN_TEMPLATE_EXPORT
NGPaintFragment::List<NGPaintFragment::TraverseNextSibling>;
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_
......@@ -312,8 +312,8 @@ class SelectionPaintState {
PhysicalRect ComputeSelectionRect(const PhysicalOffset& box_offset) {
if (!selection_rect_) {
selection_rect_ = ComputeLocalSelectionRectForText(containing_block_,
selection_status_);
selection_rect_ =
containing_block_.CurrentLocalSelectionRectForText(selection_status_);
selection_rect_->offset += box_offset;
}
return *selection_rect_;
......
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