Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: ash/wm/cursor_manager.cc

Issue 11035050: Enable CursorManager::LockCursor to lock cursor visibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/cursor_manager.h" 5 #include "ash/wm/cursor_manager.h"
6 6
7 #include "ash/wm/cursor_delegate.h" 7 #include "ash/shell.h"
8 #include "ash/wm/image_cursors.h" 8 #include "ash/wm/image_cursors.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/aura/env.h" 10 #include "ui/aura/root_window.h"
11 #include "ui/base/cursor/cursor.h" 11 #include "ui/base/cursor/cursor.h"
12 12
13 namespace {
14
15 void SetRootWindowsCursor(gfx::NativeCursor cursor) {
oshima 2012/10/09 23:08:38 SetCursorOnAllRootWindows would be better
mazda 2012/10/10 00:59:12 Done.
16 ash::Shell::RootWindowList root_windows =
17 ash::Shell::GetInstance()->GetAllRootWindows();
18 for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
19 iter != root_windows.end(); ++iter)
20 (*iter)->SetCursor(cursor);
21 }
22
23 void NotifyCursorVisibilityChange(bool visible) {
24 ash::Shell::RootWindowList root_windows =
25 ash::Shell::GetInstance()->GetAllRootWindows();
26 for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
27 iter != root_windows.end(); ++iter)
28 (*iter)->OnCursorVisibilityChanged(visible);
29 }
30
31 } // namespace
32
13 namespace ash { 33 namespace ash {
14 34
15 CursorManager::CursorManager() 35 CursorManager::CursorManager()
16 : delegate_(NULL), 36 : cursor_lock_count_(0),
17 cursor_lock_count_(0),
18 did_cursor_change_(false), 37 did_cursor_change_(false),
19 cursor_to_set_on_unlock_(0), 38 cursor_to_set_on_unlock_(0),
39 did_visibility_change_(false),
40 show_on_unlock_(true),
20 cursor_visible_(true), 41 cursor_visible_(true),
21 current_cursor_(ui::kCursorNone), 42 current_cursor_(ui::kCursorNone),
22 image_cursors_(new ImageCursors) { 43 image_cursors_(new ImageCursors) {
23 } 44 }
24 45
25 CursorManager::~CursorManager() { 46 CursorManager::~CursorManager() {
26 } 47 }
27 48
28 void CursorManager::LockCursor() { 49 void CursorManager::LockCursor() {
29 cursor_lock_count_++; 50 cursor_lock_count_++;
30 } 51 }
31 52
32 void CursorManager::UnlockCursor() { 53 void CursorManager::UnlockCursor() {
33 cursor_lock_count_--; 54 cursor_lock_count_--;
34 DCHECK_GE(cursor_lock_count_, 0); 55 DCHECK_GE(cursor_lock_count_, 0);
35 if (cursor_lock_count_ == 0) { 56 if (cursor_lock_count_ > 0)
36 if (did_cursor_change_) { 57 return;
37 did_cursor_change_ = false; 58
38 if (delegate_) 59 if (did_cursor_change_)
39 SetCursorInternal(cursor_to_set_on_unlock_); 60 SetCursorInternal(cursor_to_set_on_unlock_);
40 } 61 did_cursor_change_ = false;
41 did_cursor_change_ = false; 62 cursor_to_set_on_unlock_ = gfx::kNullCursor;
42 cursor_to_set_on_unlock_ = gfx::kNullCursor; 63
43 } 64 if (did_visibility_change_)
65 ShowCursorInternal(show_on_unlock_);
66 did_visibility_change_ = false;
44 } 67 }
45 68
46 void CursorManager::SetCursor(gfx::NativeCursor cursor) { 69 void CursorManager::SetCursor(gfx::NativeCursor cursor) {
47 if (cursor_lock_count_ == 0) { 70 if (cursor_lock_count_ == 0) {
48 if (delegate_) 71 SetCursorInternal(cursor);
49 SetCursorInternal(cursor);
50 } else { 72 } else {
51 cursor_to_set_on_unlock_ = cursor; 73 cursor_to_set_on_unlock_ = cursor;
52 did_cursor_change_ = true; 74 did_cursor_change_ = true;
53 } 75 }
54 } 76 }
55 77
56 void CursorManager::ShowCursor(bool show) { 78 void CursorManager::ShowCursor(bool show) {
57 cursor_visible_ = show; 79 if (cursor_lock_count_ == 0) {
58 if (delegate_) 80 ShowCursorInternal(show);
59 delegate_->ShowCursor(show); 81 } else {
82 show_on_unlock_ = show;
83 did_visibility_change_ = true;
84 }
60 } 85 }
61 86
62 bool CursorManager::IsCursorVisible() const { 87 bool CursorManager::IsCursorVisible() const {
63 return cursor_visible_; 88 return cursor_visible_;
64 } 89 }
65 90
66 void CursorManager::SetDeviceScaleFactor(float device_scale_factor) { 91 void CursorManager::SetDeviceScaleFactor(float device_scale_factor) {
67 if (image_cursors_->GetDeviceScaleFactor() == device_scale_factor) 92 if (image_cursors_->GetDeviceScaleFactor() == device_scale_factor)
68 return; 93 return;
69 image_cursors_->SetDeviceScaleFactor(device_scale_factor); 94 image_cursors_->SetDeviceScaleFactor(device_scale_factor);
70 SetCursorInternal(current_cursor_); 95 SetCursorInternal(current_cursor_);
71 } 96 }
72 97
73 void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) { 98 void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) {
74 DCHECK(delegate_);
75 current_cursor_ = cursor; 99 current_cursor_ = cursor;
76 image_cursors_->SetPlatformCursor(&current_cursor_); 100 image_cursors_->SetPlatformCursor(&current_cursor_);
77 current_cursor_.set_device_scale_factor( 101 current_cursor_.set_device_scale_factor(
78 image_cursors_->GetDeviceScaleFactor()); 102 image_cursors_->GetDeviceScaleFactor());
79 delegate_->SetCursor(current_cursor_); 103
104 if (cursor_visible_)
105 SetRootWindowsCursor(current_cursor_);
106 }
107
108 void CursorManager::ShowCursorInternal(bool show) {
109 if (cursor_visible_ == show)
110 return;
111
112 cursor_visible_ = show;
113
114 if (show) {
115 SetCursorInternal(current_cursor_);
116 } else {
117 gfx::NativeCursor invisible_cursor(ui::kCursorNone);
118 image_cursors_->SetPlatformCursor(&invisible_cursor);
119 invisible_cursor.set_device_scale_factor(
120 image_cursors_->GetDeviceScaleFactor());
oshima 2012/10/09 23:08:38 can you explain why we need to set the scale facto
mazda 2012/10/10 00:59:12 This isn't necessary in practice. I just wanted to
121 SetRootWindowsCursor(invisible_cursor);
122 }
123
124 NotifyCursorVisibilityChange(show);
80 } 125 }
81 126
82 } // namespace ash 127 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698