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