Commit 33f10e33 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

[NGFragmentItem] Fix hit test on position:relative inline element

This patch fixes hit test on position:relative inline element by changing
|NGInlineCursor::PositionForPointInInlineBox()| and
|LayoutInline::NodeAtPoint()| with descendants to pass assertions in following
tests:
 - All/LayoutViewHitTestTest.HitTestHorizontal/*
 - All/LayoutViewHitTestTest.HitTestVerticalLR/*
 - All/ParameterizedLayoutInlineTest.MultilineRelativePositionedHitTest/1

This patch also changes |LayoutViewHitTestTest| class to check whether LayoutNG
is enabled or disabled by |RuntimeEnabledFlag| instead of gTest's parameter for
ease of working with |LayoutNGFragmentItem| runtime enabled feature.

Note: Changes of |LayoutInline::NodeAtPoint()| is brought by
http://crrev.com/c/2109575.

Bug: 982194
Change-Id: I5d13542a2f57ca8ddd9dcf61a90f3ebbe4b2e0da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2104812
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751910}
parent e380470d
......@@ -1081,7 +1081,7 @@ bool LayoutInline::NodeAtPoint(HitTestResult& result,
accumulated_offset + item.OffsetInContainerBlock();
if (NGBoxFragmentPainter(cursor, item, *box_fragment)
.NodeAtPoint(result, hit_test_location, child_offset,
hit_test_action))
accumulated_offset, hit_test_action))
return true;
}
return false;
......
......@@ -74,11 +74,11 @@ class LayoutViewHitTestTest : public testing::WithParamInterface<HitTestConfig>,
public RenderingTest {
public:
LayoutViewHitTestTest()
: ScopedLayoutNGForTest(LayoutNG()),
: ScopedLayoutNGForTest(GetParam().layout_ng),
RenderingTest(MakeGarbageCollected<SingleChildLocalFrameClient>()) {}
protected:
bool LayoutNG() { return GetParam().layout_ng; }
bool LayoutNG() { return RuntimeEnabledFeatures::LayoutNGEnabled(); }
bool IsAndroidOrWindowsEditingBehavior() {
// TODO(crbug.com/971414): For now LayoutNG always uses Android/Windows
// behavior for ShouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom().
......
......@@ -736,7 +736,8 @@ PositionWithAffinity NGInlineCursor::PositionForPointInInlineBox(
}
const NGFragmentItem* container = CurrentItem();
DCHECK(container);
DCHECK_EQ(container->Type(), NGFragmentItem::kLine);
DCHECK(container->Type() == NGFragmentItem::kLine ||
container->Type() == NGFragmentItem::kBox);
const ComputedStyle& container_style = container->Style();
const WritingMode writing_mode = container_style.GetWritingMode();
const TextDirection direction = container_style.Direction();
......@@ -802,6 +803,8 @@ PositionWithAffinity NGInlineCursor::PositionForPointInInlineBox(
if (const PositionWithAffinity child_position =
descendants.PositionForPointInChild(point, *closest_child_after))
return child_position;
// TODO(yosin): we should do like "closest_child_before" once we have a
// case.
}
if (closest_child_before) {
......@@ -809,6 +812,11 @@ PositionWithAffinity NGInlineCursor::PositionForPointInInlineBox(
if (const PositionWithAffinity child_position =
descendants.PositionForPointInChild(point, *closest_child_before))
return child_position;
if (closest_child_before->BoxFragment()) {
// LayoutViewHitTest.HitTestHorizontal "Top-right corner (outside) of div"
// reach here.
return descendants.PositionForPointInInlineBox(point);
}
}
return PositionWithAffinity();
......
......@@ -1659,6 +1659,16 @@ bool NGBoxFragmentPainter::NodeAtPoint(HitTestResult& result,
return NodeAtPoint(hit_test, physical_offset);
}
bool NGBoxFragmentPainter::NodeAtPoint(HitTestResult& result,
const HitTestLocation& hit_test_location,
const PhysicalOffset& physical_offset,
const PhysicalOffset& inline_root_offset,
HitTestAction action) {
HitTestContext hit_test(action, hit_test_location, inline_root_offset,
&result);
return NodeAtPoint(hit_test, physical_offset);
}
bool NGBoxFragmentPainter::NodeAtPoint(const HitTestContext& hit_test,
const PhysicalOffset& physical_offset) {
const NGPhysicalBoxFragment& fragment = PhysicalFragment();
......
......@@ -60,6 +60,11 @@ class NGBoxFragmentPainter : public BoxPainterBase {
const HitTestLocation& hit_test_location,
const PhysicalOffset& physical_offset,
HitTestAction);
bool NodeAtPoint(HitTestResult&,
const HitTestLocation& hit_test_location,
const PhysicalOffset& physical_offset,
const PhysicalOffset& inline_root_offset,
HitTestAction);
bool HitTestAllPhases(HitTestResult&,
const HitTestLocation&,
......
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