OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ozone/platform/x11/x11_cursor_factory_ozone.h" | 5 #include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "ui/base/cursor/cursors_aura.h" | 8 #include "ui/base/cursor/cursors_aura.h" |
9 #include "ui/gfx/geometry/point.h" | 9 #include "ui/gfx/geometry/point.h" |
10 | 10 |
11 namespace ui { | 11 namespace ui { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 X11CursorOzone* ToX11CursorOzone(PlatformCursor cursor) { | 15 X11CursorOzone* ToX11CursorOzone(PlatformCursor cursor) { |
16 return static_cast<X11CursorOzone*>(cursor); | 16 return static_cast<X11CursorOzone*>(cursor); |
17 } | 17 } |
18 | 18 |
19 PlatformCursor ToPlatformCursor(X11CursorOzone* cursor) { | 19 PlatformCursor ToPlatformCursor(X11CursorOzone* cursor) { |
20 return static_cast<PlatformCursor>(cursor); | 20 return static_cast<PlatformCursor>(cursor); |
21 } | 21 } |
22 | 22 |
23 // Gets default aura cursor bitmap/hotspot and creates a X11CursorOzone with it. | 23 // Gets default aura cursor bitmap/hotspot and creates a X11CursorOzone with it. |
24 scoped_refptr<X11CursorOzone> CreateAuraX11Cursor(int type) { | 24 scoped_refptr<X11CursorOzone> CreateAuraX11Cursor(CursorType type) { |
25 SkBitmap bitmap; | 25 SkBitmap bitmap; |
26 gfx::Point hotspot; | 26 gfx::Point hotspot; |
27 if (GetCursorBitmap(type, &bitmap, &hotspot)) { | 27 if (GetCursorBitmap(type, &bitmap, &hotspot)) { |
28 return new X11CursorOzone(bitmap, hotspot); | 28 return new X11CursorOzone(bitmap, hotspot); |
29 } | 29 } |
30 return nullptr; | 30 return nullptr; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 X11CursorFactoryOzone::X11CursorFactoryOzone() | 35 X11CursorFactoryOzone::X11CursorFactoryOzone() |
36 : invisible_cursor_(X11CursorOzone::CreateInvisible()) {} | 36 : invisible_cursor_(X11CursorOzone::CreateInvisible()) {} |
37 | 37 |
38 X11CursorFactoryOzone::~X11CursorFactoryOzone() {} | 38 X11CursorFactoryOzone::~X11CursorFactoryOzone() {} |
39 | 39 |
40 PlatformCursor X11CursorFactoryOzone::GetDefaultCursor(int type) { | 40 PlatformCursor X11CursorFactoryOzone::GetDefaultCursor(CursorType type) { |
41 return ToPlatformCursor(GetDefaultCursorInternal(type).get()); | 41 return ToPlatformCursor(GetDefaultCursorInternal(type).get()); |
42 } | 42 } |
43 | 43 |
44 PlatformCursor X11CursorFactoryOzone::CreateImageCursor( | 44 PlatformCursor X11CursorFactoryOzone::CreateImageCursor( |
45 const SkBitmap& bitmap, | 45 const SkBitmap& bitmap, |
46 const gfx::Point& hotspot, | 46 const gfx::Point& hotspot, |
47 float bitmap_dpi) { | 47 float bitmap_dpi) { |
48 // There is a problem with custom cursors that have no custom data. The | 48 // There is a problem with custom cursors that have no custom data. The |
49 // resulting SkBitmap is empty and X crashes when creating a zero size cursor | 49 // resulting SkBitmap is empty and X crashes when creating a zero size cursor |
50 // image. Return invisible cursor here instead. | 50 // image. Return invisible cursor here instead. |
(...skipping 18 matching lines...) Expand all Loading... |
69 | 69 |
70 void X11CursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { | 70 void X11CursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { |
71 ToX11CursorOzone(cursor)->AddRef(); | 71 ToX11CursorOzone(cursor)->AddRef(); |
72 } | 72 } |
73 | 73 |
74 void X11CursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { | 74 void X11CursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { |
75 ToX11CursorOzone(cursor)->Release(); | 75 ToX11CursorOzone(cursor)->Release(); |
76 } | 76 } |
77 | 77 |
78 scoped_refptr<X11CursorOzone> X11CursorFactoryOzone::GetDefaultCursorInternal( | 78 scoped_refptr<X11CursorOzone> X11CursorFactoryOzone::GetDefaultCursorInternal( |
79 int type) { | 79 CursorType type) { |
80 if (type == kCursorNone) | 80 if (type == CursorType::kNone) |
81 return invisible_cursor_; | 81 return invisible_cursor_; |
82 | 82 |
83 // TODO(kylechar): Use predefined X cursors here instead. | 83 // TODO(kylechar): Use predefined X cursors here instead. |
84 if (!default_cursors_.count(type)) { | 84 if (!default_cursors_.count(type)) { |
85 // Loads the default aura cursor bitmap for cursor type. Falls back on | 85 // Loads the default aura cursor bitmap for cursor type. Falls back on |
86 // pointer cursor then invisible cursor if this fails. | 86 // pointer cursor then invisible cursor if this fails. |
87 scoped_refptr<X11CursorOzone> cursor = CreateAuraX11Cursor(type); | 87 scoped_refptr<X11CursorOzone> cursor = CreateAuraX11Cursor(type); |
88 if (!cursor.get()) { | 88 if (!cursor.get()) { |
89 if (type != kCursorPointer) { | 89 if (type != CursorType::kPointer) { |
90 cursor = GetDefaultCursorInternal(kCursorPointer); | 90 cursor = GetDefaultCursorInternal(CursorType::kPointer); |
91 } else { | 91 } else { |
92 NOTREACHED() << "Failed to load default cursor bitmap"; | 92 NOTREACHED() << "Failed to load default cursor bitmap"; |
93 } | 93 } |
94 } | 94 } |
95 default_cursors_[type] = cursor; | 95 default_cursors_[type] = cursor; |
96 } | 96 } |
97 | 97 |
98 // Returns owned default cursor for this type. | 98 // Returns owned default cursor for this type. |
99 return default_cursors_[type]; | 99 return default_cursors_[type]; |
100 } | 100 } |
101 | 101 |
102 } // namespace ui | 102 } // namespace ui |
OLD | NEW |