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 "core/platform/graphics/Image.h"
30#include "core/platform/graphics/IntPoint.h"
31#include "wtf/Assertions.h"
32#include "wtf/RefPtr.h"
33
34namespace WebCore {
35
36class Cursor {
37    WTF_MAKE_FAST_ALLOCATED;
38public:
39    enum Type {
40        Pointer = 0,
41        Cross,
42        Hand,
43        IBeam,
44        Wait,
45        Help,
46        EastResize,
47        NorthResize,
48        NorthEastResize,
49        NorthWestResize,
50        SouthResize,
51        SouthEastResize,
52        SouthWestResize,
53        WestResize,
54        NorthSouthResize,
55        EastWestResize,
56        NorthEastSouthWestResize,
57        NorthWestSouthEastResize,
58        ColumnResize,
59        RowResize,
60        MiddlePanning,
61        EastPanning,
62        NorthPanning,
63        NorthEastPanning,
64        NorthWestPanning,
65        SouthPanning,
66        SouthEastPanning,
67        SouthWestPanning,
68        WestPanning,
69        Move,
70        VerticalText,
71        Cell,
72        ContextMenu,
73        Alias,
74        Progress,
75        NoDrop,
76        Copy,
77        None,
78        NotAllowed,
79        ZoomIn,
80        ZoomOut,
81        Grab,
82        Grabbing,
83        Custom
84    };
85
86    static const Cursor& fromType(Cursor::Type);
87
88    Cursor()
89        // This is an invalid Cursor and should never actually get used.
90        : m_type(static_cast<Type>(-1))
91    {
92    }
93
94    Cursor(Image*, const IntPoint& hotSpot);
95
96    // Hot spot is in image pixels.
97    Cursor(Image*, const IntPoint& hotSpot, float imageScaleFactor);
98
99    Cursor(const Cursor&);
100    ~Cursor();
101    Cursor& operator=(const Cursor&);
102
103    explicit Cursor(Type);
104    Type type() const
105    {
106        ASSERT(m_type >= 0 && m_type <= Custom);
107        return m_type;
108    }
109    Image* image() const { return m_image.get(); }
110    const IntPoint& hotSpot() const { return m_hotSpot; }
111    // Image scale in image pixels per logical (UI) pixel.
112    float imageScaleFactor() const { return m_imageScaleFactor; }
113
114private:
115    Type m_type;
116    RefPtr<Image> m_image;
117    IntPoint m_hotSpot;
118    float m_imageScaleFactor;
119};
120
121IntPoint determineHotSpot(Image*, const IntPoint& specifiedHotSpot);
122
123const Cursor& pointerCursor();
124const Cursor& crossCursor();
125const Cursor& handCursor();
126const Cursor& moveCursor();
127const Cursor& iBeamCursor();
128const Cursor& waitCursor();
129const Cursor& helpCursor();
130const Cursor& eastResizeCursor();
131const Cursor& northResizeCursor();
132const Cursor& northEastResizeCursor();
133const Cursor& northWestResizeCursor();
134const Cursor& southResizeCursor();
135const Cursor& southEastResizeCursor();
136const Cursor& southWestResizeCursor();
137const Cursor& westResizeCursor();
138const Cursor& northSouthResizeCursor();
139const Cursor& eastWestResizeCursor();
140const Cursor& northEastSouthWestResizeCursor();
141const Cursor& northWestSouthEastResizeCursor();
142const Cursor& columnResizeCursor();
143const Cursor& rowResizeCursor();
144const Cursor& middlePanningCursor();
145const Cursor& eastPanningCursor();
146const Cursor& northPanningCursor();
147const Cursor& northEastPanningCursor();
148const Cursor& northWestPanningCursor();
149const Cursor& southPanningCursor();
150const Cursor& southEastPanningCursor();
151const Cursor& southWestPanningCursor();
152const Cursor& westPanningCursor();
153const Cursor& verticalTextCursor();
154const Cursor& cellCursor();
155const Cursor& contextMenuCursor();
156const Cursor& noDropCursor();
157const Cursor& notAllowedCursor();
158const Cursor& progressCursor();
159const Cursor& aliasCursor();
160const Cursor& zoomInCursor();
161const Cursor& zoomOutCursor();
162const Cursor& copyCursor();
163const Cursor& noneCursor();
164const Cursor& grabCursor();
165const Cursor& grabbingCursor();
166
167} // namespace WebCore
168
169#endif // Cursor_h
170