Commit bcf61e48 authored by Siye Liu's avatar Siye Liu Committed by Commit Bot

Should ask hittest frame to invoke context menu on long tap.

During long tap, |WebViewImpl::HandleGestureEvent| asks the main
frame's GestureManager is the long tap should invoke context menu.
However, the previeus long press event was routed to iframe's
GestureManager. Therefore, main frame's GestureManager returns false
in |GestureManager::LongTapShouldInvokeContextMenu|. Therefore, context
menu is not invoked if the link is in an iframe. We should ask the hit
frame to decide whether we should invoke context menu during long tap.

Bug: 1112987
Change-Id: I90f5e1f09380258b6bdf83c9cc78b9764d2adeca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2382054Reviewed-by: default avatarSiye Liu <siliu@microsoft.com>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: Siye Liu <siliu@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#805167}
parent c17a107e
......@@ -594,12 +594,18 @@ WebInputEventResult WebViewImpl::HandleGestureEvent(
if (!MainFrameImpl() || !MainFrameImpl()->GetFrameView())
break;
if (event.GetType() == WebInputEvent::Type::kGestureLongTap &&
!MainFrameImpl()
->GetFrame()
->GetEventHandler()
.LongTapShouldInvokeContextMenu())
break;
if (event.GetType() == WebInputEvent::Type::kGestureLongTap) {
if (LocalFrame* inner_frame =
targeted_event.GetHitTestResult().InnerNodeFrame()) {
if (!inner_frame->GetEventHandler().LongTapShouldInvokeContextMenu())
break;
} else if (!MainFrameImpl()
->GetFrame()
->GetEventHandler()
.LongTapShouldInvokeContextMenu()) {
break;
}
}
page_->GetContextMenuController().ClearContextMenu();
{
......
......@@ -5995,4 +5995,51 @@ TEST_F(WebViewTest, UpdateTargetURLWithInvalidURL) {
EXPECT_EQ(invalid_kurl, web_view->target_url_);
}
// Regression test for https://crbug.com/1112987
TEST_F(WebViewTest, LongPressAndThenLongTapLinkInIframeShouldShowContextMenu) {
RegisterMockedHttpURLLoad("long_press_link_in_iframe.html");
WebViewImpl* web_view = web_view_helper_.InitializeAndLoad(
base_url_ + "long_press_link_in_iframe.html");
web_view->SettingsImpl()->SetTouchDragDropEnabled(true);
web_view->MainFrameWidget()->Resize(WebSize(500, 300));
UpdateAllLifecyclePhases();
RunPendingTasks();
WebLocalFrameImpl* frame = web_view->MainFrameImpl();
Document* document = frame->GetFrame()->GetDocument();
Element* child_frame = document->getElementById("childframe");
DCHECK(child_frame);
Document* child_document =
To<HTMLIFrameElement>(child_frame)->contentDocument();
Element* anchor = child_document->getElementById("anchorTag");
IntPoint center =
To<WebLocalFrameImpl>(
web_view->MainFrame()->FirstChild()->ToWebLocalFrame())
->GetFrameView()
->FrameToScreen(anchor->GetLayoutObject()->AbsoluteBoundingBoxRect())
.Center();
WebGestureEvent event(WebInputEvent::Type::kGestureLongPress,
WebInputEvent::kNoModifiers,
WebInputEvent::GetStaticTimeStampForTests(),
WebGestureDevice::kTouchscreen);
event.SetPositionInWidget(gfx::PointF(center.X(), center.X()));
EXPECT_EQ(WebInputEventResult::kHandledSystem,
web_view->MainFrameWidget()->HandleInputEvent(
WebCoalescedInputEvent(event, ui::LatencyInfo())));
WebGestureEvent tap_event(WebInputEvent::Type::kGestureLongTap,
WebInputEvent::kNoModifiers,
WebInputEvent::GetStaticTimeStampForTests(),
WebGestureDevice::kTouchscreen);
tap_event.SetPositionInWidget(gfx::PointF(center.X(), center.X()));
EXPECT_EQ(WebInputEventResult::kNotHandled,
web_view->MainFrameWidget()->HandleInputEvent(
WebCoalescedInputEvent(tap_event, ui::LatencyInfo())));
EXPECT_EQ("anchor contextmenu",
web_view->MainFrameImpl()->GetDocument().Title());
}
} // namespace blink
<html>
<head>
<script>
function onLoad() {
var iframeDocument = document.getElementById("childframe").contentDocument;
iframeDocument.body.innerHTML = "<div><a id='anchorTag' href='http://www.example.com' style='position: absolute; left: 20px; top: 20px; height: 20px;'>Link to example.com</a></div>";
var anchor = iframeDocument.getElementById("anchorTag");
anchor.addEventListener("contextmenu", function(event) { document.title = "anchor contextmenu"; });
}
</script>
</head>
<body onload="onLoad()">
<iframe id="childframe" style="width: 100px; height: 100px;"></iframe>
</body>
<html>
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