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_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 // Ref-counted cursor that supports both default and custom cursors.
     86 class UI_EXPORT Cursor {
     87  public:
     88   Cursor();
     89 
     90   // Implicit constructor.
     91   Cursor(int type);
     92 
     93   // Allow copy.
     94   Cursor(const Cursor& cursor);
     95 
     96   ~Cursor();
     97 
     98   void SetPlatformCursor(const PlatformCursor& platform);
     99 
    100   void RefCustomCursor();
    101   void UnrefCustomCursor();
    102 
    103   int native_type() const { return native_type_; }
    104   PlatformCursor platform() const { return platform_cursor_; }
    105   float device_scale_factor() const {
    106     return device_scale_factor_;
    107   }
    108   void set_device_scale_factor(float device_scale_factor) {
    109     device_scale_factor_ = device_scale_factor;
    110   }
    111 
    112   bool operator==(int type) const { return native_type_ == type; }
    113   bool operator==(const Cursor& cursor) const {
    114     return native_type_ == cursor.native_type_ &&
    115            platform_cursor_ == cursor.platform_cursor_ &&
    116            device_scale_factor_ == cursor.device_scale_factor_;
    117   }
    118   bool operator!=(int type) const { return native_type_ != type; }
    119   bool operator!=(const Cursor& cursor) const {
    120     return native_type_ != cursor.native_type_ ||
    121            platform_cursor_ != cursor.platform_cursor_ ||
    122            device_scale_factor_ != cursor.device_scale_factor_;
    123   }
    124 
    125   void operator=(const Cursor& cursor) {
    126     Assign(cursor);
    127   }
    128 
    129  private:
    130   void Assign(const Cursor& cursor);
    131 
    132   // See definitions above.
    133   int native_type_;
    134 
    135   PlatformCursor platform_cursor_;
    136 
    137   // The device scale factor for the cursor.
    138   float device_scale_factor_;
    139 };
    140 
    141 }  // namespace ui
    142 
    143 #endif  // UI_BASE_CURSOR_CURSOR_H_
    144