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

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: rebase 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
« no previous file with comments | « ash/wm/cursor_manager.h ('k') | ash/wm/image_cursors.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
42 void CursorManager::SetCursor(gfx::NativeCursor cursor) { 46 void CursorManager::SetCursor(gfx::NativeCursor cursor) {
43 if (cursor_lock_count_ == 0) { 47 if (cursor_lock_count_ == 0) {
44 if (delegate_) 48 if (delegate_)
45 delegate_->SetCursor(cursor); 49 SetCursorInternal(cursor);
46 } else { 50 } else {
47 cursor_to_set_on_unlock_ = cursor; 51 cursor_to_set_on_unlock_ = cursor;
48 did_cursor_change_ = true; 52 did_cursor_change_ = true;
49 } 53 }
50 } 54 }
51 55
52 void CursorManager::ShowCursor(bool show) { 56 void CursorManager::ShowCursor(bool show) {
53 cursor_visible_ = show; 57 cursor_visible_ = show;
54 if (delegate_) 58 if (delegate_)
55 delegate_->ShowCursor(show); 59 delegate_->ShowCursor(show);
56 } 60 }
57 61
58 bool CursorManager::IsCursorVisible() const { 62 bool CursorManager::IsCursorVisible() const {
59 return cursor_visible_; 63 return cursor_visible_;
60 } 64 }
61 65
66 void CursorManager::SetDeviceScaleFactor(float device_scale_factor) {
67 if (image_cursors_->GetDeviceScaleFactor() == device_scale_factor)
68 return;
69 image_cursors_->SetDeviceScaleFactor(device_scale_factor);
70 SetCursorInternal(current_cursor_);
71 }
72
73 void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) {
74 DCHECK(delegate_);
75 current_cursor_ = cursor;
76 image_cursors_->SetPlatformCursor(&current_cursor_);
77 current_cursor_.set_device_scale_factor(
78 image_cursors_->GetDeviceScaleFactor());
79 delegate_->SetCursor(current_cursor_);
80 }
81
62 } // namespace ash 82 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/cursor_manager.h ('k') | ash/wm/image_cursors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698