1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/cursors/webcursor.h"
7 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
8 #include "ui/base/cursor/cursor.h"
9 #include "ui/base/cursor/cursor_util.h"
10 #include "ui/ozone/public/cursor_factory_ozone.h"
13 const float kMaxCursorWidth
= 64.f
;
14 const float kMaxCursorHeight
= 64.f
;
19 ui::PlatformCursor
WebCursor::GetPlatformCursor() {
21 return platform_cursor_
;
24 ImageFromCustomData(&bitmap
);
25 gfx::Point hotspot
= hotspot_
;
27 // TODO(spang): Consider allowing larger cursors if the hardware supports it.
28 float scale
= device_scale_factor_
/ custom_scale_
;
29 scale
= std::min(scale
, kMaxCursorWidth
/ bitmap
.width());
30 scale
= std::min(scale
, kMaxCursorHeight
/ bitmap
.height());
32 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale
, rotation_
, &bitmap
,
36 ui::CursorFactoryOzone::GetInstance()->CreateImageCursor(bitmap
, hotspot
);
37 return platform_cursor_
;
40 void WebCursor::SetDisplayInfo(const gfx::Display
& display
) {
41 if (rotation_
== display
.rotation() &&
42 device_scale_factor_
== display
.device_scale_factor())
45 device_scale_factor_
= display
.device_scale_factor();
46 rotation_
= display
.rotation();
48 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor_
);
49 platform_cursor_
= NULL
;
50 // It is not necessary to recreate platform_cursor_ yet, since it will be
51 // recreated on demand when GetPlatformCursor is called.
54 void WebCursor::InitPlatformData() {
55 platform_cursor_
= NULL
;
56 device_scale_factor_
= 1.f
;
57 rotation_
= gfx::Display::ROTATE_0
;
60 bool WebCursor::SerializePlatformData(base::Pickle
* pickle
) const {
64 bool WebCursor::DeserializePlatformData(base::PickleIterator
* iter
) {
68 bool WebCursor::IsPlatformDataEqual(const WebCursor
& other
) const {
72 void WebCursor::CleanupPlatformData() {
73 if (platform_cursor_
) {
74 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor_
);
75 platform_cursor_
= NULL
;
79 void WebCursor::CopyPlatformData(const WebCursor
& other
) {
81 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor_
);
82 platform_cursor_
= other
.platform_cursor_
;
84 ui::CursorFactoryOzone::GetInstance()->RefImageCursor(platform_cursor_
);
86 device_scale_factor_
= other
.device_scale_factor_
;
89 } // namespace content