OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
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. | |
13 * | |
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. | |
25 */ | |
26 | |
27 #include "config.h" | |
28 #include "core/platform/Widget.h" | |
29 | |
30 #include "platform/HostWindow.h" | |
31 #include "platform/geometry/IntRect.h" | |
32 | |
33 #include "wtf/Assertions.h" | |
34 | |
35 namespace WebCore { | |
36 | |
37 Widget::Widget() | |
38 : m_parent(0) | |
39 , m_selfVisible(false) | |
40 , m_parentVisible(false) | |
41 { | |
42 } | |
43 | |
44 Widget::~Widget() | |
45 { | |
46 ASSERT(!parent()); | |
47 } | |
48 | |
49 void Widget::setCursor(const Cursor& cursor) | |
50 { | |
51 if (Widget* view = root()) | |
52 view->hostWindow()->setCursor(cursor); | |
53 } | |
54 | |
55 void Widget::setParent(Widget* widget) | |
56 { | |
57 ASSERT(!widget || !m_parent); | |
58 if (!widget || !widget->isVisible()) | |
59 setParentVisible(false); | |
60 m_parent = widget; | |
61 if (widget && widget->isVisible()) | |
62 setParentVisible(true); | |
63 } | |
64 | |
65 Widget* Widget::root() const | |
66 { | |
67 const Widget* top = this; | |
68 while (top->parent()) | |
69 top = top->parent(); | |
70 if (top->isFrameView()) | |
71 return const_cast<Widget*>(static_cast<const Widget*>(top)); | |
72 return 0; | |
73 } | |
74 | |
75 HostWindow* Widget::hostWindow() const | |
76 { | |
77 if (root()) | |
78 root()->hostWindow(); | |
79 ASSERT_NOT_REACHED(); | |
80 return 0; | |
81 } | |
82 | |
83 IntRect Widget::convertFromRootView(const IntRect& rootRect) const | |
84 { | |
85 if (const Widget* parentWidget = parent()) { | |
86 IntRect parentRect = parentWidget->convertFromRootView(rootRect); | |
87 return convertFromContainingView(parentRect); | |
88 } | |
89 return rootRect; | |
90 } | |
91 | |
92 IntRect Widget::convertToRootView(const IntRect& localRect) const | |
93 { | |
94 if (const Widget* parentWidget = parent()) { | |
95 IntRect parentRect = convertToContainingView(localRect); | |
96 return parentWidget->convertToRootView(parentRect); | |
97 } | |
98 return localRect; | |
99 } | |
100 | |
101 IntPoint Widget::convertFromRootView(const IntPoint& rootPoint) const | |
102 { | |
103 if (const Widget* parentWidget = parent()) { | |
104 IntPoint parentPoint = parentWidget->convertFromRootView(rootPoint); | |
105 return convertFromContainingView(parentPoint); | |
106 } | |
107 return rootPoint; | |
108 } | |
109 | |
110 IntPoint Widget::convertToRootView(const IntPoint& localPoint) const | |
111 { | |
112 if (const Widget* parentWidget = parent()) { | |
113 IntPoint parentPoint = convertToContainingView(localPoint); | |
114 return parentWidget->convertToRootView(parentPoint); | |
115 } | |
116 return localPoint; | |
117 } | |
118 | |
119 IntRect Widget::convertFromContainingWindow(const IntRect& windowRect) const | |
120 { | |
121 if (const Widget* parentWidget = parent()) { | |
122 IntRect parentRect = parentWidget->convertFromContainingWindow(windowRec
t); | |
123 return convertFromContainingView(parentRect); | |
124 } | |
125 return windowRect; | |
126 } | |
127 | |
128 IntRect Widget::convertToContainingWindow(const IntRect& localRect) const | |
129 { | |
130 if (const Widget* parentWidget = parent()) { | |
131 IntRect parentRect = convertToContainingView(localRect); | |
132 return parentWidget->convertToContainingWindow(parentRect); | |
133 } | |
134 return localRect; | |
135 } | |
136 | |
137 IntPoint Widget::convertFromContainingWindow(const IntPoint& windowPoint) const | |
138 { | |
139 if (const Widget* parentWidget = parent()) { | |
140 IntPoint parentPoint = parentWidget->convertFromContainingWindow(windowP
oint); | |
141 return convertFromContainingView(parentPoint); | |
142 } | |
143 return windowPoint; | |
144 } | |
145 | |
146 IntPoint Widget::convertToContainingWindow(const IntPoint& localPoint) const | |
147 { | |
148 if (const Widget* parentWidget = parent()) { | |
149 IntPoint parentPoint = convertToContainingView(localPoint); | |
150 return parentWidget->convertToContainingWindow(parentPoint); | |
151 } | |
152 return localPoint; | |
153 } | |
154 | |
155 IntRect Widget::convertToContainingView(const IntRect& localRect) const | |
156 { | |
157 if (const Widget* parentWidget = parent()) { | |
158 IntRect parentRect(localRect); | |
159 parentRect.setLocation(parentWidget->convertChildToSelf(this, localRect.
location())); | |
160 return parentRect; | |
161 } | |
162 return localRect; | |
163 } | |
164 | |
165 IntRect Widget::convertFromContainingView(const IntRect& parentRect) const | |
166 { | |
167 if (const Widget* parentWidget = parent()) { | |
168 IntRect localRect = parentRect; | |
169 localRect.setLocation(parentWidget->convertSelfToChild(this, localRect.l
ocation())); | |
170 return localRect; | |
171 } | |
172 | |
173 return parentRect; | |
174 } | |
175 | |
176 IntPoint Widget::convertToContainingView(const IntPoint& localPoint) const | |
177 { | |
178 if (const Widget* parentWidget = parent()) | |
179 return parentWidget->convertChildToSelf(this, localPoint); | |
180 | |
181 return localPoint; | |
182 } | |
183 | |
184 IntPoint Widget::convertFromContainingView(const IntPoint& parentPoint) const | |
185 { | |
186 if (const Widget* parentWidget = parent()) | |
187 return parentWidget->convertSelfToChild(this, parentPoint); | |
188 | |
189 return parentPoint; | |
190 } | |
191 | |
192 IntPoint Widget::convertChildToSelf(const Widget*, const IntPoint& point) const | |
193 { | |
194 return point; | |
195 } | |
196 | |
197 IntPoint Widget::convertSelfToChild(const Widget*, const IntPoint& point) const | |
198 { | |
199 return point; | |
200 } | |
201 | |
202 } // namespace WebCore | |
OLD | NEW |