Index: ash/wm/cursor_manager.cc |
diff --git a/ash/wm/cursor_manager.cc b/ash/wm/cursor_manager.cc |
index b25105172d2e9011cadedc603ee297e5479a770a..3de6660a9fa1f067f9960779d1704154121d07b6 100644 |
--- a/ash/wm/cursor_manager.cc |
+++ b/ash/wm/cursor_manager.cc |
@@ -6,12 +6,18 @@ |
#include "ash/shell.h" |
#include "ash/wm/image_cursors.h" |
+#include "base/basictypes.h" |
#include "base/logging.h" |
+#include "ui/aura/env.h" |
#include "ui/aura/root_window.h" |
#include "ui/base/cursor/cursor.h" |
namespace { |
+// The coordinate of the cursor used when the cursor is disabled. |
+const int kDisabledCursorLocationX = -10000; |
+const int kDisabledCursorLocationY = -10000; |
+ |
void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { |
ash::Shell::RootWindowList root_windows = |
ash::Shell::GetInstance()->GetAllRootWindows(); |
@@ -20,26 +26,73 @@ void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { |
(*iter)->SetCursor(cursor); |
} |
-void NotifyCursorVisibilityChange(bool visible) { |
+void NotifyCursorEnableStateChange(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); |
+ (*iter)->OnCursorEnableStateChanged(visible); |
} |
} // namespace |
namespace ash { |
+namespace internal { |
+ |
+// Represents the cursor state which is composed of cursor type, visibility, and |
+// enabled state. When the cursor is disabled, the cursor is always invisible. |
+// In other words, the cursor cannot be disabled and visible at the same time. |
+class CursorState { |
+ public: |
+ explicit CursorState(gfx::NativeCursor cursor) |
+ : cursor_(cursor), |
+ visible_(true), |
+ enabled_(true), |
+ visible_on_enabled_(true) { |
+ } |
+ |
+ gfx::NativeCursor cursor() const { return cursor_; } |
+ void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; } |
+ |
+ bool visible() const { return visible_; } |
+ void SetVisible(bool visible) { |
+ if (enabled_) |
+ visible_ = visible; |
+ // Ignores the call when the cursor is disabled. |
+ } |
+ |
+ bool enabled() const { return enabled_; } |
+ void SetEnabled(bool enabled) { |
+ enabled_ = enabled; |
+ |
+ // Restores the visibility when the cursor is enabled. |
+ if (enabled) { |
+ visible_ = visible_on_enabled_; |
+ } else { |
+ visible_on_enabled_ = visible_; |
+ visible_ = false; |
+ } |
+ } |
+ |
+ private: |
+ gfx::NativeCursor cursor_; |
+ bool visible_; |
+ bool enabled_; |
+ |
+ // The visibility to set when the cursor is enabled. |
+ bool visible_on_enabled_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CursorState); |
+}; |
+ |
+} // namespace internal |
CursorManager::CursorManager() |
: 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), |
+ cursor_enabled_(true), |
current_cursor_(ui::kCursorNone), |
+ state_on_unlock_(new internal::CursorState(ui::kCursorNone)), |
image_cursors_(new ImageCursors) { |
} |
@@ -47,27 +100,27 @@ CursorManager::~CursorManager() { |
} |
void CursorManager::SetCursor(gfx::NativeCursor cursor) { |
- if (cursor_lock_count_ == 0) { |
- SetCursorInternal(cursor); |
- } else { |
- cursor_to_set_on_unlock_ = cursor; |
- did_cursor_change_ = true; |
- } |
+ state_on_unlock_->set_cursor(cursor); |
+ if (cursor_lock_count_ == 0) |
+ SetCursorInternal(state_on_unlock_->cursor()); |
} |
void CursorManager::ShowCursor(bool show) { |
- if (cursor_lock_count_ == 0) { |
- ShowCursorInternal(show); |
- } else { |
- show_on_unlock_ = show; |
- did_visibility_change_ = true; |
- } |
+ state_on_unlock_->SetVisible(show); |
+ if (cursor_lock_count_ == 0) |
+ ShowCursorInternal(state_on_unlock_->visible()); |
} |
bool CursorManager::IsCursorVisible() const { |
return cursor_visible_; |
} |
+void CursorManager::EnableCursor(bool enabled) { |
+ state_on_unlock_->SetEnabled(enabled); |
+ if (cursor_lock_count_ == 0) |
+ EnableCursorInternal(state_on_unlock_->enabled()); |
+} |
+ |
void CursorManager::SetDeviceScaleFactor(float device_scale_factor) { |
if (image_cursors_->SetDeviceScaleFactor(device_scale_factor)) |
SetCursorInternal(current_cursor_); |
@@ -83,14 +136,14 @@ void CursorManager::UnlockCursor() { |
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 (current_cursor_ != state_on_unlock_->cursor()) |
+ SetCursorInternal(state_on_unlock_->cursor()); |
+ |
+ if (cursor_enabled_ != state_on_unlock_->enabled()) |
+ EnableCursorInternal(state_on_unlock_->enabled()); |
- if (did_visibility_change_) |
- ShowCursorInternal(show_on_unlock_); |
- did_visibility_change_ = false; |
+ if (cursor_visible_ != state_on_unlock_->visible()) |
+ ShowCursorInternal(state_on_unlock_->visible()); |
oshima
2012/12/06 18:55:46
It'd be better to have "current_state_", and
"stat
mazda
2012/12/07 20:50:51
That's a good idea to have current_state_ and I ch
|
} |
void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) { |
@@ -116,8 +169,25 @@ void CursorManager::ShowCursorInternal(bool show) { |
image_cursors_->SetPlatformCursor(&invisible_cursor); |
SetCursorOnAllRootWindows(invisible_cursor); |
} |
+} |
- NotifyCursorVisibilityChange(show); |
+void CursorManager::EnableCursorInternal(bool enabled) { |
+ if (cursor_enabled_ == enabled) |
+ return; |
+ |
+ cursor_enabled_ = enabled; |
+ |
+ if (enabled) { |
+ aura::Env::GetInstance()->set_last_mouse_location( |
+ disabled_cursor_location_); |
+ } else { |
+ disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); |
+ aura::Env::GetInstance()->set_last_mouse_location( |
+ gfx::Point(kDisabledCursorLocationX, kDisabledCursorLocationY)); |
+ } |
+ ShowCursorInternal(state_on_unlock_->visible()); |
+ NotifyCursorEnableStateChange(enabled); |
} |
+ |
} // namespace ash |