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

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: 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 gfx::NativeCursor CursorManager::GetCursorFromNativeType(
47 gfx::NativeCursor cursor) {
48 image_cursors_->SetPlatformCursor(&cursor);
49 cursor.set_device_scale_factor(image_cursors_->GetDeviceScaleFactor());
50 return cursor;
51 }
52
53 void CursorManager::HideHostCursor() {
54 image_cursors_->HideHostCursor();
55 }
56
42 void CursorManager::SetCursor(gfx::NativeCursor cursor) { 57 void CursorManager::SetCursor(gfx::NativeCursor cursor) {
43 if (cursor_lock_count_ == 0) { 58 if (cursor_lock_count_ == 0) {
44 if (delegate_) 59 if (delegate_)
45 delegate_->SetCursor(cursor); 60 SetCursorInternal(cursor);
46 } else { 61 } else {
47 cursor_to_set_on_unlock_ = cursor; 62 cursor_to_set_on_unlock_ = cursor;
48 did_cursor_change_ = true; 63 did_cursor_change_ = true;
49 } 64 }
50 } 65 }
51 66
52 void CursorManager::ShowCursor(bool show) { 67 void CursorManager::ShowCursor(bool show) {
53 cursor_visible_ = show; 68 cursor_visible_ = show;
54 if (delegate_) 69 if (delegate_)
55 delegate_->ShowCursor(show); 70 delegate_->ShowCursor(show);
56 } 71 }
57 72
58 bool CursorManager::IsCursorVisible() const { 73 bool CursorManager::IsCursorVisible() const {
59 return cursor_visible_; 74 return cursor_visible_;
60 } 75 }
61 76
77 void CursorManager::SetDeviceScaleFactor(float device_scale_factor) {
78 if (image_cursors_->GetDeviceScaleFactor() == device_scale_factor)
79 return;
80 image_cursors_->Reload(device_scale_factor);
81 SetCursorInternal(current_cursor_);
82 }
83
84 void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) {
85 DCHECK(delegate_);
86 current_cursor_ = GetCursorFromNativeType(cursor);
87 delegate_->SetCursor(current_cursor_);
88 }
89
62 } // namespace ash 90 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698