| 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 "web/RotationViewportAnchor.h" | 5 #include "web/RotationViewportAnchor.h" |
| 6 | 6 |
| 7 #include "core/dom/ContainerNode.h" | 7 #include "core/dom/ContainerNode.h" |
| 8 #include "core/dom/Node.h" | 8 #include "core/dom/Node.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 RotationViewportAnchor::~RotationViewportAnchor() { | 99 RotationViewportAnchor::~RotationViewportAnchor() { |
| 100 restoreToAnchor(); | 100 restoreToAnchor(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void RotationViewportAnchor::setAnchor() { | 103 void RotationViewportAnchor::setAnchor() { |
| 104 RootFrameViewport* rootFrameViewport = | 104 RootFrameViewport* rootFrameViewport = |
| 105 m_rootFrameView->getRootFrameViewport(); | 105 m_rootFrameView->getRootFrameViewport(); |
| 106 DCHECK(rootFrameViewport); | 106 DCHECK(rootFrameViewport); |
| 107 | 107 |
| 108 IntRect outerViewRect = | |
| 109 layoutViewport().visibleContentRect(IncludeScrollbars); | |
| 110 IntRect innerViewRect = rootFrameViewport->visibleContentRect(); | |
| 111 | |
| 112 m_oldPageScaleFactor = m_visualViewport->scale(); | 108 m_oldPageScaleFactor = m_visualViewport->scale(); |
| 113 m_oldMinimumPageScaleFactor = | 109 m_oldMinimumPageScaleFactor = |
| 114 m_pageScaleConstraintsSet.finalConstraints().minimumScale; | 110 m_pageScaleConstraintsSet.finalConstraints().minimumScale; |
| 115 | 111 |
| 116 // Save the absolute location in case we won't find the anchor node, we'll | 112 // Save the absolute location in case we won't find the anchor node, we'll |
| 117 // fall back to that. | 113 // fall back to that. |
| 118 m_visualViewportInDocument = | 114 m_visualViewportInDocument = |
| 119 FloatPoint(rootFrameViewport->visibleContentRect().location()); | 115 FloatPoint(rootFrameViewport->visibleContentRect().location()); |
| 120 | 116 |
| 121 m_anchorNode.clear(); | 117 m_anchorNode.clear(); |
| 122 m_anchorNodeBounds = LayoutRect(); | 118 m_anchorNodeBounds = LayoutRect(); |
| 123 m_anchorInNodeCoords = FloatSize(); | 119 m_anchorInNodeCoords = FloatSize(); |
| 124 m_normalizedVisualViewportOffset = FloatSize(); | 120 m_normalizedVisualViewportOffset = FloatSize(); |
| 125 | 121 |
| 126 if (innerViewRect.isEmpty()) | 122 IntRect innerViewRect = rootFrameViewport->visibleContentRect(); |
| 123 |
| 124 // Preserve origins at the absolute screen origin. |
| 125 if (innerViewRect.location() == IntPoint::zero() || innerViewRect.isEmpty()) |
| 127 return; | 126 return; |
| 128 | 127 |
| 129 // Preserve origins at the absolute screen origin | 128 IntRect outerViewRect = |
| 130 if (innerViewRect.location() == IntPoint::zero()) | 129 layoutViewport().visibleContentRect(IncludeScrollbars); |
| 131 return; | |
| 132 | |
| 133 // Inner rectangle should be within the outer one. | |
| 134 DCHECK(outerViewRect.contains(innerViewRect)); | |
| 135 | |
| 136 // Outer rectangle is used as a scale, we need positive width and height. | |
| 137 DCHECK(!outerViewRect.isEmpty()); | |
| 138 | |
| 139 m_normalizedVisualViewportOffset = | |
| 140 FloatSize(innerViewRect.location() - outerViewRect.location()); | |
| 141 | 130 |
| 142 // Normalize by the size of the outer rect | 131 // Normalize by the size of the outer rect |
| 132 DCHECK(!outerViewRect.isEmpty()); |
| 133 m_normalizedVisualViewportOffset = m_visualViewport->scrollOffset(); |
| 143 m_normalizedVisualViewportOffset.scale(1.0 / outerViewRect.width(), | 134 m_normalizedVisualViewportOffset.scale(1.0 / outerViewRect.width(), |
| 144 1.0 / outerViewRect.height()); | 135 1.0 / outerViewRect.height()); |
| 145 | 136 |
| 146 FloatPoint anchorOffset(innerViewRect.size()); | 137 // Note, we specifically use the unscaled visual viewport size here as the |
| 138 // conversion into content-space below will apply the scale. |
| 139 FloatPoint anchorOffset(m_visualViewport->size()); |
| 147 anchorOffset.scale(m_anchorInInnerViewCoords.width(), | 140 anchorOffset.scale(m_anchorInInnerViewCoords.width(), |
| 148 m_anchorInInnerViewCoords.height()); | 141 m_anchorInInnerViewCoords.height()); |
| 149 | 142 |
| 150 const FloatPoint anchorPointInContents = m_rootFrameView->rootFrameToContents( | 143 // Note, we specifically convert to the rootFrameView contents here, rather |
| 144 // than the layout viewport. That's because hit testing works from the |
| 145 // FrameView's content coordinates even if it's not the layout viewport. |
| 146 const FloatPoint anchorPointInContents = m_rootFrameView->frameToContents( |
| 151 m_visualViewport->viewportToRootFrame(anchorOffset)); | 147 m_visualViewport->viewportToRootFrame(anchorOffset)); |
| 152 | 148 |
| 153 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPointInContents), | 149 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPointInContents), |
| 154 innerViewRect, | 150 innerViewRect, |
| 155 m_rootFrameView->frame().eventHandler()); | 151 m_rootFrameView->frame().eventHandler()); |
| 156 if (!node) | 152 if (!node) |
| 157 return; | 153 return; |
| 158 | 154 |
| 159 m_anchorNode = node; | 155 m_anchorNode = node; |
| 160 m_anchorNodeBounds = node->boundingBox(); | 156 m_anchorNodeBounds = node->boundingBox(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 anchorOffsetFromNode; | 243 anchorOffsetFromNode; |
| 248 | 244 |
| 249 // Compute the new origin point relative to the new anchor point | 245 // Compute the new origin point relative to the new anchor point |
| 250 FloatSize anchorOffsetFromOrigin = innerSize; | 246 FloatSize anchorOffsetFromOrigin = innerSize; |
| 251 anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), | 247 anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), |
| 252 m_anchorInInnerViewCoords.height()); | 248 m_anchorInInnerViewCoords.height()); |
| 253 return anchorPoint - anchorOffsetFromOrigin; | 249 return anchorPoint - anchorOffsetFromOrigin; |
| 254 } | 250 } |
| 255 | 251 |
| 256 } // namespace blink | 252 } // namespace blink |
| OLD | NEW |