summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 18:55:23 +0000
committermazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 18:55:23 +0000
commit60c262022cb339a122533e88a7c6f2c3c8f1c96e (patch)
treeb13489e89b87ab5cd2cf816653f42c544b28240d
parent4cdfc9eb6233602313079f66d45a8b168f5b2947 (diff)
downloadchromium_src-60c262022cb339a122533e88a7c6f2c3c8f1c96e.zip
chromium_src-60c262022cb339a122533e88a7c6f2c3c8f1c96e.tar.gz
chromium_src-60c262022cb339a122533e88a7c6f2c3c8f1c96e.tar.bz2
Enable CursorManager::LockCursor to lock cursor visibility.
This CL changes mainly three parts: - Add LockCursor and UnlockCursor to CursorClient. - Move the code to change cursor visibility from aura::RootWindow and aura::RootWindowHostLinux to ash::CursorManager. - Remove CursorDelegate, which was too much simple delegation and unnecessary. BUG=153702 TEST=CursorManagerTest.ShowCursor Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=161454 Review URL: https://chromiumcodereview.appspot.com/11035050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161629 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/extended_desktop_unittest.cc7
-rw-r--r--ash/magnifier/magnification_controller.cc11
-rw-r--r--ash/shell.cc18
-rw-r--r--ash/shell.h8
-rw-r--r--ash/wm/cursor_delegate.h26
-rw-r--r--ash/wm/cursor_manager.cc101
-rw-r--r--ash/wm/cursor_manager.h21
-rw-r--r--ash/wm/cursor_manager_unittest.cc52
-rw-r--r--ash/wm/window_manager_unittest.cc10
-rw-r--r--ui/aura/client/cursor_client.h9
-rw-r--r--ui/aura/desktop/desktop_cursor_client.cc31
-rw-r--r--ui/aura/desktop/desktop_cursor_client.h5
-rw-r--r--ui/aura/remote_root_window_host_win.cc4
-rw-r--r--ui/aura/remote_root_window_host_win.h2
-rw-r--r--ui/aura/root_window.cc27
-rw-r--r--ui/aura/root_window.h8
-rw-r--r--ui/aura/root_window_host.h3
-rw-r--r--ui/aura/root_window_host_linux.cc13
-rw-r--r--ui/aura/root_window_host_linux.h7
-rw-r--r--ui/aura/root_window_host_win.cc4
-rw-r--r--ui/aura/root_window_host_win.h1
-rw-r--r--ui/aura/root_window_unittest.cc6
-rw-r--r--ui/aura/shared/compound_event_filter_unittest.cc6
-rw-r--r--ui/views/widget/desktop_root_window_host_linux.cc24
-rw-r--r--ui/views/widget/desktop_root_window_host_linux.h4
-rw-r--r--ui/views/widget/desktop_root_window_host_win.cc3
-rw-r--r--ui/views/widget/desktop_root_window_host_win.h1
27 files changed, 239 insertions, 173 deletions
diff --git a/ash/extended_desktop_unittest.cc b/ash/extended_desktop_unittest.cc
index 4cc75fa..2bde459 100644
--- a/ash/extended_desktop_unittest.cc
+++ b/ash/extended_desktop_unittest.cc
@@ -172,14 +172,7 @@ TEST_F(ExtendedDesktopTest, SystemModal) {
TEST_F(ExtendedDesktopTest, TestCursor) {
UpdateDisplay("1000x600,600x400");
- Shell::GetInstance()->cursor_manager()->ShowCursor(false);
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
- EXPECT_FALSE(root_windows[0]->cursor_shown());
- EXPECT_FALSE(root_windows[1]->cursor_shown());
- Shell::GetInstance()->cursor_manager()->ShowCursor(true);
- EXPECT_TRUE(root_windows[0]->cursor_shown());
- EXPECT_TRUE(root_windows[1]->cursor_shown());
-
EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc
index 1fa8244..be1482b 100644
--- a/ash/magnifier/magnification_controller.cc
+++ b/ash/magnifier/magnification_controller.cc
@@ -6,6 +6,7 @@
#include "ash/shell.h"
#include "ash/shell_delegate.h"
+#include "ui/aura/client/cursor_client.h"
#include "ui/aura/event_filter.h"
#include "ui/aura/root_window.h"
#include "ui/aura/shared/compound_event_filter.h"
@@ -309,7 +310,10 @@ void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) {
int y_diff = origin_.y() - window_rect.y();
// If the magnified region is moved, hides the mouse cursor and moves it.
if (x_diff != 0 || y_diff != 0) {
- root_window_->ShowCursor(false);
+ aura::client::CursorClient* cursor_client =
+ aura::client::GetCursorClient(root_window_);
+ if (cursor_client)
+ cursor_client->ShowCursor(false);
mouse.set_x(mouse.x() - (origin_.x() - window_rect.x()));
mouse.set_y(mouse.y() - (origin_.y() - window_rect.y()));
root_window_->MoveCursorTo(mouse);
@@ -352,7 +356,10 @@ void MagnificationControllerImpl::ValidateScale(float* scale) {
}
void MagnificationControllerImpl::OnImplicitAnimationsCompleted() {
- root_window_->ShowCursor(true);
+ aura::client::CursorClient* cursor_client =
+ aura::client::GetCursorClient(root_window_);
+ if (cursor_client)
+ cursor_client->ShowCursor(true);
is_on_zooming_ = false;
}
diff --git a/ash/shell.cc b/ash/shell.cc
index d1cfb73..77451c4 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -203,8 +203,6 @@ Shell::~Shell() {
if (active_root_window_)
active_root_window_->GetFocusManager()->SetFocusedWindow(NULL, NULL);
- cursor_manager_.set_delegate(NULL);
-
// Please keep in same order as in Init() because it's easy to miss one.
RemoveEnvEventFilter(user_activity_detector_.get());
RemoveEnvEventFilter(event_rewriter_filter_.get());
@@ -355,8 +353,6 @@ void Shell::Init() {
env_filter_.reset(new aura::shared::CompoundEventFilter);
AddEnvEventFilter(env_filter_.get());
- cursor_manager_.set_delegate(this);
-
focus_manager_.reset(new aura::FocusManager);
activation_controller_.reset(
new internal::ActivationController(focus_manager_.get()));
@@ -738,20 +734,6 @@ void Shell::InitRootWindowController(
////////////////////////////////////////////////////////////////////////////////
// Shell, private:
-void Shell::SetCursor(gfx::NativeCursor cursor) {
- RootWindowList root_windows = GetAllRootWindows();
- for (RootWindowList::iterator iter = root_windows.begin();
- iter != root_windows.end(); ++iter)
- (*iter)->SetCursor(cursor);
-}
-
-void Shell::ShowCursor(bool visible) {
- RootWindowList root_windows = GetAllRootWindows();
- for (RootWindowList::iterator iter = root_windows.begin();
- iter != root_windows.end(); ++iter)
- (*iter)->ShowCursor(visible);
-}
-
bool Shell::CanWindowReceiveEvents(aura::Window* window) {
RootWindowControllerList controllers = GetAllRootWindowControllers();
for (RootWindowControllerList::iterator iter = controllers.begin();
diff --git a/ash/shell.h b/ash/shell.h
index 5200854..d56e56f 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -10,7 +10,6 @@
#include "ash/ash_export.h"
#include "ash/system/user/login_status.h"
-#include "ash/wm/cursor_delegate.h"
#include "ash/wm/cursor_manager.h"
#include "ash/wm/shelf_types.h"
#include "ash/wm/system_modal_container_event_filter_delegate.h"
@@ -113,8 +112,7 @@ class WorkspaceController;
//
// Upon creation, the Shell sets itself as the RootWindow's delegate, which
// takes ownership of the Shell.
-class ASH_EXPORT Shell : CursorDelegate,
- internal::SystemModalContainerEventFilterDelegate {
+class ASH_EXPORT Shell : internal::SystemModalContainerEventFilterDelegate{
public:
typedef std::vector<aura::RootWindow*> RootWindowList;
typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
@@ -400,10 +398,6 @@ class ASH_EXPORT Shell : CursorDelegate,
void InitLayoutManagersForPrimaryDisplay(
internal::RootWindowController* root_window_controller);
- // aura::CursorManager::Delegate overrides:
- virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
- virtual void ShowCursor(bool visible) OVERRIDE;
-
// ash::internal::SystemModalContainerEventFilterDelegate overrides:
virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
diff --git a/ash/wm/cursor_delegate.h b/ash/wm/cursor_delegate.h
deleted file mode 100644
index 05d901f..0000000
--- a/ash/wm/cursor_delegate.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ASH_WM_CURSOR_DELEGATE_H_
-#define ASH_WM_CURSOR_DELEGATE_H_
-
-#include "ash/ash_export.h"
-#include "ui/gfx/native_widget_types.h"
-
-namespace ash {
-
-// This interface is implmented by a platform specific object that changes
-// the cursor's image and visibility.
-class ASH_EXPORT CursorDelegate {
- public:
- virtual void SetCursor(gfx::NativeCursor cursor) = 0;
- virtual void ShowCursor(bool visible) = 0;
-
- protected:
- virtual ~CursorDelegate() {};
-};
-
-} // namespace aura
-
-#endif // ASH_WM_CURSOR_DELEGATE_H_
diff --git a/ash/wm/cursor_manager.cc b/ash/wm/cursor_manager.cc
index da2248e..d1bfa83 100644
--- a/ash/wm/cursor_manager.cc
+++ b/ash/wm/cursor_manager.cc
@@ -4,19 +4,40 @@
#include "ash/wm/cursor_manager.h"
-#include "ash/wm/cursor_delegate.h"
+#include "ash/shell.h"
#include "ash/wm/image_cursors.h"
#include "base/logging.h"
-#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
#include "ui/base/cursor/cursor.h"
+namespace {
+
+void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) {
+ ash::Shell::RootWindowList root_windows =
+ ash::Shell::GetInstance()->GetAllRootWindows();
+ for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
+ iter != root_windows.end(); ++iter)
+ (*iter)->SetCursor(cursor);
+}
+
+void NotifyCursorVisibilityChange(bool visible) {
+ ash::Shell::RootWindowList root_windows =
+ ash::Shell::GetInstance()->GetAllRootWindows();
+ for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
+ iter != root_windows.end(); ++iter)
+ (*iter)->OnCursorVisibilityChanged(visible);
+}
+
+} // namespace
+
namespace ash {
CursorManager::CursorManager()
- : delegate_(NULL),
- cursor_lock_count_(0),
+ : cursor_lock_count_(0),
did_cursor_change_(false),
cursor_to_set_on_unlock_(0),
+ did_visibility_change_(false),
+ show_on_unlock_(true),
cursor_visible_(true),
current_cursor_(ui::kCursorNone),
image_cursors_(new ImageCursors) {
@@ -25,28 +46,9 @@ CursorManager::CursorManager()
CursorManager::~CursorManager() {
}
-void CursorManager::LockCursor() {
- cursor_lock_count_++;
-}
-
-void CursorManager::UnlockCursor() {
- cursor_lock_count_--;
- DCHECK_GE(cursor_lock_count_, 0);
- if (cursor_lock_count_ == 0) {
- if (did_cursor_change_) {
- did_cursor_change_ = false;
- if (delegate_)
- SetCursorInternal(cursor_to_set_on_unlock_);
- }
- did_cursor_change_ = false;
- cursor_to_set_on_unlock_ = gfx::kNullCursor;
- }
-}
-
void CursorManager::SetCursor(gfx::NativeCursor cursor) {
if (cursor_lock_count_ == 0) {
- if (delegate_)
- SetCursorInternal(cursor);
+ SetCursorInternal(cursor);
} else {
cursor_to_set_on_unlock_ = cursor;
did_cursor_change_ = true;
@@ -54,9 +56,12 @@ void CursorManager::SetCursor(gfx::NativeCursor cursor) {
}
void CursorManager::ShowCursor(bool show) {
- cursor_visible_ = show;
- if (delegate_)
- delegate_->ShowCursor(show);
+ if (cursor_lock_count_ == 0) {
+ ShowCursorInternal(show);
+ } else {
+ show_on_unlock_ = show;
+ did_visibility_change_ = true;
+ }
}
bool CursorManager::IsCursorVisible() const {
@@ -70,13 +75,51 @@ void CursorManager::SetDeviceScaleFactor(float device_scale_factor) {
SetCursorInternal(current_cursor_);
}
+void CursorManager::LockCursor() {
+ cursor_lock_count_++;
+}
+
+void CursorManager::UnlockCursor() {
+ cursor_lock_count_--;
+ DCHECK_GE(cursor_lock_count_, 0);
+ if (cursor_lock_count_ > 0)
+ return;
+
+ if (did_cursor_change_)
+ SetCursorInternal(cursor_to_set_on_unlock_);
+ did_cursor_change_ = false;
+ cursor_to_set_on_unlock_ = gfx::kNullCursor;
+
+ if (did_visibility_change_)
+ ShowCursorInternal(show_on_unlock_);
+ did_visibility_change_ = false;
+}
+
void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) {
- DCHECK(delegate_);
current_cursor_ = cursor;
image_cursors_->SetPlatformCursor(&current_cursor_);
current_cursor_.set_device_scale_factor(
image_cursors_->GetDeviceScaleFactor());
- delegate_->SetCursor(current_cursor_);
+
+ if (cursor_visible_)
+ SetCursorOnAllRootWindows(current_cursor_);
+}
+
+void CursorManager::ShowCursorInternal(bool show) {
+ if (cursor_visible_ == show)
+ return;
+
+ cursor_visible_ = show;
+
+ if (show) {
+ SetCursorInternal(current_cursor_);
+ } else {
+ gfx::NativeCursor invisible_cursor(ui::kCursorNone);
+ image_cursors_->SetPlatformCursor(&invisible_cursor);
+ SetCursorOnAllRootWindows(invisible_cursor);
+ }
+
+ NotifyCursorVisibilityChange(show);
}
} // namespace ash
diff --git a/ash/wm/cursor_manager.h b/ash/wm/cursor_manager.h
index f2b857e..c203c70 100644
--- a/ash/wm/cursor_manager.h
+++ b/ash/wm/cursor_manager.h
@@ -18,7 +18,6 @@ namespace test {
class CursorManagerTestApi;
}
-class CursorDelegate;
class ImageCursors;
// This class controls the visibility and the type of the cursor.
@@ -29,12 +28,6 @@ class ASH_EXPORT CursorManager : public aura::client::CursorClient {
CursorManager();
virtual ~CursorManager();
- void set_delegate(CursorDelegate* delegate) { delegate_ = delegate; }
-
- // Locks/Unlocks the cursor change.
- void LockCursor();
- void UnlockCursor();
-
bool is_cursor_locked() const { return cursor_lock_count_ > 0; }
// Shows or hides the cursor.
@@ -45,25 +38,33 @@ class ASH_EXPORT CursorManager : public aura::client::CursorClient {
virtual void ShowCursor(bool show) OVERRIDE;
virtual bool IsCursorVisible() const OVERRIDE;
virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE;
+ virtual void LockCursor() OVERRIDE;
+ virtual void UnlockCursor() OVERRIDE;
private:
friend class test::CursorManagerTestApi;
void SetCursorInternal(gfx::NativeCursor cursor);
-
- CursorDelegate* delegate_;
+ void ShowCursorInternal(bool show);
// Number of times LockCursor() has been invoked without a corresponding
// UnlockCursor().
int cursor_lock_count_;
- // Set to true if UpdateCursor() is invoked while |cursor_lock_count_| == 0.
+ // Set to true if SetCursor() is invoked while |cursor_lock_count_| == 0.
bool did_cursor_change_;
// Cursor to set once |cursor_lock_count_| is set to 0. Only valid if
// |did_cursor_change_| is true.
gfx::NativeCursor cursor_to_set_on_unlock_;
+ // Set to true if ShowCursor() is invoked while |cursor_lock_count_| == 0.
+ bool did_visibility_change_;
+
+ // The visibility to set once |cursor_lock_count_| is set to 0. Only valid if
+ // |did_visibility_change_| is true.
+ bool show_on_unlock_;
+
// Is cursor visible?
bool cursor_visible_;
diff --git a/ash/wm/cursor_manager_unittest.cc b/ash/wm/cursor_manager_unittest.cc
index 79b2aea..d997b30 100644
--- a/ash/wm/cursor_manager_unittest.cc
+++ b/ash/wm/cursor_manager_unittest.cc
@@ -56,6 +56,58 @@ TEST_F(CursorManagerTest, SetCursor) {
EXPECT_TRUE(test_api.GetCurrentCursor().platform());
}
+TEST_F(CursorManagerTest, ShowCursor) {
+ CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
+ CursorManagerTestApi test_api(cursor_manager);
+
+ cursor_manager->SetCursor(ui::kCursorCopy);
+ EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
+
+ cursor_manager->ShowCursor(true);
+ EXPECT_TRUE(cursor_manager->cursor_visible());
+ cursor_manager->ShowCursor(false);
+ EXPECT_FALSE(cursor_manager->cursor_visible());
+ // The current cursor does not change even when the cursor is not shown.
+ EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
+
+ // Check if cursor visibility is locked.
+ cursor_manager->LockCursor();
+ EXPECT_FALSE(cursor_manager->cursor_visible());
+ cursor_manager->ShowCursor(true);
+ EXPECT_FALSE(cursor_manager->cursor_visible());
+ cursor_manager->UnlockCursor();
+ EXPECT_TRUE(cursor_manager->cursor_visible());
+
+ cursor_manager->LockCursor();
+ EXPECT_TRUE(cursor_manager->cursor_visible());
+ cursor_manager->ShowCursor(false);
+ EXPECT_TRUE(cursor_manager->cursor_visible());
+ cursor_manager->UnlockCursor();
+ EXPECT_FALSE(cursor_manager->cursor_visible());
+
+ // Checks setting visiblity while cursor is locked does not affect the
+ // subsequent uses of UnlockCursor.
+ cursor_manager->LockCursor();
+ cursor_manager->ShowCursor(false);
+ cursor_manager->UnlockCursor();
+ EXPECT_FALSE(cursor_manager->cursor_visible());
+
+ cursor_manager->ShowCursor(true);
+ cursor_manager->LockCursor();
+ cursor_manager->UnlockCursor();
+ EXPECT_TRUE(cursor_manager->cursor_visible());
+
+ cursor_manager->LockCursor();
+ cursor_manager->ShowCursor(true);
+ cursor_manager->UnlockCursor();
+ EXPECT_TRUE(cursor_manager->cursor_visible());
+
+ cursor_manager->ShowCursor(false);
+ cursor_manager->LockCursor();
+ cursor_manager->UnlockCursor();
+ EXPECT_FALSE(cursor_manager->cursor_visible());
+}
+
TEST_F(CursorManagerTest, SetDeviceScaleFactor) {
CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
CursorManagerTestApi test_api(cursor_manager);
diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc
index b99bbb8..b7ceac1 100644
--- a/ash/wm/window_manager_unittest.cc
+++ b/ash/wm/window_manager_unittest.cc
@@ -598,6 +598,10 @@ TEST_F(WindowManagerTest, UpdateCursorVisibility) {
ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime());
ui::TouchEvent touch_pressed2(
ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime());
+ ui::TouchEvent touch_released1(
+ ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 0, getTime());
+ ui::TouchEvent touch_released2(
+ ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 1, getTime());
root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved);
EXPECT_TRUE(cursor_manager->cursor_visible());
@@ -605,6 +609,8 @@ TEST_F(WindowManagerTest, UpdateCursorVisibility) {
EXPECT_FALSE(cursor_manager->cursor_visible());
root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved);
EXPECT_TRUE(cursor_manager->cursor_visible());
+ root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released1);
+ EXPECT_TRUE(cursor_manager->cursor_visible());
// If someone else made cursor invisible keep it invisible even after it
// received mouse events.
@@ -615,6 +621,8 @@ TEST_F(WindowManagerTest, UpdateCursorVisibility) {
EXPECT_FALSE(cursor_manager->cursor_visible());
root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved);
EXPECT_FALSE(cursor_manager->cursor_visible());
+ root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2);
+ EXPECT_FALSE(cursor_manager->cursor_visible());
// Back to normal.
cursor_manager->ShowCursor(true);
@@ -624,6 +632,8 @@ TEST_F(WindowManagerTest, UpdateCursorVisibility) {
EXPECT_FALSE(cursor_manager->cursor_visible());
root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved);
EXPECT_TRUE(cursor_manager->cursor_visible());
+ root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2);
+ EXPECT_TRUE(cursor_manager->cursor_visible());
}
} // namespace ash
diff --git a/ui/aura/client/cursor_client.h b/ui/aura/client/cursor_client.h
index ecf67ee..3f970b0 100644
--- a/ui/aura/client/cursor_client.h
+++ b/ui/aura/client/cursor_client.h
@@ -27,6 +27,15 @@ class AURA_EXPORT CursorClient {
// Sets the device scale factor of the cursor.
virtual void SetDeviceScaleFactor(float device_scale_factor) = 0;
+ // Locks the cursor change. The cursor type and cursor visibility never change
+ // as long as lock is held by anyone.
+ virtual void LockCursor() = 0;
+
+ // Unlocks the cursor change. If all the locks are released, the cursor type
+ // and visibility are restored to the ones set by the lastest call of
+ // SetCursor and ShowCursor.
+ virtual void UnlockCursor() = 0;
+
protected:
virtual ~CursorClient() {}
};
diff --git a/ui/aura/desktop/desktop_cursor_client.cc b/ui/aura/desktop/desktop_cursor_client.cc
index 7077483..36e8f88 100644
--- a/ui/aura/desktop/desktop_cursor_client.cc
+++ b/ui/aura/desktop/desktop_cursor_client.cc
@@ -11,23 +11,34 @@ namespace aura {
DesktopCursorClient::DesktopCursorClient(aura::RootWindow* window)
: root_window_(window),
- cursor_loader_(ui::CursorLoader::Create()) {
+ cursor_loader_(ui::CursorLoader::Create()),
+ current_cursor_(ui::kCursorNone),
+ cursor_visible_(true) {
}
DesktopCursorClient::~DesktopCursorClient() {
}
void DesktopCursorClient::SetCursor(gfx::NativeCursor cursor) {
- cursor_loader_->SetPlatformCursor(&cursor);
- root_window_->SetCursor(cursor);
+ current_cursor_ = cursor;
+ cursor_loader_->SetPlatformCursor(&current_cursor_);
+ if (cursor_visible_)
+ root_window_->SetCursor(current_cursor_);
}
void DesktopCursorClient::ShowCursor(bool show) {
- root_window_->ShowCursor(show);
+ if (cursor_visible_ == show)
+ return;
+ cursor_visible_ = show;
+ if (cursor_visible_)
+ root_window_->SetCursor(current_cursor_);
+ else
+ root_window_->SetCursor(ui::kCursorNone);
+ root_window_->OnCursorVisibilityChanged(cursor_visible_);
}
bool DesktopCursorClient::IsCursorVisible() const {
- return root_window_->cursor_shown();
+ return cursor_visible_;
}
void DesktopCursorClient::SetDeviceScaleFactor(float device_scale_factor) {
@@ -35,4 +46,14 @@ void DesktopCursorClient::SetDeviceScaleFactor(float device_scale_factor) {
cursor_loader_->set_device_scale_factor(device_scale_factor);
}
+void DesktopCursorClient::LockCursor() {
+ // TODO(mazda): Implement this.
+ NOTIMPLEMENTED();
+}
+
+void DesktopCursorClient::UnlockCursor() {
+ // TODO(mazda): Implement this.
+ NOTIMPLEMENTED();
+}
+
} // namespace aura
diff --git a/ui/aura/desktop/desktop_cursor_client.h b/ui/aura/desktop/desktop_cursor_client.h
index 0bc49c4..0f292e2 100644
--- a/ui/aura/desktop/desktop_cursor_client.h
+++ b/ui/aura/desktop/desktop_cursor_client.h
@@ -29,11 +29,16 @@ class AURA_EXPORT DesktopCursorClient : public client::CursorClient {
virtual void ShowCursor(bool show) OVERRIDE;
virtual bool IsCursorVisible() const OVERRIDE;
virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE;
+ virtual void LockCursor() OVERRIDE;
+ virtual void UnlockCursor() OVERRIDE;
private:
aura::RootWindow* root_window_;
scoped_ptr<ui::CursorLoader> cursor_loader_;
+ gfx::NativeCursor current_cursor_;
+ bool cursor_visible_;
+
DISALLOW_COPY_AND_ASSIGN(DesktopCursorClient);
};
diff --git a/ui/aura/remote_root_window_host_win.cc b/ui/aura/remote_root_window_host_win.cc
index de3ccd8..619b783 100644
--- a/ui/aura/remote_root_window_host_win.cc
+++ b/ui/aura/remote_root_window_host_win.cc
@@ -94,9 +94,6 @@ void RemoteRootWindowHostWin::SetCapture() {
void RemoteRootWindowHostWin::ReleaseCapture() {
}
-void RemoteRootWindowHostWin::ShowCursor(bool show) {
-}
-
bool RemoteRootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) {
POINT pt;
GetCursorPos(&pt);
@@ -156,4 +153,3 @@ void RemoteRootWindowHostWin::OnMouseClick(int x, int y, int extra) {
}
} // namespace aura
-
diff --git a/ui/aura/remote_root_window_host_win.h b/ui/aura/remote_root_window_host_win.h
index 52990c9..795af0f 100644
--- a/ui/aura/remote_root_window_host_win.h
+++ b/ui/aura/remote_root_window_host_win.h
@@ -42,7 +42,6 @@ class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost {
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
- virtual void ShowCursor(bool show) OVERRIDE;
virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;
@@ -64,4 +63,3 @@ class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost {
} // namespace aura
#endif // UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_
-
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index c9cdbbd..205da39 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -131,9 +131,6 @@ RootWindow::RootWindow(const CreateParams& params)
mouse_button_flags_(0),
touch_ids_down_(0),
last_cursor_(ui::kCursorNull),
- // TODO(ivankr): this currently tracks the default state in
- // RootWindowHostLinux. Other platforms do not implement ShowCursor().
- cursor_shown_(true),
mouse_pressed_handler_(NULL),
mouse_moved_handler_(NULL),
mouse_event_dispatch_target_(NULL),
@@ -260,15 +257,11 @@ void RootWindow::SetCursor(gfx::NativeCursor cursor) {
host_->SetCursor(cursor);
}
-void RootWindow::ShowCursor(bool show) {
+void RootWindow::OnCursorVisibilityChanged(bool 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();
- }
+ Env::GetInstance()->SetCursorShown(show);
+ PostMouseMoveEventAfterWindowChange();
}
void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) {
@@ -542,19 +535,23 @@ void RootWindow::OnDeviceScaleFactorChanged(
float device_scale_factor) {
const bool cursor_is_in_bounds =
GetBoundsInScreen().Contains(Env::GetInstance()->last_mouse_location());
- if (cursor_is_in_bounds && cursor_shown_)
- ShowCursor(false);
+ bool cursor_visible = false;
+ client::CursorClient* cursor_client = client::GetCursorClient(this);
+ if (cursor_is_in_bounds && cursor_client) {
+ cursor_visible = cursor_client->IsCursorVisible();
+ if (cursor_visible)
+ cursor_client->ShowCursor(false);
+ }
host_->OnDeviceScaleFactorChanged(device_scale_factor);
Window::OnDeviceScaleFactorChanged(device_scale_factor);
// Update the device scale factor of the cursor client only when the last
// mouse location is on this root window.
if (cursor_is_in_bounds) {
- client::CursorClient* cursor_client = client::GetCursorClient(this);
if (cursor_client)
cursor_client->SetDeviceScaleFactor(device_scale_factor);
}
- if (cursor_is_in_bounds && cursor_shown_)
- ShowCursor(true);
+ if (cursor_is_in_bounds && cursor_client && cursor_visible)
+ cursor_client->ShowCursor(true);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 2e12218..b28e79e 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -107,7 +107,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
ui::Compositor* compositor() { return compositor_.get(); }
gfx::NativeCursor last_cursor() const { return last_cursor_; }
Window* mouse_pressed_handler() { return mouse_pressed_handler_; }
- bool cursor_shown() const { return cursor_shown_; }
void set_focus_manager(FocusManager* focus_manager) {
focus_manager_ = focus_manager;
@@ -143,8 +142,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// used.
void SetCursor(gfx::NativeCursor cursor);
- // Shows or hides the cursor.
- void ShowCursor(bool show);
+ // Invoked when the cursor's visibility has changed.
+ void OnCursorVisibilityChanged(bool visible);
// Moves the cursor to the specified location relative to the root window.
virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
@@ -382,9 +381,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Last cursor set. Used for testing.
gfx::NativeCursor last_cursor_;
- // Is the cursor currently shown? Used for testing.
- bool cursor_shown_;
-
ObserverList<RootWindowObserver> observers_;
Window* mouse_pressed_handler_;
diff --git a/ui/aura/root_window_host.h b/ui/aura/root_window_host.h
index 001e812..1b6e483 100644
--- a/ui/aura/root_window_host.h
+++ b/ui/aura/root_window_host.h
@@ -70,9 +70,6 @@ class AURA_EXPORT RootWindowHost {
// Sets the currently displayed cursor.
virtual void SetCursor(gfx::NativeCursor cursor) = 0;
- // Shows or hides the cursor.
- virtual void ShowCursor(bool show) = 0;
-
// Queries the mouse's current position relative to the host window and sets
// it in |location_return|. Returns true if the cursor is within the host
// window. The position set to |location_return| is constrained within the
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index e21c870..83dcee0 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -282,8 +282,6 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
x_root_window_(DefaultRootWindow(xdisplay_)),
current_cursor_(ui::kCursorNull),
window_mapped_(false),
- cursor_shown_(true),
- invisible_cursor_(ui::CreateInvisibleCursor(), xdisplay_),
bounds_(bounds),
focus_when_shown_(false),
pointer_barriers_(NULL),
@@ -741,16 +739,7 @@ void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) {
if (cursor == current_cursor_)
return;
current_cursor_ = cursor;
-
- if (cursor_shown_)
- SetCursorInternal(cursor);
-}
-
-void RootWindowHostLinux::ShowCursor(bool show) {
- if (show == cursor_shown_)
- return;
- cursor_shown_ = show;
- SetCursorInternal(show ? current_cursor_ : invisible_cursor_.get());
+ SetCursorInternal(cursor);
}
bool RootWindowHostLinux::QueryMouseLocation(gfx::Point* location_return) {
diff --git a/ui/aura/root_window_host_linux.h b/ui/aura/root_window_host_linux.h
index 6858eeb..808475f 100644
--- a/ui/aura/root_window_host_linux.h
+++ b/ui/aura/root_window_host_linux.h
@@ -57,7 +57,6 @@ class RootWindowHostLinux : public RootWindowHost,
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE;
- virtual void ShowCursor(bool show) OVERRIDE;
virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;
@@ -98,12 +97,6 @@ class RootWindowHostLinux : public RootWindowHost,
// Is the window mapped to the screen?
bool window_mapped_;
- // Is the cursor currently shown?
- bool cursor_shown_;
-
- // The invisible cursor.
- ui::XScopedCursor invisible_cursor_;
-
// The bounds of |xwindow_|.
gfx::Rect bounds_;
diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc
index 5978f21..df387cf 100644
--- a/ui/aura/root_window_host_win.cc
+++ b/ui/aura/root_window_host_win.cc
@@ -160,10 +160,6 @@ void RootWindowHostWin::ReleaseCapture() {
}
}
-void RootWindowHostWin::ShowCursor(bool show) {
- // NOTIMPLEMENTED();
-}
-
bool RootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) {
POINT pt;
GetCursorPos(&pt);
diff --git a/ui/aura/root_window_host_win.h b/ui/aura/root_window_host_win.h
index fa4533b..7d02de6 100644
--- a/ui/aura/root_window_host_win.h
+++ b/ui/aura/root_window_host_win.h
@@ -28,7 +28,6 @@ class RootWindowHostWin : public RootWindowHost, public ui::WindowImpl {
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
- virtual void ShowCursor(bool show) OVERRIDE;
virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;
diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc
index 5c8f3f7..20e7cbb 100644
--- a/ui/aura/root_window_unittest.cc
+++ b/ui/aura/root_window_unittest.cc
@@ -189,7 +189,7 @@ TEST_F(RootWindowTest, HideCursor) {
delegate.get(), -1234, bounds, NULL));
aura::Window* window_ptr = &*window;
- root_window()->ShowCursor(true);
+ root_window()->OnCursorVisibilityChanged(true);
// Send a mouse event to window.
gfx::Point point(101, 201);
gfx::Point local_point;
@@ -202,14 +202,14 @@ TEST_F(RootWindowTest, HideCursor) {
EXPECT_TRUE(window->bounds().Contains(local_point));
// Location is now out of window.
- root_window()->ShowCursor(false);
+ root_window()->OnCursorVisibilityChanged(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);
+ root_window()->OnCursorVisibilityChanged(true);
RunAllPendingInMessageLoop();
local_point = delegate->mouse_event_location();
aura::Window::ConvertPointToTarget(window_ptr, root_window(), &local_point);
diff --git a/ui/aura/shared/compound_event_filter_unittest.cc b/ui/aura/shared/compound_event_filter_unittest.cc
index 4b56fc4..b23b57c 100644
--- a/ui/aura/shared/compound_event_filter_unittest.cc
+++ b/ui/aura/shared/compound_event_filter_unittest.cc
@@ -40,6 +40,12 @@ class TestVisibleClient : public aura::client::CursorClient {
virtual void SetDeviceScaleFactor(float scale_factor) OVERRIDE {
}
+ virtual void LockCursor() OVERRIDE {
+ }
+
+ virtual void UnlockCursor() OVERRIDE {
+ }
+
private:
bool visible_;
};
diff --git a/ui/views/widget/desktop_root_window_host_linux.cc b/ui/views/widget/desktop_root_window_host_linux.cc
index 3b3df6d..25d9846 100644
--- a/ui/views/widget/desktop_root_window_host_linux.cc
+++ b/ui/views/widget/desktop_root_window_host_linux.cc
@@ -682,13 +682,6 @@ void DesktopRootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) {
SetCursorInternal(cursor);
}
-void DesktopRootWindowHostLinux::ShowCursor(bool show) {
- if (show == cursor_shown_)
- return;
- cursor_shown_ = show;
- SetCursorInternal(show ? current_cursor_ : invisible_cursor_);
-}
-
bool DesktopRootWindowHostLinux::QueryMouseLocation(
gfx::Point* location_return) {
::Window root_return, child_return;
@@ -782,6 +775,13 @@ void DesktopRootWindowHostLinux::PrepareForShutdown() {
////////////////////////////////////////////////////////////////////////////////
// DesktopRootWindowHostLinux, aura::CursorClient implementation:
+void DesktopRootWindowHostLinux::ShowCursor(bool show) {
+ if (show == cursor_shown_)
+ return;
+ cursor_shown_ = show;
+ SetCursorInternal(show ? current_cursor_ : invisible_cursor_);
+}
+
bool DesktopRootWindowHostLinux::IsCursorVisible() const {
return cursor_shown_;
}
@@ -792,6 +792,16 @@ void DesktopRootWindowHostLinux::SetDeviceScaleFactor(
cursor_loader_.set_device_scale_factor(device_scale_factor);
}
+void DesktopRootWindowHostLinux::LockCursor() {
+ // TODO(mazda): Implement this.
+ NOTIMPLEMENTED();
+}
+
+void DesktopRootWindowHostLinux::UnlockCursor() {
+ // TODO(mazda): Implement this.
+ NOTIMPLEMENTED();
+}
+
////////////////////////////////////////////////////////////////////////////////
// DesktopRootWindowHostLinux, views::internal::InputMethodDelegate:
diff --git a/ui/views/widget/desktop_root_window_host_linux.h b/ui/views/widget/desktop_root_window_host_linux.h
index a322353..b7d0c91 100644
--- a/ui/views/widget/desktop_root_window_host_linux.h
+++ b/ui/views/widget/desktop_root_window_host_linux.h
@@ -146,7 +146,6 @@ class VIEWS_EXPORT DesktopRootWindowHostLinux
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
- virtual void ShowCursor(bool show) OVERRIDE;
virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;
@@ -161,8 +160,11 @@ class VIEWS_EXPORT DesktopRootWindowHostLinux
// Overridden from aura::CursorClient:
// Note: other methods are just set on aura::RootWindowHost:
+ virtual void ShowCursor(bool show) OVERRIDE;
virtual bool IsCursorVisible() const OVERRIDE;
virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE;
+ virtual void LockCursor() OVERRIDE;
+ virtual void UnlockCursor() OVERRIDE;
// Overridden from views::internal::InputMethodDelegate:
virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
diff --git a/ui/views/widget/desktop_root_window_host_win.cc b/ui/views/widget/desktop_root_window_host_win.cc
index bd79a34..88826a8 100644
--- a/ui/views/widget/desktop_root_window_host_win.cc
+++ b/ui/views/widget/desktop_root_window_host_win.cc
@@ -373,9 +373,6 @@ void DesktopRootWindowHostWin::SetCursor(gfx::NativeCursor cursor) {
message_handler_->SetCursor(cursor.platform());
}
-void DesktopRootWindowHostWin::ShowCursor(bool show) {
-}
-
bool DesktopRootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) {
return false;
}
diff --git a/ui/views/widget/desktop_root_window_host_win.h b/ui/views/widget/desktop_root_window_host_win.h
index 1481e2e..d40f4b5 100644
--- a/ui/views/widget/desktop_root_window_host_win.h
+++ b/ui/views/widget/desktop_root_window_host_win.h
@@ -107,7 +107,6 @@ class VIEWS_EXPORT DesktopRootWindowHostWin
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
- virtual void ShowCursor(bool show) OVERRIDE;
virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;