Commit b306b1e6 authored by ananta's avatar ananta Committed by Commit bot

Ensure that mouse lock works correctly on Chrome ASH in Windows 8.

The lock mouse operation invoked by plugins or pages hides the mouse cursor and ensures that the cursor stays within the bounds
of the webpage. To ensure that the mouse stays within the bounds of the page, the SetCursorPos operation is executed by the host.
In ASH, the SetCursorPos API is executed by the viewer process for historical reasons.

As a result on Windows 8 there is a faint possibility that the user may move the mouse to the charms section of the OS, which causes the cursor to
become visible.

Fix for this is to track if the mouse changed from what was last set in the viewer process and restore it.

The other change is in the RemoteWindowTreeHostWin class where the member ignore_mouse_moves_until_set_cursor_ack_ has been changed to a count
from a bool flag. This is because the RemoteWindowTreeHostWin::MoveCursorToNative function can be called multiple times before the acks are received
causing DCHECKs to fire on the ignore_mouse_moves_until_set_cursor_ack_ flag.

BUG=398792

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

Cr-Commit-Position: refs/heads/master@{#294274}
parent 6226ba67
......@@ -93,7 +93,7 @@ RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Instance() {
RemoteWindowTreeHostWin::RemoteWindowTreeHostWin()
: remote_window_(NULL),
host_(NULL),
ignore_mouse_moves_until_set_cursor_ack_(false),
ignore_mouse_moves_until_set_cursor_ack_(0),
event_flags_(0),
window_size_(aura::WindowTreeHost::GetNativeScreenSize()) {
CHECK(!g_instance);
......@@ -262,7 +262,7 @@ void RemoteWindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
// this we invoke the SetCursor API in the viewer process and ignore
// mouse messages until we received an ACK from the viewer indicating that
// the SetCursor operation completed.
ignore_mouse_moves_until_set_cursor_ack_ = true;
ignore_mouse_moves_until_set_cursor_ack_++;
VLOG(1) << "In MoveCursorTo. Sending IPC";
host_->Send(new MetroViewerHostMsg_SetCursorPos(location.x(), location.y()));
}
......@@ -430,8 +430,8 @@ void RemoteWindowTreeHostWin::OnTouchMoved(int32 x,
}
void RemoteWindowTreeHostWin::OnSetCursorPosAck() {
DCHECK(ignore_mouse_moves_until_set_cursor_ack_);
ignore_mouse_moves_until_set_cursor_ack_ = false;
DCHECK_GT(ignore_mouse_moves_until_set_cursor_ack_, 0);
ignore_mouse_moves_until_set_cursor_ack_--;
}
ui::RemoteInputMethodPrivateWin*
......
......@@ -171,9 +171,9 @@ class AURA_EXPORT RemoteWindowTreeHostWin
IPC::Sender* host_;
scoped_ptr<ui::ViewProp> prop_;
// Set to true if we need to ignore mouse messages until the SetCursorPos
// Incremented if we need to ignore mouse messages until the SetCursorPos
// operation is acked by the viewer.
bool ignore_mouse_moves_until_set_cursor_ack_;
int ignore_mouse_moves_until_set_cursor_ack_;
// Tracking last click event for synthetically generated mouse events.
scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
......
......@@ -530,7 +530,8 @@ ChromeAppViewAsh::ChromeAppViewAsh()
ui_channel_(nullptr),
core_window_hwnd_(NULL),
metro_dpi_scale_(0),
win32_dpi_scale_(0) {
win32_dpi_scale_(0),
last_cursor_(NULL) {
DVLOG(1) << __FUNCTION__;
globals.previous_state =
winapp::Activation::ApplicationExecutionState_NotRunning;
......@@ -815,7 +816,8 @@ void ChromeAppViewAsh::OnOpenURLOnDesktop(const base::FilePath& shortcut,
}
void ChromeAppViewAsh::OnSetCursor(HCURSOR cursor) {
::SetCursor(HCURSOR(cursor));
::SetCursor(cursor);
last_cursor_ = cursor;
}
void ChromeAppViewAsh::OnDisplayFileOpenDialog(
......@@ -1082,6 +1084,11 @@ HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender,
return hr;
if (pointer.IsMouse()) {
// If the mouse was moved towards the charms or the OS specific section,
// the cursor may change from what the browser last set. Restore it here.
if (::GetCursor() != last_cursor_)
SetCursor(last_cursor_);
GenerateMouseEventFromMoveIfNecessary(pointer);
ui_channel_->Send(new MetroViewerHostMsg_MouseMoved(
pointer.x(),
......
......@@ -238,6 +238,9 @@ class ChromeAppViewAsh
// The win32 dpi scale which is queried via GetDeviceCaps. Please refer to
// ui/gfx/win/dpi.cc for more information.
float win32_dpi_scale_;
// The cursor set by the chroem browser process.
HCURSOR last_cursor_;
};
#endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_
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