| 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 130 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 FrameView& scrollView, const FloatSize
& innerSize, | 151 void ViewportAnchor::computeOrigins(const FrameView& frameView, 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 = frameView.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; |
| 162 | 162 |
| 163 IntRect outerRect = IntRect(flooredIntPoint(outerOrigin), outerSize); | 163 IntRect outerRect = IntRect(flooredIntPoint(outerOrigin), outerSize); |
| 164 FloatRect innerRect = FloatRect(innerOrigin, innerSize); | 164 FloatRect innerRect = FloatRect(innerOrigin, innerSize); |
| 165 | 165 |
| 166 moveToEncloseRect(outerRect, innerRect); | 166 moveToEncloseRect(outerRect, innerRect); |
| 167 | 167 |
| 168 outerRect.setLocation(scrollView.adjustScrollPositionWithinRange(outerRect.l
ocation())); | 168 outerRect.setLocation(frameView.adjustScrollPositionWithinRange(outerRect.lo
cation())); |
| 169 | 169 |
| 170 moveIntoRect(innerRect, outerRect); | 170 moveIntoRect(innerRect, outerRect); |
| 171 | 171 |
| 172 mainFrameOffset = outerRect.location(); | 172 mainFrameOffset = outerRect.location(); |
| 173 pinchViewportOffset = FloatPoint(innerRect.location() - outerRect.location()
); | 173 pinchViewportOffset = FloatPoint(innerRect.location() - outerRect.location()
); |
| 174 } | 174 } |
| 175 | 175 |
| 176 FloatPoint ViewportAnchor::getInnerOrigin(const FloatSize& innerSize) const | 176 FloatPoint ViewportAnchor::getInnerOrigin(const FloatSize& innerSize) const |
| 177 { | 177 { |
| 178 if (!m_anchorNode || !m_anchorNode->inDocument()) | 178 if (!m_anchorNode || !m_anchorNode->inDocument()) |
| 179 return m_pinchViewportInDocument; | 179 return m_pinchViewportInDocument; |
| 180 | 180 |
| 181 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); | 181 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); |
| 182 if (m_anchorNodeBounds == currentNodeBounds) | 182 if (m_anchorNodeBounds == currentNodeBounds) |
| 183 return m_pinchViewportInDocument; | 183 return m_pinchViewportInDocument; |
| 184 | 184 |
| 185 // Compute the new anchor point relative to the node position | 185 // Compute the new anchor point relative to the node position |
| 186 FloatSize anchorOffsetFromNode = currentNodeBounds.size(); | 186 FloatSize anchorOffsetFromNode = currentNodeBounds.size(); |
| 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 |