| 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 Widget::Widget() | 35 Widget::Widget() |
| 36 : m_parent(0) | 36 : m_parent(0) |
| 37 { | 37 { |
| 38 } | 38 } |
| 39 | 39 |
| 40 Widget::~Widget() | 40 Widget::~Widget() |
| 41 { | 41 { |
| 42 ASSERT(!parent()); | |
| 43 } | 42 } |
| 44 | 43 |
| 45 Widget* Widget::root() const | 44 Widget* Widget::root() const |
| 46 { | 45 { |
| 47 const Widget* top = this; | 46 const Widget* top = this; |
| 48 while (top->parent()) | 47 while (top->parent()) |
| 49 top = top->parent(); | 48 top = top->parent(); |
| 50 if (top->isFrameView()) | 49 if (top->isFrameView()) |
| 51 return const_cast<Widget*>(static_cast<const Widget*>(top)); | 50 return const_cast<Widget*>(static_cast<const Widget*>(top)); |
| 52 return 0; | 51 return 0; |
| 53 } | 52 } |
| 54 | 53 |
| 55 IntRect Widget::convertFromRootView(const IntRect& rootRect) const | |
| 56 { | |
| 57 if (const Widget* parentWidget = parent()) { | |
| 58 IntRect parentRect = parentWidget->convertFromRootView(rootRect); | |
| 59 return convertFromContainingView(parentRect); | |
| 60 } | |
| 61 return rootRect; | |
| 62 } | |
| 63 | |
| 64 IntRect Widget::convertToRootView(const IntRect& localRect) const | |
| 65 { | |
| 66 if (const Widget* parentWidget = parent()) { | |
| 67 IntRect parentRect = convertToContainingView(localRect); | |
| 68 return parentWidget->convertToRootView(parentRect); | |
| 69 } | |
| 70 return localRect; | |
| 71 } | |
| 72 | |
| 73 IntPoint Widget::convertFromRootView(const IntPoint& rootPoint) const | |
| 74 { | |
| 75 if (const Widget* parentWidget = parent()) { | |
| 76 IntPoint parentPoint = parentWidget->convertFromRootView(rootPoint); | |
| 77 return convertFromContainingView(parentPoint); | |
| 78 } | |
| 79 return rootPoint; | |
| 80 } | |
| 81 | |
| 82 IntPoint Widget::convertToRootView(const IntPoint& localPoint) const | |
| 83 { | |
| 84 if (const Widget* parentWidget = parent()) { | |
| 85 IntPoint parentPoint = convertToContainingView(localPoint); | |
| 86 return parentWidget->convertToRootView(parentPoint); | |
| 87 } | |
| 88 return localPoint; | |
| 89 } | |
| 90 | |
| 91 IntRect Widget::convertFromContainingWindow(const IntRect& windowRect) const | |
| 92 { | |
| 93 if (const Widget* parentWidget = parent()) { | |
| 94 IntRect parentRect = parentWidget->convertFromContainingWindow(windowRec
t); | |
| 95 return convertFromContainingView(parentRect); | |
| 96 } | |
| 97 return windowRect; | |
| 98 } | |
| 99 | |
| 100 IntRect Widget::convertToContainingWindow(const IntRect& localRect) const | |
| 101 { | |
| 102 if (const Widget* parentWidget = parent()) { | |
| 103 IntRect parentRect = convertToContainingView(localRect); | |
| 104 return parentWidget->convertToContainingWindow(parentRect); | |
| 105 } | |
| 106 return localRect; | |
| 107 } | |
| 108 | |
| 109 IntPoint Widget::convertFromContainingWindow(const IntPoint& windowPoint) const | |
| 110 { | |
| 111 if (const Widget* parentWidget = parent()) { | |
| 112 IntPoint parentPoint = parentWidget->convertFromContainingWindow(windowP
oint); | |
| 113 return convertFromContainingView(parentPoint); | |
| 114 } | |
| 115 return windowPoint; | |
| 116 } | |
| 117 | |
| 118 | |
| 119 FloatPoint Widget::convertFromContainingWindow(const FloatPoint& windowPoint) co
nst | |
| 120 { | |
| 121 // Widgets / windows are required to be IntPoint aligned, but we may need to
convert | |
| 122 // FloatPoint values within them (eg. for event co-ordinates). | |
| 123 IntPoint flooredPoint = flooredIntPoint(windowPoint); | |
| 124 FloatPoint parentPoint = this->convertFromContainingWindow(flooredPoint); | |
| 125 FloatSize windowFraction = windowPoint - flooredPoint; | |
| 126 // Use linear interpolation handle any fractional value (eg. for iframes sub
ject to a transform | |
| 127 // beyond just a simple translation). | |
| 128 // FIXME: Add FloatPoint variants of all co-ordinate space conversion APIs. | |
| 129 if (!windowFraction.isEmpty()) { | |
| 130 const int kFactor = 1000; | |
| 131 IntPoint parentLineEnd = this->convertFromContainingWindow(flooredPoint
+ roundedIntSize(windowFraction.scaledBy(kFactor))); | |
| 132 FloatSize parentFraction = (parentLineEnd - parentPoint).scaledBy(1.0f /
kFactor); | |
| 133 parentPoint.move(parentFraction); | |
| 134 } | |
| 135 return parentPoint; | |
| 136 } | |
| 137 | |
| 138 IntPoint Widget::convertToContainingWindow(const IntPoint& localPoint) const | |
| 139 { | |
| 140 if (const Widget* parentWidget = parent()) { | |
| 141 IntPoint parentPoint = convertToContainingView(localPoint); | |
| 142 return parentWidget->convertToContainingWindow(parentPoint); | |
| 143 } | |
| 144 return localPoint; | |
| 145 } | |
| 146 | |
| 147 IntRect Widget::convertToContainingView(const IntRect& localRect) const | |
| 148 { | |
| 149 return localRect; | |
| 150 } | |
| 151 | |
| 152 IntRect Widget::convertFromContainingView(const IntRect& parentRect) const | |
| 153 { | |
| 154 return parentRect; | |
| 155 } | |
| 156 | |
| 157 IntPoint Widget::convertToContainingView(const IntPoint& localPoint) const | |
| 158 { | |
| 159 return localPoint; | |
| 160 } | |
| 161 | |
| 162 IntPoint Widget::convertFromContainingView(const IntPoint& parentPoint) const | |
| 163 { | |
| 164 return parentPoint; | |
| 165 } | |
| 166 | |
| 167 } // namespace blink | 54 } // namespace blink |
| OLD | NEW |