Merge 4280: Add early return to NGBoxFragmentPainter::HitTestLineBoxFragment

When |NGBoxFragmentPainter::HitTestLineBoxFragment| ported
the logic from |InlineFlowBox::NodeAtPoint()|, it missed the
early return by using |InkOverflow()|. This patch adds this.

Test case: blink_perf/layout/culled-inline-hittest
Before r793989:      420ms
Before r807114:    9,064ms
ToT:                 374ms
ToT (PaintFragment): 421ms
ToT (legacy):          4.5ms
This patch:            2.9ms

crbug.com/1127976 added a heuristic switch, which is effective
when there are many lines (and therefore |IsDescendantsCursor|
is very small subset), but it may have negative effects in
other cases. The root problem is NG calls it too much because
of the lack of this early return. I'll remove the heuristic
switch in a separate patch because it is probably no longer
necessary with this numbers.

(cherry picked from commit 5cb87631082064b382733dba206551769c1f4bd0)

Bug: 1128937, 1127976
Change-Id: Icb26007d90461c0e763d5af424704e56489e626f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463086
Commit-Queue: Koji Ishii <[email protected]>
Reviewed-by: Yoshifumi Inoue <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#815524}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467047
Reviewed-by: Koji Ishii <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#307}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/third_party/blink/renderer/core/paint/ng/ng_box_fragment_painter.cc b/third_party/blink/renderer/core/paint/ng/ng_box_fragment_painter.cc
index af50914..d070bbb 100644
--- a/third_party/blink/renderer/core/paint/ng/ng_box_fragment_painter.cc
+++ b/third_party/blink/renderer/core/paint/ng/ng_box_fragment_painter.cc
@@ -2046,6 +2046,11 @@
     const NGPhysicalLineBoxFragment& fragment,
     const NGInlineBackwardCursor& cursor,
     const PhysicalOffset& physical_offset) {
+  PhysicalRect overflow_rect = cursor.Current().InkOverflow();
+  overflow_rect.Move(physical_offset);
+  if (!hit_test.location.Intersects(overflow_rect))
+    return false;
+
   if (HitTestChildren(hit_test, PhysicalFragment(),
                       cursor.CursorForDescendants(), physical_offset))
     return true;