• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2008 Collabora Ltd.  All rights reserved.
4  * Copyright (C) 2013 Google Inc.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef Widget_h
29 #define Widget_h
30 
31 #include "platform/PlatformExport.h"
32 #include "platform/geometry/IntRect.h"
33 #include "wtf/Forward.h"
34 #include "wtf/RefCounted.h"
35 
36 namespace WebCore {
37 
38 class Event;
39 class GraphicsContext;
40 class HostWindow;
41 
42 // The Widget class serves as a base class for three kinds of objects:
43 // (1) Scrollable areas (ScrollView)
44 // (2) Scrollbars (Scrollbar)
45 // (3) Plugins (PluginView)
46 //
47 // Widgets are connected in a hierarchy, with the restriction that plugins and
48 // scrollbars are always leaves of the tree. Only ScrollViews can have children
49 // (and therefore the Widget class has no concept of children).
50 class PLATFORM_EXPORT Widget : public RefCounted<Widget> {
51 public:
52     Widget();
53     virtual ~Widget();
54 
x()55     int x() const { return frameRect().x(); }
y()56     int y() const { return frameRect().y(); }
width()57     int width() const { return frameRect().width(); }
height()58     int height() const { return frameRect().height(); }
size()59     IntSize size() const { return frameRect().size(); }
location()60     IntPoint location() const { return frameRect().location(); }
61 
setFrameRect(const IntRect & frame)62     virtual void setFrameRect(const IntRect& frame) { m_frame = frame; }
frameRect()63     const IntRect& frameRect() const { return m_frame; }
boundsRect()64     IntRect boundsRect() const { return IntRect(0, 0, width(),  height()); }
65 
resize(int w,int h)66     void resize(int w, int h) { setFrameRect(IntRect(x(), y(), w, h)); }
resize(const IntSize & s)67     void resize(const IntSize& s) { setFrameRect(IntRect(location(), s)); }
move(int x,int y)68     void move(int x, int y) { setFrameRect(IntRect(x, y, width(), height())); }
move(const IntPoint & p)69     void move(const IntPoint& p) { setFrameRect(IntRect(p, size())); }
70 
paint(GraphicsContext *,const IntRect &)71     virtual void paint(GraphicsContext*, const IntRect&) { }
invalidate()72     void invalidate() { invalidateRect(boundsRect()); }
73     virtual void invalidateRect(const IntRect&) = 0;
74 
setFocus(bool)75     virtual void setFocus(bool) { }
76 
show()77     virtual void show() { }
hide()78     virtual void hide() { }
isSelfVisible()79     bool isSelfVisible() const { return m_selfVisible; } // Whether or not we have been explicitly marked as visible or not.
isParentVisible()80     bool isParentVisible() const { return m_parentVisible; } // Whether or not our parent is visible.
isVisible()81     bool isVisible() const { return m_selfVisible && m_parentVisible; } // Whether or not we are actually visible.
setParentVisible(bool visible)82     virtual void setParentVisible(bool visible) { m_parentVisible = visible; }
setSelfVisible(bool v)83     void setSelfVisible(bool v) { m_selfVisible = v; }
84 
isFrameView()85     virtual bool isFrameView() const { return false; }
isPluginView()86     virtual bool isPluginView() const { return false; }
isPluginContainer()87     virtual bool isPluginContainer() const { return false; }
isScrollbar()88     virtual bool isScrollbar() const { return false; }
isScrollView()89     virtual bool isScrollView() const { return false; }
90 
hostWindow()91     virtual HostWindow* hostWindow() const { ASSERT_NOT_REACHED(); return 0; }
92     virtual void setParent(Widget*);
parent()93     Widget* parent() const { return m_parent; }
94     Widget* root() const;
95 
handleEvent(Event *)96     virtual void handleEvent(Event*) { }
97 
98     IntRect convertToRootView(const IntRect&) const;
99     IntRect convertFromRootView(const IntRect&) const;
100 
101     IntPoint convertToRootView(const IntPoint&) const;
102     IntPoint convertFromRootView(const IntPoint&) const;
103 
104     // It is important for cross-platform code to realize that Mac has flipped coordinates. Therefore any code
105     // that tries to convert the location of a rect using the point-based convertFromContainingWindow will end
106     // up with an inaccurate rect. Always make sure to use the rect-based convertFromContainingWindow method
107     // when converting window rects.
108     IntRect convertToContainingWindow(const IntRect&) const;
109     IntRect convertFromContainingWindow(const IntRect&) const;
110 
111     IntPoint convertToContainingWindow(const IntPoint&) const;
112     IntPoint convertFromContainingWindow(const IntPoint&) const;
113 
frameRectsChanged()114     virtual void frameRectsChanged() { }
115 
116     // Notifies this widget that other widgets on the page have been repositioned.
widgetPositionsUpdated()117     virtual void widgetPositionsUpdated() { }
118 
119     // Notifies this widget that its clip rect changed.
clipRectChanged()120     virtual void clipRectChanged() { }
121 
122     // Virtual methods to convert points to/from the containing ScrollView
123     virtual IntRect convertToContainingView(const IntRect&) const;
124     virtual IntRect convertFromContainingView(const IntRect&) const;
125     virtual IntPoint convertToContainingView(const IntPoint&) const;
126     virtual IntPoint convertFromContainingView(const IntPoint&) const;
127 
128     // Virtual methods to convert points to/from child widgets
129     virtual IntPoint convertChildToSelf(const Widget*, const IntPoint&) const;
130     virtual IntPoint convertSelfToChild(const Widget*, const IntPoint&) const;
131 
132     // Notifies this widget that it will no longer be receiving events.
eventListenersRemoved()133     virtual void eventListenersRemoved() { }
134 
135 private:
136     Widget* m_parent;
137     IntRect m_frame;
138     bool m_selfVisible;
139     bool m_parentVisible;
140 };
141 
142 } // namespace WebCore
143 
144 #endif // Widget_h
145