Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: Source/core/frame/PinchViewport.cpp

Issue 584833003: Made double-tap zoom work in pinch virtual viewport mode. (Blink-side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: TODO->FIXME Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 FloatPoint clampedOffset(clampOffsetToBoundaries(location));
174
175 if (clampedOffset != m_offset) {
176 m_offset = clampedOffset;
177
178 ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordina tor();
179 ASSERT(coordinator);
180 coordinator->scrollableAreaScrollLayerDidChange(this);
181
182 valuesChanged = true;
183 }
184
185 if (!valuesChanged)
176 return; 186 return;
177 187
178 m_scale = scale; 188 mainFrame()->loader().saveScrollState();
179
180 if (mainFrame())
181 mainFrame()->loader().saveScrollState();
182 189
183 // Old-style pinch sets scale here but we shouldn't call into the 190 // Old-style pinch sets scale here but we shouldn't call into the
184 // clamping code below. 191 // clamping code below. Can be removed when there's no old-style pinch.
185 if (!m_innerViewportScrollLayer) 192 if (!m_innerViewportScrollLayer)
186 return; 193 return;
187 194
188 // Ensure we clamp so we remain within the bounds. 195 clampToBoundaries();
189 setLocation(visibleRect().location());
190
191 // TODO: We should probably be calling scaleDidChange type functions here.
192 // see Page::setPageScaleFactor.
193 } 196 }
194 197
195 // Modifies the top of the graphics layer tree to add layers needed to support 198 // 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, 199 // the inner/outer viewport fixed-position model for pinch zoom. When finished,
197 // the tree will look like this (with * denoting added layers): 200 // the tree will look like this (with * denoting added layers):
198 // 201 //
199 // *rootTransformLayer 202 // *rootTransformLayer
200 // +- *innerViewportContainerLayer (fixed pos container) 203 // +- *innerViewportContainerLayer (fixed pos container)
201 // +- *pageScaleLayer 204 // +- *pageScaleLayer
202 // | +- *innerViewportScrollLayer 205 // | +- *innerViewportScrollLayer
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 IntPoint PinchViewport::minimumScrollPosition() const 347 IntPoint PinchViewport::minimumScrollPosition() const
345 { 348 {
346 return IntPoint(); 349 return IntPoint();
347 } 350 }
348 351
349 IntPoint PinchViewport::maximumScrollPosition() const 352 IntPoint PinchViewport::maximumScrollPosition() const
350 { 353 {
351 return flooredIntPoint(FloatSize(contentsSize()) - visibleRect().size()); 354 return flooredIntPoint(FloatSize(contentsSize()) - visibleRect().size());
352 } 355 }
353 356
357 IntPoint PinchViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float scale)
358 {
359 if (!mainFrame() || !mainFrame()->view())
360 return IntPoint();
361
362 FrameView* view = mainFrame()->view();
363
364 FloatSize scaledSize(m_size);
365 scaledSize.scale(1 / scale);
366
367 IntPoint pinchViewportMax = flooredIntPoint(FloatSize(contentsSize()) - scal edSize);
368 IntPoint max = view->maximumScrollPosition() + pinchViewportMax;
369 IntPoint min = view->minimumScrollPosition(); // PinchViewportMin should be (0, 0)
370
371 IntPoint clamped = offset;
372 clamped = clamped.shrunkTo(max);
373 clamped = clamped.expandedTo(min);
374 return clamped;
375 }
376
354 IntRect PinchViewport::scrollableAreaBoundingBox() const 377 IntRect PinchViewport::scrollableAreaBoundingBox() const
355 { 378 {
356 // This method should return the bounding box in the parent view's coordinat e 379 // 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. 380 // space; however, PinchViewport technically isn't a child of any Frames.
358 // Nonetheless, the PinchViewport always occupies the entire main frame so j ust 381 // Nonetheless, the PinchViewport always occupies the entire main frame so j ust
359 // return that. 382 // return that.
360 LocalFrame* frame = mainFrame(); 383 LocalFrame* frame = mainFrame();
361 384
362 if (!frame || !frame->view()) 385 if (!frame || !frame->view())
363 return IntRect(); 386 return IntRect();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 444 }
422 445
423 FloatPoint PinchViewport::clampOffsetToBoundaries(const FloatPoint& offset) 446 FloatPoint PinchViewport::clampOffsetToBoundaries(const FloatPoint& offset)
424 { 447 {
425 FloatPoint clampedOffset(offset); 448 FloatPoint clampedOffset(offset);
426 clampedOffset = clampedOffset.shrunkTo(FloatPoint(maximumScrollPosition())); 449 clampedOffset = clampedOffset.shrunkTo(FloatPoint(maximumScrollPosition()));
427 clampedOffset = clampedOffset.expandedTo(FloatPoint(minimumScrollPosition()) ); 450 clampedOffset = clampedOffset.expandedTo(FloatPoint(minimumScrollPosition()) );
428 return clampedOffset; 451 return clampedOffset;
429 } 452 }
430 453
454 void PinchViewport::clampToBoundaries()
455 {
456 setLocation(m_offset);
457 }
458
431 String PinchViewport::debugName(const GraphicsLayer* graphicsLayer) 459 String PinchViewport::debugName(const GraphicsLayer* graphicsLayer)
432 { 460 {
433 String name; 461 String name;
434 if (graphicsLayer == m_innerViewportContainerLayer.get()) { 462 if (graphicsLayer == m_innerViewportContainerLayer.get()) {
435 name = "Inner Viewport Container Layer"; 463 name = "Inner Viewport Container Layer";
436 } else if (graphicsLayer == m_pageScaleLayer.get()) { 464 } else if (graphicsLayer == m_pageScaleLayer.get()) {
437 name = "Page Scale Layer"; 465 name = "Page Scale Layer";
438 } else if (graphicsLayer == m_innerViewportScrollLayer.get()) { 466 } else if (graphicsLayer == m_innerViewportScrollLayer.get()) {
439 name = "Inner Viewport Scroll Layer"; 467 name = "Inner Viewport Scroll Layer";
440 } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) { 468 } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) {
441 name = "Overlay Scrollbar Horizontal Layer"; 469 name = "Overlay Scrollbar Horizontal Layer";
442 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { 470 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) {
443 name = "Overlay Scrollbar Vertical Layer"; 471 name = "Overlay Scrollbar Vertical Layer";
444 } else { 472 } else {
445 ASSERT_NOT_REACHED(); 473 ASSERT_NOT_REACHED();
446 } 474 }
447 475
448 return name; 476 return name;
449 } 477 }
450 478
451 } // namespace blink 479 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698