| 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 "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 13 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
| 14 #include "ui/base/x/x11_util.h" | 15 #include "ui/base/x/x11_util.h" |
| 15 | 16 |
| 16 const ui::PlatformCursor WebCursor::GetPlatformCursor() { | 17 const ui::PlatformCursor WebCursor::GetPlatformCursor() { |
| 17 if (platform_cursor_) | 18 if (platform_cursor_) |
| 18 return platform_cursor_; | 19 return platform_cursor_; |
| 19 | 20 |
| 20 SkBitmap bitmap; | 21 SkBitmap bitmap; |
| 21 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 22 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 22 custom_size_.width(), custom_size_.height()); | 23 custom_size_.width(), custom_size_.height()); |
| 23 bitmap.allocPixels(); | 24 bitmap.allocPixels(); |
| 24 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); | 25 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); |
| 25 | 26 |
| 26 XcursorImage* image = ui::SkBitmapToXcursorImage(&bitmap, hotspot_); | 27 XcursorImage* image = NULL; |
| 28 if (scale_factor_ == 1.f) { |
| 29 image = ui::SkBitmapToXcursorImage(&bitmap, hotspot_); |
| 30 } else { |
| 31 gfx::Size scaled_size = custom_size_.Scale(scale_factor_); |
| 32 SkBitmap scaled_bitmap = skia::ImageOperations::Resize(bitmap, |
| 33 skia::ImageOperations::RESIZE_BETTER, |
| 34 scaled_size.width(), |
| 35 scaled_size.height()); |
| 36 image = ui::SkBitmapToXcursorImage(&scaled_bitmap, |
| 37 hotspot_.Scale(scale_factor_)); |
| 38 } |
| 27 platform_cursor_ = ui::CreateReffedCustomXCursor(image); | 39 platform_cursor_ = ui::CreateReffedCustomXCursor(image); |
| 28 return platform_cursor_; | 40 return platform_cursor_; |
| 29 } | 41 } |
| 30 | 42 |
| 43 void WebCursor::SetScaleFactor(float scale_factor) { |
| 44 if (scale_factor_ == scale_factor) |
| 45 return; |
| 46 |
| 47 scale_factor_ = scale_factor; |
| 48 if (platform_cursor_) |
| 49 ui::UnrefCustomXCursor(platform_cursor_); |
| 50 platform_cursor_ = 0; |
| 51 // It is not necessary to recreate platform_cursor_ yet, since it will be |
| 52 // recreated on demand when GetPlatformCursor is called. |
| 53 } |
| 54 |
| 31 void WebCursor::InitPlatformData() { | 55 void WebCursor::InitPlatformData() { |
| 32 platform_cursor_ = 0; | 56 platform_cursor_ = 0; |
| 57 scale_factor_ = 1.f; |
| 33 } | 58 } |
| 34 | 59 |
| 35 bool WebCursor::SerializePlatformData(Pickle* pickle) const { | 60 bool WebCursor::SerializePlatformData(Pickle* pickle) const { |
| 36 return true; | 61 return true; |
| 37 } | 62 } |
| 38 | 63 |
| 39 bool WebCursor::DeserializePlatformData(PickleIterator* iter) { | 64 bool WebCursor::DeserializePlatformData(PickleIterator* iter) { |
| 40 return true; | 65 return true; |
| 41 } | 66 } |
| 42 | 67 |
| 43 bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { | 68 bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { |
| 44 return true; | 69 return true; |
| 45 } | 70 } |
| 46 | 71 |
| 47 void WebCursor::CleanupPlatformData() { | 72 void WebCursor::CleanupPlatformData() { |
| 48 if (platform_cursor_) { | 73 if (platform_cursor_) { |
| 49 ui::UnrefCustomXCursor(platform_cursor_); | 74 ui::UnrefCustomXCursor(platform_cursor_); |
| 50 platform_cursor_ = 0; | 75 platform_cursor_ = 0; |
| 51 } | 76 } |
| 52 } | 77 } |
| 53 | 78 |
| 54 void WebCursor::CopyPlatformData(const WebCursor& other) { | 79 void WebCursor::CopyPlatformData(const WebCursor& other) { |
| 55 if (platform_cursor_) | 80 if (platform_cursor_) |
| 56 ui::UnrefCustomXCursor(platform_cursor_); | 81 ui::UnrefCustomXCursor(platform_cursor_); |
| 57 platform_cursor_ = other.platform_cursor_; | 82 platform_cursor_ = other.platform_cursor_; |
| 58 if (platform_cursor_) | 83 if (platform_cursor_) |
| 59 ui::RefCustomXCursor(platform_cursor_); | 84 ui::RefCustomXCursor(platform_cursor_); |
| 85 |
| 86 scale_factor_ = other.scale_factor_; |
| 60 } | 87 } |
| OLD | NEW |