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 "webkit/glue/webcursor.h" | 5 #include "webkit/glue/webcursor.h" |
6 | 6 |
7 #include <X11/Xcursor/Xcursor.h> | 7 #include <X11/Xcursor/Xcursor.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/cursorfont.h> | 9 #include <X11/cursorfont.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
14 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
15 #include "ui/base/x/x11_util.h" | 15 #include "ui/base/x/x11_util.h" |
| 16 #include "ui/gfx/point_conversions.h" |
| 17 #include "ui/gfx/size_conversions.h" |
16 | 18 |
17 const ui::PlatformCursor WebCursor::GetPlatformCursor() { | 19 const ui::PlatformCursor WebCursor::GetPlatformCursor() { |
18 if (platform_cursor_) | 20 if (platform_cursor_) |
19 return platform_cursor_; | 21 return platform_cursor_; |
20 | 22 |
21 SkBitmap bitmap; | 23 SkBitmap bitmap; |
22 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 24 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
23 custom_size_.width(), custom_size_.height()); | 25 custom_size_.width(), custom_size_.height()); |
24 bitmap.allocPixels(); | 26 bitmap.allocPixels(); |
25 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); | 27 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); |
26 | 28 |
27 XcursorImage* image = NULL; | 29 XcursorImage* image = NULL; |
28 if (scale_factor_ == 1.f) { | 30 if (scale_factor_ == 1.f) { |
29 image = ui::SkBitmapToXcursorImage(&bitmap, hotspot_); | 31 image = ui::SkBitmapToXcursorImage(&bitmap, hotspot_); |
30 } else { | 32 } else { |
31 gfx::Size scaled_size = custom_size_.Scale(scale_factor_); | 33 gfx::Size scaled_size = gfx::ToFlooredSize( |
| 34 custom_size_.Scale(scale_factor_)); |
32 SkBitmap scaled_bitmap = skia::ImageOperations::Resize(bitmap, | 35 SkBitmap scaled_bitmap = skia::ImageOperations::Resize(bitmap, |
33 skia::ImageOperations::RESIZE_BETTER, | 36 skia::ImageOperations::RESIZE_BETTER, |
34 scaled_size.width(), | 37 scaled_size.width(), |
35 scaled_size.height()); | 38 scaled_size.height()); |
36 image = ui::SkBitmapToXcursorImage(&scaled_bitmap, | 39 image = ui::SkBitmapToXcursorImage(&scaled_bitmap, |
37 hotspot_.Scale(scale_factor_)); | 40 gfx::ToFlooredPoint( |
| 41 hotspot_.Scale(scale_factor_))); |
38 } | 42 } |
39 platform_cursor_ = ui::CreateReffedCustomXCursor(image); | 43 platform_cursor_ = ui::CreateReffedCustomXCursor(image); |
40 return platform_cursor_; | 44 return platform_cursor_; |
41 } | 45 } |
42 | 46 |
43 void WebCursor::SetScaleFactor(float scale_factor) { | 47 void WebCursor::SetScaleFactor(float scale_factor) { |
44 if (scale_factor_ == scale_factor) | 48 if (scale_factor_ == scale_factor) |
45 return; | 49 return; |
46 | 50 |
47 scale_factor_ = scale_factor; | 51 scale_factor_ = scale_factor; |
(...skipping 30 matching lines...) Expand all Loading... |
78 | 82 |
79 void WebCursor::CopyPlatformData(const WebCursor& other) { | 83 void WebCursor::CopyPlatformData(const WebCursor& other) { |
80 if (platform_cursor_) | 84 if (platform_cursor_) |
81 ui::UnrefCustomXCursor(platform_cursor_); | 85 ui::UnrefCustomXCursor(platform_cursor_); |
82 platform_cursor_ = other.platform_cursor_; | 86 platform_cursor_ = other.platform_cursor_; |
83 if (platform_cursor_) | 87 if (platform_cursor_) |
84 ui::RefCustomXCursor(platform_cursor_); | 88 ui::RefCustomXCursor(platform_cursor_); |
85 | 89 |
86 scale_factor_ = other.scale_factor_; | 90 scale_factor_ = other.scale_factor_; |
87 } | 91 } |
OLD | NEW |