2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008 Collabora Ltd. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
31 #include <wtf/Forward.h>
32 #include <wtf/RefCounted.h>
34 #if PLATFORM(CHROMIUM)
35 #include "PlatformWidget.h"
39 #include <wtf/RetainPtr.h>
44 #include <QWeakPointer>
55 typedef NSView *PlatformWidget;
59 typedef struct HWND__* HWND;
60 typedef HWND PlatformWidget;
64 typedef struct _GtkWidget GtkWidget;
65 typedef struct _GtkContainer GtkContainer;
66 typedef GtkWidget* PlatformWidget;
73 typedef QWidget* PlatformWidget;
78 typedef wxWindow* PlatformWidget;
83 typedef BView* PlatformWidget;
87 typedef void* PlatformWidget;
91 typedef struct _Evas_Object Evas_Object;
92 typedef struct _Evas Evas;
93 typedef struct _Ecore_Evas Ecore_Evas;
94 typedef Evas_Object* PlatformWidget;
99 typedef QWebPageClient* PlatformPageClient;
101 typedef PlatformWidget PlatformPageClient;
110 class GraphicsContext;
111 class PlatformMouseEvent;
115 enum WidgetNotification { WillPaintFlattened, DidPaintFlattened };
117 // The Widget class serves as a base class for three kinds of objects:
118 // (1) Scrollable areas (ScrollView)
119 // (2) Scrollbars (Scrollbar)
120 // (3) Plugins (PluginView)
122 // A widget may or may not be backed by a platform-specific object (e.g., HWND on Windows, NSView on Mac, QWidget on Qt).
124 // Widgets are connected in a hierarchy, with the restriction that plugins and scrollbars are always leaves of the
125 // tree. Only ScrollViews can have children (and therefore the Widget class has no concept of children).
127 // The rules right now for which widgets get platform-specific objects are as follows:
129 // Scrollbar - Mac, Gtk
130 // Plugin - Mac, Windows (windowed only), Qt (windowed only, widget is an HWND on windows), Gtk (windowed only)
132 class Widget : public RefCounted<Widget> {
134 Widget(PlatformWidget = 0);
137 PlatformWidget platformWidget() const;
138 void setPlatformWidget(PlatformWidget);
141 PlatformWidget topLevelPlatformWidget() const { return m_topLevelPlatformWidget; }
142 void setTopLevelPlatformWidget(PlatformWidget widget)
144 m_topLevelPlatformWidget = widget;
148 int x() const { return frameRect().x(); }
149 int y() const { return frameRect().y(); }
150 int width() const { return frameRect().width(); }
151 int height() const { return frameRect().height(); }
152 IntSize size() const { return frameRect().size(); }
153 IntPoint location() const { return frameRect().location(); }
155 virtual void setFrameRect(const IntRect&);
156 virtual void setBoundsSize(const IntSize&);
157 virtual IntRect frameRect() const;
158 IntRect boundsRect() const { return IntRect(0, 0, width(), height()); }
160 void resize(int w, int h) { setFrameRect(IntRect(x(), y(), w, h)); setBoundsSize(IntSize(w, h)); }
161 void resize(const IntSize& s) { setFrameRect(IntRect(location(), s)); setBoundsSize(s); }
162 void move(int x, int y) { setFrameRect(IntRect(x, y, width(), height())); }
163 void move(const IntPoint& p) { setFrameRect(IntRect(p, size())); }
165 virtual void paint(GraphicsContext*, const IntRect&);
166 void invalidate() { invalidateRect(boundsRect()); }
167 virtual void invalidateRect(const IntRect&) = 0;
169 virtual void setFocus(bool);
171 void setCursor(const Cursor&);
175 bool isSelfVisible() const { return m_selfVisible; } // Whether or not we have been explicitly marked as visible or not.
176 bool isParentVisible() const { return m_parentVisible; } // Whether or not our parent is visible.
177 bool isVisible() const { return m_selfVisible && m_parentVisible; } // Whether or not we are actually visible.
178 virtual void setParentVisible(bool visible) { m_parentVisible = visible; }
179 void setSelfVisible(bool v) { m_selfVisible = v; }
181 void setIsSelected(bool);
183 virtual bool isFrameView() const { return false; }
184 virtual bool isPluginView() const { return false; }
185 // FIXME: The Mac plug-in code should inherit from PluginView. When this happens PluginViewBase and PluginView can become one class.
186 virtual bool isPluginViewBase() const { return false; }
187 virtual bool isScrollbar() const { return false; }
189 void removeFromParent();
190 virtual void setParent(ScrollView* view);
191 ScrollView* parent() const { return m_parent; }
192 ScrollView* root() const;
194 virtual void handleEvent(Event*) { }
196 virtual void notifyWidget(WidgetNotification) { }
198 // It is important for cross-platform code to realize that Mac has flipped coordinates. Therefore any code
199 // that tries to convert the location of a rect using the point-based convertFromContainingWindow will end
200 // up with an inaccurate rect. Always make sure to use the rect-based convertFromContainingWindow method
201 // when converting window rects.
202 IntRect convertToContainingWindow(const IntRect&) const;
203 IntRect convertFromContainingWindow(const IntRect&) const;
205 IntPoint convertToContainingWindow(const IntPoint&) const;
206 IntPoint convertFromContainingWindow(const IntPoint&) const;
208 virtual void frameRectsChanged();
210 // Notifies this widget that other widgets on the page have been repositioned.
211 virtual void widgetPositionsUpdated() {}
214 NSView* getOuterView() const;
216 static void beforeMouseDown(NSView*, Widget*);
217 static void afterMouseDown(NSView*, Widget*);
219 void removeFromSuperview();
223 // FIXME: These should really go to PlatformWidget. They're here currently since
224 // the EFL port considers that Evas_Object (a C object) is a PlatformWidget, but
225 // encapsulating that into a C++ class will make this header clean as it should be.
228 void setEvasObject(Evas_Object*);
229 Evas_Object* evasObject() const;
231 const String edjeTheme() const;
232 void setEdjeTheme(const String &);
233 const String edjeThemeRecursive() const;
236 #if PLATFORM(CHROMIUM)
237 virtual bool isPluginContainer() const { return false; }
241 QObject* bindingObject() const;
242 void setBindingObject(QObject*);
245 // Virtual methods to convert points to/from the containing ScrollView
246 virtual IntRect convertToContainingView(const IntRect&) const;
247 virtual IntRect convertFromContainingView(const IntRect&) const;
248 virtual IntPoint convertToContainingView(const IntPoint&) const;
249 virtual IntPoint convertFromContainingView(const IntPoint&) const;
251 // A means to access the AX cache when this object can get a pointer to it.
252 virtual AXObjectCache* axObjectCache() const { return 0; }
255 void init(PlatformWidget); // Must be called by all Widget constructors to initialize cross-platform data.
257 void releasePlatformWidget();
258 void retainPlatformWidget();
260 // These methods are used to convert from the root widget to the containing window,
261 // which has behavior that may differ between platforms (e.g. Mac uses flipped window coordinates).
262 static IntRect convertFromRootToContainingWindow(const Widget* rootWidget, const IntRect&);
263 static IntRect convertFromContainingWindowToRoot(const Widget* rootWidget, const IntRect&);
265 static IntPoint convertFromRootToContainingWindow(const Widget* rootWidget, const IntPoint&);
266 static IntPoint convertFromContainingWindowToRoot(const Widget* rootWidget, const IntPoint&);
269 ScrollView* m_parent;
271 PlatformWidget m_widget;
273 RetainPtr<NSView> m_widget;
276 bool m_parentVisible;
278 IntRect m_frame; // Not used when a native widget exists.
281 // FIXME: Please see the previous #if PLATFORM(EFL) block.
282 Ecore_Evas* ecoreEvas() const;
284 void applyFallbackCursor();
288 #if PLATFORM(MAC) || PLATFORM(EFL)
289 WidgetPrivate* m_data;
293 QWeakPointer<QObject> m_bindingObject;
297 PlatformWidget m_topLevelPlatformWidget;
303 inline PlatformWidget Widget::platformWidget() const
308 inline void Widget::setPlatformWidget(PlatformWidget widget)
310 if (widget != m_widget) {
311 releasePlatformWidget();
313 retainPlatformWidget();
321 inline void Widget::releasePlatformWidget()
325 inline void Widget::retainPlatformWidget()
331 } // namespace WebCore