| 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 "content/common/cursors/webcursor.h" | 5 #include "content/common/cursors/webcursor.h" |
| 6 | 6 |
| 7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
| 8 #include <X11/Xcursor/Xcursor.h> | 8 #include <X11/Xcursor/Xcursor.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 12 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 13 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
| 14 #include "ui/base/cursor/cursor_loader_x11.h" | 14 #include "ui/base/cursor/cursor_loader_x11.h" |
| 15 #include "ui/base/cursor/cursor_util.h" | |
| 16 #include "ui/base/x/x11_util.h" | 15 #include "ui/base/x/x11_util.h" |
| 17 | 16 |
| 18 namespace content { | 17 namespace content { |
| 19 | 18 |
| 20 ui::PlatformCursor WebCursor::GetPlatformCursor() { | 19 ui::PlatformCursor WebCursor::GetPlatformCursor() { |
| 21 if (platform_cursor_) | 20 if (platform_cursor_) |
| 22 return platform_cursor_; | 21 return platform_cursor_; |
| 23 | 22 |
| 24 if (custom_data_.size() == 0) | 23 if (custom_data_.size() == 0) |
| 25 return 0; | 24 return 0; |
| 26 | 25 |
| 27 SkBitmap bitmap; | 26 SkBitmap bitmap; |
| 28 bitmap.allocN32Pixels(custom_size_.width(), custom_size_.height()); | 27 gfx::Point hotspot; |
| 29 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); | 28 CreateScaledBitmapAndHotspotFromCustomData(&bitmap, &hotspot); |
| 30 gfx::Point hotspot = hotspot_; | |
| 31 ui::ScaleAndRotateCursorBitmapAndHotpoint( | |
| 32 device_scale_factor_, gfx::Display::ROTATE_0, &bitmap, &hotspot); | |
| 33 | 29 |
| 34 XcursorImage* image = ui::SkBitmapToXcursorImage(&bitmap, hotspot); | 30 XcursorImage* image = ui::SkBitmapToXcursorImage(&bitmap, hotspot); |
| 35 platform_cursor_ = ui::CreateReffedCustomXCursor(image); | 31 platform_cursor_ = ui::CreateReffedCustomXCursor(image); |
| 36 return platform_cursor_; | 32 return platform_cursor_; |
| 37 } | 33 } |
| 38 | 34 |
| 39 void WebCursor::SetDisplayInfo(const gfx::Display& display) { | |
| 40 if (device_scale_factor_ == display.device_scale_factor()) | |
| 41 return; | |
| 42 | |
| 43 device_scale_factor_ = display.device_scale_factor(); | |
| 44 if (platform_cursor_) | |
| 45 ui::UnrefCustomXCursor(platform_cursor_); | |
| 46 platform_cursor_ = 0; | |
| 47 // It is not necessary to recreate platform_cursor_ yet, since it will be | |
| 48 // recreated on demand when GetPlatformCursor is called. | |
| 49 } | |
| 50 | |
| 51 void WebCursor::InitPlatformData() { | 35 void WebCursor::InitPlatformData() { |
| 52 platform_cursor_ = 0; | 36 platform_cursor_ = 0; |
| 53 device_scale_factor_ = 1.f; | 37 device_scale_factor_ = 1.f; |
| 54 } | 38 } |
| 55 | 39 |
| 56 bool WebCursor::SerializePlatformData(base::Pickle* pickle) const { | 40 bool WebCursor::SerializePlatformData(base::Pickle* pickle) const { |
| 57 return true; | 41 return true; |
| 58 } | 42 } |
| 59 | 43 |
| 60 bool WebCursor::DeserializePlatformData(base::PickleIterator* iter) { | 44 bool WebCursor::DeserializePlatformData(base::PickleIterator* iter) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 76 if (platform_cursor_) | 60 if (platform_cursor_) |
| 77 ui::UnrefCustomXCursor(platform_cursor_); | 61 ui::UnrefCustomXCursor(platform_cursor_); |
| 78 platform_cursor_ = other.platform_cursor_; | 62 platform_cursor_ = other.platform_cursor_; |
| 79 if (platform_cursor_) | 63 if (platform_cursor_) |
| 80 ui::RefCustomXCursor(platform_cursor_); | 64 ui::RefCustomXCursor(platform_cursor_); |
| 81 | 65 |
| 82 device_scale_factor_ = other.device_scale_factor_; | 66 device_scale_factor_ = other.device_scale_factor_; |
| 83 } | 67 } |
| 84 | 68 |
| 85 } // namespace content | 69 } // namespace content |
| OLD | NEW |