| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "web/RotationViewportAnchor.h" | 6 #include "web/RotationViewportAnchor.h" |
| 7 | 7 |
| 8 #include "core/dom/ContainerNode.h" | 8 #include "core/dom/ContainerNode.h" |
| 9 #include "core/dom/Node.h" | 9 #include "core/dom/Node.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Preserve origins at the absolute screen origin | 121 // Preserve origins at the absolute screen origin |
| 122 if (innerViewRect.location() == IntPoint::zero()) | 122 if (innerViewRect.location() == IntPoint::zero()) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 // Inner rectangle should be within the outer one. | 125 // Inner rectangle should be within the outer one. |
| 126 ASSERT(outerViewRect.contains(innerViewRect)); | 126 ASSERT(outerViewRect.contains(innerViewRect)); |
| 127 | 127 |
| 128 // Outer rectangle is used as a scale, we need positive width and height. | 128 // Outer rectangle is used as a scale, we need positive width and height. |
| 129 ASSERT(!outerViewRect.isEmpty()); | 129 ASSERT(!outerViewRect.isEmpty()); |
| 130 | 130 |
| 131 m_normalizedVisualViewportOffset = innerViewRect.location() - outerViewRect.
location(); | 131 m_normalizedVisualViewportOffset = FloatSize(innerViewRect.location() - oute
rViewRect.location()); |
| 132 | 132 |
| 133 // Normalize by the size of the outer rect | 133 // Normalize by the size of the outer rect |
| 134 m_normalizedVisualViewportOffset.scale(1.0 / outerViewRect.width(), 1.0 / ou
terViewRect.height()); | 134 m_normalizedVisualViewportOffset.scale(1.0 / outerViewRect.width(), 1.0 / ou
terViewRect.height()); |
| 135 | 135 |
| 136 FloatSize anchorOffset = innerViewRect.size(); | 136 FloatSize anchorOffset(innerViewRect.size()); |
| 137 anchorOffset.scale(m_anchorInInnerViewCoords.width(), m_anchorInInnerViewCoo
rds.height()); | 137 anchorOffset.scale(m_anchorInInnerViewCoords.width(), m_anchorInInnerViewCoo
rds.height()); |
| 138 const FloatPoint anchorPoint = FloatPoint(innerViewRect.location()) + anchor
Offset; | 138 const FloatPoint anchorPoint = FloatPoint(innerViewRect.location()) + anchor
Offset; |
| 139 | 139 |
| 140 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewR
ect, m_rootFrameView->frame().eventHandler()); | 140 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewR
ect, m_rootFrameView->frame().eventHandler()); |
| 141 if (!node) | 141 if (!node) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 m_anchorNode = node; | 144 m_anchorNode = node; |
| 145 m_anchorNodeBounds = node->boundingBox(); | 145 m_anchorNodeBounds = node->boundingBox(); |
| 146 m_anchorInNodeCoords = anchorPoint - FloatPoint(m_anchorNodeBounds.location(
)); | 146 m_anchorInNodeCoords = anchorPoint - FloatPoint(m_anchorNodeBounds.location(
)); |
| 147 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN
odeBounds.height()); | 147 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN
odeBounds.height()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void RotationViewportAnchor::restoreToAnchor() | 150 void RotationViewportAnchor::restoreToAnchor() |
| 151 { | 151 { |
| 152 float newPageScaleFactor = m_oldPageScaleFactor / m_oldMinimumPageScaleFacto
r * m_pageScaleConstraintsSet.finalConstraints().minimumScale; | 152 float newPageScaleFactor = m_oldPageScaleFactor / m_oldMinimumPageScaleFacto
r * m_pageScaleConstraintsSet.finalConstraints().minimumScale; |
| 153 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().clampToCon
straints(newPageScaleFactor); | 153 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().clampToCon
straints(newPageScaleFactor); |
| 154 | 154 |
| 155 FloatSize visualViewportSize = m_visualViewport->size(); | 155 FloatSize visualViewportSize(m_visualViewport->size()); |
| 156 visualViewportSize.scale(1 / newPageScaleFactor); | 156 visualViewportSize.scale(1 / newPageScaleFactor); |
| 157 | 157 |
| 158 IntPoint mainFrameOrigin; | 158 IntPoint mainFrameOrigin; |
| 159 FloatPoint visualViewportOrigin; | 159 FloatPoint visualViewportOrigin; |
| 160 | 160 |
| 161 computeOrigins(visualViewportSize, mainFrameOrigin, visualViewportOrigin); | 161 computeOrigins(visualViewportSize, mainFrameOrigin, visualViewportOrigin); |
| 162 | 162 |
| 163 m_rootFrameView->layoutViewportScrollableArea()->setScrollPosition(mainFrame
Origin, ProgrammaticScroll); | 163 m_rootFrameView->layoutViewportScrollableArea()->setScrollPosition(mainFrame
Origin, ProgrammaticScroll); |
| 164 | 164 |
| 165 // Set scale before location, since location can be clamped on setting scale
. | 165 // Set scale before location, since location can be clamped on setting scale
. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord
s.height()); | 205 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord
s.height()); |
| 206 FloatPoint anchorPoint = FloatPoint(currentNodeBounds.location()) + anchorOf
fsetFromNode; | 206 FloatPoint anchorPoint = FloatPoint(currentNodeBounds.location()) + anchorOf
fsetFromNode; |
| 207 | 207 |
| 208 // Compute the new origin point relative to the new anchor point | 208 // Compute the new origin point relative to the new anchor point |
| 209 FloatSize anchorOffsetFromOrigin = innerSize; | 209 FloatSize anchorOffsetFromOrigin = innerSize; |
| 210 anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), m_anchorInIn
nerViewCoords.height()); | 210 anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), m_anchorInIn
nerViewCoords.height()); |
| 211 return anchorPoint - anchorOffsetFromOrigin; | 211 return anchorPoint - anchorOffsetFromOrigin; |
| 212 } | 212 } |
| 213 | 213 |
| 214 } // namespace blink | 214 } // namespace blink |
| OLD | NEW |