Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef Cursor_h
     27 #define Cursor_h
     28 
     29 #include "Image.h"
     30 #include "IntPoint.h"
     31 #include <wtf/RefPtr.h>
     32 
     33 #if PLATFORM(WIN)
     34 typedef struct HICON__* HICON;
     35 typedef HICON HCURSOR;
     36 #include <wtf/PassRefPtr.h>
     37 #include <wtf/RefCounted.h>
     38 #elif PLATFORM(MAC)
     39 #include <wtf/RetainPtr.h>
     40 #elif PLATFORM(GTK)
     41 #include "GRefPtrGtk.h"
     42 #elif PLATFORM(QT)
     43 #include <QCursor>
     44 #elif PLATFORM(CHROMIUM)
     45 #include "PlatformCursor.h"
     46 #elif PLATFORM(HAIKU)
     47 #include <app/Cursor.h>
     48 #endif
     49 
     50 #if PLATFORM(MAC)
     51 #ifdef __OBJC__
     52 @class NSCursor;
     53 #else
     54 class NSCursor;
     55 #endif
     56 #endif
     57 
     58 #if PLATFORM(WX)
     59 class wxCursor;
     60 #endif
     61 
     62 #if PLATFORM(WIN)
     63 typedef struct HICON__ *HICON;
     64 typedef HICON HCURSOR;
     65 #endif
     66 
     67 #if PLATFORM(WIN) || PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
     68 #define WTF_USE_LAZY_NATIVE_CURSOR 1
     69 #endif
     70 
     71 namespace WebCore {
     72 
     73     class Image;
     74 
     75 #if PLATFORM(WIN)
     76     class SharedCursor : public RefCounted<SharedCursor> {
     77     public:
     78         static PassRefPtr<SharedCursor> create(HCURSOR nativeCursor) { return adoptRef(new SharedCursor(nativeCursor)); }
     79         ~SharedCursor();
     80         HCURSOR nativeCursor() const { return m_nativeCursor; }
     81     private:
     82         SharedCursor(HCURSOR nativeCursor) : m_nativeCursor(nativeCursor) { }
     83         HCURSOR m_nativeCursor;
     84     };
     85     typedef RefPtr<SharedCursor> PlatformCursor;
     86 #elif PLATFORM(MAC)
     87     typedef NSCursor *PlatformCursor;
     88 #elif PLATFORM(GTK)
     89     typedef GRefPtr<GdkCursor> PlatformCursor;
     90 #elif PLATFORM(EFL)
     91     typedef const char* PlatformCursor;
     92 #elif PLATFORM(QT) && !defined(QT_NO_CURSOR)
     93     // Do not need to be shared but need to be created dynamically via ensurePlatformCursor.
     94     typedef QCursor* PlatformCursor;
     95 #elif PLATFORM(WX)
     96     typedef wxCursor* PlatformCursor;
     97 #elif PLATFORM(CHROMIUM)
     98     // See PlatformCursor.h
     99 #elif PLATFORM(HAIKU)
    100     typedef BCursor* PlatformCursor;
    101 #else
    102     typedef void* PlatformCursor;
    103 #endif
    104 
    105     class Cursor {
    106     public:
    107         enum Type {
    108             Pointer,
    109             Cross,
    110             Hand,
    111             IBeam,
    112             Wait,
    113             Help,
    114             EastResize,
    115             NorthResize,
    116             NorthEastResize,
    117             NorthWestResize,
    118             SouthResize,
    119             SouthEastResize,
    120             SouthWestResize,
    121             WestResize,
    122             NorthSouthResize,
    123             EastWestResize,
    124             NorthEastSouthWestResize,
    125             NorthWestSouthEastResize,
    126             ColumnResize,
    127             RowResize,
    128             MiddlePanning,
    129             EastPanning,
    130             NorthPanning,
    131             NorthEastPanning,
    132             NorthWestPanning,
    133             SouthPanning,
    134             SouthEastPanning,
    135             SouthWestPanning,
    136             WestPanning,
    137             Move,
    138             VerticalText,
    139             Cell,
    140             ContextMenu,
    141             Alias,
    142             Progress,
    143             NoDrop,
    144             Copy,
    145             None,
    146             NotAllowed,
    147             ZoomIn,
    148             ZoomOut,
    149             Grab,
    150             Grabbing,
    151             Custom
    152         };
    153 
    154         static const Cursor& fromType(Cursor::Type);
    155 
    156         Cursor()
    157 #if !PLATFORM(EFL)
    158             : m_platformCursor(0)
    159 #endif
    160         {
    161         }
    162 
    163         Cursor(Image*, const IntPoint& hotSpot);
    164         Cursor(const Cursor&);
    165         ~Cursor();
    166         Cursor& operator=(const Cursor&);
    167 
    168 #if USE(LAZY_NATIVE_CURSOR)
    169         Cursor(Type);
    170         Type type() const { return m_type; }
    171         Image* image() const { return m_image.get(); }
    172         const IntPoint& hotSpot() const { return m_hotSpot; }
    173         PlatformCursor platformCursor() const;
    174 #else
    175         Cursor(PlatformCursor);
    176         PlatformCursor impl() const { return m_platformCursor; }
    177 #endif
    178 
    179      private:
    180 #if USE(LAZY_NATIVE_CURSOR)
    181         void ensurePlatformCursor() const;
    182 
    183         Type m_type;
    184         RefPtr<Image> m_image;
    185         IntPoint m_hotSpot;
    186 #endif
    187 
    188 #if !PLATFORM(MAC)
    189         mutable PlatformCursor m_platformCursor;
    190 #else
    191         mutable RetainPtr<NSCursor> m_platformCursor;
    192 #endif
    193     };
    194 
    195     IntPoint determineHotSpot(Image*, const IntPoint& specifiedHotSpot);
    196     const char* nameForCursorType(Cursor::Type);
    197 
    198     const Cursor& pointerCursor();
    199     const Cursor& crossCursor();
    200     const Cursor& handCursor();
    201     const Cursor& moveCursor();
    202     const Cursor& iBeamCursor();
    203     const Cursor& waitCursor();
    204     const Cursor& helpCursor();
    205     const Cursor& eastResizeCursor();
    206     const Cursor& northResizeCursor();
    207     const Cursor& northEastResizeCursor();
    208     const Cursor& northWestResizeCursor();
    209     const Cursor& southResizeCursor();
    210     const Cursor& southEastResizeCursor();
    211     const Cursor& southWestResizeCursor();
    212     const Cursor& westResizeCursor();
    213     const Cursor& northSouthResizeCursor();
    214     const Cursor& eastWestResizeCursor();
    215     const Cursor& northEastSouthWestResizeCursor();
    216     const Cursor& northWestSouthEastResizeCursor();
    217     const Cursor& columnResizeCursor();
    218     const Cursor& rowResizeCursor();
    219     const Cursor& middlePanningCursor();
    220     const Cursor& eastPanningCursor();
    221     const Cursor& northPanningCursor();
    222     const Cursor& northEastPanningCursor();
    223     const Cursor& northWestPanningCursor();
    224     const Cursor& southPanningCursor();
    225     const Cursor& southEastPanningCursor();
    226     const Cursor& southWestPanningCursor();
    227     const Cursor& westPanningCursor();
    228     const Cursor& verticalTextCursor();
    229     const Cursor& cellCursor();
    230     const Cursor& contextMenuCursor();
    231     const Cursor& noDropCursor();
    232     const Cursor& notAllowedCursor();
    233     const Cursor& progressCursor();
    234     const Cursor& aliasCursor();
    235     const Cursor& zoomInCursor();
    236     const Cursor& zoomOutCursor();
    237     const Cursor& copyCursor();
    238     const Cursor& noneCursor();
    239     const Cursor& grabCursor();
    240     const Cursor& grabbingCursor();
    241 
    242 } // namespace WebCore
    243 
    244 #endif // Cursor_h
    245