| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 RotationViewportAnchor::~RotationViewportAnchor() | 95 RotationViewportAnchor::~RotationViewportAnchor() |
| 96 { | 96 { |
| 97 restoreToAnchor(); | 97 restoreToAnchor(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void RotationViewportAnchor::setAnchor() | 100 void RotationViewportAnchor::setAnchor() |
| 101 { | 101 { |
| 102 // FIXME: Scroll offsets are now fractional (DoublePoint and FloatPoint for
the FrameView and PinchViewport | 102 // FIXME: Scroll offsets are now fractional (DoublePoint and FloatPoint for
the FrameView and PinchViewport |
| 103 // respectively. This path should be rewritten without pixel snapping
. | 103 // respectively. This path should be rewritten without pixel snapping
. |
| 104 IntRect outerViewRect = m_rootFrameView->visibleContentRect(); | 104 IntRect outerViewRect = m_rootFrameView->layoutViewportScrollableArea()->vis
ibleContentRect(); |
| 105 IntRect innerViewRect = enclosedIntRect(m_rootFrameView->scrollableArea()->v
isibleContentRectDouble()); | 105 IntRect innerViewRect = enclosedIntRect(m_rootFrameView->scrollableArea()->v
isibleContentRectDouble()); |
| 106 | 106 |
| 107 m_oldPageScaleFactor = m_pinchViewport->scale(); | 107 m_oldPageScaleFactor = m_pinchViewport->scale(); |
| 108 m_oldMinimumPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().m
inimumScale; | 108 m_oldMinimumPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().m
inimumScale; |
| 109 | 109 |
| 110 // Save the absolute location in case we won't find the anchor node, we'll f
all back to that. | 110 // Save the absolute location in case we won't find the anchor node, we'll f
all back to that. |
| 111 m_pinchViewportInDocument = FloatPoint(m_rootFrameView->scrollableArea()->vi
sibleContentRectDouble().location()); | 111 m_pinchViewportInDocument = FloatPoint(m_rootFrameView->scrollableArea()->vi
sibleContentRectDouble().location()); |
| 112 | 112 |
| 113 m_anchorNode.clear(); | 113 m_anchorNode.clear(); |
| 114 m_anchorNodeBounds = LayoutRect(); | 114 m_anchorNodeBounds = LayoutRect(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().clampToCon
straints(newPageScaleFactor); | 153 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().clampToCon
straints(newPageScaleFactor); |
| 154 | 154 |
| 155 FloatSize pinchViewportSize = m_pinchViewport->size(); | 155 FloatSize pinchViewportSize = m_pinchViewport->size(); |
| 156 pinchViewportSize.scale(1 / newPageScaleFactor); | 156 pinchViewportSize.scale(1 / newPageScaleFactor); |
| 157 | 157 |
| 158 IntPoint mainFrameOrigin; | 158 IntPoint mainFrameOrigin; |
| 159 FloatPoint pinchViewportOrigin; | 159 FloatPoint pinchViewportOrigin; |
| 160 | 160 |
| 161 computeOrigins(pinchViewportSize, mainFrameOrigin, pinchViewportOrigin); | 161 computeOrigins(pinchViewportSize, mainFrameOrigin, pinchViewportOrigin); |
| 162 | 162 |
| 163 m_rootFrameView->setScrollPosition(mainFrameOrigin, 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
. |
| 166 m_pinchViewport->setScale(newPageScaleFactor); | 166 m_pinchViewport->setScale(newPageScaleFactor); |
| 167 m_pinchViewport->setLocation(pinchViewportOrigin); | 167 m_pinchViewport->setLocation(pinchViewportOrigin); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void RotationViewportAnchor::computeOrigins(const FloatSize& innerSize, IntPoint
& mainFrameOffset, FloatPoint& pinchViewportOffset) const | 170 void RotationViewportAnchor::computeOrigins(const FloatSize& innerSize, IntPoint
& mainFrameOffset, FloatPoint& pinchViewportOffset) const |
| 171 { | 171 { |
| 172 IntSize outerSize = m_rootFrameView->visibleContentRect().size(); | 172 IntSize outerSize = m_rootFrameView->layoutViewportScrollableArea()->visible
ContentRect().size(); |
| 173 | 173 |
| 174 // Compute the viewport origins in CSS pixels relative to the document. | 174 // Compute the viewport origins in CSS pixels relative to the document. |
| 175 FloatSize absPinchViewportOffset = m_normalizedPinchViewportOffset; | 175 FloatSize absPinchViewportOffset = m_normalizedPinchViewportOffset; |
| 176 absPinchViewportOffset.scale(outerSize.width(), outerSize.height()); | 176 absPinchViewportOffset.scale(outerSize.width(), outerSize.height()); |
| 177 | 177 |
| 178 FloatPoint innerOrigin = getInnerOrigin(innerSize); | 178 FloatPoint innerOrigin = getInnerOrigin(innerSize); |
| 179 FloatPoint outerOrigin = innerOrigin - absPinchViewportOffset; | 179 FloatPoint outerOrigin = innerOrigin - absPinchViewportOffset; |
| 180 | 180 |
| 181 IntRect outerRect = IntRect(flooredIntPoint(outerOrigin), outerSize); | 181 IntRect outerRect = IntRect(flooredIntPoint(outerOrigin), outerSize); |
| 182 FloatRect innerRect = FloatRect(innerOrigin, innerSize); | 182 FloatRect innerRect = FloatRect(innerOrigin, innerSize); |
| 183 | 183 |
| 184 moveToEncloseRect(outerRect, innerRect); | 184 moveToEncloseRect(outerRect, innerRect); |
| 185 | 185 |
| 186 outerRect.setLocation(m_rootFrameView->clampScrollPosition(outerRect.locatio
n())); | 186 outerRect.setLocation(m_rootFrameView->layoutViewportScrollableArea()->clamp
ScrollPosition(outerRect.location())); |
| 187 | 187 |
| 188 moveIntoRect(innerRect, outerRect); | 188 moveIntoRect(innerRect, outerRect); |
| 189 | 189 |
| 190 mainFrameOffset = outerRect.location(); | 190 mainFrameOffset = outerRect.location(); |
| 191 pinchViewportOffset = FloatPoint(innerRect.location() - outerRect.location()
); | 191 pinchViewportOffset = FloatPoint(innerRect.location() - outerRect.location()
); |
| 192 } | 192 } |
| 193 | 193 |
| 194 FloatPoint RotationViewportAnchor::getInnerOrigin(const FloatSize& innerSize) co
nst | 194 FloatPoint RotationViewportAnchor::getInnerOrigin(const FloatSize& innerSize) co
nst |
| 195 { | 195 { |
| 196 if (!m_anchorNode || !m_anchorNode->inDocument()) | 196 if (!m_anchorNode || !m_anchorNode->inDocument()) |
| 197 return m_pinchViewportInDocument; | 197 return m_pinchViewportInDocument; |
| 198 | 198 |
| 199 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); | 199 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); |
| 200 if (m_anchorNodeBounds == currentNodeBounds) | 200 if (m_anchorNodeBounds == currentNodeBounds) |
| 201 return m_pinchViewportInDocument; | 201 return m_pinchViewportInDocument; |
| 202 | 202 |
| 203 // Compute the new anchor point relative to the node position | 203 // Compute the new anchor point relative to the node position |
| 204 FloatSize anchorOffsetFromNode(currentNodeBounds.size()); | 204 FloatSize anchorOffsetFromNode(currentNodeBounds.size()); |
| 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 |