2 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include "ScrollView.h"
32 #include <wtf/Assertions.h>
36 void Widget::init(PlatformWidget widget)
39 m_selfVisible = false;
40 m_parentVisible = false;
43 retainPlatformWidget();
46 void Widget::setParent(ScrollView* view)
48 ASSERT(!view || !m_parent);
49 if (!view || !view->isVisible())
50 setParentVisible(false);
52 if (view && view->isVisible())
53 setParentVisible(true);
56 ScrollView* Widget::root() const
58 const Widget* top = this;
61 if (top->isFrameView())
62 return const_cast<ScrollView*>(static_cast<const ScrollView*>(top));
66 void Widget::removeFromParent()
69 parent()->removeChild(this);
72 IntRect Widget::convertFromContainingWindow(const IntRect& windowRect) const
74 if (const ScrollView* parentScrollView = parent()) {
75 IntRect parentRect = parentScrollView->convertFromContainingWindow(windowRect);
76 return convertFromContainingView(parentRect);
78 return convertFromContainingWindowToRoot(this, windowRect);
81 IntRect Widget::convertToContainingWindow(const IntRect& localRect) const
83 if (const ScrollView* parentScrollView = parent()) {
84 IntRect parentRect = convertToContainingView(localRect);
85 return parentScrollView->convertToContainingWindow(parentRect);
87 return convertFromRootToContainingWindow(this, localRect);
90 IntPoint Widget::convertFromContainingWindow(const IntPoint& windowPoint) const
92 if (const ScrollView* parentScrollView = parent()) {
93 IntPoint parentPoint = parentScrollView->convertFromContainingWindow(windowPoint);
94 return convertFromContainingView(parentPoint);
96 return convertFromContainingWindowToRoot(this, windowPoint);
99 IntPoint Widget::convertToContainingWindow(const IntPoint& localPoint) const
101 if (const ScrollView* parentScrollView = parent()) {
102 IntPoint parentPoint = convertToContainingView(localPoint);
103 return parentScrollView->convertToContainingWindow(parentPoint);
105 return convertFromRootToContainingWindow(this, localPoint);
109 void Widget::setBoundsSize(const IntSize&)
113 IntRect Widget::convertFromRootToContainingWindow(const Widget*, const IntRect& rect)
118 IntRect Widget::convertFromContainingWindowToRoot(const Widget*, const IntRect& rect)
123 IntPoint Widget::convertFromRootToContainingWindow(const Widget*, const IntPoint& point)
128 IntPoint Widget::convertFromContainingWindowToRoot(const Widget*, const IntPoint& point)
134 IntRect Widget::convertToContainingView(const IntRect& localRect) const
136 if (const ScrollView* parentScrollView = parent()) {
137 IntRect parentRect(localRect);
138 parentRect.setLocation(parentScrollView->convertChildToSelf(this, localRect.location()));
144 IntRect Widget::convertFromContainingView(const IntRect& parentRect) const
146 if (const ScrollView* parentScrollView = parent()) {
147 IntRect localRect = parentRect;
148 localRect.setLocation(parentScrollView->convertSelfToChild(this, localRect.location()));
155 IntPoint Widget::convertToContainingView(const IntPoint& localPoint) const
157 if (const ScrollView* parentScrollView = parent())
158 return parentScrollView->convertChildToSelf(this, localPoint);
163 IntPoint Widget::convertFromContainingView(const IntPoint& parentPoint) const
165 if (const ScrollView* parentScrollView = parent())
166 return parentScrollView->convertSelfToChild(this, parentPoint);
172 void Widget::frameRectsChanged()
177 } // namespace WebCore