Commit ef8a2f7c authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Match LayoutNG's hit-test early return to newer logic

r813630 crrev.com/c/2448269 added the early return for hit-
testing in NG.

It turned out that the logic in |LayoutNGBlockFlowMixIn| was
copied from |LayoutBox| in 2017 (r508056 crrev.com/c/710498)
but the logic in |LayoutBox| has evolved since then.

The new logic was then improved further and extracted to
|LayoutBox::MayIntersect| in r814225 crrev.com/c/2448709. This
patch changes LayoutNG to use the code instead.

Note, we may need to add more early return checks to
|NGBoxFragmentPainter|, e.g., |HitTestBlockChildren| and/or
|HitTestChildBoxFragment|, but the early return itself has
some costs. I will investigate the hit-testing in
FragmentTraversal codepath and how much adding early return
can improve in future patches.

Bug: 1134574
Change-Id: Ibe95bfd5fdaafe1d3e6cd964f479eda98d48306a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2452011Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814604}
parent 87a869af
......@@ -424,6 +424,17 @@ PhysicalRect NGPhysicalBoxFragment::OverflowClipRect(
return box->OverflowClipRect(location, overlay_scrollbar_clip_behavior);
}
bool NGPhysicalBoxFragment::MayIntersect(
const HitTestResult& result,
const HitTestLocation& hit_test_location,
const PhysicalOffset& accumulated_offset) const {
if (const LayoutBox* box = ToLayoutBoxOrNull(GetLayoutObject()))
return box->MayIntersect(result, hit_test_location, accumulated_offset);
// TODO(kojii): (!IsCSSBox() || IsInlineBox()) is not supported yet. Implement
// if needed. For now, just return |true| not to do early return.
return true;
}
PhysicalRect NGPhysicalBoxFragment::ScrollableOverflow(
TextHeightType height_type) const {
DCHECK(GetLayoutObject());
......
......@@ -219,6 +219,11 @@ class CORE_EXPORT NGPhysicalBoxFragment final
// corresponds to children that overflows their parent.
PhysicalRect ContentsInkOverflow() const;
// Fast check if |NodeAtPoint| may find a hit.
bool MayIntersect(const HitTestResult& result,
const HitTestLocation& hit_test_location,
const PhysicalOffset& accumulated_offset) const;
// Fragment offset is this fragment's offset from parent.
// Needed to compensate for LayoutInline Legacy code offsets.
void AddSelfOutlineRects(const PhysicalOffset& additional_offset,
......
......@@ -1858,17 +1858,9 @@ bool NGBoxFragmentPainter::NodeAtPoint(HitTestResult& result,
bool NGBoxFragmentPainter::NodeAtPoint(const HitTestContext& hit_test,
const PhysicalOffset& physical_offset) {
const NGPhysicalBoxFragment& fragment = PhysicalFragment();
if (fragment.IsCSSBox() && !fragment.IsInlineBox() &&
!fragment.IsEffectiveRootScroller()) {
// Check if we need to do anything at all.
// If we have clipping, then we can't have any spillout.
PhysicalRect overflow_box = fragment.IsScrollContainer()
? fragment.LocalRect()
: fragment.InkOverflow();
overflow_box.Move(physical_offset);
if (!hit_test.location.Intersects(overflow_box))
return false;
}
if (!fragment.MayIntersect(*hit_test.result, hit_test.location,
physical_offset))
return false;
bool hit_test_self = fragment.IsInSelfHitTestingPhase(hit_test.action);
if (hit_test_self && box_fragment_.IsScrollContainer() &&
......
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