Chromium Code Reviews| Index: Source/web/ViewportAnchor.cpp |
| diff --git a/Source/web/ViewportAnchor.cpp b/Source/web/ViewportAnchor.cpp |
| index 4a6a3d40164d5d6fb0f61dfd69c1936e049087c7..2f5a77faa8df92e48aca31eea7f9835800d1b9b7 100644 |
| --- a/Source/web/ViewportAnchor.cpp |
| +++ b/Source/web/ViewportAnchor.cpp |
| @@ -73,26 +73,28 @@ Node* findNonEmptyAnchorNode(const IntPoint& point, const IntRect& viewRect, Eve |
| ViewportAnchor::ViewportAnchor(EventHandler* eventHandler) |
| : m_eventHandler(eventHandler) { } |
| -void ViewportAnchor::setAnchor(const IntRect& viewRect, const FloatSize& anchorInViewCoords) |
| +void ViewportAnchor::setAnchor(const IntRect& innerViewRect, const IntRect& outerViewRect, |
| + const FloatSize& anchorInViewCoords) |
| { |
| - m_viewRect = viewRect; |
| + m_viewRect = innerViewRect; |
| m_anchorNode.clear(); |
| m_anchorNodeBounds = LayoutRect(); |
| m_anchorInNodeCoords = FloatSize(); |
| m_anchorInViewCoords = anchorInViewCoords; |
| + m_outerInInnerCoords = FloatSize(); |
| - if (viewRect.isEmpty()) |
| + if (innerViewRect.isEmpty()) |
| return; |
| // Preserve origins at the absolute screen origin |
| - if (viewRect.location() == IntPoint::zero()) |
| + if (innerViewRect.location() == IntPoint::zero()) |
| return; |
| - FloatSize anchorOffset = viewRect.size(); |
| + FloatSize anchorOffset = innerViewRect.size(); |
| anchorOffset.scale(anchorInViewCoords.width(), anchorInViewCoords.height()); |
| - const FloatPoint anchorPoint = FloatPoint(viewRect.location()) + anchorOffset; |
| + const FloatPoint anchorPoint = FloatPoint(innerViewRect.location()) + anchorOffset; |
| - Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), viewRect, m_eventHandler); |
| + Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewRect, m_eventHandler); |
| if (!node) |
| return; |
| @@ -100,9 +102,20 @@ void ViewportAnchor::setAnchor(const IntRect& viewRect, const FloatSize& anchorI |
| m_anchorNodeBounds = node->boundingBox(); |
| m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); |
| m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorNodeBounds.height()); |
| + |
| + // Inner rectangle should be within the outer one. |
| + ASSERT(outerViewRect.contains(innerViewRect)); |
| + |
| + // Outer rectangle is used as a scale, we need positive width and height. |
| + ASSERT(!outerViewRect.isEmpty()); |
| + |
| + m_outerInInnerCoords = outerViewRect.location() - innerViewRect.location(); |
| + |
| + // Make m_outerInInnerCoords relative to the size of the outer rect |
| + m_outerInInnerCoords.scale(1.0 / outerViewRect.width(), 1.0 / outerViewRect.height()); |
| } |
| -IntPoint ViewportAnchor::computeOrigin(const IntSize& currentViewSize) const |
| +IntPoint ViewportAnchor::computeInnerViewportOrigin(const IntSize& innerSize) const |
|
aelias_OOO_until_Jul13
2014/09/10 01:46:24
Could you make this a FloatPoint instead, and like
timav
2014/09/10 18:22:40
Yes, this was one of my questions, should everythi
|
| { |
| if (!m_anchorNode || !m_anchorNode->inDocument()) |
| return m_viewRect.location(); |
| @@ -117,9 +130,18 @@ IntPoint ViewportAnchor::computeOrigin(const IntSize& currentViewSize) const |
| FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode; |
| // Compute the new origin point relative to the new anchor point |
| - FloatSize anchorOffsetFromOrigin = currentViewSize; |
| + FloatSize anchorOffsetFromOrigin = innerSize; |
| anchorOffsetFromOrigin.scale(m_anchorInViewCoords.width(), m_anchorInViewCoords.height()); |
| return flooredIntPoint(anchorPoint - anchorOffsetFromOrigin); |
| } |
| +IntPoint ViewportAnchor::computeOuterViewportOrigin(const IntPoint& innerOrigin, const IntSize& outerSize) const |
| +{ |
| + FloatSize outerOffset = m_outerInInnerCoords; |
| + |
| + outerOffset.scale(outerSize.width(), outerSize.height()); |
| + |
| + return flooredIntPoint(FloatPoint(innerOrigin) + outerOffset); |
| +} |
| + |
| } // namespace blink |