Commit 00dd6740 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Reset the cursor from WindowTreeHostPlatform on ET_MOUSE_EXITED

When the mouse cursor exits from the browser window,
'CompoundEventFilter' doesn't update the cursor and it doesn't
know whether ET_MOUSE_EXITED happens when the window is destroying
or the mouse exits from the window. WindowTreeHostPlatform keeps
the previous cursor and WaylandWindow, one of PlatformWindows,
also keeps it.

This patch resets the cursor from WindowTreeHostPlatform on
ET_MOUSE_EXITED to update it when it reenters the window.

Test: aura_unittests
Bug: 879448
Change-Id: I52919aaadef4a0934eb6ad88c1f4d4ba75f802b0
Reviewed-on: https://chromium-review.googlesource.com/1198714
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarAntonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#589812}
parent e173abbe
......@@ -10,6 +10,7 @@
#include "base/run_loop.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
......@@ -215,8 +216,23 @@ void WindowTreeHostPlatform::OnDamageRect(const gfx::Rect& damage_rect) {
void WindowTreeHostPlatform::DispatchEvent(ui::Event* event) {
TRACE_EVENT0("input", "WindowTreeHostPlatform::DispatchEvent");
ui::EventDispatchDetails details = SendEventToSink(event);
if (details.dispatcher_destroyed)
if (details.dispatcher_destroyed) {
event->SetHandled();
return;
}
// Reset the cursor on ET_MOUSE_EXITED, so that when the mouse re-enters the
// window, the cursor is updated correctly.
if (event->type() == ui::ET_MOUSE_EXITED) {
client::CursorClient* cursor_client = client::GetCursorClient(window());
if (cursor_client) {
// The cursor-change needs to happen through the CursorClient so that
// other external states are updated correctly, instead of just changing
// |current_cursor_| here.
cursor_client->SetCursor(ui::CursorType::kNone);
DCHECK_EQ(ui::CursorType::kNone, current_cursor_.native_type());
}
}
}
void WindowTreeHostPlatform::OnCloseRequest() {
......
......@@ -84,6 +84,9 @@ class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost,
bool IsKeyLocked(ui::DomCode dom_code) override;
base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override;
// This function is only for test purpose.
gfx::NativeCursor* GetCursorNative() { return &current_cursor_; }
private:
gfx::AcceleratedWidget widget_;
std::unique_ptr<ui::PlatformWindow> platform_window_;
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_cursor_client.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/window_event_dispatcher_test_api.h"
#include "ui/aura/window.h"
......@@ -10,6 +11,7 @@
#include "ui/base/ime/input_method.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event_rewriter.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/platform_window/stub/stub_window.h"
......@@ -141,12 +143,51 @@ class TestWindowTreeHost : public WindowTreeHostPlatform {
CreateCompositor();
}
ui::CursorType GetCursorType() { return GetCursorNative()->native_type(); }
void DispatchEventForTest(ui::Event* event) { DispatchEvent(event); }
private:
DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHost);
};
class TestCursorClient : public test::TestCursorClient {
public:
explicit TestCursorClient(aura::Window* root_window)
: test::TestCursorClient(root_window) {
window_ = root_window;
}
~TestCursorClient() override {}
// Overridden from test::TestCursorClient:
void SetCursor(gfx::NativeCursor cursor) override {
WindowTreeHost* host = window_->GetHost();
if (host)
host->SetCursor(cursor);
}
private:
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(TestCursorClient);
};
TEST_F(WindowTreeHostTest, LostCaptureDuringTearDown) {
TestWindowTreeHost host;
}
// Tests if the cursor type is reset after ET_MOUSE_EXITED event.
TEST_F(WindowTreeHostTest, ResetCursorOnExit) {
TestWindowTreeHost host;
aura::TestCursorClient cursor_client(host.window());
// Set the cursor with the specific type to check if it's reset after
// ET_MOUSE_EXITED event.
host.SetCursorNative(ui::CursorType::kCross);
ui::MouseEvent exit_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0);
host.DispatchEventForTest(&exit_event);
EXPECT_EQ(host.GetCursorType(), ui::CursorType::kNone);
}
} // namespace aura
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