OLD | NEW |
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 "ui/base/cursor/cursor_loader_x11.h" | 5 #include "ui/base/cursor/cursor_loader_x11.h" |
6 | 6 |
7 #include <float.h> | 7 #include <float.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/cursorfont.h> | 9 #include <X11/cursorfont.h> |
10 | 10 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 void CursorLoaderX11::LoadImageCursor(int id, | 157 void CursorLoaderX11::LoadImageCursor(int id, |
158 int resource_id, | 158 int resource_id, |
159 const gfx::Point& hot) { | 159 const gfx::Point& hot) { |
160 const gfx::ImageSkia* image = | 160 const gfx::ImageSkia* image = |
161 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); | 161 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
162 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); | 162 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); |
163 SkBitmap bitmap = image_rep.sk_bitmap(); | 163 SkBitmap bitmap = image_rep.sk_bitmap(); |
164 gfx::Point hotpoint = hot; | 164 gfx::Point hotpoint = hot; |
| 165 // TODO(oshima): The cursor should use resource scale factor when |
| 166 // fractional scale factor is enabled. crbug.com/372212 |
165 ScaleAndRotateCursorBitmapAndHotpoint( | 167 ScaleAndRotateCursorBitmapAndHotpoint( |
166 scale(), rotation(), &bitmap, &hotpoint); | 168 scale() / image_rep.scale(), rotation(), &bitmap, &hotpoint); |
167 | 169 |
168 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint); | 170 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint); |
169 cursors_[id] = CreateReffedCustomXCursor(x_image); | 171 cursors_[id] = CreateReffedCustomXCursor(x_image); |
170 // |image_rep| is owned by the resource bundle. So we do not need to free it. | 172 // |image_rep| is owned by the resource bundle. So we do not need to free it. |
171 } | 173 } |
172 | 174 |
173 void CursorLoaderX11::LoadAnimatedCursor(int id, | 175 void CursorLoaderX11::LoadAnimatedCursor(int id, |
174 int resource_id, | 176 int resource_id, |
175 const gfx::Point& hot, | 177 const gfx::Point& hot, |
176 int frame_delay_ms) { | 178 int frame_delay_ms) { |
| 179 // TODO(oshima|tdanderson): Support rotation and fractional scale factor. |
177 const gfx::ImageSkia* image = | 180 const gfx::ImageSkia* image = |
178 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); | 181 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
179 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); | 182 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); |
180 SkBitmap bitmap = image_rep.sk_bitmap(); | 183 SkBitmap bitmap = image_rep.sk_bitmap(); |
181 int frame_width = bitmap.height(); | 184 int frame_width = bitmap.height(); |
182 int frame_height = frame_width; | 185 int frame_height = frame_width; |
183 int total_width = bitmap.width(); | 186 int total_width = bitmap.width(); |
184 DCHECK_EQ(total_width % frame_width, 0); | 187 DCHECK_EQ(total_width % frame_width, 0); |
185 int frame_count = total_width / frame_width; | 188 int frame_count = total_width / frame_width; |
186 DCHECK_GT(frame_count, 0); | 189 DCHECK_GT(frame_count, 0); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 xcursor = cursor->platform(); | 236 xcursor = cursor->platform(); |
234 else if (scale() == 1.0f && rotation() == gfx::Display::ROTATE_0) { | 237 else if (scale() == 1.0f && rotation() == gfx::Display::ROTATE_0) { |
235 xcursor = GetXCursor(CursorShapeFromNative(*cursor)); | 238 xcursor = GetXCursor(CursorShapeFromNative(*cursor)); |
236 } else { | 239 } else { |
237 xcursor = ImageCursorFromNative(kCursorPointer); | 240 xcursor = ImageCursorFromNative(kCursorPointer); |
238 } | 241 } |
239 | 242 |
240 cursor->SetPlatformCursor(xcursor); | 243 cursor->SetPlatformCursor(xcursor); |
241 } | 244 } |
242 | 245 |
| 246 const XcursorImage* CursorLoaderX11::GetXcursorImageForTest(int id) { |
| 247 return test::GetCachedXcursorImage(cursors_[id]); |
| 248 } |
| 249 |
243 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) { | 250 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) { |
244 int type = native_cursor.native_type(); | 251 int type = native_cursor.native_type(); |
245 return cursors_.count(type) || animated_cursors_.count(type); | 252 return cursors_.count(type) || animated_cursors_.count(type); |
246 } | 253 } |
247 | 254 |
248 ::Cursor CursorLoaderX11::ImageCursorFromNative( | 255 ::Cursor CursorLoaderX11::ImageCursorFromNative( |
249 gfx::NativeCursor native_cursor) { | 256 gfx::NativeCursor native_cursor) { |
250 int type = native_cursor.native_type(); | 257 int type = native_cursor.native_type(); |
251 if (animated_cursors_.count(type)) | 258 if (animated_cursors_.count(type)) |
252 return animated_cursors_[type].first; | 259 return animated_cursors_[type].first; |
253 | 260 |
254 ImageCursorMap::iterator find = cursors_.find(type); | 261 ImageCursorMap::iterator find = cursors_.find(type); |
255 if (find != cursors_.end()) | 262 if (find != cursors_.end()) |
256 return cursors_[type]; | 263 return cursors_[type]; |
257 return GetXCursor(CursorShapeFromNative(native_cursor)); | 264 return GetXCursor(CursorShapeFromNative(native_cursor)); |
258 } | 265 } |
259 | 266 |
260 } // namespace ui | 267 } // namespace ui |
OLD | NEW |