Commit 15d6d41f authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[LayoutNG] Rewrite ng_caret_rect.cc on top of NGPaintFragment

This patch rewrites the NG implementation of LocalCaretRectOfPosition()
on top of NGPaintFragment instead of NGPhysicalFragment. Since paint
fragments store parent pointers but physical fragments don't, this patch
utilizes parent pointers to stop keeping track of line boxes for each
inline fragment, which simplifies the implementation.

As a side product, this patch also removes a non-self-contained member
function NGPhysicalLineBoxFragment::HasSoftWrapFromPreviousLine().

Bug: 822575
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_layout_ng;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Idfd2af884a1933daa1d2bac265d51757949cbb14
Reviewed-on: https://chromium-review.googlesource.com/1000952
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550110}
parent bf1c67f2
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#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/geometry/ng_physical_offset_rect.h" #include "third_party/blink/renderer/core/layout/ng/geometry/ng_physical_offset_rect.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/optional.h" #include "third_party/blink/renderer/platform/wtf/optional.h"
...@@ -15,6 +14,7 @@ namespace blink { ...@@ -15,6 +14,7 @@ namespace blink {
// This file provides utility functions for computing caret rect in LayoutNG. // This file provides utility functions for computing caret rect in LayoutNG.
class NGPaintFragment;
class LayoutBlockFlow; class LayoutBlockFlow;
struct LocalCaretRect; struct LocalCaretRect;
...@@ -25,7 +25,7 @@ CORE_EXPORT LocalCaretRect ComputeNGLocalCaretRect(const LayoutBlockFlow&, ...@@ -25,7 +25,7 @@ CORE_EXPORT LocalCaretRect ComputeNGLocalCaretRect(const LayoutBlockFlow&,
const PositionWithAffinity&); const PositionWithAffinity&);
// An NGCaretPosition indicates a caret position relative to an inline // An NGCaretPosition indicates a caret position relative to an inline
// NGPhysicalFragment: // NGPaintFragment:
// - When |fragment| is box, |position_type| is either |kBeforeBox| or // - When |fragment| is box, |position_type| is either |kBeforeBox| or
// |kAfterBox|, indicating either of the two caret positions by the box sides; // |kAfterBox|, indicating either of the two caret positions by the box sides;
// |text_offset| is |nullopt| in this case. // |text_offset| is |nullopt| in this case.
...@@ -40,7 +40,7 @@ struct NGCaretPosition { ...@@ -40,7 +40,7 @@ struct NGCaretPosition {
bool IsNull() const { return !fragment; } bool IsNull() const { return !fragment; }
scoped_refptr<const NGPhysicalFragment> fragment; const NGPaintFragment* fragment = nullptr; // owned by root LayoutNGMixin
NGCaretPositionType position_type; NGCaretPositionType position_type;
Optional<unsigned> text_offset; Optional<unsigned> text_offset;
}; };
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h" #include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.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"
namespace blink { namespace blink {
...@@ -60,11 +61,12 @@ class NGCaretRectTest : public NGLayoutTest { ...@@ -60,11 +61,12 @@ class NGCaretRectTest : public NGLayoutTest {
const NGPhysicalBoxFragment* root_fragment_; const NGPhysicalBoxFragment* root_fragment_;
}; };
#define TEST_CARET(caret, fragment_, type_, offset_) \ #define TEST_CARET(caret, fragment_, type_, offset_) \
{ \ { \
EXPECT_EQ(caret.fragment.get(), fragment_) << caret.fragment->ToString(); \ EXPECT_EQ(&caret.fragment->PhysicalFragment(), fragment_) \
EXPECT_EQ(caret.position_type, NGCaretPositionType::type_); \ << caret.fragment->PhysicalFragment().ToString(); \
EXPECT_EQ(caret.text_offset, offset_) << caret.text_offset.value_or(-1); \ EXPECT_EQ(caret.position_type, NGCaretPositionType::type_); \
EXPECT_EQ(caret.text_offset, offset_) << caret.text_offset.value_or(-1); \
} }
TEST_F(NGCaretRectTest, CaretPositionInOneLineOfText) { TEST_F(NGCaretRectTest, CaretPositionInOneLineOfText) {
......
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