| 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 "platform/Widget.h" | |
| 28 | |
| 29 #include "wtf/Assertions.h" | |
| 30 | |
| 31 namespace blink { | |
| 32 | |
| 33 Widget::Widget() | |
| 34 : m_parent(nullptr), m_selfVisible(false), m_parentVisible(false) {} | |
| 35 | |
| 36 Widget::~Widget() {} | |
| 37 | |
| 38 DEFINE_TRACE(Widget) { | |
| 39 visitor->trace(m_parent); | |
| 40 } | |
| 41 | |
| 42 void Widget::setParent(Widget* widget) { | |
| 43 ASSERT(!widget || !m_parent); | |
| 44 if (!widget || !widget->isVisible()) | |
| 45 setParentVisible(false); | |
| 46 m_parent = widget; | |
| 47 if (widget && widget->isVisible()) | |
| 48 setParentVisible(true); | |
| 49 } | |
| 50 | |
| 51 Widget* Widget::root() const { | |
| 52 const Widget* top = this; | |
| 53 while (top->parent()) | |
| 54 top = top->parent(); | |
| 55 if (top->isFrameView()) | |
| 56 return const_cast<Widget*>(static_cast<const Widget*>(top)); | |
| 57 return 0; | |
| 58 } | |
| 59 | |
| 60 IntRect Widget::convertFromRootFrame(const IntRect& rectInRootFrame) const { | |
| 61 if (const Widget* parentWidget = parent()) { | |
| 62 IntRect parentRect = parentWidget->convertFromRootFrame(rectInRootFrame); | |
| 63 return convertFromContainingWidget(parentRect); | |
| 64 } | |
| 65 return rectInRootFrame; | |
| 66 } | |
| 67 | |
| 68 IntRect Widget::convertToRootFrame(const IntRect& localRect) const { | |
| 69 if (const Widget* parentWidget = parent()) { | |
| 70 IntRect parentRect = convertToContainingWidget(localRect); | |
| 71 return parentWidget->convertToRootFrame(parentRect); | |
| 72 } | |
| 73 return localRect; | |
| 74 } | |
| 75 | |
| 76 IntPoint Widget::convertFromRootFrame(const IntPoint& pointInRootFrame) const { | |
| 77 if (const Widget* parentWidget = parent()) { | |
| 78 IntPoint parentPoint = parentWidget->convertFromRootFrame(pointInRootFrame); | |
| 79 return convertFromContainingWidget(parentPoint); | |
| 80 } | |
| 81 return pointInRootFrame; | |
| 82 } | |
| 83 | |
| 84 FloatPoint Widget::convertFromRootFrame( | |
| 85 const FloatPoint& pointInRootFrame) const { | |
| 86 // Widgets / windows are required to be IntPoint aligned, but we may need to | |
| 87 // convert FloatPoint values within them (eg. for event co-ordinates). | |
| 88 IntPoint flooredPoint = flooredIntPoint(pointInRootFrame); | |
| 89 FloatPoint parentPoint = this->convertFromRootFrame(flooredPoint); | |
| 90 FloatSize windowFraction = pointInRootFrame - flooredPoint; | |
| 91 // Use linear interpolation handle any fractional value (eg. for iframes | |
| 92 // subject to a transform beyond just a simple translation). | |
| 93 // FIXME: Add FloatPoint variants of all co-ordinate space conversion APIs. | |
| 94 if (!windowFraction.isEmpty()) { | |
| 95 const int kFactor = 1000; | |
| 96 IntPoint parentLineEnd = this->convertFromRootFrame( | |
| 97 flooredPoint + roundedIntSize(windowFraction.scaledBy(kFactor))); | |
| 98 FloatSize parentFraction = | |
| 99 (parentLineEnd - parentPoint).scaledBy(1.0f / kFactor); | |
| 100 parentPoint.move(parentFraction); | |
| 101 } | |
| 102 return parentPoint; | |
| 103 } | |
| 104 | |
| 105 IntPoint Widget::convertToRootFrame(const IntPoint& localPoint) const { | |
| 106 if (const Widget* parentWidget = parent()) { | |
| 107 IntPoint parentPoint = convertToContainingWidget(localPoint); | |
| 108 return parentWidget->convertToRootFrame(parentPoint); | |
| 109 } | |
| 110 return localPoint; | |
| 111 } | |
| 112 | |
| 113 IntRect Widget::convertToContainingWidget(const IntRect& localRect) const { | |
| 114 if (const Widget* parentWidget = parent()) { | |
| 115 IntRect parentRect(localRect); | |
| 116 parentRect.setLocation( | |
| 117 parentWidget->convertChildToSelf(this, localRect.location())); | |
| 118 return parentRect; | |
| 119 } | |
| 120 return localRect; | |
| 121 } | |
| 122 | |
| 123 IntRect Widget::convertFromContainingWidget(const IntRect& parentRect) const { | |
| 124 if (const Widget* parentWidget = parent()) { | |
| 125 IntRect localRect = parentRect; | |
| 126 localRect.setLocation( | |
| 127 parentWidget->convertSelfToChild(this, localRect.location())); | |
| 128 return localRect; | |
| 129 } | |
| 130 | |
| 131 return parentRect; | |
| 132 } | |
| 133 | |
| 134 IntPoint Widget::convertToContainingWidget(const IntPoint& localPoint) const { | |
| 135 if (const Widget* parentWidget = parent()) | |
| 136 return parentWidget->convertChildToSelf(this, localPoint); | |
| 137 | |
| 138 return localPoint; | |
| 139 } | |
| 140 | |
| 141 IntPoint Widget::convertFromContainingWidget( | |
| 142 const IntPoint& parentPoint) const { | |
| 143 if (const Widget* parentWidget = parent()) | |
| 144 return parentWidget->convertSelfToChild(this, parentPoint); | |
| 145 | |
| 146 return parentPoint; | |
| 147 } | |
| 148 | |
| 149 IntPoint Widget::convertChildToSelf(const Widget*, | |
| 150 const IntPoint& point) const { | |
| 151 return point; | |
| 152 } | |
| 153 | |
| 154 IntPoint Widget::convertSelfToChild(const Widget*, | |
| 155 const IntPoint& point) const { | |
| 156 return point; | |
| 157 } | |
| 158 | |
| 159 } // namespace blink | |
| OLD | NEW |