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 { ...@@ -65,16 +65,20 @@ class AbstractLineBox {
return GetRootInlineBox().LogicalHeight() && return GetRootInlineBox().LogicalHeight() &&
GetRootInlineBox().FirstLeafChild(); GetRootInlineBox().FirstLeafChild();
} }
if (GetLineBoxFragment().IsEmptyLineBox()) if (cursor_.IsEmptyLineBox())
return false; return false;
const PhysicalSize physical_size = GetLineBoxFragment().Size(); const PhysicalSize physical_size = cursor_.CurrentSize();
const LogicalSize logical_size = physical_size.ConvertToLogical( const LogicalSize logical_size =
GetLineBoxFragment().Style().GetWritingMode()); physical_size.ConvertToLogical(cursor_.CurrentStyle().GetWritingMode());
if (!logical_size.block_size) if (!logical_size.block_size)
return false; return false;
// Use |ClosestLeafChildForPoint| to check if there's any leaf child. // Use |ClosestLeafChildForPoint| to check if there's any leaf child.
return GetLineBoxFragment().ClosestLeafChildForPoint(PhysicalOffset(), // TODO(yosin): We should use |NGInlineCursor| version of
false); // |ClosestLeafChildForPoint()|.
const bool only_editable_leaves = false;
return To<NGPhysicalLineBoxFragment>(
cursor_.CurrentPaintFragment()->PhysicalFragment())
.ClosestLeafChildForPoint(PhysicalOffset(), only_editable_leaves);
} }
AbstractLineBox PreviousLine() const { AbstractLineBox PreviousLine() const {
...@@ -84,14 +88,9 @@ class AbstractLineBox { ...@@ -84,14 +88,9 @@ class AbstractLineBox {
return previous_root ? AbstractLineBox(*previous_root) return previous_root ? AbstractLineBox(*previous_root)
: AbstractLineBox(); : AbstractLineBox();
} }
const auto children = ng_box_fragment_->Children(); NGInlineCursor previous_line = cursor_;
for (wtf_size_t i = ng_child_index_; i;) { previous_line.MoveToPreviousLine();
--i; return previous_line ? AbstractLineBox(previous_line) : AbstractLineBox();
if (!children[i]->IsLineBox())
continue;
return AbstractLineBox(*ng_box_fragment_, i);
}
return AbstractLineBox();
} }
AbstractLineBox NextLine() const { AbstractLineBox NextLine() const {
...@@ -100,13 +99,9 @@ class AbstractLineBox { ...@@ -100,13 +99,9 @@ class AbstractLineBox {
const RootInlineBox* next_root = GetRootInlineBox().NextRootBox(); const RootInlineBox* next_root = GetRootInlineBox().NextRootBox();
return next_root ? AbstractLineBox(*next_root) : AbstractLineBox(); return next_root ? AbstractLineBox(*next_root) : AbstractLineBox();
} }
const auto children = ng_box_fragment_->Children(); NGInlineCursor next_line = cursor_;
for (wtf_size_t i = ng_child_index_ + 1; i < children.size(); ++i) { next_line.MoveToNextLine();
if (!children[i]->IsLineBox()) return next_line ? AbstractLineBox(next_line) : AbstractLineBox();
continue;
return AbstractLineBox(*ng_box_fragment_, i);
}
return AbstractLineBox();
} }
PhysicalOffset AbsoluteLineDirectionPointToLocalPointInBlock( PhysicalOffset AbsoluteLineDirectionPointToLocalPointInBlock(
...@@ -137,23 +132,21 @@ class AbstractLineBox { ...@@ -137,23 +132,21 @@ class AbstractLineBox {
return GetRootInlineBox().ClosestLeafChildForPoint( return GetRootInlineBox().ClosestLeafChildForPoint(
GetBlock().FlipForWritingMode(point), only_editable_leaves); GetBlock().FlipForWritingMode(point), only_editable_leaves);
} }
const PhysicalOffset local_physical_point = const PhysicalOffset local_physical_point = point - cursor_.CurrentOffset();
point - ng_box_fragment_->Children()[ng_child_index_].offset; // TODO(yosin): We should use |NGInlineCursor| version of
return GetLineBoxFragment().ClosestLeafChildForPoint(local_physical_point, // |ClosestLeafChildForPoint()|.
only_editable_leaves); return To<NGPhysicalLineBoxFragment>(
cursor_.CurrentPaintFragment()->PhysicalFragment())
.ClosestLeafChildForPoint(local_physical_point, only_editable_leaves);
} }
private: private:
explicit AbstractLineBox(const RootInlineBox& root_inline_box) explicit AbstractLineBox(const RootInlineBox& root_inline_box)
: root_inline_box_(&root_inline_box), type_(Type::kOldLayout) {} : root_inline_box_(&root_inline_box), type_(Type::kOldLayout) {}
AbstractLineBox(const NGPhysicalBoxFragment& box_fragment, explicit AbstractLineBox(const NGInlineCursor& cursor)
wtf_size_t child_index) : cursor_(cursor), type_(Type::kLayoutNG) {
: ng_box_fragment_(&box_fragment), DCHECK(cursor_.IsLineBox());
ng_child_index_(child_index),
type_(Type::kLayoutNG) {
DCHECK_LT(child_index, box_fragment.Children().size());
DCHECK(box_fragment.Children()[child_index]->IsLineBox());
} }
const LayoutBlockFlow& GetBlock() const { const LayoutBlockFlow& GetBlock() const {
...@@ -162,8 +155,7 @@ class AbstractLineBox { ...@@ -162,8 +155,7 @@ class AbstractLineBox {
return *To<LayoutBlockFlow>( return *To<LayoutBlockFlow>(
LineLayoutAPIShim::LayoutObjectFrom(GetRootInlineBox().Block())); LineLayoutAPIShim::LayoutObjectFrom(GetRootInlineBox().Block()));
} }
DCHECK(ng_box_fragment_->GetLayoutObject()); return *cursor_.GetLayoutBlockFlow();
return *To<LayoutBlockFlow>(ng_box_fragment_->GetLayoutObject());
} }
LayoutUnit PhysicalBlockOffset() const { LayoutUnit PhysicalBlockOffset() const {
...@@ -172,9 +164,8 @@ class AbstractLineBox { ...@@ -172,9 +164,8 @@ class AbstractLineBox {
return GetBlock().FlipForWritingMode( return GetBlock().FlipForWritingMode(
GetRootInlineBox().BlockDirectionPointInLine()); GetRootInlineBox().BlockDirectionPointInLine());
} }
const PhysicalOffset physical_offset = const PhysicalOffset physical_offset = cursor_.CurrentOffset();
ng_box_fragment_->Children()[ng_child_index_].offset; return cursor_.CurrentStyle().IsHorizontalWritingMode()
return ng_box_fragment_->Style().IsHorizontalWritingMode()
? physical_offset.top ? physical_offset.top
: physical_offset.left; : physical_offset.left;
} }
...@@ -188,17 +179,16 @@ class AbstractLineBox { ...@@ -188,17 +179,16 @@ class AbstractLineBox {
return *root_inline_box_; return *root_inline_box_;
} }
const NGPhysicalLineBoxFragment& GetLineBoxFragment() const { static bool IsEditable(const NGInlineCursor& cursor) {
DCHECK(IsLayoutNG()); const LayoutObject* const layout_object = cursor.CurrentLayoutObject();
return To<NGPhysicalLineBoxFragment>( return layout_object && layout_object->GetNode() &&
*ng_box_fragment_->Children()[ng_child_index_]); HasEditableStyle(*layout_object->GetNode());
} }
enum class Type { kNull, kOldLayout, kLayoutNG }; enum class Type { kNull, kOldLayout, kLayoutNG };
const RootInlineBox* root_inline_box_ = nullptr; const RootInlineBox* root_inline_box_ = nullptr;
const NGPhysicalBoxFragment* ng_box_fragment_ = nullptr; NGInlineCursor cursor_;
wtf_size_t ng_child_index_ = 0u;
Type type_ = Type::kNull; Type type_ = Type::kNull;
}; };
...@@ -213,19 +203,9 @@ AbstractLineBox AbstractLineBox::CreateFor(const VisiblePosition& position) { ...@@ -213,19 +203,9 @@ AbstractLineBox AbstractLineBox::CreateFor(const VisiblePosition& position) {
if (adjusted.IsNull()) if (adjusted.IsNull())
return AbstractLineBox(); return AbstractLineBox();
if (const NGPaintFragment* line_paint_fragment = const NGInlineCursor& line = NGContainingLineBoxOf(adjusted);
NGContainingLineBoxOf(adjusted)) { if (line)
const NGPhysicalBoxFragment& box_fragment = To<NGPhysicalBoxFragment>( return AbstractLineBox(line);
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 InlineBox* box = const InlineBox* box =
ComputeInlineBoxPositionForInlineAdjustedPosition(adjusted).inline_box; ComputeInlineBoxPositionForInlineAdjustedPosition(adjusted).inline_box;
......
...@@ -6,25 +6,25 @@ ...@@ -6,25 +6,25 @@
#include "third_party/blink/renderer/core/editing/position_with_affinity.h" #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/layout/ng/inline/ng_caret_position.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
namespace blink { namespace blink {
const NGPaintFragment* NGContainingLineBoxOf( NGInlineCursor NGContainingLineBoxOf(const PositionWithAffinity& position) {
const PositionWithAffinity& position) {
const NGCaretPosition caret_position = ComputeNGCaretPosition(position); const NGCaretPosition caret_position = ComputeNGCaretPosition(position);
if (caret_position.IsNull()) if (caret_position.IsNull())
return nullptr; return NGInlineCursor();
return caret_position.PaintFragment()->ContainerLineBox(); NGInlineCursor line = caret_position.cursor;
line.MoveToContainingLine();
return line;
} }
bool InSameNGLineBox(const PositionWithAffinity& position1, bool InSameNGLineBox(const PositionWithAffinity& position1,
const PositionWithAffinity& position2) { const PositionWithAffinity& position2) {
const NGPaintFragment* line_box1 = NGContainingLineBoxOf(position1); const NGInlineCursor& line_box1 = NGContainingLineBoxOf(position1);
if (!line_box1) if (!line_box1)
return false; return false;
const NGPaintFragment* line_box2 = NGContainingLineBoxOf(position2); const NGInlineCursor& line_box2 = NGContainingLineBoxOf(position2);
return line_box1 == line_box2; return line_box1 == line_box2;
} }
......
...@@ -6,15 +6,14 @@ ...@@ -6,15 +6,14 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_INLINE_NG_LINE_UTILS_H_ #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/editing/forward.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
namespace blink { namespace blink {
class NGPaintFragment;
// Returns the NG line box fragment containing the caret position of the given // 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 // position. Returns false if the position is not in Layout NG, or does not
// have any caret position. // 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 // Returns true if the caret positions of the two positions are in the same NG
// line box. Returns false in all other cases. // line box. Returns false in all other cases.
......
...@@ -105,6 +105,7 @@ crbug.com/982194 compositing/video/video-neg-offset-outline.html [ Failure Pass ...@@ -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/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/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/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/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/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 ] 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 ] ...@@ -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-170d.xml [ Failure Pass ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-171.xml [ Failure ] 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-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-175c.xml [ Failure ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-176.xml [ Failure Pass ] crbug.com/982194 css3/selectors3/xml/css3-modsel-176.xml [ Failure Pass ]
crbug.com/982194 css3/selectors3/xml/css3-modsel-177b.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 ...@@ -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/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-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/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/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-timeout.html [ Crash ]
crbug.com/982194 virtual/stable/http/tests/navigation/document-location-click.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