Commit 1f8b56a8 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize NGInlineCursor in AbstractLineBox

This patch changes |AbstractLineBox| to utilize |NGInlineCursor| to reduce usage
of |NGPhysicalLineBoxFragment| for prepration of migrating |NGFragmentItem|.

Note: To reduce patch size, following patch will introduce |NGInlineCursor|
version of |ClosestLeafChildForPoint()|.

Bug: 982194
Change-Id: I539b940509ae608f0068a013670889bfc16dd4ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877499
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709438}
parent 01840059
......@@ -65,16 +65,20 @@ class AbstractLineBox {
return GetRootInlineBox().LogicalHeight() &&
GetRootInlineBox().FirstLeafChild();
}
if (GetLineBoxFragment().IsEmptyLineBox())
if (cursor_.IsEmptyLineBox())
return false;
const PhysicalSize physical_size = GetLineBoxFragment().Size();
const LogicalSize logical_size = physical_size.ConvertToLogical(
GetLineBoxFragment().Style().GetWritingMode());
const PhysicalSize physical_size = cursor_.CurrentSize();
const LogicalSize logical_size =
physical_size.ConvertToLogical(cursor_.CurrentStyle().GetWritingMode());
if (!logical_size.block_size)
return false;
// Use |ClosestLeafChildForPoint| to check if there's any leaf child.
return GetLineBoxFragment().ClosestLeafChildForPoint(PhysicalOffset(),
false);
// TODO(yosin): We should use |NGInlineCursor| version of
// |ClosestLeafChildForPoint()|.
const bool only_editable_leaves = false;
return To<NGPhysicalLineBoxFragment>(
cursor_.CurrentPaintFragment()->PhysicalFragment())
.ClosestLeafChildForPoint(PhysicalOffset(), only_editable_leaves);
}
AbstractLineBox PreviousLine() const {
......@@ -84,14 +88,9 @@ class AbstractLineBox {
return previous_root ? AbstractLineBox(*previous_root)
: AbstractLineBox();
}
const auto children = ng_box_fragment_->Children();
for (wtf_size_t i = ng_child_index_; i;) {
--i;
if (!children[i]->IsLineBox())
continue;
return AbstractLineBox(*ng_box_fragment_, i);
}
return AbstractLineBox();
NGInlineCursor previous_line = cursor_;
previous_line.MoveToPreviousLine();
return previous_line ? AbstractLineBox(previous_line) : AbstractLineBox();
}
AbstractLineBox NextLine() const {
......@@ -100,13 +99,9 @@ class AbstractLineBox {
const RootInlineBox* next_root = GetRootInlineBox().NextRootBox();
return next_root ? AbstractLineBox(*next_root) : AbstractLineBox();
}
const auto children = ng_box_fragment_->Children();
for (wtf_size_t i = ng_child_index_ + 1; i < children.size(); ++i) {
if (!children[i]->IsLineBox())
continue;
return AbstractLineBox(*ng_box_fragment_, i);
}
return AbstractLineBox();
NGInlineCursor next_line = cursor_;
next_line.MoveToNextLine();
return next_line ? AbstractLineBox(next_line) : AbstractLineBox();
}
PhysicalOffset AbsoluteLineDirectionPointToLocalPointInBlock(
......@@ -137,23 +132,21 @@ class AbstractLineBox {
return GetRootInlineBox().ClosestLeafChildForPoint(
GetBlock().FlipForWritingMode(point), only_editable_leaves);
}
const PhysicalOffset local_physical_point =
point - ng_box_fragment_->Children()[ng_child_index_].offset;
return GetLineBoxFragment().ClosestLeafChildForPoint(local_physical_point,
only_editable_leaves);
const PhysicalOffset local_physical_point = point - cursor_.CurrentOffset();
// TODO(yosin): We should use |NGInlineCursor| version of
// |ClosestLeafChildForPoint()|.
return To<NGPhysicalLineBoxFragment>(
cursor_.CurrentPaintFragment()->PhysicalFragment())
.ClosestLeafChildForPoint(local_physical_point, only_editable_leaves);
}
private:
explicit AbstractLineBox(const RootInlineBox& root_inline_box)
: root_inline_box_(&root_inline_box), type_(Type::kOldLayout) {}
AbstractLineBox(const NGPhysicalBoxFragment& box_fragment,
wtf_size_t child_index)
: ng_box_fragment_(&box_fragment),
ng_child_index_(child_index),
type_(Type::kLayoutNG) {
DCHECK_LT(child_index, box_fragment.Children().size());
DCHECK(box_fragment.Children()[child_index]->IsLineBox());
explicit AbstractLineBox(const NGInlineCursor& cursor)
: cursor_(cursor), type_(Type::kLayoutNG) {
DCHECK(cursor_.IsLineBox());
}
const LayoutBlockFlow& GetBlock() const {
......@@ -162,8 +155,7 @@ class AbstractLineBox {
return *To<LayoutBlockFlow>(
LineLayoutAPIShim::LayoutObjectFrom(GetRootInlineBox().Block()));
}
DCHECK(ng_box_fragment_->GetLayoutObject());
return *To<LayoutBlockFlow>(ng_box_fragment_->GetLayoutObject());
return *cursor_.GetLayoutBlockFlow();
}
LayoutUnit PhysicalBlockOffset() const {
......@@ -172,9 +164,8 @@ class AbstractLineBox {
return GetBlock().FlipForWritingMode(
GetRootInlineBox().BlockDirectionPointInLine());
}
const PhysicalOffset physical_offset =
ng_box_fragment_->Children()[ng_child_index_].offset;
return ng_box_fragment_->Style().IsHorizontalWritingMode()
const PhysicalOffset physical_offset = cursor_.CurrentOffset();
return cursor_.CurrentStyle().IsHorizontalWritingMode()
? physical_offset.top
: physical_offset.left;
}
......@@ -188,17 +179,16 @@ class AbstractLineBox {
return *root_inline_box_;
}
const NGPhysicalLineBoxFragment& GetLineBoxFragment() const {
DCHECK(IsLayoutNG());
return To<NGPhysicalLineBoxFragment>(
*ng_box_fragment_->Children()[ng_child_index_]);
static bool IsEditable(const NGInlineCursor& cursor) {
const LayoutObject* const layout_object = cursor.CurrentLayoutObject();
return layout_object && layout_object->GetNode() &&
HasEditableStyle(*layout_object->GetNode());
}
enum class Type { kNull, kOldLayout, kLayoutNG };
const RootInlineBox* root_inline_box_ = nullptr;
const NGPhysicalBoxFragment* ng_box_fragment_ = nullptr;
wtf_size_t ng_child_index_ = 0u;
NGInlineCursor cursor_;
Type type_ = Type::kNull;
};
......@@ -213,19 +203,9 @@ AbstractLineBox AbstractLineBox::CreateFor(const VisiblePosition& position) {
if (adjusted.IsNull())
return AbstractLineBox();
if (const NGPaintFragment* line_paint_fragment =
NGContainingLineBoxOf(adjusted)) {
const NGPhysicalBoxFragment& box_fragment = To<NGPhysicalBoxFragment>(
line_paint_fragment->Parent()->PhysicalFragment());
const NGPhysicalFragment& line_box_fragment =
line_paint_fragment->PhysicalFragment();
for (wtf_size_t i = 0; i < box_fragment.Children().size(); ++i) {
if (box_fragment.Children()[i].get() == &line_box_fragment)
return AbstractLineBox(box_fragment, i);
}
NOTREACHED();
return AbstractLineBox();
}
const NGInlineCursor& line = NGContainingLineBoxOf(adjusted);
if (line)
return AbstractLineBox(line);
const InlineBox* box =
ComputeInlineBoxPositionForInlineAdjustedPosition(adjusted).inline_box;
......
......@@ -6,25 +6,25 @@
#include "third_party/blink/renderer/core/editing/position_with_affinity.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_caret_position.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
namespace blink {
const NGPaintFragment* NGContainingLineBoxOf(
const PositionWithAffinity& position) {
NGInlineCursor NGContainingLineBoxOf(const PositionWithAffinity& position) {
const NGCaretPosition caret_position = ComputeNGCaretPosition(position);
if (caret_position.IsNull())
return nullptr;
return caret_position.PaintFragment()->ContainerLineBox();
return NGInlineCursor();
NGInlineCursor line = caret_position.cursor;
line.MoveToContainingLine();
return line;
}
bool InSameNGLineBox(const PositionWithAffinity& position1,
const PositionWithAffinity& position2) {
const NGPaintFragment* line_box1 = NGContainingLineBoxOf(position1);
const NGInlineCursor& line_box1 = NGContainingLineBoxOf(position1);
if (!line_box1)
return false;
const NGPaintFragment* line_box2 = NGContainingLineBoxOf(position2);
const NGInlineCursor& line_box2 = NGContainingLineBoxOf(position2);
return line_box1 == line_box2;
}
......
......@@ -6,15 +6,14 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_INLINE_NG_LINE_UTILS_H_
#include "third_party/blink/renderer/core/editing/forward.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
namespace blink {
class NGPaintFragment;
// Returns the NG line box fragment containing the caret position of the given
// position. Returns false if the position is not in Layout NG, or does not
// have any caret position.
const NGPaintFragment* NGContainingLineBoxOf(const PositionWithAffinity&);
NGInlineCursor NGContainingLineBoxOf(const PositionWithAffinity&);
// Returns true if the caret positions of the two positions are in the same NG
// line box. Returns false in all other cases.
......
......@@ -105,6 +105,7 @@ crbug.com/982194 compositing/video/video-neg-offset-outline.html [ Failure Pass
crbug.com/749738 crbug.com/420008 http/tests/devtools/editor/text-editor-word-jumps.js [ Pass Timeout Timeout Crash ]
crbug.com/916975 crbug.com/420008 http/tests/devtools/tracing/timeline-misc/timeline-event-causes.js [ Pass Failure Timeout Crash ]
crbug.com/916975 crbug.com/450493 http/tests/devtools/sources/debugger-ui/call-stack-show-more.js [ Pass Failure Timeout Crash ]
crbug.com/982194 http/tests/devtools/console/console-message-from-inline-with-url.js [ Crash Timeout ]
crbug.com/916975 crbug.com/451577 http/tests/devtools/console/console-repeat-count.js [ Pass Failure Timeout Crash ]
crbug.com/762529 crbug.com/679833 http/tests/devtools/network/network-datareceived.js [ Failure Timeout Crash ]
crbug.com/874695 crbug.com/869364 http/tests/devtools/console/console-correct-suggestions.js [ Pass Timeout Timeout Crash ]
......@@ -286,6 +287,7 @@ crbug.com/982194 css3/selectors3/xml/css3-modsel-170c.xml [ Failure ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-170d.xml [ Failure Pass ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-171.xml [ Failure ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-175a.xml [ Failure ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-175b.xml [ Failure ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-175c.xml [ Failure ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-176.xml [ Failure Pass ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-177b.xml [ Failure Pass ]
......@@ -5991,6 +5993,7 @@ crbug.com/982194 virtual/scroll_customization/fast/scrolling/wheel-scrolling-ove
crbug.com/902685 virtual/site-isolated-code-cache/http/tests/devtools/isolated-code-cache/cross-origin-test.js [ Crash Pass Timeout ]
crbug.com/982194 virtual/speech-with-unified-autoplay/external/wpt/speech-api/SpeechSynthesis-speak-ownership.html [ Timeout ]
crbug.com/982194 virtual/speech-with-unified-autoplay/external/wpt/speech-api/SpeechSynthesis-speak-without-activation-fails.tentative.html [ Pass ]
crbug.com/982194 virtual/split-http-cache-not-site-per-process/http/tests/devtools/isolated-code-cache/cross-origin-test.js [ Crash Timeout ]
crbug.com/982194 virtual/stable/http/tests/navigation/anchor-frames-shifting-focus.html [ Crash ]
crbug.com/982194 virtual/stable/http/tests/navigation/document-location-click-timeout.html [ Crash ]
crbug.com/982194 virtual/stable/http/tests/navigation/document-location-click.html [ Crash ]
......
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