Commit 22b75da2 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Don't return text node from WebViewImpl::BestTapNode()

In cases like
<div style="display: contents; cursor: pointer">Text</div>,
previously WebViewImpl::BestTapNode() returned the text node, which
caused crash in LinkHighlightImpl::Paint() because a text node can't
have paint properties.

Let WebViewImpl::BestTapNode() return nullptr in the case because a
text node can't have touch actions, to fix the crash.

Bug: 1052650, 1016587
Change-Id: If9f6d3f8c7368649e00ea804e9d48a17eef3fbc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063770
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742465}
parent 9b3b01f0
......@@ -954,6 +954,8 @@ static bool ShowsHandCursor(Node* node, LocalFrame* frame) {
frame->GetEventHandler().UseHandCursor(node, node->IsLink()));
}
// This is for tap (link) highlight and is tested in
// link_highlight_impl_test.cc.
Node* WebViewImpl::BestTapNode(
const GestureEventWithHitTestResults& targeted_tap_event) {
TRACE_EVENT0("input", "WebViewImpl::bestTapNode");
......@@ -1001,6 +1003,14 @@ Node* WebViewImpl::BestTapNode(
ShowsHandCursor(cursor_defining_ancestor,
page->DeprecatedLocalMainFrame()));
// This happens in cases like:
// <div style="display: contents; cursor: pointer">Text</div>.
// The text node inherits cursor: pointer and the div doesn't have a
// LayoutObject, so |best_touch_node| is the text node here. We should not
// return the text node because it can't have touch actions.
if (best_touch_node->IsTextNode())
return nullptr;
return best_touch_node;
}
......
......@@ -379,4 +379,26 @@ TEST_P(LinkHighlightImplTest, MultiColumn) {
EXPECT_EQ(layer_count_before_highlight, LayerCount());
}
TEST_P(LinkHighlightImplTest, DisplayContents) {
WebViewImpl* web_view_impl = web_view_helper_.GetWebView();
int page_width = 640;
int page_height = 480;
web_view_impl->MainFrameWidget()->Resize(WebSize(page_width, page_height));
UpdateAllLifecyclePhases();
WebGestureEvent touch_event(WebInputEvent::kGestureShowPress,
WebInputEvent::kNoModifiers,
WebInputEvent::GetStaticTimeStampForTests(),
WebGestureDevice::kTouchscreen);
// This will touch the div with display:contents and cursor:pointer.
touch_event.SetPositionInWidget(gfx::PointF(20, 400));
GestureEventWithHitTestResults targeted_event = GetTargetedEvent(touch_event);
EXPECT_FALSE(web_view_impl->BestTapNode(targeted_event));
web_view_impl->EnableTapHighlightAtPoint(targeted_event);
EXPECT_FALSE(GetLinkHighlightImpl());
}
} // namespace blink
<!DOCTYPE html>
<link rel="stylesheet" href="resources/link-highlight-style.css">
Highlight&nbsp;
<!DOCTYPE html>
<script src="resources/link-highlight-helper.js"></script>
<link rel="stylesheet" href="resources/link-highlight-style.css">
<div id="highlightTarget" style="display: inline-block">
<div class="opaqueHighlight" style="display: contents; cursor: pointer">Highlight</div>
</div>
<script>
onload = testHighlightTarget;
</script>
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