| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 && rotation() == gfx::Display::ROTATE_0) { |
| 237 display().rotation() == gfx::Display::ROTATE_0) { | |
| 238 xcursor = GetXCursor(CursorShapeFromNative(*cursor)); | 235 xcursor = GetXCursor(CursorShapeFromNative(*cursor)); |
| 239 } else { | 236 } else { |
| 240 xcursor = ImageCursorFromNative(kCursorPointer); | 237 xcursor = ImageCursorFromNative(kCursorPointer); |
| 241 } | 238 } |
| 242 | 239 |
| 243 cursor->SetPlatformCursor(xcursor); | 240 cursor->SetPlatformCursor(xcursor); |
| 244 } | 241 } |
| 245 | 242 |
| 246 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) { | 243 bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) { |
| 247 int type = native_cursor.native_type(); | 244 int type = native_cursor.native_type(); |
| 248 return cursors_.count(type) || animated_cursors_.count(type); | 245 return cursors_.count(type) || animated_cursors_.count(type); |
| 249 } | 246 } |
| 250 | 247 |
| 251 ::Cursor CursorLoaderX11::ImageCursorFromNative( | 248 ::Cursor CursorLoaderX11::ImageCursorFromNative( |
| 252 gfx::NativeCursor native_cursor) { | 249 gfx::NativeCursor native_cursor) { |
| 253 int type = native_cursor.native_type(); | 250 int type = native_cursor.native_type(); |
| 254 if (animated_cursors_.count(type)) | 251 if (animated_cursors_.count(type)) |
| 255 return animated_cursors_[type].first; | 252 return animated_cursors_[type].first; |
| 256 | 253 |
| 257 ImageCursorMap::iterator find = cursors_.find(type); | 254 ImageCursorMap::iterator find = cursors_.find(type); |
| 258 if (find != cursors_.end()) | 255 if (find != cursors_.end()) |
| 259 return cursors_[type]; | 256 return cursors_[type]; |
| 260 return GetXCursor(CursorShapeFromNative(native_cursor)); | 257 return GetXCursor(CursorShapeFromNative(native_cursor)); |
| 261 } | 258 } |
| 262 | 259 |
| 263 } // namespace ui | 260 } // namespace ui |
| OLD | NEW |