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

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

Issue 10919135: Move ash specific cursor code to CursorManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comment Created 8 years, 3 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/wm/cursor_delegate.h"
8 #include "ash/wm/image_cursors.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "ui/aura/env.h" 10 #include "ui/aura/env.h"
11 #include "ui/base/cursor/cursor.h"
10 12
11 namespace ash { 13 namespace ash {
12 14
13 CursorManager::CursorManager() 15 CursorManager::CursorManager()
14 : delegate_(NULL), 16 : delegate_(NULL),
15 cursor_lock_count_(0), 17 cursor_lock_count_(0),
16 did_cursor_change_(false), 18 did_cursor_change_(false),
17 cursor_to_set_on_unlock_(0), 19 cursor_to_set_on_unlock_(0),
18 cursor_visible_(true) { 20 cursor_visible_(true),
21 current_cursor_(ui::kCursorNone),
22 image_cursors_(new ImageCursors) {
19 } 23 }
20 24
21 CursorManager::~CursorManager() { 25 CursorManager::~CursorManager() {
22 } 26 }
23 27
24 void CursorManager::LockCursor() { 28 void CursorManager::LockCursor() {
25 cursor_lock_count_++; 29 cursor_lock_count_++;
26 } 30 }
27 31
28 void CursorManager::UnlockCursor() { 32 void CursorManager::UnlockCursor() {
29 cursor_lock_count_--; 33 cursor_lock_count_--;
30 DCHECK_GE(cursor_lock_count_, 0); 34 DCHECK_GE(cursor_lock_count_, 0);
31 if (cursor_lock_count_ == 0) { 35 if (cursor_lock_count_ == 0) {
32 if (did_cursor_change_) { 36 if (did_cursor_change_) {
33 did_cursor_change_ = false; 37 did_cursor_change_ = false;
34 if (delegate_) 38 if (delegate_)
35 delegate_->SetCursor(cursor_to_set_on_unlock_); 39 delegate_->SetCursor(cursor_to_set_on_unlock_);
36 } 40 }
37 did_cursor_change_ = false; 41 did_cursor_change_ = false;
38 cursor_to_set_on_unlock_ = gfx::kNullCursor; 42 cursor_to_set_on_unlock_ = gfx::kNullCursor;
39 } 43 }
40 } 44 }
41 45
46 void CursorManager::HideHostCursor() {
47 image_cursors_->HideHostCursor();
48 }
49
42 void CursorManager::SetCursor(gfx::NativeCursor cursor) { 50 void CursorManager::SetCursor(gfx::NativeCursor cursor) {
43 if (cursor_lock_count_ == 0) { 51 if (cursor_lock_count_ == 0) {
44 if (delegate_) 52 if (delegate_)
45 delegate_->SetCursor(cursor); 53 SetCursorInternal(cursor);
46 } else { 54 } else {
47 cursor_to_set_on_unlock_ = cursor; 55 cursor_to_set_on_unlock_ = cursor;
48 did_cursor_change_ = true; 56 did_cursor_change_ = true;
49 } 57 }
50 } 58 }
51 59
52 void CursorManager::ShowCursor(bool show) { 60 void CursorManager::ShowCursor(bool show) {
53 cursor_visible_ = show; 61 cursor_visible_ = show;
54 if (delegate_) 62 if (delegate_)
55 delegate_->ShowCursor(show); 63 delegate_->ShowCursor(show);
56 } 64 }
57 65
58 bool CursorManager::IsCursorVisible() const { 66 bool CursorManager::IsCursorVisible() const {
59 return cursor_visible_; 67 return cursor_visible_;
60 } 68 }
61 69
70 void CursorManager::SetDeviceScaleFactor(float device_scale_factor) {
71 if (image_cursors_->GetDeviceScaleFactor() == device_scale_factor)
72 return;
73 image_cursors_->SetDeviceScaleFactor(device_scale_factor);
74 SetCursorInternal(current_cursor_);
75 }
76
77 void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) {
78 DCHECK(delegate_);
79 current_cursor_ = cursor;
80 image_cursors_->SetPlatformCursor(&current_cursor_);
81 current_cursor_.set_device_scale_factor(
82 image_cursors_->GetDeviceScaleFactor());
83 delegate_->SetCursor(current_cursor_);
84 }
85
62 } // namespace ash 86 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698