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