Move cursor when it's hidden so that UX can update correctly

BUG=136057
TEST=None

Review URL: https://chromiumcodereview.appspot.com/10829180

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151705 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b655538
......@@ -59,6 +59,7 @@ void AshTestBase::SetUp() {
ash::Shell::CreateInstance(delegate);
Shell::GetPrimaryRootWindow()->Show();
Shell::GetPrimaryRootWindow()->SetHostSize(gfx::Size(800, 600));
Shell::GetInstance()->cursor_manager()->ShowCursor(true);
// Disable animations during tests.
ui::LayerAnimator::set_disable_animations_for_test(true);
......
......@@ -28,6 +28,7 @@ Env* Env::instance_ = NULL;
Env::Env()
: mouse_button_flags_(0),
is_cursor_hidden_(false),
is_touch_down_(false),
render_white_bg_(true),
stacking_client_(NULL) {
......@@ -69,6 +70,19 @@ void Env::SetLastMouseLocation(const Window& window,
client->ConvertPointToScreen(&window, &last_mouse_location_);
}
void Env::SetCursorShown(bool cursor_shown) {
if (cursor_shown) {
// Protect against restoring a position that hadn't been saved.
if (is_cursor_hidden_)
last_mouse_location_ = hidden_cursor_location_;
is_cursor_hidden_ = false;
} else {
hidden_cursor_location_ = last_mouse_location_;
last_mouse_location_ = gfx::Point(-10000, -10000);
is_cursor_hidden_ = true;
}
}
void Env::SetDisplayManager(DisplayManager* display_manager) {
display_manager_.reset(display_manager);
#if defined(USE_X11)
......
......@@ -51,6 +51,10 @@ class AURA_EXPORT Env {
void SetLastMouseLocation(const Window& window,
const gfx::Point& location_in_root);
// If |cursor_shown| is false, sets the last_mouse_position to an invalid
// location. If |cursor_shown| is true, restores the last_mouse_position.
void SetCursorShown(bool cursor_shown);
// Whether any touch device is currently down.
bool is_touch_down() const { return is_touch_down_; }
void set_touch_down(bool value) { is_touch_down_ = value; }
......@@ -100,6 +104,9 @@ class AURA_EXPORT Env {
int mouse_button_flags_;
// Location of last mouse event, in screen coordinates.
gfx::Point last_mouse_location_;
// If the cursor is hidden, saves the previous last_mouse_position.
gfx::Point hidden_cursor_location_;
bool is_cursor_hidden_;
bool is_touch_down_;
bool render_white_bg_;
client::StackingClient* stacking_client_;
......
......@@ -231,8 +231,14 @@ void RootWindow::SetCursor(gfx::NativeCursor cursor) {
}
void RootWindow::ShowCursor(bool show) {
cursor_shown_ = show;
host_->ShowCursor(show);
// Send entered / exited so that visual state can be updated to match
// cursor state.
if (show != cursor_shown_) {
cursor_shown_ = show;
host_->ShowCursor(show);
Env::GetInstance()->SetCursorShown(show);
PostMouseMoveEventAfterWindowChange();
}
}
void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) {
......
......@@ -155,6 +155,47 @@ TEST_F(RootWindowTest, OnHostMouseEvent) {
EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT);
}
#if defined(OS_WIN)
// Temporarily disabled for windows. See crbug.com/112222.
TEST_F(RootWindowTest, DISABLED_HideCursor) {
#else
TEST_F(RootWindowTest, HideCursor) {
#endif // defined(OS_WIN)
scoped_ptr<NonClientDelegate> delegate(new NonClientDelegate());
const int kWindowWidth = 123;
const int kWindowHeight = 45;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, NULL));
aura::Window* window_ptr = &*window;
root_window()->ShowCursor(true);
// Send a mouse event to window.
gfx::Point point(101, 201);
gfx::Point local_point;
ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0);
root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event);
// Location was in window.
local_point = delegate->mouse_event_location();
aura::Window::ConvertPointToTarget(window_ptr, root_window(), &local_point);
EXPECT_TRUE(window->bounds().Contains(local_point));
// Location is now out of window.
root_window()->ShowCursor(false);
RunAllPendingInMessageLoop();
local_point = delegate->mouse_event_location();
aura::Window::ConvertPointToTarget(window_ptr, root_window(), &local_point);
EXPECT_FALSE(window->bounds().Contains(local_point));
// Location is back in window.
root_window()->ShowCursor(true);
RunAllPendingInMessageLoop();
local_point = delegate->mouse_event_location();
aura::Window::ConvertPointToTarget(window_ptr, root_window(), &local_point);
EXPECT_TRUE(window->bounds().Contains(local_point));
}
// Check that we correctly track the state of the mouse buttons in response to
// button press and release events.
TEST_F(RootWindowTest, MouseButtonState) {
......
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