Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / 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  * 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/FloatPoint.h"
33 #include "platform/geometry/IntRect.h"
34 #include "platform/heap/Handle.h"
35 #include "wtf/Forward.h"
36 #include "wtf/RefCounted.h"
37
38 namespace blink {
39
40 class Event;
41 class GraphicsContext;
42 class HostWindow;
43
44 // The Widget class serves as a base class for FrameView, Scrollbar, and PluginView.
45 //
46 // Widgets are connected in a hierarchy, with the restriction that plugins and
47 // scrollbars are always leaves of the tree. Only FrameView can have children
48 // (and therefore the Widget class has no concept of children).
49 class PLATFORM_EXPORT Widget : public RefCountedWillBeGarbageCollectedFinalized<Widget> {
50 public:
51     Widget();
52     virtual ~Widget();
53
54     int x() const { return frameRect().x(); }
55     int y() const { return frameRect().y(); }
56     int width() const { return frameRect().width(); }
57     int height() const { return frameRect().height(); }
58     IntSize size() const { return frameRect().size(); }
59     IntPoint location() const { return frameRect().location(); }
60
61     virtual void setFrameRect(const IntRect& frame) { m_frame = frame; }
62     const IntRect& frameRect() const { return m_frame; }
63     IntRect boundsRect() const { return IntRect(0, 0, width(),  height()); }
64
65     void resize(int w, int h) { setFrameRect(IntRect(x(), y(), w, h)); }
66     void resize(const IntSize& s) { setFrameRect(IntRect(location(), s)); }
67     void move(int x, int y) { setFrameRect(IntRect(x, y, width(), height())); }
68     void move(const IntPoint& p) { setFrameRect(IntRect(p, size())); }
69
70     virtual void paint(GraphicsContext*, const IntRect&) { }
71     void invalidate() { invalidateRect(boundsRect()); }
72     virtual void invalidateRect(const IntRect&) = 0;
73
74     virtual void setFocus(bool) { }
75
76     virtual void show() { }
77     virtual void hide() { }
78     bool isSelfVisible() const { return m_selfVisible; } // Whether or not we have been explicitly marked as visible or not.
79     bool isParentVisible() const { return m_parentVisible; } // Whether or not our parent is visible.
80     bool isVisible() const { return m_selfVisible && m_parentVisible; } // Whether or not we are actually visible.
81     virtual void setParentVisible(bool visible) { m_parentVisible = visible; }
82     void setSelfVisible(bool v) { m_selfVisible = v; }
83
84     virtual bool isFrameView() const { return false; }
85     virtual bool isRemoteFrameView() const { return false; }
86     virtual bool isPluginView() const { return false; }
87     virtual bool isPluginContainer() const { return false; }
88     virtual bool pluginShouldPersist() const { return false; }
89     virtual bool isScrollbar() const { return false; }
90
91     virtual HostWindow* hostWindow() const { ASSERT_NOT_REACHED(); return 0; }
92     virtual void setParent(Widget*);
93     Widget* parent() const { return m_parent; }
94     Widget* root() const;
95
96     virtual void handleEvent(Event*) { }
97
98     // It is important for cross-platform code to realize that Mac has flipped coordinates. Therefore any code
99     // that tries to convert the location of a rect using the point-based convertFromContainingWindow will end
100     // up with an inaccurate rect. Always make sure to use the rect-based convertFromContainingWindow method
101     // when converting window rects.
102     IntRect convertToContainingWindow(const IntRect&) const;
103     IntRect convertFromContainingWindow(const IntRect&) const;
104
105     IntPoint convertToContainingWindow(const IntPoint&) const;
106     IntPoint convertFromContainingWindow(const IntPoint&) const;
107     FloatPoint convertFromContainingWindow(const FloatPoint&) const;
108
109     virtual void frameRectsChanged() { }
110
111     // Notifies this widget that other widgets on the page have been repositioned.
112     virtual void widgetPositionsUpdated() { }
113
114     // Virtual methods to convert points to/from the containing Widget
115     virtual IntRect convertToContainingView(const IntRect&) const;
116     virtual IntRect convertFromContainingView(const IntRect&) const;
117     virtual IntPoint convertToContainingView(const IntPoint&) const;
118     virtual IntPoint convertFromContainingView(const IntPoint&) const;
119
120     // Virtual methods to convert points to/from child widgets
121     virtual IntPoint convertChildToSelf(const Widget*, const IntPoint&) const;
122     virtual IntPoint convertSelfToChild(const Widget*, const IntPoint&) const;
123
124     // Notifies this widget that it will no longer be receiving events.
125     virtual void eventListenersRemoved() { }
126
127     virtual void trace(Visitor*);
128     virtual void dispose() { }
129
130 private:
131     RawPtrWillBeMember<Widget> m_parent;
132     IntRect m_frame;
133     bool m_selfVisible;
134     bool m_parentVisible;
135 };
136
137 } // namespace blink
138
139 #endif // Widget_h