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.
30 #include <wtf/Platform.h>
40 typedef NSView* PlatformWidget;
44 typedef struct HWND__* HWND;
45 typedef HWND PlatformWidget;
49 typedef struct _GdkDrawable GdkDrawable;
50 typedef struct _GtkWidget GtkWidget;
51 typedef struct _GtkContainer GtkContainer;
52 typedef GtkWidget* PlatformWidget;
60 typedef QWidget* PlatformWidget;
65 typedef wxWindow* PlatformWidget;
68 #if PLATFORM(CHROMIUM)
69 #include "PlatformWidget.h"
81 class GraphicsContext;
82 class PlatformMouseEvent;
87 // The Widget class serves as a base class for three kinds of objects:
88 // (1) Scrollable areas (ScrollView)
89 // (2) Scrollbars (Scrollbar)
90 // (3) Plugins (PluginView)
92 // A widget may or may not be backed by a platform-specific object (e.g., HWND on Windows, NSView on Mac, QWidget on Qt).
94 // Widgets are connected in a hierarchy, with the restriction that plugins and scrollbars are always leaves of the
95 // tree. Only ScrollViews can have children (and therefore the Widget class has no concept of children).
97 // The rules right now for which widgets get platform-specific objects are as follows:
99 // Scrollbar - Mac, Gtk
100 // Plugin - Mac, Windows (windowed only), Qt (windowed only, widget is an HWND on windows), Gtk (windowed only)
104 Widget(PlatformWidget = 0);
107 PlatformWidget platformWidget() const { return m_widget; }
108 void setPlatformWidget(PlatformWidget widget)
110 if (widget != m_widget) {
111 releasePlatformWidget();
113 retainPlatformWidget();
117 int x() const { return frameRect().x(); }
118 int y() const { return frameRect().y(); }
119 int width() const { return frameRect().width(); }
120 int height() const { return frameRect().height(); }
121 IntSize size() const { return frameRect().size(); }
122 IntPoint pos() const { return frameRect().location(); }
124 virtual void setFrameRect(const IntRect&);
125 virtual IntRect frameRect() const;
126 IntRect boundsRect() const { return IntRect(0, 0, width(), height()); }
128 void resize(int w, int h) { setFrameRect(IntRect(x(), y(), w, h)); }
129 void resize(const IntSize& s) { setFrameRect(IntRect(pos(), s)); }
130 void move(int x, int y) { setFrameRect(IntRect(x, y, width(), height())); }
131 void move(const IntPoint& p) { setFrameRect(IntRect(p, size())); }
133 virtual void paint(GraphicsContext*, const IntRect&);
134 void invalidate() { invalidateRect(boundsRect()); }
135 virtual void invalidateRect(const IntRect&) = 0;
137 virtual void setFocus();
139 void setCursor(const Cursor&);
144 bool isSelfVisible() const { return m_selfVisible; } // Whether or not we have been explicitly marked as visible or not.
145 bool isParentVisible() const { return m_parentVisible; } // Whether or not our parent is visible.
146 bool isVisible() const { return m_selfVisible && m_parentVisible; } // Whether or not we are actually visible.
147 virtual void setParentVisible(bool visible) { m_parentVisible = visible; }
148 void setSelfVisible(bool v) { m_selfVisible = v; }
150 void setIsSelected(bool);
152 virtual bool isFrameView() const { return false; }
153 virtual bool isPluginView() const { return false; }
155 void removeFromParent();
156 virtual void setParent(ScrollView* view);
157 ScrollView* parent() const { return m_parent; }
158 ScrollView* root() const;
160 virtual void handleEvent(Event*) { }
162 // It is important for cross-platform code to realize that Mac has flipped coordinates. Therefore any code
163 // that tries to convert the location of a rect using the point-based convertFromContainingWindow will end
164 // up with an inaccurate rect. Always make sure to use the rect-based convertFromContainingWindow method
165 // when converting window rects.
166 IntRect convertToContainingWindow(const IntRect&) const;
167 IntPoint convertToContainingWindow(const IntPoint&) const;
168 IntPoint convertFromContainingWindow(const IntPoint&) const; // See comment above about when not to use this method.
169 IntRect convertFromContainingWindow(const IntRect&) const;
171 virtual void frameRectsChanged() {}
174 NSView* getOuterView() const;
176 static void beforeMouseDown(NSView*, Widget*);
177 static void afterMouseDown(NSView*, Widget*);
179 void removeFromSuperview();
183 void init(PlatformWidget); // Must be called by all Widget constructors to initialize cross-platform data.
185 void releasePlatformWidget();
186 void retainPlatformWidget();
189 ScrollView* m_parent;
190 PlatformWidget m_widget;
192 bool m_parentVisible;
194 IntRect m_frame; // Not used when a native widget exists.
196 #if PLATFORM(MAC) || PLATFORM(GTK)
197 WidgetPrivate* m_data;
201 } // namespace WebCore