Commit e35026fa authored by Bret Sepulveda's avatar Bret Sepulveda Committed by Commit Bot

Reland: Use the real mouse position when synthesizing mouse events.

Aura synthesizes a mouse event at certain times, including when the
window comes back from being minimized. Currently it uses the last known
mouse position, which works in most cases. However, the window doesn't
get mouse events when minimized, so the last known position isn't
updated. When the window comes back, if the user's mouse is not over the
window it can cause buttons to get stuck in the hovered state until the
user moves the mouse back into the window.

To fix this, this patch uses the real mouse position.

This patch also updates content_shell to move the mouse to 0,0 in
headless mode, to avoid any queries to the real mouse position from
interfering with blink tests. This patch also adds an implementation
for MoveCursorTo on Windows.

Bug: 828591, 834166
Change-Id: I81354c77805c1928eb0cbccb900856a8c523709d
Reviewed-on: https://chromium-review.googlesource.com/1022959Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555843}
parent 86417fba
...@@ -444,6 +444,9 @@ void Shell::PlatformSetContents() { ...@@ -444,6 +444,9 @@ void Shell::PlatformSetContents() {
aura::Window* parent = platform_->host()->window(); aura::Window* parent = platform_->host()->window();
if (!parent->Contains(content)) { if (!parent->Contains(content)) {
parent->AddChild(content); parent->AddChild(content);
// Move the cursor to a fixed position before tests run to avoid getting
// an unpredictable result from mouse events.
content->MoveCursorTo(gfx::Point());
content->Show(); content->Show();
} }
content->SetBounds(gfx::Rect(content_size_)); content->SetBounds(gfx::Rect(content_size_));
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/compositor/dip_util.h" #include "ui/compositor/dip_util.h"
#include "ui/display/screen.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/gestures/gesture_recognizer.h" #include "ui/events/gestures/gesture_recognizer.h"
...@@ -227,10 +228,7 @@ void WindowEventDispatcher::ReleasePointerMoves() { ...@@ -227,10 +228,7 @@ void WindowEventDispatcher::ReleasePointerMoves() {
gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const {
gfx::Point location = Env::GetInstance()->last_mouse_location(); gfx::Point location = Env::GetInstance()->last_mouse_location();
client::ScreenPositionClient* client = ConvertPointFromScreen(&location);
client::GetScreenPositionClient(window());
if (client)
client->ConvertPointFromScreen(window(), &location);
return location; return location;
} }
...@@ -264,6 +262,13 @@ const Window* WindowEventDispatcher::window() const { ...@@ -264,6 +262,13 @@ const Window* WindowEventDispatcher::window() const {
return host_->window(); return host_->window();
} }
void WindowEventDispatcher::ConvertPointFromScreen(gfx::Point* point) const {
client::ScreenPositionClient* client =
client::GetScreenPositionClient(window());
if (client)
client->ConvertPointFromScreen(window(), point);
}
void WindowEventDispatcher::TransformEventForDeviceScaleFactor( void WindowEventDispatcher::TransformEventForDeviceScaleFactor(
ui::LocatedEvent* event) { ui::LocatedEvent* event) {
event->UpdateForRootTransform( event->UpdateForRootTransform(
...@@ -860,10 +865,14 @@ ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() { ...@@ -860,10 +865,14 @@ ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() {
if (Env::GetInstance()->mouse_button_flags()) if (Env::GetInstance()->mouse_button_flags())
return details; return details;
gfx::Point root_mouse_location = GetLastMouseLocationInRoot(); // Do not use GetLastMouseLocationInRoot here because it's not updated when
if (!window()->bounds().Contains(root_mouse_location)) // the mouse is not over the window or when the window is minimized.
gfx::Point mouse_location =
display::Screen::GetScreen()->GetCursorScreenPoint();
ConvertPointFromScreen(&mouse_location);
if (!window()->bounds().Contains(mouse_location))
return details; return details;
gfx::Point host_mouse_location = root_mouse_location; gfx::Point host_mouse_location = mouse_location;
host_->ConvertDIPToPixels(&host_mouse_location); host_->ConvertDIPToPixels(&host_mouse_location);
ui::MouseEvent event(ui::ET_MOUSE_MOVED, host_mouse_location, ui::MouseEvent event(ui::ET_MOUSE_MOVED, host_mouse_location,
host_mouse_location, ui::EventTimeForNow(), host_mouse_location, ui::EventTimeForNow(),
......
...@@ -147,6 +147,10 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, ...@@ -147,6 +147,10 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
Window* window(); Window* window();
const Window* window() const; const Window* window() const;
// Converts a point from screen coordinates to the coordinate space used by
// the Window returned from window().
void ConvertPointFromScreen(gfx::Point* screen_point) const;
// Updates the event with the appropriate transform for the device scale // Updates the event with the appropriate transform for the device scale
// factor. The WindowEventDispatcher dispatches events in the physical pixel // factor. The WindowEventDispatcher dispatches events in the physical pixel
// coordinate. But the event processing from WindowEventDispatcher onwards // coordinate. But the event processing from WindowEventDispatcher onwards
......
...@@ -125,7 +125,9 @@ void WinWindow::SetCursor(PlatformCursor cursor) { ...@@ -125,7 +125,9 @@ void WinWindow::SetCursor(PlatformCursor cursor) {
::SetCursor(cursor); ::SetCursor(cursor);
} }
void WinWindow::MoveCursorTo(const gfx::Point& location) {} void WinWindow::MoveCursorTo(const gfx::Point& location) {
::SetCursorPos(location.x(), location.y());
}
void WinWindow::ConfineCursorToBounds(const gfx::Rect& bounds) { void WinWindow::ConfineCursorToBounds(const gfx::Rect& bounds) {
} }
......
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