OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/base/cursor/image_cursors.h" | 5 #include "ui/base/cursor/image_cursors.h" |
6 | 6 |
7 #include <float.h> | 7 #include <float.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 CursorType::kNorthWestSouthEastResize, | 53 CursorType::kNorthWestSouthEastResize, |
54 CursorType::kGrab, | 54 CursorType::kGrab, |
55 CursorType::kGrabbing, | 55 CursorType::kGrabbing, |
56 }; | 56 }; |
57 | 57 |
58 const CursorType kAnimatedCursorIds[] = {CursorType::kWait, | 58 const CursorType kAnimatedCursorIds[] = {CursorType::kWait, |
59 CursorType::kProgress}; | 59 CursorType::kProgress}; |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 ImageCursors::ImageCursors() : cursor_set_(CURSOR_SET_NORMAL) { | 63 ImageCursors::ImageCursors() : cursor_size_(CursorSize::kNormal) {} |
64 } | |
65 | 64 |
66 ImageCursors::~ImageCursors() { | 65 ImageCursors::~ImageCursors() { |
67 } | 66 } |
68 | 67 |
69 float ImageCursors::GetScale() const { | 68 float ImageCursors::GetScale() const { |
70 if (!cursor_loader_) { | 69 if (!cursor_loader_) { |
71 NOTREACHED(); | 70 NOTREACHED(); |
72 // Returning default on release build as it's not serious enough to crash | 71 // Returning default on release build as it's not serious enough to crash |
73 // even if this ever happens. | 72 // even if this ever happens. |
74 return 1.0f; | 73 return 1.0f; |
(...skipping 27 matching lines...) Expand all Loading... |
102 } | 101 } |
103 | 102 |
104 void ImageCursors::ReloadCursors() { | 103 void ImageCursors::ReloadCursors() { |
105 float device_scale_factor = cursor_loader_->scale(); | 104 float device_scale_factor = cursor_loader_->scale(); |
106 | 105 |
107 cursor_loader_->UnloadAll(); | 106 cursor_loader_->UnloadAll(); |
108 | 107 |
109 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { | 108 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { |
110 int resource_id = -1; | 109 int resource_id = -1; |
111 gfx::Point hot_point; | 110 gfx::Point hot_point; |
112 bool success = GetCursorDataFor(cursor_set_, | 111 bool success = |
113 kImageCursorIds[i], | 112 GetCursorDataFor(cursor_size_, kImageCursorIds[i], device_scale_factor, |
114 device_scale_factor, | 113 &resource_id, &hot_point); |
115 &resource_id, | |
116 &hot_point); | |
117 DCHECK(success); | 114 DCHECK(success); |
118 cursor_loader_->LoadImageCursor(kImageCursorIds[i], resource_id, hot_point); | 115 cursor_loader_->LoadImageCursor(kImageCursorIds[i], resource_id, hot_point); |
119 } | 116 } |
120 for (size_t i = 0; i < arraysize(kAnimatedCursorIds); ++i) { | 117 for (size_t i = 0; i < arraysize(kAnimatedCursorIds); ++i) { |
121 int resource_id = -1; | 118 int resource_id = -1; |
122 gfx::Point hot_point; | 119 gfx::Point hot_point; |
123 bool success = GetAnimatedCursorDataFor(cursor_set_, | 120 bool success = |
124 kAnimatedCursorIds[i], | 121 GetAnimatedCursorDataFor(cursor_size_, kAnimatedCursorIds[i], |
125 device_scale_factor, | 122 device_scale_factor, &resource_id, &hot_point); |
126 &resource_id, | |
127 &hot_point); | |
128 DCHECK(success); | 123 DCHECK(success); |
129 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], | 124 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], |
130 resource_id, | 125 resource_id, |
131 hot_point, | 126 hot_point, |
132 kAnimatedCursorFrameDelayMs); | 127 kAnimatedCursorFrameDelayMs); |
133 } | 128 } |
134 } | 129 } |
135 | 130 |
136 void ImageCursors::SetCursorSet(CursorSetType cursor_set) { | 131 void ImageCursors::SetCursorSize(CursorSize cursor_size) { |
137 if (cursor_set_ == cursor_set) | 132 if (cursor_size_ == cursor_size) |
138 return; | 133 return; |
139 | 134 |
140 cursor_set_ = cursor_set; | 135 cursor_size_ = cursor_size; |
141 | 136 |
142 if (cursor_loader_.get()) | 137 if (cursor_loader_.get()) |
143 ReloadCursors(); | 138 ReloadCursors(); |
144 } | 139 } |
145 | 140 |
146 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { | 141 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { |
147 cursor_loader_->SetPlatformCursor(cursor); | 142 cursor_loader_->SetPlatformCursor(cursor); |
148 } | 143 } |
149 | 144 |
150 } // namespace ui | 145 } // namespace ui |
OLD | NEW |