Commit 34b06d0e authored by David Bienvenu's avatar David Bienvenu Committed by Commit Bot

Fix right click handling from left click initiated system menu

If you open app window (e.g., chrome://apps,
right click on Youtube, check "open in window", and open it),
then left click just to the right of "Youtube" in the title bar of the app
window, and then right click, a second context menu gets opened.

This CL makes HwndMessageHandler ignore the right click when displaying
a system menu opened with left click.

Bug: 1053460
Change-Id: I0c32cf30995ce6e970c93d40a2e20b7b2f63d3a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071253Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746167}
parent b0e76bc7
......@@ -2568,9 +2568,16 @@ void HWNDMessageHandler::OnSysCommand(UINT notification_code,
if (delegate_->HandleCommand(notification_code))
return;
bool is_mouse_menu = (notification_code & sc_mask) == SC_MOUSEMENU;
if (is_mouse_menu)
handling_mouse_menu_ = true;
base::WeakPtr<HWNDMessageHandler> ref(msg_handler_weak_factory_.GetWeakPtr());
// If the delegate can't handle it, the system implementation will be called.
DefWindowProc(hwnd(), WM_SYSCOMMAND, notification_code,
MAKELPARAM(point.x(), point.y()));
if (is_mouse_menu && ref)
handling_mouse_menu_ = false;
}
void HWNDMessageHandler::OnThemeChanged() {
......@@ -3001,9 +3008,16 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
}
// There are cases where the code handling the message destroys the window,
// so use the weak ptr to check if destruction occured or not.
// so use the weak ptr to check if destruction occurred or not.
base::WeakPtr<HWNDMessageHandler> ref(msg_handler_weak_factory_.GetWeakPtr());
bool handled = delegate_->HandleMouseEvent(&event);
bool handled = false;
// Don't send right mouse button up to the delegate when displaying system
// command menu. This prevents left clicking in the upper left hand corner of
// an app window and then right clicking from sending the right click to the
// renderer and bringing up a web contents context menu.
if (!handling_mouse_menu_ || message != WM_RBUTTONUP)
handled = delegate_->HandleMouseEvent(&event);
if (!ref.get())
return 0;
......@@ -3164,7 +3178,7 @@ LRESULT HWNDMessageHandler::HandlePointerEventTypePen(UINT message,
message, pointer_id, pointer_pen_info, point);
// There are cases where the code handling the message destroys the
// window, so use the weak ptr to check if destruction occured or not.
// window, so use the weak ptr to check if destruction occurred or not.
base::WeakPtr<HWNDMessageHandler> ref(msg_handler_weak_factory_.GetWeakPtr());
if (event) {
if (event->IsTouchEvent())
......
......@@ -782,6 +782,11 @@ class VIEWS_EXPORT HWNDMessageHandler : public gfx::WindowImpl,
// True if is handling mouse WM_INPUT messages.
bool using_wm_input_ = false;
// True if we're displaying the system menu on the title bar. If we are,
// then we want to ignore right mouse clicks instead of bringing up a
// context menu.
bool handling_mouse_menu_ = false;
// This is a map of the HMONITOR to full screeen window instance. It is safe
// to keep a raw pointer to the HWNDMessageHandler instance as we track the
// window destruction and ensure that the map is cleaned up.
......
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