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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 node = node->parentNode(); | 66 node = node->parentNode(); |
67 | 67 |
68 return node; | 68 return node; |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 ViewportAnchor::ViewportAnchor(EventHandler* eventHandler) | 73 ViewportAnchor::ViewportAnchor(EventHandler* eventHandler) |
74 : m_eventHandler(eventHandler) { } | 74 : m_eventHandler(eventHandler) { } |
75 | 75 |
76 void ViewportAnchor::setAnchor(const IntRect& viewRect, const FloatSize& anchorI nViewCoords) | 76 void ViewportAnchor::setAnchor(const IntRect& innerViewRect, const IntRect& oute rViewRect, |
77 const FloatSize& anchorInViewCoords) | |
77 { | 78 { |
78 m_viewRect = viewRect; | 79 m_viewRect = innerViewRect; |
79 m_anchorNode.clear(); | 80 m_anchorNode.clear(); |
80 m_anchorNodeBounds = LayoutRect(); | 81 m_anchorNodeBounds = LayoutRect(); |
81 m_anchorInNodeCoords = FloatSize(); | 82 m_anchorInNodeCoords = FloatSize(); |
82 m_anchorInViewCoords = anchorInViewCoords; | 83 m_anchorInViewCoords = anchorInViewCoords; |
84 m_outerInInnerCoords = FloatSize(); | |
83 | 85 |
84 if (viewRect.isEmpty()) | 86 if (innerViewRect.isEmpty()) |
85 return; | 87 return; |
86 | 88 |
87 // Preserve origins at the absolute screen origin | 89 // Preserve origins at the absolute screen origin |
88 if (viewRect.location() == IntPoint::zero()) | 90 if (innerViewRect.location() == IntPoint::zero()) |
89 return; | 91 return; |
90 | 92 |
91 FloatSize anchorOffset = viewRect.size(); | 93 FloatSize anchorOffset = innerViewRect.size(); |
92 anchorOffset.scale(anchorInViewCoords.width(), anchorInViewCoords.height()); | 94 anchorOffset.scale(anchorInViewCoords.width(), anchorInViewCoords.height()); |
93 const FloatPoint anchorPoint = FloatPoint(viewRect.location()) + anchorOffse t; | 95 const FloatPoint anchorPoint = FloatPoint(innerViewRect.location()) + anchor Offset; |
94 | 96 |
95 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), viewRect, m_eventHandler); | 97 Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewR ect, m_eventHandler); |
96 if (!node) | 98 if (!node) |
97 return; | 99 return; |
98 | 100 |
99 m_anchorNode = node; | 101 m_anchorNode = node; |
100 m_anchorNodeBounds = node->boundingBox(); | 102 m_anchorNodeBounds = node->boundingBox(); |
101 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); | 103 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); |
102 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN odeBounds.height()); | 104 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN odeBounds.height()); |
105 | |
106 // Inner rectangle should be within the outer one. | |
107 ASSERT(outerViewRect.contains(innerViewRect)); | |
108 | |
109 // Outer rectangle is used as a scale, we need positive width and height. | |
110 ASSERT(!outerViewRect.isEmpty()); | |
111 | |
112 m_outerInInnerCoords = outerViewRect.location() - innerViewRect.location(); | |
113 | |
114 // Make m_outerInInnerCoords relative to the size of the outer rect | |
115 m_outerInInnerCoords.scale(1.0 / outerViewRect.width(), 1.0 / outerViewRect. height()); | |
103 } | 116 } |
104 | 117 |
105 IntPoint ViewportAnchor::computeOrigin(const IntSize& currentViewSize) const | 118 IntPoint ViewportAnchor::computeInnerViewportOrigin(const IntSize& innerSize) co nst |
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
| |
106 { | 119 { |
107 if (!m_anchorNode || !m_anchorNode->inDocument()) | 120 if (!m_anchorNode || !m_anchorNode->inDocument()) |
108 return m_viewRect.location(); | 121 return m_viewRect.location(); |
109 | 122 |
110 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); | 123 const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); |
111 if (m_anchorNodeBounds == currentNodeBounds) | 124 if (m_anchorNodeBounds == currentNodeBounds) |
112 return m_viewRect.location(); | 125 return m_viewRect.location(); |
113 | 126 |
114 // Compute the new anchor point relative to the node position | 127 // Compute the new anchor point relative to the node position |
115 FloatSize anchorOffsetFromNode = currentNodeBounds.size(); | 128 FloatSize anchorOffsetFromNode = currentNodeBounds.size(); |
116 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord s.height()); | 129 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord s.height()); |
117 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode ; | 130 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode ; |
118 | 131 |
119 // Compute the new origin point relative to the new anchor point | 132 // Compute the new origin point relative to the new anchor point |
120 FloatSize anchorOffsetFromOrigin = currentViewSize; | 133 FloatSize anchorOffsetFromOrigin = innerSize; |
121 anchorOffsetFromOrigin.scale(m_anchorInViewCoords.width(), m_anchorInViewCoo rds.height()); | 134 anchorOffsetFromOrigin.scale(m_anchorInViewCoords.width(), m_anchorInViewCoo rds.height()); |
122 return flooredIntPoint(anchorPoint - anchorOffsetFromOrigin); | 135 return flooredIntPoint(anchorPoint - anchorOffsetFromOrigin); |
123 } | 136 } |
124 | 137 |
138 IntPoint ViewportAnchor::computeOuterViewportOrigin(const IntPoint& innerOrigin, const IntSize& outerSize) const | |
139 { | |
140 FloatSize outerOffset = m_outerInInnerCoords; | |
141 | |
142 outerOffset.scale(outerSize.width(), outerSize.height()); | |
143 | |
144 return flooredIntPoint(FloatPoint(innerOrigin) + outerOffset); | |
145 } | |
146 | |
125 } // namespace blink | 147 } // namespace blink |
OLD | NEW |