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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 PinchViewport::~PinchViewport() { } | 74 PinchViewport::~PinchViewport() { } |
75 | 75 |
76 void PinchViewport::setSize(const IntSize& size) | 76 void PinchViewport::setSize(const IntSize& size) |
77 { | 77 { |
78 if (m_size == size) | 78 if (m_size == size) |
79 return; | 79 return; |
80 | 80 |
81 TRACE_EVENT2("blink", "PinchViewport::setSize", "width", size.width(), "heig
ht", size.height()); | 81 TRACE_EVENT2("blink", "PinchViewport::setSize", "width", size.width(), "heig
ht", size.height()); |
82 m_size = size; | 82 m_size = size; |
83 | 83 |
84 // Make sure we clamp the offset to within the new bounds. | 84 clampToBoundaries(); |
85 setLocation(m_offset); | |
86 | 85 |
87 if (m_innerViewportContainerLayer) { | 86 if (m_innerViewportContainerLayer) { |
88 m_innerViewportContainerLayer->setSize(m_size); | 87 m_innerViewportContainerLayer->setSize(m_size); |
89 | 88 |
90 // Need to re-compute sizes for the overlay scrollbars. | 89 // Need to re-compute sizes for the overlay scrollbars. |
91 setupScrollbar(WebScrollbar::Horizontal); | 90 setupScrollbar(WebScrollbar::Horizontal); |
92 setupScrollbar(WebScrollbar::Vertical); | 91 setupScrollbar(WebScrollbar::Vertical); |
93 } | 92 } |
94 } | 93 } |
95 | 94 |
96 void PinchViewport::reset() | 95 void PinchViewport::reset() |
97 { | 96 { |
98 setLocation(FloatPoint()); | 97 setScaleAndLocation(1, FloatPoint()); |
99 setScale(1); | |
100 } | 98 } |
101 | 99 |
102 void PinchViewport::mainFrameDidChangeSize() | 100 void PinchViewport::mainFrameDidChangeSize() |
103 { | 101 { |
104 TRACE_EVENT0("blink", "PinchViewport::mainFrameDidChangeSize"); | 102 TRACE_EVENT0("blink", "PinchViewport::mainFrameDidChangeSize"); |
105 | 103 |
106 // In unit tests we may not have initialized the layer tree. | 104 // In unit tests we may not have initialized the layer tree. |
107 if (m_innerViewportScrollLayer) | 105 if (m_innerViewportScrollLayer) |
108 m_innerViewportScrollLayer->setSize(contentsSize()); | 106 m_innerViewportScrollLayer->setSize(contentsSize()); |
109 | 107 |
110 // Make sure the viewport's offset is clamped within the newly sized main fr
ame. | 108 clampToBoundaries(); |
111 setLocation(m_offset); | |
112 } | 109 } |
113 | 110 |
114 FloatRect PinchViewport::visibleRect() const | 111 FloatRect PinchViewport::visibleRect() const |
115 { | 112 { |
116 FloatSize scaledSize(m_size); | 113 FloatSize scaledSize(m_size); |
117 scaledSize.scale(1 / m_scale); | 114 scaledSize.scale(1 / m_scale); |
118 return FloatRect(m_offset, scaledSize); | 115 return FloatRect(m_offset, scaledSize); |
119 } | 116 } |
120 | 117 |
121 FloatRect PinchViewport::visibleRectInDocument() const | 118 FloatRect PinchViewport::visibleRectInDocument() const |
(...skipping 22 matching lines...) Expand all Loading... |
144 rect.y() - centeringOffsetY - visibleRect().y()); | 141 rect.y() - centeringOffsetY - visibleRect().y()); |
145 | 142 |
146 view->setScrollPosition(flooredIntPoint(targetOffset)); | 143 view->setScrollPosition(flooredIntPoint(targetOffset)); |
147 | 144 |
148 FloatPoint remainder = FloatPoint(targetOffset - view->scrollPosition()); | 145 FloatPoint remainder = FloatPoint(targetOffset - view->scrollPosition()); |
149 move(remainder); | 146 move(remainder); |
150 } | 147 } |
151 | 148 |
152 void PinchViewport::setLocation(const FloatPoint& newLocation) | 149 void PinchViewport::setLocation(const FloatPoint& newLocation) |
153 { | 150 { |
154 FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation)); | 151 setScaleAndLocation(m_scale, newLocation); |
155 | |
156 if (clampedOffset == m_offset) | |
157 return; | |
158 | |
159 m_offset = clampedOffset; | |
160 | |
161 ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator(
); | |
162 ASSERT(coordinator); | |
163 coordinator->scrollableAreaScrollLayerDidChange(this); | |
164 | |
165 mainFrame()->loader().saveScrollState(); | |
166 } | 152 } |
167 | 153 |
168 void PinchViewport::move(const FloatPoint& delta) | 154 void PinchViewport::move(const FloatPoint& delta) |
169 { | 155 { |
170 setLocation(m_offset + delta); | 156 setLocation(m_offset + delta); |
171 } | 157 } |
172 | 158 |
173 void PinchViewport::setScale(float scale) | 159 void PinchViewport::setScale(float scale) |
174 { | 160 { |
175 if (scale == m_scale) | 161 setScaleAndLocation(scale, m_offset); |
| 162 } |
| 163 |
| 164 void PinchViewport::setScaleAndLocation(float scale, const FloatPoint& location) |
| 165 { |
| 166 bool valuesChanged = false; |
| 167 |
| 168 if (scale != m_scale) { |
| 169 m_scale = scale; |
| 170 valuesChanged = true; |
| 171 } |
| 172 |
| 173 // Old-style pinch sets scale here but we shouldn't call into the |
| 174 // location code below. Can be removed when there's no old-style pinch. |
| 175 // FIXME(bokan): Remove when cleaning up old pinch code. |
| 176 if (!m_innerViewportScrollLayer) { |
| 177 if (valuesChanged) |
| 178 mainFrame()->loader().saveScrollState(); |
| 179 |
| 180 return; |
| 181 } |
| 182 |
| 183 FloatPoint clampedOffset(clampOffsetToBoundaries(location)); |
| 184 |
| 185 if (clampedOffset != m_offset) { |
| 186 m_offset = clampedOffset; |
| 187 |
| 188 ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordina
tor(); |
| 189 ASSERT(coordinator); |
| 190 coordinator->scrollableAreaScrollLayerDidChange(this); |
| 191 |
| 192 valuesChanged = true; |
| 193 } |
| 194 |
| 195 if (!valuesChanged) |
176 return; | 196 return; |
177 | 197 |
178 m_scale = scale; | 198 mainFrame()->loader().saveScrollState(); |
179 | 199 |
180 if (mainFrame()) | 200 clampToBoundaries(); |
181 mainFrame()->loader().saveScrollState(); | |
182 | |
183 // Old-style pinch sets scale here but we shouldn't call into the | |
184 // clamping code below. | |
185 if (!m_innerViewportScrollLayer) | |
186 return; | |
187 | |
188 // Ensure we clamp so we remain within the bounds. | |
189 setLocation(visibleRect().location()); | |
190 | |
191 // TODO: We should probably be calling scaleDidChange type functions here. | |
192 // see Page::setPageScaleFactor. | |
193 } | 201 } |
194 | 202 |
195 // Modifies the top of the graphics layer tree to add layers needed to support | 203 // Modifies the top of the graphics layer tree to add layers needed to support |
196 // the inner/outer viewport fixed-position model for pinch zoom. When finished, | 204 // the inner/outer viewport fixed-position model for pinch zoom. When finished, |
197 // the tree will look like this (with * denoting added layers): | 205 // the tree will look like this (with * denoting added layers): |
198 // | 206 // |
199 // *rootTransformLayer | 207 // *rootTransformLayer |
200 // +- *innerViewportContainerLayer (fixed pos container) | 208 // +- *innerViewportContainerLayer (fixed pos container) |
201 // +- *pageScaleLayer | 209 // +- *pageScaleLayer |
202 // | +- *innerViewportScrollLayer | 210 // | +- *innerViewportScrollLayer |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 IntPoint PinchViewport::minimumScrollPosition() const | 352 IntPoint PinchViewport::minimumScrollPosition() const |
345 { | 353 { |
346 return IntPoint(); | 354 return IntPoint(); |
347 } | 355 } |
348 | 356 |
349 IntPoint PinchViewport::maximumScrollPosition() const | 357 IntPoint PinchViewport::maximumScrollPosition() const |
350 { | 358 { |
351 return flooredIntPoint(FloatSize(contentsSize()) - visibleRect().size()); | 359 return flooredIntPoint(FloatSize(contentsSize()) - visibleRect().size()); |
352 } | 360 } |
353 | 361 |
| 362 IntPoint PinchViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float
scale) |
| 363 { |
| 364 if (!mainFrame() || !mainFrame()->view()) |
| 365 return IntPoint(); |
| 366 |
| 367 FrameView* view = mainFrame()->view(); |
| 368 |
| 369 FloatSize scaledSize(m_size); |
| 370 scaledSize.scale(1 / scale); |
| 371 |
| 372 IntPoint pinchViewportMax = flooredIntPoint(FloatSize(contentsSize()) - scal
edSize); |
| 373 IntPoint max = view->maximumScrollPosition() + pinchViewportMax; |
| 374 IntPoint min = view->minimumScrollPosition(); // PinchViewportMin should be
(0, 0) |
| 375 |
| 376 IntPoint clamped = offset; |
| 377 clamped = clamped.shrunkTo(max); |
| 378 clamped = clamped.expandedTo(min); |
| 379 return clamped; |
| 380 } |
| 381 |
354 IntRect PinchViewport::scrollableAreaBoundingBox() const | 382 IntRect PinchViewport::scrollableAreaBoundingBox() const |
355 { | 383 { |
356 // This method should return the bounding box in the parent view's coordinat
e | 384 // This method should return the bounding box in the parent view's coordinat
e |
357 // space; however, PinchViewport technically isn't a child of any Frames. | 385 // space; however, PinchViewport technically isn't a child of any Frames. |
358 // Nonetheless, the PinchViewport always occupies the entire main frame so j
ust | 386 // Nonetheless, the PinchViewport always occupies the entire main frame so j
ust |
359 // return that. | 387 // return that. |
360 LocalFrame* frame = mainFrame(); | 388 LocalFrame* frame = mainFrame(); |
361 | 389 |
362 if (!frame || !frame->view()) | 390 if (!frame || !frame->view()) |
363 return IntRect(); | 391 return IntRect(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 449 } |
422 | 450 |
423 FloatPoint PinchViewport::clampOffsetToBoundaries(const FloatPoint& offset) | 451 FloatPoint PinchViewport::clampOffsetToBoundaries(const FloatPoint& offset) |
424 { | 452 { |
425 FloatPoint clampedOffset(offset); | 453 FloatPoint clampedOffset(offset); |
426 clampedOffset = clampedOffset.shrunkTo(FloatPoint(maximumScrollPosition())); | 454 clampedOffset = clampedOffset.shrunkTo(FloatPoint(maximumScrollPosition())); |
427 clampedOffset = clampedOffset.expandedTo(FloatPoint(minimumScrollPosition())
); | 455 clampedOffset = clampedOffset.expandedTo(FloatPoint(minimumScrollPosition())
); |
428 return clampedOffset; | 456 return clampedOffset; |
429 } | 457 } |
430 | 458 |
| 459 void PinchViewport::clampToBoundaries() |
| 460 { |
| 461 setLocation(m_offset); |
| 462 } |
| 463 |
431 String PinchViewport::debugName(const GraphicsLayer* graphicsLayer) | 464 String PinchViewport::debugName(const GraphicsLayer* graphicsLayer) |
432 { | 465 { |
433 String name; | 466 String name; |
434 if (graphicsLayer == m_innerViewportContainerLayer.get()) { | 467 if (graphicsLayer == m_innerViewportContainerLayer.get()) { |
435 name = "Inner Viewport Container Layer"; | 468 name = "Inner Viewport Container Layer"; |
436 } else if (graphicsLayer == m_pageScaleLayer.get()) { | 469 } else if (graphicsLayer == m_pageScaleLayer.get()) { |
437 name = "Page Scale Layer"; | 470 name = "Page Scale Layer"; |
438 } else if (graphicsLayer == m_innerViewportScrollLayer.get()) { | 471 } else if (graphicsLayer == m_innerViewportScrollLayer.get()) { |
439 name = "Inner Viewport Scroll Layer"; | 472 name = "Inner Viewport Scroll Layer"; |
440 } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) { | 473 } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) { |
441 name = "Overlay Scrollbar Horizontal Layer"; | 474 name = "Overlay Scrollbar Horizontal Layer"; |
442 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { | 475 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { |
443 name = "Overlay Scrollbar Vertical Layer"; | 476 name = "Overlay Scrollbar Vertical Layer"; |
444 } else { | 477 } else { |
445 ASSERT_NOT_REACHED(); | 478 ASSERT_NOT_REACHED(); |
446 } | 479 } |
447 | 480 |
448 return name; | 481 return name; |
449 } | 482 } |
450 | 483 |
451 } // namespace blink | 484 } // namespace blink |
OLD | NEW |