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>
33 #define NSView WAKView
44 typedef NSView
* PlatformWidget
;
48 typedef struct HWND__
* HWND
;
49 typedef HWND PlatformWidget
;
53 typedef struct _GdkDrawable GdkDrawable
;
54 typedef struct _GtkWidget GtkWidget
;
55 typedef struct _GtkContainer GtkContainer
;
56 typedef GtkWidget
* PlatformWidget
;
64 typedef QWidget
* PlatformWidget
;
69 typedef wxWindow
* PlatformWidget
;
72 #if PLATFORM(CHROMIUM)
73 #include "PlatformWidget.h"
85 class GraphicsContext
;
86 class PlatformMouseEvent
;
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)
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).
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).
101 // The rules right now for which widgets get platform-specific objects are as follows:
103 // Scrollbar - Mac, Gtk
104 // Plugin - Mac, Windows (windowed only), Qt (windowed only, widget is an HWND on windows), Gtk (windowed only)
108 Widget(PlatformWidget
= 0);
111 PlatformWidget
platformWidget() const { return m_widget
; }
112 void setPlatformWidget(PlatformWidget widget
)
114 if (widget
!= m_widget
) {
115 releasePlatformWidget();
117 retainPlatformWidget();
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(); }
128 virtual void setFrameRect(const IntRect
&);
129 virtual IntRect
frameRect() const;
130 IntRect
boundsRect() const { return IntRect(0, 0, width(), height()); }
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())); }
137 virtual void paint(GraphicsContext
*, const IntRect
&);
138 void invalidate() { invalidateRect(boundsRect()); }
139 virtual void invalidateRect(const IntRect
&) = 0;
141 virtual void setFocus();
143 void setCursor(const Cursor
&);
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
; }
154 void setIsSelected(bool);
156 virtual bool isFrameView() const { return false; }
157 virtual bool isPluginView() const { return false; }
159 void removeFromParent();
160 virtual void setParent(ScrollView
* view
);
161 ScrollView
* parent() const { return m_parent
; }
162 ScrollView
* root() const;
164 virtual void handleEvent(Event
*) { }
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;
175 virtual void frameRectsChanged() {}
178 NSView
* getOuterView() const;
180 static void beforeMouseDown(NSView
*, Widget
*);
181 static void afterMouseDown(NSView
*, Widget
*);
183 void removeFromSuperview();
185 void addToSuperview(NSView
* superview
);
188 void init(PlatformWidget
); // Must be called by all Widget constructors to initialize cross-platform data.
190 void releasePlatformWidget();
191 void retainPlatformWidget();
194 ScrollView
* m_parent
;
195 PlatformWidget m_widget
;
197 bool m_parentVisible
;
199 IntRect m_frame
; // Not used when a native widget exists.
201 #if PLATFORM(MAC) || PLATFORM(GTK)
202 WidgetPrivate
* m_data
;
206 } // namespace WebCore