]> git.saurik.com Git - iphone-api.git/blob - WebCore/Widget.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / Widget.h
1 /*
2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008 Collabora Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef Widget_h
28 #define Widget_h
29
30 #include <wtf/Platform.h>
31
32 #ifndef NSView
33 #define NSView WAKView
34 #endif
35
36 #if PLATFORM(MAC)
37 #ifdef __OBJC__
38 @class NSView;
39 @class NSWindow;
40 #else
41 class NSView;
42 class NSWindow;
43 #endif
44 typedef NSView* PlatformWidget;
45 #endif
46
47 #if PLATFORM(WIN)
48 typedef struct HWND__* HWND;
49 typedef HWND PlatformWidget;
50 #endif
51
52 #if PLATFORM(GTK)
53 typedef struct _GdkDrawable GdkDrawable;
54 typedef struct _GtkWidget GtkWidget;
55 typedef struct _GtkContainer GtkContainer;
56 typedef GtkWidget* PlatformWidget;
57 #endif
58
59 #if PLATFORM(QT)
60 #include <qglobal.h>
61 QT_BEGIN_NAMESPACE
62 class QWidget;
63 QT_END_NAMESPACE
64 typedef QWidget* PlatformWidget;
65 #endif
66
67 #if PLATFORM(WX)
68 class wxWindow;
69 typedef wxWindow* PlatformWidget;
70 #endif
71
72 #if PLATFORM(CHROMIUM)
73 #include "PlatformWidget.h"
74 #endif
75
76 #include "IntPoint.h"
77 #include "IntRect.h"
78 #include "IntSize.h"
79
80 namespace WebCore {
81
82 class Cursor;
83 class Event;
84 class Font;
85 class GraphicsContext;
86 class PlatformMouseEvent;
87 class ScrollView;
88 class WidgetClient;
89 class WidgetPrivate;
90
91 // The Widget class serves as a base class for three kinds of objects:
92 // (1) Scrollable areas (ScrollView)
93 // (2) Scrollbars (Scrollbar)
94 // (3) Plugins (PluginView)
95 //
96 // A widget may or may not be backed by a platform-specific object (e.g., HWND on Windows, NSView on Mac, QWidget on Qt).
97 //
98 // Widgets are connected in a hierarchy, with the restriction that plugins and scrollbars are always leaves of the
99 // tree. Only ScrollViews can have children (and therefore the Widget class has no concept of children).
100 //
101 // The rules right now for which widgets get platform-specific objects are as follows:
102 // ScrollView - Mac
103 // Scrollbar - Mac, Gtk
104 // Plugin - Mac, Windows (windowed only), Qt (windowed only, widget is an HWND on windows), Gtk (windowed only)
105 //
106 class Widget {
107 public:
108 Widget(PlatformWidget = 0);
109 virtual ~Widget();
110
111 PlatformWidget platformWidget() const { return m_widget; }
112 void setPlatformWidget(PlatformWidget widget)
113 {
114 if (widget != m_widget) {
115 releasePlatformWidget();
116 m_widget = widget;
117 retainPlatformWidget();
118 }
119 }
120
121 int x() const { return frameRect().x(); }
122 int y() const { return frameRect().y(); }
123 int width() const { return frameRect().width(); }
124 int height() const { return frameRect().height(); }
125 IntSize size() const { return frameRect().size(); }
126 IntPoint pos() const { return frameRect().location(); }
127
128 virtual void setFrameRect(const IntRect&);
129 virtual IntRect frameRect() const;
130 IntRect boundsRect() const { return IntRect(0, 0, width(), height()); }
131
132 void resize(int w, int h) { setFrameRect(IntRect(x(), y(), w, h)); }
133 void resize(const IntSize& s) { setFrameRect(IntRect(pos(), s)); }
134 void move(int x, int y) { setFrameRect(IntRect(x, y, width(), height())); }
135 void move(const IntPoint& p) { setFrameRect(IntRect(p, size())); }
136
137 virtual void paint(GraphicsContext*, const IntRect&);
138 void invalidate() { invalidateRect(boundsRect()); }
139 virtual void invalidateRect(const IntRect&) = 0;
140
141 virtual void setFocus();
142
143 void setCursor(const Cursor&);
144 Cursor cursor();
145
146 virtual void show();
147 virtual void hide();
148 bool isSelfVisible() const { return m_selfVisible; } // Whether or not we have been explicitly marked as visible or not.
149 bool isParentVisible() const { return m_parentVisible; } // Whether or not our parent is visible.
150 bool isVisible() const { return m_selfVisible && m_parentVisible; } // Whether or not we are actually visible.
151 virtual void setParentVisible(bool visible) { m_parentVisible = visible; }
152 void setSelfVisible(bool v) { m_selfVisible = v; }
153
154 void setIsSelected(bool);
155
156 virtual bool isFrameView() const { return false; }
157 virtual bool isPluginView() const { return false; }
158
159 void removeFromParent();
160 virtual void setParent(ScrollView* view);
161 ScrollView* parent() const { return m_parent; }
162 ScrollView* root() const;
163
164 virtual void handleEvent(Event*) { }
165
166 // It is important for cross-platform code to realize that Mac has flipped coordinates. Therefore any code
167 // that tries to convert the location of a rect using the point-based convertFromContainingWindow will end
168 // up with an inaccurate rect. Always make sure to use the rect-based convertFromContainingWindow method
169 // when converting window rects.
170 IntRect convertToContainingWindow(const IntRect&) const;
171 IntPoint convertToContainingWindow(const IntPoint&) const;
172 IntPoint convertFromContainingWindow(const IntPoint&) const; // See comment above about when not to use this method.
173 IntRect convertFromContainingWindow(const IntRect&) const;
174
175 virtual void frameRectsChanged() {}
176
177 #if PLATFORM(MAC)
178 NSView* getOuterView() const;
179
180 static void beforeMouseDown(NSView*, Widget*);
181 static void afterMouseDown(NSView*, Widget*);
182
183 void removeFromSuperview();
184 #endif
185 void addToSuperview(NSView* superview);
186
187 private:
188 void init(PlatformWidget); // Must be called by all Widget constructors to initialize cross-platform data.
189
190 void releasePlatformWidget();
191 void retainPlatformWidget();
192
193 private:
194 ScrollView* m_parent;
195 PlatformWidget m_widget;
196 bool m_selfVisible;
197 bool m_parentVisible;
198
199 IntRect m_frame; // Not used when a native widget exists.
200
201 #if PLATFORM(MAC) || PLATFORM(GTK)
202 WidgetPrivate* m_data;
203 #endif
204 };
205
206 } // namespace WebCore
207
208 #endif // Widget_h