 Chromium Code Reviews
 Chromium Code Reviews Issue 556703005:
  Initial draft - modify ViewportAnchor to know about both inner and outer viewports.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 556703005:
  Initial draft - modify ViewportAnchor to know about both inner and outer viewports.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 pointOffset.scale(viewportAnchorRelativeEpsilon); | 61 pointOffset.scale(viewportAnchorRelativeEpsilon); | 
| 62 node = eventHandler->hitTestResultAtPoint(point + pointOffset, HitTestRe quest::ReadOnly | HitTestRequest::Active).innerNode(); | 62 node = eventHandler->hitTestResultAtPoint(point + pointOffset, HitTestRe quest::ReadOnly | HitTestRequest::Active).innerNode(); | 
| 63 } | 63 } | 
| 64 | 64 | 
| 65 while (node && node->boundingBox().isEmpty()) | 65 while (node && node->boundingBox().isEmpty()) | 
| 66 node = node->parentNode(); | 66 node = node->parentNode(); | 
| 67 | 67 | 
| 68 return node; | 68 return node; | 
| 69 } | 69 } | 
| 70 | 70 | 
| 71 void moveToEncloseRect(FloatRect * outer, const FloatRect & inner) | |
| 72 { | |
| 73 ASSERT(outer); | |
| 74 | |
| 75 FloatPoint minimumPosition = inner.location() + inner.size() - outer->size() ; | |
| 76 | |
| 77 // Minimum position should be positive or zero | |
| 78 minimumPosition = minimumPosition.expandedTo(FloatPoint()); | |
| 79 | |
| 80 FloatPoint maximumPosition = inner.location(); | |
| 81 | |
| 82 FloatPoint outerOrigin = outer->location(); | |
| 83 outerOrigin = outerOrigin.expandedTo(minimumPosition); | |
| 84 outerOrigin = outerOrigin.shrunkTo(maximumPosition); | |
| 85 | |
| 86 outer->setLocation(outerOrigin); | |
| 87 } | |
| 88 | |
| 71 } // namespace | 89 } // namespace | 
| 72 | 90 | 
| 73 ViewportAnchor::ViewportAnchor(EventHandler* eventHandler) | 91 ViewportAnchor::ViewportAnchor(EventHandler* eventHandler) | 
| 74 : m_eventHandler(eventHandler) { } | 92 : m_eventHandler(eventHandler) { } | 
| 75 | 93 | 
| 76 void ViewportAnchor::setAnchor(const IntRect& viewRect, const FloatSize& anchorI nViewCoords) | 94 void ViewportAnchor::setAnchor(const IntRect& outerViewRect, const IntRect& inne rViewRect, | 
| 95 const FloatSize& anchorInInnerViewCoords) | |
| 77 { | 96 { | 
| 78 m_viewRect = viewRect; | 97 // Preserve the inner viewport position in document in case we won't find th e anchor | 
| 98 m_pinchViewportInDocument = innerViewRect.location(); | |
| 99 | |
| 79 m_anchorNode.clear(); | 100 m_anchorNode.clear(); | 
| 80 m_anchorNodeBounds = LayoutRect(); | 101 m_anchorNodeBounds = LayoutRect(); | 
| 81 m_anchorInNodeCoords = FloatSize(); | 102 m_anchorInNodeCoords = FloatSize(); | 
| 82 m_anchorInViewCoords = anchorInViewCoords; | 103 m_anchorInInnerViewCoords = anchorInInnerViewCoords; | 
| 104 m_normalizedPinchViewportOffset = FloatSize(); | |
| 83 | 105 | 
| 84 if (viewRect.isEmpty()) | 106 if (innerViewRect.isEmpty()) | 
| 85 return; | 107 return; | 
| 86 | 108 | 
| 87 // Preserve origins at the absolute screen origin | 109 // Preserve origins at the absolute screen origin | 
| 88 if (viewRect.location() == IntPoint::zero()) | 110 if (innerViewRect.location() == IntPoint::zero()) | 
| 89 return; | 111 return; | 
| 90 | 112 | 
| 91 FloatSize anchorOffset = viewRect.size(); | 113 // Inner rectangle should be within the outer one. | 
| 92 anchorOffset.scale(anchorInViewCoords.width(), anchorInViewCoords.height()); | 114 ASSERT(outerViewRect.contains(innerViewRect)); | 
| 93 const FloatPoint anchorPoint = FloatPoint(viewRect.location()) + anchorOffse t; | |
| 94 | 115 | 
| 95 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), viewRect, m_eventHandler); | 116 // Outer rectangle is used as a scale, we need positive width and height. | 
| 117 ASSERT(!outerViewRect.isEmpty()); | |
| 118 | |
| 119 m_normalizedPinchViewportOffset = innerViewRect.location() - outerViewRect.l ocation(); | |
| 120 | |
| 121 // Normalize by the size of the outer rect | |
| 122 m_normalizedPinchViewportOffset.scale(1.0 / outerViewRect.width(), 1.0 / out erViewRect.height()); | |
| 123 | |
| 124 | |
| 125 FloatSize anchorOffset = innerViewRect.size(); | |
| 126 anchorOffset.scale(anchorInInnerViewCoords.width(), anchorInInnerViewCoords. height()); | |
| 127 const FloatPoint anchorPoint = FloatPoint(innerViewRect.location()) + anchor Offset; | |
| 128 | |
| 129 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewR ect, m_eventHandler); | |
| 96 if (!node) | 130 if (!node) | 
| 97 return; | 131 return; | 
| 98 | 132 | 
| 99 m_anchorNode = node; | 133 m_anchorNode = node; | 
| 100 m_anchorNodeBounds = node->boundingBox(); | 134 m_anchorNodeBounds = node->boundingBox(); | 
| 101 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); | 135 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); | 
| 102 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN odeBounds.height()); | 136 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN odeBounds.height()); | 
| 103 } | 137 } | 
| 104 | 138 | 
| 105 IntPoint ViewportAnchor::computeOrigin(const IntSize& currentViewSize) const | 139 void ViewportAnchor::computeOrigins(const IntSize& outerSize, const IntSize& inn erSize, | 
| 140 IntPoint* mainFrameOffset, FloatPoint* pinchViewportOffset) const | |
| 141 { | |
| 142 FloatSize absPinchViewportOffset = m_normalizedPinchViewportOffset; | |
| 143 absPinchViewportOffset.scale(outerSize.width(), outerSize.height()); | |
| 144 | |
| 145 FloatPoint innerOrigin = getInnerOrigin(innerSize); // relative to the docum ent | |
| 146 FloatPoint outerOrigin = innerOrigin - absPinchViewportOffset; | |
| 147 | |
| 148 // Move outer viewport to enclose inner viewport | |
| 149 FloatRect outerRect = FloatRect(outerOrigin, outerSize); | |
| 150 moveToEncloseRect(&outerRect, FloatRect(innerOrigin, FloatSize(innerSize))); | |
| 
timav
2014/09/11 21:52:05
At first I thought this move is necessary, but now
 
bokan
2014/09/12 20:53:07
In general, the outer viewport can be scrolled hor
 
timav
2014/09/12 23:33:35
David, my idea here was different (of course if I
 
timav
2014/09/12 23:42:28
Correction: I actually wanted to say that this wou
 
timav
2014/09/12 23:59:52
Correction 2: I did not realize that if I move the
 
bokan
2014/09/15 15:36:35
Right, the end result is the same though, we want
 
timav
2014/09/15 20:04:34
Yes, absolutely. I realized it after I submitted m
 | |
| 151 | |
| 152 *mainFrameOffset = flooredIntPoint(outerRect.location()); | |
| 153 *pinchViewportOffset = FloatPoint(absPinchViewportOffset); | |
| 154 } | |
| 155 | |
| 156 | |
| 157 FloatPoint ViewportAnchor::getInnerOrigin(const IntSize& innerSize) const | |
| 106 { | 158 { | 
| 107 if (!m_anchorNode || !m_anchorNode->inDocument()) | 159 if (!m_anchorNode || !m_anchorNode->inDocument()) | 
| 108 return m_viewRect.location(); | 160 return m_pinchViewportInDocument; | 
| 109 | 161 | 
| 110 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); | 162 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); | 
| 111 if (m_anchorNodeBounds == currentNodeBounds) | 163 if (m_anchorNodeBounds == currentNodeBounds) | 
| 112 return m_viewRect.location(); | 164 return m_pinchViewportInDocument; | 
| 113 | 165 | 
| 114 // Compute the new anchor point relative to the node position | 166 // Compute the new anchor point relative to the node position | 
| 115 FloatSize anchorOffsetFromNode = currentNodeBounds.size(); | 167 FloatSize anchorOffsetFromNode = currentNodeBounds.size(); | 
| 116 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord s.height()); | 168 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord s.height()); | 
| 117 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode ; | 169 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode ; | 
| 118 | 170 | 
| 119 // Compute the new origin point relative to the new anchor point | 171 // Compute the new origin point relative to the new anchor point | 
| 120 FloatSize anchorOffsetFromOrigin = currentViewSize; | 172 FloatSize anchorOffsetFromOrigin = innerSize; | 
| 121 anchorOffsetFromOrigin.scale(m_anchorInViewCoords.width(), m_anchorInViewCoo rds.height()); | 173 anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), m_anchorInIn nerViewCoords.height()); | 
| 122 return flooredIntPoint(anchorPoint - anchorOffsetFromOrigin); | 174 return anchorPoint - anchorOffsetFromOrigin; | 
| 123 } | 175 } | 
| 124 | 176 | 
| 125 } // namespace blink | 177 } // namespace blink | 
| OLD | NEW |