| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 } // namespace | 140 } // namespace |
| 141 | 141 |
| 142 namespace ui { | 142 namespace ui { |
| 143 | 143 |
| 144 CursorLoader* CursorLoader::Create() { | 144 CursorLoader* CursorLoader::Create() { |
| 145 return new CursorLoaderX11; | 145 return new CursorLoaderX11; |
| 146 } | 146 } |
| 147 | 147 |
| 148 CursorLoaderX11::CursorLoaderX11() | 148 CursorLoaderX11::CursorLoaderX11() |
| 149 : invisible_cursor_(CreateInvisibleCursor(), GetXDisplay()) { | 149 : invisible_cursor_(CreateInvisibleCursor(), gfx::GetXDisplay()) { |
| 150 } | 150 } |
| 151 | 151 |
| 152 CursorLoaderX11::~CursorLoaderX11() { | 152 CursorLoaderX11::~CursorLoaderX11() { |
| 153 UnloadAll(); | 153 UnloadAll(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void CursorLoaderX11::LoadImageCursor(int id, | 156 void CursorLoaderX11::LoadImageCursor(int id, |
| 157 int resource_id, | 157 int resource_id, |
| 158 const gfx::Point& hot) { | 158 const gfx::Point& hot) { |
| 159 const gfx::ImageSkia* image = | 159 const gfx::ImageSkia* image = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 DCHECK_EQ(frame_width, cropped.width()); | 198 DCHECK_EQ(frame_width, cropped.width()); |
| 199 DCHECK_EQ(frame_height, cropped.height()); | 199 DCHECK_EQ(frame_height, cropped.height()); |
| 200 | 200 |
| 201 XcursorImage* x_image = SkBitmapToXcursorImage(&cropped, hotpoint); | 201 XcursorImage* x_image = SkBitmapToXcursorImage(&cropped, hotpoint); |
| 202 | 202 |
| 203 x_image->delay = frame_delay_ms; | 203 x_image->delay = frame_delay_ms; |
| 204 x_images->images[frame] = x_image; | 204 x_images->images[frame] = x_image; |
| 205 } | 205 } |
| 206 | 206 |
| 207 animated_cursors_[id] = std::make_pair( | 207 animated_cursors_[id] = std::make_pair( |
| 208 XcursorImagesLoadCursor(GetXDisplay(), x_images), x_images); | 208 XcursorImagesLoadCursor(gfx::GetXDisplay(), x_images), x_images); |
| 209 // |bitmap| is owned by the resource bundle. So we do not need to free it. | 209 // |bitmap| is owned by the resource bundle. So we do not need to free it. |
| 210 } | 210 } |
| 211 | 211 |
| 212 void CursorLoaderX11::UnloadAll() { | 212 void CursorLoaderX11::UnloadAll() { |
| 213 for (ImageCursorMap::const_iterator it = cursors_.begin(); | 213 for (ImageCursorMap::const_iterator it = cursors_.begin(); |
| 214 it != cursors_.end(); ++it) | 214 it != cursors_.end(); ++it) |
| 215 UnrefCustomXCursor(it->second); | 215 UnrefCustomXCursor(it->second); |
| 216 | 216 |
| 217 // Free animated cursors and images. | 217 // Free animated cursors and images. |
| 218 for (AnimatedCursorMap::iterator it = animated_cursors_.begin(); | 218 for (AnimatedCursorMap::iterator it = animated_cursors_.begin(); |
| 219 it != animated_cursors_.end(); ++it) { | 219 it != animated_cursors_.end(); ++it) { |
| 220 XcursorImagesDestroy(it->second.second); // also frees individual frames. | 220 XcursorImagesDestroy(it->second.second); // also frees individual frames. |
| 221 XFreeCursor(GetXDisplay(), it->second.first); | 221 XFreeCursor(gfx::GetXDisplay(), it->second.first); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) { | 225 void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) { |
| 226 DCHECK(cursor); | 226 DCHECK(cursor); |
| 227 | 227 |
| 228 ::Cursor xcursor; | 228 ::Cursor xcursor; |
| 229 if (IsImageCursor(*cursor)) | 229 if (IsImageCursor(*cursor)) |
| 230 xcursor = ImageCursorFromNative(*cursor); | 230 xcursor = ImageCursorFromNative(*cursor); |
| 231 else if (*cursor == kCursorNone) | 231 else if (*cursor == kCursorNone) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 297 |
| 298 *bitmap = skia::ImageOperations::Resize( | 298 *bitmap = skia::ImageOperations::Resize( |
| 299 *bitmap, | 299 *bitmap, |
| 300 skia::ImageOperations::RESIZE_BETTER, | 300 skia::ImageOperations::RESIZE_BETTER, |
| 301 scaled_size.width(), | 301 scaled_size.width(), |
| 302 scaled_size.height()); | 302 scaled_size.height()); |
| 303 *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale)); | 303 *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale)); |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace ui | 306 } // namespace ui |
| OLD | NEW |