| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "web/ViewportAnchor.h" | 32 #include "web/ViewportAnchor.h" |
| 33 | 33 |
| 34 #include "core/dom/ContainerNode.h" | 34 #include "core/dom/ContainerNode.h" |
| 35 #include "core/dom/Node.h" | 35 #include "core/dom/Node.h" |
| 36 #include "core/frame/FrameView.h" |
| 36 #include "core/page/EventHandler.h" | 37 #include "core/page/EventHandler.h" |
| 37 #include "core/rendering/HitTestResult.h" | 38 #include "core/rendering/HitTestResult.h" |
| 38 #include "platform/scroll/ScrollView.h" | |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 static const float viewportAnchorRelativeEpsilon = 0.1f; | 44 static const float viewportAnchorRelativeEpsilon = 0.1f; |
| 45 static const int viewportToNodeMaxRelativeArea = 2; | 45 static const int viewportToNodeMaxRelativeArea = 2; |
| 46 | 46 |
| 47 template <typename RectType> | 47 template <typename RectType> |
| 48 int area(const RectType& rect) { | 48 int area(const RectType& rect) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewR
ect, m_eventHandler); | 141 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewR
ect, m_eventHandler); |
| 142 if (!node) | 142 if (!node) |
| 143 return; | 143 return; |
| 144 | 144 |
| 145 m_anchorNode = node; | 145 m_anchorNode = node; |
| 146 m_anchorNodeBounds = node->boundingBox(); | 146 m_anchorNodeBounds = node->boundingBox(); |
| 147 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); | 147 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); |
| 148 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN
odeBounds.height()); | 148 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN
odeBounds.height()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void ViewportAnchor::computeOrigins(const ScrollView& scrollView, const FloatSiz
e& innerSize, | 151 void ViewportAnchor::computeOrigins(const FrameView& scrollView, const FloatSize
& innerSize, |
| 152 IntPoint& mainFrameOffset, FloatPoint& pinchViewportOffset) const | 152 IntPoint& mainFrameOffset, FloatPoint& pinchViewportOffset) const |
| 153 { | 153 { |
| 154 IntSize outerSize = scrollView.visibleContentRect().size(); | 154 IntSize outerSize = scrollView.visibleContentRect().size(); |
| 155 | 155 |
| 156 // Compute the viewport origins in CSS pixels relative to the document. | 156 // Compute the viewport origins in CSS pixels relative to the document. |
| 157 FloatSize absPinchViewportOffset = m_normalizedPinchViewportOffset; | 157 FloatSize absPinchViewportOffset = m_normalizedPinchViewportOffset; |
| 158 absPinchViewportOffset.scale(outerSize.width(), outerSize.height()); | 158 absPinchViewportOffset.scale(outerSize.width(), outerSize.height()); |
| 159 | 159 |
| 160 FloatPoint innerOrigin = getInnerOrigin(innerSize); | 160 FloatPoint innerOrigin = getInnerOrigin(innerSize); |
| 161 FloatPoint outerOrigin = innerOrigin - absPinchViewportOffset; | 161 FloatPoint outerOrigin = innerOrigin - absPinchViewportOffset; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 187 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord
s.height()); | 187 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord
s.height()); |
| 188 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode
; | 188 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode
; |
| 189 | 189 |
| 190 // Compute the new origin point relative to the new anchor point | 190 // Compute the new origin point relative to the new anchor point |
| 191 FloatSize anchorOffsetFromOrigin = innerSize; | 191 FloatSize anchorOffsetFromOrigin = innerSize; |
| 192 anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), m_anchorInIn
nerViewCoords.height()); | 192 anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), m_anchorInIn
nerViewCoords.height()); |
| 193 return anchorPoint - anchorOffsetFromOrigin; | 193 return anchorPoint - anchorOffsetFromOrigin; |
| 194 } | 194 } |
| 195 | 195 |
| 196 } // namespace blink | 196 } // namespace blink |
| OLD | NEW |