Commit ff3ee46b authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize NGInlineCursor ComputeNGLocal{Caret,Selection}Rect()

This patch chagnes |ComputeNGLocal{Caret,Selection}Rect()| to utilize
|NGInlineCursor| instead of |NGPaintFragment| for prepration of migrating
|NGFragmentItem|.

Bug: 982194
Change-Id: I040c946dd405237e145af4702669304eecfe34ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877505
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709828}
parent 5751c53a
......@@ -9,37 +9,36 @@
#include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_caret_position.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
namespace blink {
namespace {
PhysicalRect ComputeLocalCaretRectByBoxSide(const NGPaintFragment& fragment,
PhysicalRect ComputeLocalCaretRectByBoxSide(const NGInlineCursor& cursor,
NGCaretPositionType position_type) {
const bool is_horizontal = fragment.Style().IsHorizontalWritingMode();
DCHECK(fragment.ContainerLineBox());
const NGPaintFragment& line_box = *fragment.ContainerLineBox();
const bool is_horizontal = cursor.CurrentStyle().IsHorizontalWritingMode();
NGInlineCursor line_box(cursor);
line_box.MoveToContainingLine();
DCHECK(line_box);
const PhysicalOffset offset_to_line_box =
fragment.InlineOffsetToContainerBox() -
line_box.InlineOffsetToContainerBox();
LayoutUnit caret_height =
is_horizontal ? line_box.Size().height : line_box.Size().width;
cursor.CurrentOffset() - line_box.CurrentOffset();
LayoutUnit caret_height = is_horizontal ? line_box.CurrentSize().height
: line_box.CurrentSize().width;
LayoutUnit caret_top =
is_horizontal ? -offset_to_line_box.top : -offset_to_line_box.left;
const LocalFrameView* frame_view =
fragment.GetLayoutObject()->GetDocument().View();
cursor.CurrentLayoutObject()->GetDocument().View();
LayoutUnit caret_width = frame_view->CaretWidth();
const bool is_ltr = IsLtr(fragment.PhysicalFragment().ResolvedDirection());
const bool is_ltr = IsLtr(cursor.CurrentResolvedDirection());
LayoutUnit caret_left;
if (is_ltr != (position_type == NGCaretPositionType::kBeforeBox)) {
if (is_horizontal)
caret_left = fragment.Size().width - caret_width;
caret_left = cursor.CurrentSize().width - caret_width;
else
caret_left = fragment.Size().height - caret_width;
caret_left = cursor.CurrentSize().height - caret_width;
}
if (!is_horizontal) {
......@@ -52,26 +51,24 @@ PhysicalRect ComputeLocalCaretRectByBoxSide(const NGPaintFragment& fragment,
return PhysicalRect(caret_location, caret_size);
}
PhysicalRect ComputeLocalCaretRectAtTextOffset(
const NGPaintFragment& paint_fragment,
unsigned offset) {
const auto& fragment =
To<NGPhysicalTextFragment>(paint_fragment.PhysicalFragment());
DCHECK_GE(offset, fragment.StartOffset());
DCHECK_LE(offset, fragment.EndOffset());
PhysicalRect ComputeLocalCaretRectAtTextOffset(const NGInlineCursor& cursor,
unsigned offset) {
DCHECK(cursor.IsText());
DCHECK_GE(offset, cursor.CurrentTextStartOffset());
DCHECK_LE(offset, cursor.CurrentTextEndOffset());
const LocalFrameView* frame_view =
fragment.GetLayoutObject()->GetDocument().View();
cursor.CurrentLayoutObject()->GetDocument().View();
LayoutUnit caret_width = frame_view->CaretWidth();
const bool is_horizontal = fragment.Style().IsHorizontalWritingMode();
const bool is_horizontal = cursor.CurrentStyle().IsHorizontalWritingMode();
LayoutUnit caret_height =
is_horizontal ? fragment.Size().height : fragment.Size().width;
is_horizontal ? cursor.CurrentSize().height : cursor.CurrentSize().width;
LayoutUnit caret_top;
LayoutUnit caret_left = fragment.InlinePositionForOffset(offset);
if (!fragment.IsLineBreak())
LayoutUnit caret_left = cursor.InlinePositionForOffset(offset);
if (!cursor.IsLineBreak())
caret_left -= caret_width / 2;
if (!is_horizontal) {
......@@ -80,15 +77,16 @@ PhysicalRect ComputeLocalCaretRectAtTextOffset(
}
// Adjust the location to be relative to the inline formatting context.
PhysicalOffset caret_location = PhysicalOffset(caret_left, caret_top) +
paint_fragment.InlineOffsetToContainerBox();
PhysicalSize caret_size(caret_width, caret_height);
PhysicalOffset caret_location =
PhysicalOffset(caret_left, caret_top) + cursor.CurrentOffset();
const PhysicalSize caret_size(caret_width, caret_height);
const NGPaintFragment& context_fragment =
*NGPaintFragment::GetForInlineContainer(fragment.GetLayoutObject());
const NGPaintFragment* line_box = paint_fragment.ContainerLineBox();
const PhysicalOffset line_box_offset = line_box->InlineOffsetToContainerBox();
const PhysicalRect line_box_rect(line_box_offset, line_box->Size());
const NGPhysicalBoxFragment& fragmentainer =
*cursor.CurrentLayoutObject()->ContainingBlockFlowFragment();
NGInlineCursor line_box(cursor);
line_box.MoveToContainingLine();
const PhysicalOffset line_box_offset = line_box.CurrentOffset();
const PhysicalRect line_box_rect(line_box_offset, line_box.CurrentSize());
// For horizontal text, adjust the location in the x direction to ensure that
// it completely falls in the union of line box and containing block, and
......@@ -97,7 +95,7 @@ PhysicalRect ComputeLocalCaretRectAtTextOffset(
const LayoutUnit min_x = std::min(LayoutUnit(), line_box_offset.left);
caret_location.left = std::max(caret_location.left, min_x);
const LayoutUnit max_x =
std::max(context_fragment.Size().width, line_box_rect.Right());
std::max(fragmentainer.Size().width, line_box_rect.Right());
caret_location.left = std::min(caret_location.left, max_x - caret_width);
caret_location.left = LayoutUnit(caret_location.left.Round());
return PhysicalRect(caret_location, caret_size);
......@@ -107,7 +105,7 @@ PhysicalRect ComputeLocalCaretRectAtTextOffset(
const LayoutUnit min_y = std::min(LayoutUnit(), line_box_offset.top);
caret_location.top = std::max(caret_location.top, min_y);
const LayoutUnit max_y =
std::max(context_fragment.Size().height, line_box_rect.Bottom());
std::max(fragmentainer.Size().height, line_box_rect.Bottom());
caret_location.top = std::min(caret_location.top, max_y - caret_height);
caret_location.top = LayoutUnit(caret_location.top.Round());
return PhysicalRect(caret_location, caret_size);
......@@ -117,21 +115,21 @@ LocalCaretRect ComputeLocalCaretRect(const NGCaretPosition& caret_position) {
if (caret_position.IsNull())
return LocalCaretRect();
const NGPaintFragment& fragment = *caret_position.PaintFragment();
const LayoutObject* layout_object = fragment.GetLayoutObject();
const LayoutObject* layout_object =
caret_position.cursor.CurrentLayoutObject();
switch (caret_position.position_type) {
case NGCaretPositionType::kBeforeBox:
case NGCaretPositionType::kAfterBox: {
DCHECK(fragment.PhysicalFragment().IsBox());
DCHECK(!caret_position.cursor.IsText());
const PhysicalRect fragment_local_rect = ComputeLocalCaretRectByBoxSide(
fragment, caret_position.position_type);
caret_position.cursor, caret_position.position_type);
return {layout_object, fragment_local_rect};
}
case NGCaretPositionType::kAtTextOffset: {
DCHECK(fragment.PhysicalFragment().IsText());
DCHECK(caret_position.cursor.IsText());
DCHECK(caret_position.text_offset.has_value());
const PhysicalRect caret_rect = ComputeLocalCaretRectAtTextOffset(
fragment, *caret_position.text_offset);
caret_position.cursor, *caret_position.text_offset);
return {layout_object, caret_rect};
}
}
......@@ -146,19 +144,19 @@ LocalCaretRect ComputeLocalSelectionRect(
if (!caret_rect.layout_object)
return caret_rect;
const NGPaintFragment& fragment = *caret_position.PaintFragment();
const NGPaintFragment* line_box = fragment.ContainerLineBox();
// TODO(xiaochengh): We'll hit this DCHECK for caret in empty block if we
NGInlineCursor line_box(caret_position.cursor);
line_box.MoveToContainingLine();
// TODO(yosin): We'll hit this DCHECK for caret in empty block if we
// enable LayoutNG in contenteditable.
DCHECK(line_box);
PhysicalRect rect = caret_rect.rect;
if (fragment.Style().IsHorizontalWritingMode()) {
rect.SetY(line_box->InlineOffsetToContainerBox().top);
rect.SetHeight(line_box->Size().height);
if (caret_position.cursor.CurrentStyle().IsHorizontalWritingMode()) {
rect.SetY(line_box.CurrentOffset().top);
rect.SetHeight(line_box.CurrentSize().height);
} else {
rect.SetX(line_box->InlineOffsetToContainerBox().left);
rect.SetHeight(line_box->Size().width);
rect.SetX(line_box.CurrentOffset().left);
rect.SetHeight(line_box.CurrentSize().width);
}
return {caret_rect.layout_object, rect};
}
......
......@@ -428,6 +428,21 @@ PhysicalRect NGInlineCursor::CurrentLocalRect(unsigned start_offset,
return PhysicalRect();
}
LayoutUnit NGInlineCursor::InlinePositionForOffset(unsigned offset) const {
DCHECK(IsText());
if (current_paint_fragment_) {
return To<NGPhysicalTextFragment>(
current_paint_fragment_->PhysicalFragment())
.InlinePositionForOffset(offset);
}
if (current_item_) {
return current_item_->InlinePositionForOffset(
current_item_->Text(*fragment_items_), offset);
}
NOTREACHED();
return LayoutUnit();
}
void NGInlineCursor::MakeNull() {
if (root_paint_fragment_) {
current_paint_fragment_ = nullptr;
......
......@@ -16,6 +16,7 @@ class ComputedStyle;
class LayoutBlockFlow;
class LayoutInline;
class LayoutObject;
class LayoutUnit;
class NGFragmentItem;
class NGFragmentItems;
class NGInlineBreakToken;
......@@ -155,6 +156,10 @@ class CORE_EXPORT NGInlineCursor {
PhysicalRect CurrentLocalRect(unsigned start_offset,
unsigned end_offset) const;
// Relative to fragment of the current position. It is error to call other
// than text.
LayoutUnit InlinePositionForOffset(unsigned offset) const;
//
// Functions to move the current position.
//
......
......@@ -302,7 +302,7 @@ crbug.com/982194 editing/selection/continuations-with-move-caret-to-boundary.htm
crbug.com/982194 editing/selection/deleteFromDocument-scoped-dispatch-event-crash.html [ Crash ]
crbug.com/982194 editing/selection/deleteFromDocument.html [ Crash ]
crbug.com/982194 editing/selection/deletefromdocument-shadow-leak.html [ Crash ]
crbug.com/982194 editing/selection/display-table-text.html [ Crash ]
crbug.com/982194 editing/selection/display-table-text.html [ Crash Failure ]
crbug.com/982194 editing/selection/dont-select-text-overflow-ellipsis-when-wrapping-ltr-mixed.html [ Crash ]
crbug.com/982194 editing/selection/dont-select-text-overflow-ellipsis-when-wrapping-rtl-mixed.html [ Crash ]
crbug.com/982194 editing/selection/dont-select-text-overflow-ellipsis-when-wrapping-rtl.html [ Crash ]
......@@ -4863,8 +4863,8 @@ crbug.com/982194 external/wpt/css/CSS2/normal-flow/inline-block-valign-002.xht [
crbug.com/982194 external/wpt/css/CSS2/normal-flow/inline-table-002a.xht [ Crash ]
crbug.com/982194 external/wpt/css/CSS2/normal-flow/inline-table-002b.xht [ Crash ]
crbug.com/982194 external/wpt/css/CSS2/normal-flow/inline-table-valign-001.xht [ Crash ]
crbug.com/982194 external/wpt/css/css-flexbox/flexbox_visibility-collapse-line-wrapping.html [ Crash ]
crbug.com/982194 external/wpt/css/css-flexbox/flexbox_visibility-collapse.html [ Crash ]
crbug.com/982194 external/wpt/css/css-flexbox/flexbox_visibility-collapse-line-wrapping.html [ Crash Failure ]
crbug.com/982194 external/wpt/css/css-flexbox/flexbox_visibility-collapse.html [ Crash Failure ]
crbug.com/982194 external/wpt/css/css-layout-api/child-constraints/available-block-size-htb-vrl.https.html [ Crash ]
crbug.com/982194 external/wpt/css/css-layout-api/child-constraints/available-block-size-invalid.https.html [ Crash ]
crbug.com/982194 external/wpt/css/css-layout-api/child-constraints/available-block-size-vrl-htb.https.html [ Crash ]
......@@ -4874,11 +4874,11 @@ crbug.com/982194 external/wpt/css/css-layout-api/child-constraints/available-inl
crbug.com/982194 external/wpt/css/css-layout-api/layout-child/before-after.https.html [ Crash ]
crbug.com/982194 external/wpt/css/css-pseudo/first-letter-property-whitelist.html [ Crash ]
crbug.com/982194 external/wpt/css/css-shapes/shape-outside/supported-shapes/ellipse/shape-outside-ellipse-031.html [ Failure Pass ]
crbug.com/982194 external/wpt/css/css-tables/visibility-collapse-rowspan-005.html [ Crash ]
crbug.com/982194 external/wpt/css/css-tables/visibility-collapse-rowspan-005.html [ Crash Failure ]
crbug.com/982194 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-align-self-vert-001.xhtml [ Crash ]
crbug.com/982194 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-baseline-multi-line-vert-001.html [ Crash ]
crbug.com/982194 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-baseline-multi-line-vert-002.html [ Crash ]
crbug.com/982194 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-collapsed-item-baseline-001.html [ Crash ]
crbug.com/982194 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-collapsed-item-baseline-001.html [ Crash Failure ]
crbug.com/982194 external/wpt/dom/nodes/Element-insertAdjacentText.html [ Crash ]
crbug.com/982194 external/wpt/fetch/corb/script-resource-with-nonsniffable-types.tentative.sub.html [ Pass ]
crbug.com/982194 external/wpt/forced-colors-mode/forced-colors-mode-19.html [ Pass ]
......@@ -4931,7 +4931,7 @@ crbug.com/982194 svg/custom/visibility-enable-on-svg-element-contained-viewport-
crbug.com/982194 svg/custom/visibility-enable-on-svg-element.html [ Failure ]
crbug.com/982194 tables/mozilla/bugs/bug103533.html [ Crash ]
crbug.com/982194 tables/mozilla_expected_failures/other/test4.html [ Crash ]
crbug.com/982194 virtual/audio-service/media/video-canvas-draw.html [ Pass ]
crbug.com/982194 virtual/audio-service/media/video-canvas-draw.html [ Failure Pass ]
crbug.com/982194 virtual/composite-after-paint/paint/background/scrolling-background-with-negative-z-child.html [ Pass ]
crbug.com/982194 virtual/controls-refresh-high-contrast/fast/forms/controls-new-ui/color-scheme-validation/button/button-appearance-basic.html [ Failure ]
crbug.com/982194 virtual/controls-refresh-high-contrast/fast/forms/controls-new-ui/color-scheme-validation/color/color-suggestion-picker-appearance-with-scrollbar.html [ Failure ]
......@@ -5270,7 +5270,7 @@ crbug.com/982194 virtual/layout_ng_block_frag/fast/multicol/vertical-rl/float-bi
crbug.com/982194 virtual/layout_ng_block_frag/fast/multicol/vertical-rl/float-truncation.html [ Failure ]
crbug.com/982194 virtual/layout_ng_block_frag/fast/multicol/vertical-rl/unsplittable-inline-block.html [ Pass ]
crbug.com/591099 virtual/layout_ng_block_frag/fast/multicol/widows.html [ Crash ]
crbug.com/982194 virtual/layout_ng_block_frag/fragmentation/auto-scrollbar-shrink-to-fit.html [ Crash ]
crbug.com/982194 virtual/layout_ng_block_frag/fragmentation/auto-scrollbar-shrink-to-fit.html [ Crash Failure ]
crbug.com/591099 virtual/layout_ng_block_frag/fragmentation/change-fragmentainer-height-inline-float.html [ Crash ]
crbug.com/591099 virtual/layout_ng_block_frag/fragmentation/change-fragmentainer-height-line-float.html [ Crash ]
crbug.com/591099 virtual/layout_ng_block_frag/fragmentation/remove-unbreakable-block-in-line-float.html [ Crash ]
......@@ -5311,7 +5311,7 @@ crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozi
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/contain/contain-paint-clip-006.html [ Failure ]
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/contain/contain-paint-ignored-cases-ib-split-001.html [ Crash ]
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/contain/contain-size-fieldset-001.html [ Crash ]
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/contain/contain-size-fieldset-002.html [ Crash ]
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/contain/contain-size-fieldset-002.html [ Crash Failure ]
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/contain/contain-size-flex-001.html [ Pass ]
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/contain/contain-size-inline-flex-001.html [ Pass ]
crbug.com/982194 virtual/layout_ng_fieldset/external/wpt/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-block-formatting-context.html [ Pass ]
......@@ -5445,8 +5445,8 @@ crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox_margin-left-ex.html [ Failure ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox_rtl-flow-reverse.html [ Failure ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox_rtl-flow.html [ Failure ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox_visibility-collapse-line-wrapping.html [ Crash ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox_visibility-collapse.html [ Crash ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox_visibility-collapse-line-wrapping.html [ Crash Failure ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/flexbox_visibility-collapse.html [ Crash Failure ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/hittest-overlapping-margin.html [ Pass ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/percentage-heights-002.html [ Failure ]
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/percentage-heights-004.html [ Failure ]
......@@ -5459,7 +5459,7 @@ crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/ttwf-re
crbug.com/982194 virtual/layout_ng_flex_box/external/wpt/css/css-flexbox/ttwf-reftest-flex-wrap.html [ Failure ]
crbug.com/982194 virtual/lazyload-image/http/tests/lazyload/style-dimension.html [ Pass ]
crbug.com/982194 virtual/mouseevent_fractional/fast/events/anchor-empty-focus.html [ Crash ]
crbug.com/982194 virtual/mouseevent_fractional/fast/events/anchor-image-scrolled-x-y.html [ Timeout ]
crbug.com/982194 virtual/mouseevent_fractional/fast/events/anchor-image-scrolled-x-y.html [ Crash Timeout ]
crbug.com/982194 virtual/mouseevent_fractional/fast/events/attribute-listener-deletion-crash.html [ Crash ]
crbug.com/982194 virtual/mouseevent_fractional/fast/events/autoscroll-disabled-in-fix.html [ Crash ]
crbug.com/982194 virtual/mouseevent_fractional/fast/events/autoscroll-iframe-no-scrolling.html [ Crash ]
......@@ -5942,7 +5942,7 @@ crbug.com/982194 webaudio/AudioContext/autoplay-state-change.html [ Crash ]
crbug.com/982194 wpt_internal/display-lock/rendersubtree/accessibility-activatable.html [ Crash ]
crbug.com/982194 wpt_internal/display-lock/rendersubtree/activation/focus-shadow.html [ Crash ]
crbug.com/982194 wpt_internal/display-lock/rendersubtree/activation/selection.html [ Crash ]
crbug.com/982194 wpt_internal/display-lock/rendersubtree/selection-shadow.html [ Crash ]
crbug.com/982194 wpt_internal/display-lock/rendersubtree/selection-shadow.html [ Crash Failure ]
crbug.com/982194 wpt_internal/display-lock/rendersubtree/selection.html [ Crash ]
crbug.com/982194 wpt_internal/std-switch/tentative/click.html [ Failure ]
crbug.com/982194 wpt_internal/virtual-scroller/move-element.html [ Failure ]
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