Commit 8f68600e authored by Koji Ishii's avatar Koji Ishii Committed by Chromium LUCI CQ

Fix hit-testing for scrolling content

This patch changes |SelectionControllerTest| to use the
unified |HitTestResult::GetPosition()| added in r827165
<crrev.com/c/2535890>. This makes the tests to run the same
code when |LayoutNGFullPositionForPoint| is enabled.

By switching to the unified code, the test for
crbug.com/985779 started to fail, because when inner node is
inline, |LocalPoint()| is in the content coordinate system,
not in the container coordinate system, that
|PositionForPoint| should not add |ScrolledContentOffset|.
Before |LayoutNGFullPositionForPoint| is enabled, this was
done in |LayoutObject| virtual functions.

Bug: 985779, 1150362, 829028
Change-Id: Ie16d228679778e64170720da105ba47bc6c3557f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2567059Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832337}
parent fba17180
...@@ -35,8 +35,7 @@ class SelectionControllerTest : public EditingTestBase { ...@@ -35,8 +35,7 @@ class SelectionControllerTest : public EditingTestBase {
static PositionWithAffinity GetPositionFromHitTestResult( static PositionWithAffinity GetPositionFromHitTestResult(
const HitTestResult& hit_test_result) { const HitTestResult& hit_test_result) {
return hit_test_result.InnerNode()->GetLayoutObject()->PositionForPoint( return hit_test_result.GetPosition();
hit_test_result.LocalPoint());
} }
PositionWithAffinity GetPositionAtLocation(const IntPoint& point) { PositionWithAffinity GetPositionAtLocation(const IntPoint& point) {
......
...@@ -186,8 +186,13 @@ PositionWithAffinity HitTestResult::GetPosition() const { ...@@ -186,8 +186,13 @@ PositionWithAffinity HitTestResult::GetPosition() const {
// relayout? // relayout?
if (box_fragment_ && if (box_fragment_ &&
RuntimeEnabledFeatures::LayoutNGFullPositionForPointEnabled() && RuntimeEnabledFeatures::LayoutNGFullPositionForPointEnabled() &&
!box_fragment_->IsLayoutObjectDestroyedOrMoved()) !box_fragment_->IsLayoutObjectDestroyedOrMoved()) {
return box_fragment_->PostLayout()->PositionForPoint(LocalPoint()); const NGPhysicalBoxFragment* fragment = box_fragment_->PostLayout();
// When the node is an inline object, |fragment| is the container fragment,
// and |LocalPoint()| is relative to the content.
const bool is_content_offset = fragment->GetLayoutObject() != layout_object;
return fragment->PositionForPoint(LocalPoint(), is_content_offset);
}
return layout_object->PositionForPoint(LocalPoint()); return layout_object->PositionForPoint(LocalPoint());
} }
......
...@@ -802,7 +802,8 @@ void NGPhysicalBoxFragment::AddOutlineRectsForInlineBox( ...@@ -802,7 +802,8 @@ void NGPhysicalBoxFragment::AddOutlineRectsForInlineBox(
} }
PositionWithAffinity NGPhysicalBoxFragment::PositionForPoint( PositionWithAffinity NGPhysicalBoxFragment::PositionForPoint(
PhysicalOffset point) const { PhysicalOffset point,
bool is_content_offset) const {
if (layout_object_->IsBox() && !layout_object_->IsLayoutNGObject()) { if (layout_object_->IsBox() && !layout_object_->IsLayoutNGObject()) {
// Layout engine boundary. Enter legacy PositionForPoint(). // Layout engine boundary. Enter legacy PositionForPoint().
return layout_object_->PositionForPoint(point); return layout_object_->PositionForPoint(point);
...@@ -816,7 +817,7 @@ PositionWithAffinity NGPhysicalBoxFragment::PositionForPoint( ...@@ -816,7 +817,7 @@ PositionWithAffinity NGPhysicalBoxFragment::PositionForPoint(
DCHECK(!IsAtomicInline() || DCHECK(!IsAtomicInline() ||
PhysicalRect(PhysicalOffset(), Size()).Contains(point)); PhysicalRect(PhysicalOffset(), Size()).Contains(point));
if (IsScrollContainer()) if (!is_content_offset && IsScrollContainer())
point += PhysicalOffset(PixelSnappedScrolledContentOffset()); point += PhysicalOffset(PixelSnappedScrolledContentOffset());
if (const NGFragmentItems* items = Items()) { if (const NGFragmentItems* items = Items()) {
......
...@@ -246,7 +246,10 @@ class CORE_EXPORT NGPhysicalBoxFragment final ...@@ -246,7 +246,10 @@ class CORE_EXPORT NGPhysicalBoxFragment final
NGOutlineType include_block_overflows, NGOutlineType include_block_overflows,
Vector<PhysicalRect>* outline_rects) const; Vector<PhysicalRect>* outline_rects) const;
PositionWithAffinity PositionForPoint(PhysicalOffset) const; // When |is_content_offset|, the offset is relative to the content, not to the
// scroll container.
PositionWithAffinity PositionForPoint(PhysicalOffset,
bool is_content_offset = false) const;
UBiDiLevel BidiLevel() const; UBiDiLevel BidiLevel() const;
......
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