• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "platform/Widget.h"
29 
30 
31 #include "wtf/Assertions.h"
32 
33 namespace WebCore {
34 
Widget()35 Widget::Widget()
36     : m_parent(0)
37     , m_selfVisible(false)
38     , m_parentVisible(false)
39 {
40 }
41 
~Widget()42 Widget::~Widget()
43 {
44     ASSERT(!parent());
45 }
46 
setParent(Widget * widget)47 void Widget::setParent(Widget* widget)
48 {
49     ASSERT(!widget || !m_parent);
50     if (!widget || !widget->isVisible())
51         setParentVisible(false);
52     m_parent = widget;
53     if (widget && widget->isVisible())
54         setParentVisible(true);
55 }
56 
root() const57 Widget* Widget::root() const
58 {
59     const Widget* top = this;
60     while (top->parent())
61         top = top->parent();
62     if (top->isFrameView())
63         return const_cast<Widget*>(static_cast<const Widget*>(top));
64     return 0;
65 }
66 
convertFromRootView(const IntRect & rootRect) const67 IntRect Widget::convertFromRootView(const IntRect& rootRect) const
68 {
69     if (const Widget* parentWidget = parent()) {
70         IntRect parentRect = parentWidget->convertFromRootView(rootRect);
71         return convertFromContainingView(parentRect);
72     }
73     return rootRect;
74 }
75 
convertToRootView(const IntRect & localRect) const76 IntRect Widget::convertToRootView(const IntRect& localRect) const
77 {
78     if (const Widget* parentWidget = parent()) {
79         IntRect parentRect = convertToContainingView(localRect);
80         return parentWidget->convertToRootView(parentRect);
81     }
82     return localRect;
83 }
84 
convertFromRootView(const IntPoint & rootPoint) const85 IntPoint Widget::convertFromRootView(const IntPoint& rootPoint) const
86 {
87     if (const Widget* parentWidget = parent()) {
88         IntPoint parentPoint = parentWidget->convertFromRootView(rootPoint);
89         return convertFromContainingView(parentPoint);
90     }
91     return rootPoint;
92 }
93 
convertToRootView(const IntPoint & localPoint) const94 IntPoint Widget::convertToRootView(const IntPoint& localPoint) const
95 {
96     if (const Widget* parentWidget = parent()) {
97         IntPoint parentPoint = convertToContainingView(localPoint);
98         return parentWidget->convertToRootView(parentPoint);
99     }
100     return localPoint;
101 }
102 
convertFromContainingWindow(const IntRect & windowRect) const103 IntRect Widget::convertFromContainingWindow(const IntRect& windowRect) const
104 {
105     if (const Widget* parentWidget = parent()) {
106         IntRect parentRect = parentWidget->convertFromContainingWindow(windowRect);
107         return convertFromContainingView(parentRect);
108     }
109     return windowRect;
110 }
111 
convertToContainingWindow(const IntRect & localRect) const112 IntRect Widget::convertToContainingWindow(const IntRect& localRect) const
113 {
114     if (const Widget* parentWidget = parent()) {
115         IntRect parentRect = convertToContainingView(localRect);
116         return parentWidget->convertToContainingWindow(parentRect);
117     }
118     return localRect;
119 }
120 
convertFromContainingWindow(const IntPoint & windowPoint) const121 IntPoint Widget::convertFromContainingWindow(const IntPoint& windowPoint) const
122 {
123     if (const Widget* parentWidget = parent()) {
124         IntPoint parentPoint = parentWidget->convertFromContainingWindow(windowPoint);
125         return convertFromContainingView(parentPoint);
126     }
127     return windowPoint;
128 }
129 
convertToContainingWindow(const IntPoint & localPoint) const130 IntPoint Widget::convertToContainingWindow(const IntPoint& localPoint) const
131 {
132     if (const Widget* parentWidget = parent()) {
133         IntPoint parentPoint = convertToContainingView(localPoint);
134         return parentWidget->convertToContainingWindow(parentPoint);
135     }
136     return localPoint;
137 }
138 
convertToContainingView(const IntRect & localRect) const139 IntRect Widget::convertToContainingView(const IntRect& localRect) const
140 {
141     if (const Widget* parentWidget = parent()) {
142         IntRect parentRect(localRect);
143         parentRect.setLocation(parentWidget->convertChildToSelf(this, localRect.location()));
144         return parentRect;
145     }
146     return localRect;
147 }
148 
convertFromContainingView(const IntRect & parentRect) const149 IntRect Widget::convertFromContainingView(const IntRect& parentRect) const
150 {
151     if (const Widget* parentWidget = parent()) {
152         IntRect localRect = parentRect;
153         localRect.setLocation(parentWidget->convertSelfToChild(this, localRect.location()));
154         return localRect;
155     }
156 
157     return parentRect;
158 }
159 
convertToContainingView(const IntPoint & localPoint) const160 IntPoint Widget::convertToContainingView(const IntPoint& localPoint) const
161 {
162     if (const Widget* parentWidget = parent())
163         return parentWidget->convertChildToSelf(this, localPoint);
164 
165     return localPoint;
166 }
167 
convertFromContainingView(const IntPoint & parentPoint) const168 IntPoint Widget::convertFromContainingView(const IntPoint& parentPoint) const
169 {
170     if (const Widget* parentWidget = parent())
171         return parentWidget->convertSelfToChild(this, parentPoint);
172 
173     return parentPoint;
174 }
175 
convertChildToSelf(const Widget *,const IntPoint & point) const176 IntPoint Widget::convertChildToSelf(const Widget*, const IntPoint& point) const
177 {
178     return point;
179 }
180 
convertSelfToChild(const Widget *,const IntPoint & point) const181 IntPoint Widget::convertSelfToChild(const Widget*, const IntPoint& point) const
182 {
183     return point;
184 }
185 
186 } // namespace WebCore
187