Home | History | Annotate | Download | only in cursor
      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 
     11 namespace gfx {
     12 class Point;
     13 class Size;
     14 }
     15 
     16 #if defined(OS_WIN)
     17 typedef struct HINSTANCE__* HINSTANCE;
     18 typedef struct HICON__* HICON;
     19 typedef HICON HCURSOR;
     20 #endif
     21 
     22 namespace ui {
     23 
     24 #if defined(OS_WIN)
     25 typedef ::HCURSOR PlatformCursor;
     26 #elif defined(USE_X11)
     27 typedef unsigned long PlatformCursor;
     28 #else
     29 typedef 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.
     36 const 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.
     40 const int kCursorPointer = 1;
     41 const int kCursorCross = 2;
     42 const int kCursorHand = 3;
     43 const int kCursorIBeam = 4;
     44 const int kCursorWait = 5;
     45 const int kCursorHelp = 6;
     46 const int kCursorEastResize = 7;
     47 const int kCursorNorthResize = 8;
     48 const int kCursorNorthEastResize = 9;
     49 const int kCursorNorthWestResize = 10;
     50 const int kCursorSouthResize = 11;
     51 const int kCursorSouthEastResize = 12;
     52 const int kCursorSouthWestResize = 13;
     53 const int kCursorWestResize = 14;
     54 const int kCursorNorthSouthResize = 15;
     55 const int kCursorEastWestResize = 16;
     56 const int kCursorNorthEastSouthWestResize = 17;
     57 const int kCursorNorthWestSouthEastResize = 18;
     58 const int kCursorColumnResize = 19;
     59 const int kCursorRowResize = 20;
     60 const int kCursorMiddlePanning = 21;
     61 const int kCursorEastPanning = 22;
     62 const int kCursorNorthPanning = 23;
     63 const int kCursorNorthEastPanning = 24;
     64 const int kCursorNorthWestPanning = 25;
     65 const int kCursorSouthPanning = 26;
     66 const int kCursorSouthEastPanning = 27;
     67 const int kCursorSouthWestPanning = 28;
     68 const int kCursorWestPanning = 29;
     69 const int kCursorMove = 30;
     70 const int kCursorVerticalText = 31;
     71 const int kCursorCell = 32;
     72 const int kCursorContextMenu = 33;
     73 const int kCursorAlias = 34;
     74 const int kCursorProgress = 35;
     75 const int kCursorNoDrop = 36;
     76 const int kCursorCopy = 37;
     77 const int kCursorNone = 38;
     78 const int kCursorNotAllowed = 39;
     79 const int kCursorZoomIn = 40;
     80 const int kCursorZoomOut = 41;
     81 const int kCursorGrab = 42;
     82 const int kCursorGrabbing = 43;
     83 const int kCursorCustom = 44;
     84 
     85 enum CursorSetType {
     86   CURSOR_SET_NORMAL,
     87   CURSOR_SET_LARGE
     88 };
     89 
     90 // Ref-counted cursor that supports both default and custom cursors.
     91 class 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