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