Commit 126116ae authored by ananta's avatar ananta Committed by Commit bot

Add a new source type MENU_SOURCE_LONG_PRESS to identify context menu's being...

Add a new source type MENU_SOURCE_LONG_PRESS to identify context menu's being opened via the long press gesture.

For context, please refer to this patch https://codereview.chromium.org/1602903003/, where we display the context menu
on Windows when the long press gesture is released. This patch used the MENU_SOURCE_TOUCH source type in the context menu
params to determine whether a menu is being opened via the long press gesture. Turns out that the MENU_SOURCE_TOUCH is
used in places like devtools to open the context menu, which does not work due to the above patch.

Fix is to add a new menu source type MENU_SOURCE_LONG_PRESS We use this in RenderWidgetHostViewAura to identify context
menus opening via the long press gesture. Added another menu source type MENU_SOURCE_LONG_TAP which indicates menus
opening via the long tap gesture.

This should fix this regression.

BUG=581005
TEST=RenderWidgetHostViewAuraWithViewHarnessTest.ContextMenuTest. Updated this test to test for the MENU_SOURCE_LONG_PRESS gesture
type.

Review URL: https://codereview.chromium.org/1637743002

Cr-Commit-Position: refs/heads/master@{#371672}
parent 34844e98
...@@ -2723,7 +2723,7 @@ bool RenderWidgetHostViewAura::OnShowContextMenu( ...@@ -2723,7 +2723,7 @@ bool RenderWidgetHostViewAura::OnShowContextMenu(
#if defined(OS_WIN) #if defined(OS_WIN)
last_context_menu_params_.reset(); last_context_menu_params_.reset();
if (params.source_type == ui::MENU_SOURCE_TOUCH) { if (params.source_type == ui::MENU_SOURCE_LONG_PRESS) {
last_context_menu_params_.reset(new ContextMenuParams); last_context_menu_params_.reset(new ContextMenuParams);
*last_context_menu_params_ = params; *last_context_menu_params_ = params;
return false; return false;
...@@ -2953,12 +2953,12 @@ void RenderWidgetHostViewAura::HandleGestureForTouchSelection( ...@@ -2953,12 +2953,12 @@ void RenderWidgetHostViewAura::HandleGestureForTouchSelection(
// On Windows we want to display the context menu when the long press // On Windows we want to display the context menu when the long press
// gesture is released. To achieve that, we switch the saved context // gesture is released. To achieve that, we switch the saved context
// menu params source type to MENU_SOURCE_MOUSE. This is to ensure that // menu params source type to MENU_SOURCE_TOUCH. This is to ensure that
// the RenderWidgetHostViewAura::OnShowContextMenu function which is // the RenderWidgetHostViewAura::OnShowContextMenu function which is
// called from the ShowContextMenu call below, does not treat it as // called from the ShowContextMenu call below, does not treat it as
// a context menu request coming in from touch. // a context menu request coming in from the long press gesture.
DCHECK(context_menu_params->source_type == ui::MENU_SOURCE_TOUCH); DCHECK(context_menu_params->source_type == ui::MENU_SOURCE_LONG_PRESS);
context_menu_params->source_type = ui::MENU_SOURCE_MOUSE; context_menu_params->source_type = ui::MENU_SOURCE_TOUCH;
RenderViewHostDelegateView* delegate_view = RenderViewHostDelegateView* delegate_view =
GetRenderViewHostDelegateView(); GetRenderViewHostDelegateView();
......
...@@ -3756,12 +3756,32 @@ TEST_F(RenderWidgetHostViewAuraWithViewHarnessTest, ...@@ -3756,12 +3756,32 @@ TEST_F(RenderWidgetHostViewAuraWithViewHarnessTest,
// A context menu request with the MENU_SOURCE_TOUCH source type should // A context menu request with the MENU_SOURCE_TOUCH source type should
// result in the MockWebContentsViewDelegate::ShowContextMenu method // result in the MockWebContentsViewDelegate::ShowContextMenu method
// getting called on non Windows platforms. This means that the request // getting called on all platforms. This means that the request worked
// worked correctly. On Windows this should be blocked. // correctly.
delegate->ClearState(); delegate->ClearState();
context_menu_params.source_type = ui::MENU_SOURCE_TOUCH; context_menu_params.source_type = ui::MENU_SOURCE_TOUCH;
contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(), contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(),
context_menu_params); context_menu_params);
EXPECT_TRUE(delegate->context_menu_request_received());
// A context menu request with the MENU_SOURCE_LONG_TAP source type should
// result in the MockWebContentsViewDelegate::ShowContextMenu method
// getting called on all platforms. This means that the request worked
// correctly.
delegate->ClearState();
context_menu_params.source_type = ui::MENU_SOURCE_LONG_TAP;
contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(),
context_menu_params);
EXPECT_TRUE(delegate->context_menu_request_received());
// A context menu request with the MENU_SOURCE_LONG_PRESS source type should
// result in the MockWebContentsViewDelegate::ShowContextMenu method
// getting called on non Windows platforms. This means that the request
// worked correctly. On Windows this should be blocked.
delegate->ClearState();
context_menu_params.source_type = ui::MENU_SOURCE_LONG_PRESS;
contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(),
context_menu_params);
#if defined(OS_WIN) #if defined(OS_WIN)
EXPECT_FALSE(delegate->context_menu_request_received()); EXPECT_FALSE(delegate->context_menu_request_received());
#else #else
...@@ -3780,7 +3800,7 @@ TEST_F(RenderWidgetHostViewAuraWithViewHarnessTest, ...@@ -3780,7 +3800,7 @@ TEST_F(RenderWidgetHostViewAuraWithViewHarnessTest,
view()->OnGestureEvent(&gesture_event); view()->OnGestureEvent(&gesture_event);
EXPECT_TRUE(delegate->context_menu_request_received()); EXPECT_TRUE(delegate->context_menu_request_received());
EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_MOUSE); EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_TOUCH);
#endif #endif
RenderViewHostFactory::set_is_real_render_view_host(false); RenderViewHostFactory::set_is_real_render_view_host(false);
......
...@@ -294,7 +294,13 @@ void RenderWidgetInputHandler::HandleInputEvent( ...@@ -294,7 +294,13 @@ void RenderWidgetInputHandler::HandleInputEvent(
if (WebInputEvent::isGestureEventType(input_event.type)) { if (WebInputEvent::isGestureEventType(input_event.type)) {
const WebGestureEvent& gesture_event = const WebGestureEvent& gesture_event =
static_cast<const WebGestureEvent&>(input_event); static_cast<const WebGestureEvent&>(input_event);
context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; if (input_event.type == WebInputEvent::GestureLongPress) {
context_menu_source_type_ = ui::MENU_SOURCE_LONG_PRESS;
} else if (input_event.type == WebInputEvent::GestureLongTap) {
context_menu_source_type_ = ui::MENU_SOURCE_LONG_TAP;
} else {
context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
}
prevent_default = prevent_default =
prevent_default || delegate_->WillHandleGestureEvent(gesture_event); prevent_default || delegate_->WillHandleGestureEvent(gesture_event);
} }
......
...@@ -47,7 +47,9 @@ enum MenuSourceType { ...@@ -47,7 +47,9 @@ enum MenuSourceType {
MENU_SOURCE_KEYBOARD = 2, MENU_SOURCE_KEYBOARD = 2,
MENU_SOURCE_TOUCH = 3, MENU_SOURCE_TOUCH = 3,
MENU_SOURCE_TOUCH_EDIT_MENU = 4, MENU_SOURCE_TOUCH_EDIT_MENU = 4,
MENU_SOURCE_TYPE_LAST = MENU_SOURCE_TOUCH_EDIT_MENU MENU_SOURCE_LONG_PRESS = 5,
MENU_SOURCE_LONG_TAP = 6,
MENU_SOURCE_TYPE_LAST = MENU_SOURCE_LONG_TAP
}; };
UI_BASE_EXPORT MenuSourceType GetMenuSourceTypeForEvent(const ui::Event& event); UI_BASE_EXPORT MenuSourceType GetMenuSourceTypeForEvent(const ui::Event& event);
......
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