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 #ifndef UI_BASE_CURSOR_CURSOR_H_ | 5 #ifndef UI_BASE_CURSOR_CURSOR_H_ |
6 #define UI_BASE_CURSOR_CURSOR_H_ | 6 #define UI_BASE_CURSOR_CURSOR_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "ui/base/ui_base_export.h" | 9 #include "ui/base/ui_base_export.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 typedef struct HINSTANCE__* HINSTANCE; | 12 typedef struct HINSTANCE__* HINSTANCE; |
13 typedef struct HICON__* HICON; | 13 typedef struct HICON__* HICON; |
14 typedef HICON HCURSOR; | 14 typedef HICON HCURSOR; |
15 #endif | 15 #endif |
16 | 16 |
17 namespace ui { | 17 namespace ui { |
18 | 18 |
19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
20 typedef ::HCURSOR PlatformCursor; | 20 typedef ::HCURSOR PlatformCursor; |
21 #elif defined(USE_X11) | 21 #elif defined(USE_X11) |
22 typedef unsigned long PlatformCursor; | 22 typedef unsigned long PlatformCursor; |
23 #else | 23 #else |
24 typedef void* PlatformCursor; | 24 typedef void* PlatformCursor; |
25 #endif | 25 #endif |
26 | 26 |
27 // TODO(jamescook): Once we're on C++0x we could change these constants | 27 enum class CursorType { |
28 // to an enum and forward declare it in native_widget_types.h. | 28 // Equivalent to a NULL HCURSOR on Windows. |
| 29 kNull = 0, |
29 | 30 |
30 // Equivalent to a NULL HCURSOR on Windows. | 31 // These cursors mirror WebKit cursors from WebCursorInfo, but are replicated |
31 const int kCursorNull = 0; | 32 // here so we don't introduce a WebKit dependency. |
| 33 kPointer = 1, |
| 34 kCross = 2, |
| 35 kHand = 3, |
| 36 kIBeam = 4, |
| 37 kWait = 5, |
| 38 kHelp = 6, |
| 39 kEastResize = 7, |
| 40 kNorthResize = 8, |
| 41 kNorthEastResize = 9, |
| 42 kNorthWestResize = 10, |
| 43 kSouthResize = 11, |
| 44 kSouthEastResize = 12, |
| 45 kSouthWestResize = 13, |
| 46 kWestResize = 14, |
| 47 kNorthSouthResize = 15, |
| 48 kEastWestResize = 16, |
| 49 kNorthEastSouthWestResize = 17, |
| 50 kNorthWestSouthEastResize = 18, |
| 51 kColumnResize = 19, |
| 52 kRowResize = 20, |
| 53 kMiddlePanning = 21, |
| 54 kEastPanning = 22, |
| 55 kNorthPanning = 23, |
| 56 kNorthEastPanning = 24, |
| 57 kNorthWestPanning = 25, |
| 58 kSouthPanning = 26, |
| 59 kSouthEastPanning = 27, |
| 60 kSouthWestPanning = 28, |
| 61 kWestPanning = 29, |
| 62 kMove = 30, |
| 63 kVerticalText = 31, |
| 64 kCell = 32, |
| 65 kContextMenu = 33, |
| 66 kAlias = 34, |
| 67 kProgress = 35, |
| 68 kNoDrop = 36, |
| 69 kCopy = 37, |
| 70 kNone = 38, |
| 71 kNotAllowed = 39, |
| 72 kZoomIn = 40, |
| 73 kZoomOut = 41, |
| 74 kGrab = 42, |
| 75 kGrabbing = 43, |
| 76 kCustom = 44, |
32 | 77 |
33 // These cursors mirror WebKit cursors from WebCursorInfo, but are replicated | 78 // These additional drag and drop cursors are not listed in WebCursorInfo. |
34 // here so we don't introduce a WebKit dependency. | 79 kDndNone = 45, |
35 const int kCursorPointer = 1; | 80 kDndMove = 46, |
36 const int kCursorCross = 2; | 81 kDndCopy = 47, |
37 const int kCursorHand = 3; | 82 kDndLink = 48, |
38 const int kCursorIBeam = 4; | 83 }; |
39 const int kCursorWait = 5; | |
40 const int kCursorHelp = 6; | |
41 const int kCursorEastResize = 7; | |
42 const int kCursorNorthResize = 8; | |
43 const int kCursorNorthEastResize = 9; | |
44 const int kCursorNorthWestResize = 10; | |
45 const int kCursorSouthResize = 11; | |
46 const int kCursorSouthEastResize = 12; | |
47 const int kCursorSouthWestResize = 13; | |
48 const int kCursorWestResize = 14; | |
49 const int kCursorNorthSouthResize = 15; | |
50 const int kCursorEastWestResize = 16; | |
51 const int kCursorNorthEastSouthWestResize = 17; | |
52 const int kCursorNorthWestSouthEastResize = 18; | |
53 const int kCursorColumnResize = 19; | |
54 const int kCursorRowResize = 20; | |
55 const int kCursorMiddlePanning = 21; | |
56 const int kCursorEastPanning = 22; | |
57 const int kCursorNorthPanning = 23; | |
58 const int kCursorNorthEastPanning = 24; | |
59 const int kCursorNorthWestPanning = 25; | |
60 const int kCursorSouthPanning = 26; | |
61 const int kCursorSouthEastPanning = 27; | |
62 const int kCursorSouthWestPanning = 28; | |
63 const int kCursorWestPanning = 29; | |
64 const int kCursorMove = 30; | |
65 const int kCursorVerticalText = 31; | |
66 const int kCursorCell = 32; | |
67 const int kCursorContextMenu = 33; | |
68 const int kCursorAlias = 34; | |
69 const int kCursorProgress = 35; | |
70 const int kCursorNoDrop = 36; | |
71 const int kCursorCopy = 37; | |
72 const int kCursorNone = 38; | |
73 const int kCursorNotAllowed = 39; | |
74 const int kCursorZoomIn = 40; | |
75 const int kCursorZoomOut = 41; | |
76 const int kCursorGrab = 42; | |
77 const int kCursorGrabbing = 43; | |
78 const int kCursorCustom = 44; | |
79 const int kCursorDndNone = 45; | |
80 const int kCursorDndMove = 46; | |
81 const int kCursorDndCopy = 47; | |
82 const int kCursorDndLink = 48; | |
83 | 84 |
84 enum CursorSetType { | 85 enum CursorSetType { |
85 CURSOR_SET_NORMAL, | 86 CURSOR_SET_NORMAL, |
86 CURSOR_SET_LARGE | 87 CURSOR_SET_LARGE |
87 }; | 88 }; |
88 | 89 |
89 // Ref-counted cursor that supports both default and custom cursors. | 90 // Ref-counted cursor that supports both default and custom cursors. |
90 class UI_BASE_EXPORT Cursor { | 91 class UI_BASE_EXPORT Cursor { |
91 public: | 92 public: |
92 Cursor(); | 93 Cursor(); |
93 | 94 |
94 // Implicit constructor. | 95 // Implicit constructor. |
95 Cursor(int type); | 96 Cursor(CursorType type); |
96 | 97 |
97 // Allow copy. | 98 // Allow copy. |
98 Cursor(const Cursor& cursor); | 99 Cursor(const Cursor& cursor); |
99 | 100 |
100 ~Cursor(); | 101 ~Cursor(); |
101 | 102 |
102 void SetPlatformCursor(const PlatformCursor& platform); | 103 void SetPlatformCursor(const PlatformCursor& platform); |
103 | 104 |
104 void RefCustomCursor(); | 105 void RefCustomCursor(); |
105 void UnrefCustomCursor(); | 106 void UnrefCustomCursor(); |
106 | 107 |
107 int native_type() const { return native_type_; } | 108 CursorType native_type() const { return native_type_; } |
108 PlatformCursor platform() const { return platform_cursor_; } | 109 PlatformCursor platform() const { return platform_cursor_; } |
109 float device_scale_factor() const { | 110 float device_scale_factor() const { |
110 return device_scale_factor_; | 111 return device_scale_factor_; |
111 } | 112 } |
112 void set_device_scale_factor(float device_scale_factor) { | 113 void set_device_scale_factor(float device_scale_factor) { |
113 device_scale_factor_ = device_scale_factor; | 114 device_scale_factor_ = device_scale_factor; |
114 } | 115 } |
115 | 116 |
116 bool operator==(int type) const { return native_type_ == type; } | 117 bool operator==(CursorType type) const { return native_type_ == type; } |
117 bool operator==(const Cursor& cursor) const { | 118 bool operator==(const Cursor& cursor) const { |
118 return native_type_ == cursor.native_type_ && | 119 return native_type_ == cursor.native_type_ && |
119 platform_cursor_ == cursor.platform_cursor_ && | 120 platform_cursor_ == cursor.platform_cursor_ && |
120 device_scale_factor_ == cursor.device_scale_factor_; | 121 device_scale_factor_ == cursor.device_scale_factor_; |
121 } | 122 } |
122 bool operator!=(int type) const { return native_type_ != type; } | 123 bool operator!=(CursorType type) const { return native_type_ != type; } |
123 bool operator!=(const Cursor& cursor) const { | 124 bool operator!=(const Cursor& cursor) const { |
124 return native_type_ != cursor.native_type_ || | 125 return native_type_ != cursor.native_type_ || |
125 platform_cursor_ != cursor.platform_cursor_ || | 126 platform_cursor_ != cursor.platform_cursor_ || |
126 device_scale_factor_ != cursor.device_scale_factor_; | 127 device_scale_factor_ != cursor.device_scale_factor_; |
127 } | 128 } |
128 | 129 |
129 void operator=(const Cursor& cursor) { | 130 void operator=(const Cursor& cursor) { |
130 Assign(cursor); | 131 Assign(cursor); |
131 } | 132 } |
132 | 133 |
133 private: | 134 private: |
134 void Assign(const Cursor& cursor); | 135 void Assign(const Cursor& cursor); |
135 | 136 |
136 // See definitions above. | 137 // See definitions above. |
137 int native_type_; | 138 CursorType native_type_; |
138 | 139 |
139 PlatformCursor platform_cursor_; | 140 PlatformCursor platform_cursor_; |
140 | 141 |
141 // The device scale factor for the cursor. | 142 // The device scale factor for the cursor. |
142 float device_scale_factor_; | 143 float device_scale_factor_; |
143 }; | 144 }; |
144 | 145 |
145 } // namespace ui | 146 } // namespace ui |
146 | 147 |
147 #endif // UI_BASE_CURSOR_CURSOR_H_ | 148 #endif // UI_BASE_CURSOR_CURSOR_H_ |
OLD | NEW |