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

Side by Side Diff: ui/base/cursor/cursor_loader_x11.cc

Issue 226293005: Use platform's device scale factor for cursor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 "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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 CursorLoaderX11::~CursorLoaderX11() { 153 CursorLoaderX11::~CursorLoaderX11() {
154 UnloadAll(); 154 UnloadAll();
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( 162 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale());
163 display().device_scale_factor());
164 SkBitmap bitmap = image_rep.sk_bitmap(); 163 SkBitmap bitmap = image_rep.sk_bitmap();
165 gfx::Point hotpoint = hot; 164 gfx::Point hotpoint = hot;
166 ScaleAndRotateCursorBitmapAndHotpoint( 165 ScaleAndRotateCursorBitmapAndHotpoint(
167 scale(), display().rotation(), &bitmap, &hotpoint); 166 scale(), rotation(), &bitmap, &hotpoint);
168 167
169 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint); 168 XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint);
170 cursors_[id] = CreateReffedCustomXCursor(x_image); 169 cursors_[id] = CreateReffedCustomXCursor(x_image);
171 // |image_rep| is owned by the resource bundle. So we do not need to free it. 170 // |image_rep| is owned by the resource bundle. So we do not need to free it.
172 } 171 }
173 172
174 void CursorLoaderX11::LoadAnimatedCursor(int id, 173 void CursorLoaderX11::LoadAnimatedCursor(int id,
175 int resource_id, 174 int resource_id,
176 const gfx::Point& hot, 175 const gfx::Point& hot,
177 int frame_delay_ms) { 176 int frame_delay_ms) {
178 const gfx::ImageSkia* image = 177 const gfx::ImageSkia* image =
179 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 178 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
180 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation( 179 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale());
181 display().device_scale_factor());
182 SkBitmap bitmap = image_rep.sk_bitmap(); 180 SkBitmap bitmap = image_rep.sk_bitmap();
183 int frame_width = bitmap.height(); 181 int frame_width = bitmap.height();
184 int frame_height = frame_width; 182 int frame_height = frame_width;
185 int total_width = bitmap.width(); 183 int total_width = bitmap.width();
186 DCHECK_EQ(total_width % frame_width, 0); 184 DCHECK_EQ(total_width % frame_width, 0);
187 int frame_count = total_width / frame_width; 185 int frame_count = total_width / frame_width;
188 DCHECK_GT(frame_count, 0); 186 DCHECK_GT(frame_count, 0);
189 XcursorImages* x_images = XcursorImagesCreate(frame_count); 187 XcursorImages* x_images = XcursorImagesCreate(frame_count);
190 x_images->nimage = frame_count; 188 x_images->nimage = frame_count;
191 189
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) { 224 void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) {
227 DCHECK(cursor); 225 DCHECK(cursor);
228 226
229 ::Cursor xcursor; 227 ::Cursor xcursor;
230 if (IsImageCursor(*cursor)) 228 if (IsImageCursor(*cursor))
231 xcursor = ImageCursorFromNative(*cursor); 229 xcursor = ImageCursorFromNative(*cursor);
232 else if (*cursor == kCursorNone) 230 else if (*cursor == kCursorNone)
233 xcursor = invisible_cursor_.get(); 231 xcursor = invisible_cursor_.get();
234 else if (*cursor == kCursorCustom) 232 else if (*cursor == kCursorCustom)
235 xcursor = cursor->platform(); 233 xcursor = cursor->platform();
236 else if (display().device_scale_factor() == 1.0f && 234 else if (scale() == 1.0f &&
237 display().rotation() == gfx::Display::ROTATE_0) { 235 rotation() == gfx::Display::ROTATE_0) {
238 xcursor = GetXCursor(CursorShapeFromNative(*cursor)); 236 xcursor = GetXCursor(CursorShapeFromNative(*cursor));
239 } else { 237 } else {
240 xcursor = ImageCursorFromNative(kCursorPointer); 238 xcursor = ImageCursorFromNative(kCursorPointer);
241 } 239 }
242 240
243 cursor->SetPlatformCursor(xcursor); 241 cursor->SetPlatformCursor(xcursor);
244 } 242 }
245 243
246 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) { 244 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) {
247 int type = native_cursor.native_type(); 245 int type = native_cursor.native_type();
248 return cursors_.count(type) || animated_cursors_.count(type); 246 return cursors_.count(type) || animated_cursors_.count(type);
249 } 247 }
250 248
251 ::Cursor CursorLoaderX11::ImageCursorFromNative( 249 ::Cursor CursorLoaderX11::ImageCursorFromNative(
252 gfx::NativeCursor native_cursor) { 250 gfx::NativeCursor native_cursor) {
253 int type = native_cursor.native_type(); 251 int type = native_cursor.native_type();
254 if (animated_cursors_.count(type)) 252 if (animated_cursors_.count(type))
255 return animated_cursors_[type].first; 253 return animated_cursors_[type].first;
256 254
257 ImageCursorMap::iterator find = cursors_.find(type); 255 ImageCursorMap::iterator find = cursors_.find(type);
258 if (find != cursors_.end()) 256 if (find != cursors_.end())
259 return cursors_[type]; 257 return cursors_[type];
260 return GetXCursor(CursorShapeFromNative(native_cursor)); 258 return GetXCursor(CursorShapeFromNative(native_cursor));
261 } 259 }
262 260
263 } // namespace ui 261 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698