initial import
[vuplus_webkit] / Source / WebCore / platform / Widget.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "config.h"
27 #include "Widget.h"
28
29 #include "IntRect.h"
30 #include "ScrollView.h"
31
32 #include <wtf/Assertions.h>
33
34 namespace WebCore {
35
36 void Widget::init(PlatformWidget widget)
37 {
38     m_parent = 0;
39     m_selfVisible = false;
40     m_parentVisible = false;
41     m_widget = widget;
42     if (m_widget)
43         retainPlatformWidget();
44 }
45
46 void Widget::setParent(ScrollView* view)
47 {
48     ASSERT(!view || !m_parent);
49     if (!view || !view->isVisible())
50         setParentVisible(false);
51     m_parent = view;
52     if (view && view->isVisible())
53         setParentVisible(true);
54 }
55
56 ScrollView* Widget::root() const
57 {
58     const Widget* top = this;
59     while (top->parent())
60         top = top->parent();
61     if (top->isFrameView())
62         return const_cast<ScrollView*>(static_cast<const ScrollView*>(top));
63     return 0;
64 }
65     
66 void Widget::removeFromParent()
67 {
68     if (parent())
69         parent()->removeChild(this);
70 }
71
72 IntRect Widget::convertFromContainingWindow(const IntRect& windowRect) const
73 {
74     if (const ScrollView* parentScrollView = parent()) {
75         IntRect parentRect = parentScrollView->convertFromContainingWindow(windowRect);
76         return convertFromContainingView(parentRect);
77     }
78     return convertFromContainingWindowToRoot(this, windowRect);
79 }
80
81 IntRect Widget::convertToContainingWindow(const IntRect& localRect) const
82 {
83     if (const ScrollView* parentScrollView = parent()) {
84         IntRect parentRect = convertToContainingView(localRect);
85         return parentScrollView->convertToContainingWindow(parentRect);
86     }
87     return convertFromRootToContainingWindow(this, localRect);
88 }
89
90 IntPoint Widget::convertFromContainingWindow(const IntPoint& windowPoint) const
91 {
92     if (const ScrollView* parentScrollView = parent()) {
93         IntPoint parentPoint = parentScrollView->convertFromContainingWindow(windowPoint);
94         return convertFromContainingView(parentPoint);
95     }
96     return convertFromContainingWindowToRoot(this, windowPoint);
97 }
98
99 IntPoint Widget::convertToContainingWindow(const IntPoint& localPoint) const
100 {
101     if (const ScrollView* parentScrollView = parent()) {
102         IntPoint parentPoint = convertToContainingView(localPoint);
103         return parentScrollView->convertToContainingWindow(parentPoint);
104     }
105     return convertFromRootToContainingWindow(this, localPoint);
106 }
107
108 #if !PLATFORM(MAC)
109 void Widget::setBoundsSize(const IntSize&)
110 {
111 }
112
113 IntRect Widget::convertFromRootToContainingWindow(const Widget*, const IntRect& rect)
114 {
115     return rect;
116 }
117
118 IntRect Widget::convertFromContainingWindowToRoot(const Widget*, const IntRect& rect)
119 {
120     return rect;
121 }
122
123 IntPoint Widget::convertFromRootToContainingWindow(const Widget*, const IntPoint& point)
124 {
125     return point;
126 }
127
128 IntPoint Widget::convertFromContainingWindowToRoot(const Widget*, const IntPoint& point)
129 {
130     return point;
131 }
132 #endif
133
134 IntRect Widget::convertToContainingView(const IntRect& localRect) const
135 {
136     if (const ScrollView* parentScrollView = parent()) {
137         IntRect parentRect(localRect);
138         parentRect.setLocation(parentScrollView->convertChildToSelf(this, localRect.location()));
139         return parentRect;
140     }
141     return localRect;
142 }
143
144 IntRect Widget::convertFromContainingView(const IntRect& parentRect) const
145 {
146     if (const ScrollView* parentScrollView = parent()) {
147         IntRect localRect = parentRect;
148         localRect.setLocation(parentScrollView->convertSelfToChild(this, localRect.location()));
149         return localRect;
150     }
151
152     return parentRect;
153 }
154
155 IntPoint Widget::convertToContainingView(const IntPoint& localPoint) const
156 {
157     if (const ScrollView* parentScrollView = parent())
158         return parentScrollView->convertChildToSelf(this, localPoint);
159
160     return localPoint;
161 }
162
163 IntPoint Widget::convertFromContainingView(const IntPoint& parentPoint) const
164 {
165     if (const ScrollView* parentScrollView = parent())
166         return parentScrollView->convertSelfToChild(this, parentPoint);
167
168     return parentPoint;
169 }
170
171 #if !PLATFORM(EFL)
172 void Widget::frameRectsChanged()
173 {
174 }
175 #endif
176
177 } // namespace WebCore