OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 m_transformedPoint.move(offset); | 115 m_transformedPoint.move(offset); |
116 m_transformedRect.move(offset); | 116 m_transformedRect.move(offset); |
117 m_boundingBox = enclosingIntRect(m_transformedRect.boundingBox()); | 117 m_boundingBox = enclosingIntRect(m_transformedRect.boundingBox()); |
118 } | 118 } |
119 | 119 |
120 template<typename RectType> | 120 template<typename RectType> |
121 bool HitTestLocation::intersectsRect(const RectType& rect, const RectType& bound
ingBox) const | 121 bool HitTestLocation::intersectsRect(const RectType& rect, const RectType& bound
ingBox) const |
122 { | 122 { |
123 // FIXME: When the hit test is not rect based we should use rect.contains(m_
point). | 123 // FIXME: When the hit test is not rect based we should use rect.contains(m_
point). |
124 // That does change some corner case tests though. | 124 // That does change some corner case tests though. |
125 | |
126 // First check if rect even intersects our bounding box. | 125 // First check if rect even intersects our bounding box. |
127 if (!rect.intersects(boundingBox)) | 126 if (!rect.intersects(boundingBox)) |
128 return false; | 127 return false; |
129 | 128 |
130 // If the transformed rect is rectilinear the bounding box intersection was
accurate. | 129 // If the transformed rect is rectilinear the bounding box intersection was
accurate. |
131 if (m_isRectilinear) | 130 if (m_isRectilinear) |
132 return true; | 131 return true; |
133 | 132 |
134 // If rect fully contains our bounding box, we are also sure of an intersect
ion. | 133 // If rect fully contains our bounding box, we are also sure of an intersect
ion. |
135 if (rect.contains(boundingBox)) | 134 if (rect.contains(boundingBox)) |
136 return true; | 135 return true; |
137 | 136 |
138 // Otherwise we need to do a slower quad based intersection test. | 137 // Otherwise we need to do a slower quad based intersection test. |
139 return m_transformedRect.intersectsRect(rect); | 138 return m_transformedRect.intersectsRect(rect); |
140 } | 139 } |
141 | 140 |
142 bool HitTestLocation::intersects(const LayoutRect& rect) const | 141 bool HitTestLocation::intersects(const LayoutRect& rect) const |
143 { | 142 { |
| 143 if (!m_isRectBased) |
| 144 return rect.contains(m_point); |
| 145 |
144 return intersectsRect(rect, LayoutRect(m_boundingBox)); | 146 return intersectsRect(rect, LayoutRect(m_boundingBox)); |
145 } | 147 } |
146 | 148 |
147 bool HitTestLocation::intersects(const FloatRect& rect) const | 149 bool HitTestLocation::intersects(const FloatRect& rect) const |
148 { | 150 { |
| 151 if (!m_isRectBased) |
| 152 return rect.contains(FloatPoint(m_point)); |
| 153 |
149 return intersectsRect(rect, FloatRect(m_boundingBox)); | 154 return intersectsRect(rect, FloatRect(m_boundingBox)); |
150 } | 155 } |
151 | 156 |
152 bool HitTestLocation::intersects(const FloatRoundedRect& rect) const | 157 bool HitTestLocation::intersects(const FloatRoundedRect& rect) const |
153 { | 158 { |
154 return rect.intersectsQuad(m_transformedRect); | 159 return rect.intersectsQuad(m_transformedRect); |
155 } | 160 } |
156 | 161 |
157 bool HitTestLocation::containsPoint(const FloatPoint& point) const | 162 bool HitTestLocation::containsPoint(const FloatPoint& point) const |
158 { | 163 { |
159 return m_transformedRect.containsPoint(point); | 164 return m_transformedRect.containsPoint(point); |
160 } | 165 } |
161 | 166 |
162 IntRect HitTestLocation::rectForPoint(const LayoutPoint& point, unsigned topPadd
ing, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding) | 167 IntRect HitTestLocation::rectForPoint(const LayoutPoint& point, unsigned topPadd
ing, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding) |
163 { | 168 { |
164 IntPoint actualPoint(flooredIntPoint(point)); | 169 IntPoint actualPoint(flooredIntPoint(point)); |
165 actualPoint -= IntSize(leftPadding, topPadding); | 170 actualPoint -= IntSize(leftPadding, topPadding); |
166 | 171 |
167 IntSize actualPadding(leftPadding + rightPadding, topPadding + bottomPadding
); | 172 IntSize actualPadding(leftPadding + rightPadding, topPadding + bottomPadding
); |
168 // As IntRect is left inclusive and right exclusive (seeing IntRect::contain
s(x, y)), adding "1". | 173 // As IntRect is left inclusive and right exclusive (seeing IntRect::contain
s(x, y)), adding "1". |
169 // FIXME: Remove this once non-rect based hit-detection stops using IntRect:
intersects. | 174 // FIXME: Remove this once non-rect based hit-detection stops using IntRect:
intersects. |
170 actualPadding += IntSize(1, 1); | 175 actualPadding += IntSize(1, 1); |
171 | 176 |
172 return IntRect(actualPoint, actualPadding); | 177 return IntRect(actualPoint, actualPadding); |
173 } | 178 } |
174 | 179 |
175 } // namespace blink | 180 } // namespace blink |
OLD | NEW |