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