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

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

Issue 643473002: Made top controls work with virtual viewport pinch-to-zoom. (Blink) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed if statement Created 6 years, 2 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 using blink::WebScrollbarLayer; 60 using blink::WebScrollbarLayer;
61 using blink::FrameHost; 61 using blink::FrameHost;
62 using blink::GraphicsLayer; 62 using blink::GraphicsLayer;
63 using blink::GraphicsLayerFactory; 63 using blink::GraphicsLayerFactory;
64 64
65 namespace blink { 65 namespace blink {
66 66
67 PinchViewport::PinchViewport(FrameHost& owner) 67 PinchViewport::PinchViewport(FrameHost& owner)
68 : m_frameHost(owner) 68 : m_frameHost(owner)
69 , m_scale(1) 69 , m_scale(1)
70 , m_topControlsAdjustment(0)
70 { 71 {
71 reset(); 72 reset();
72 } 73 }
73 74
74 PinchViewport::~PinchViewport() { } 75 PinchViewport::~PinchViewport() { }
75 76
76 void PinchViewport::setSize(const IntSize& size) 77 void PinchViewport::setSize(const IntSize& size)
77 { 78 {
78 if (m_size == size) 79 if (m_size == size)
79 return; 80 return;
80 81
81 TRACE_EVENT2("blink", "PinchViewport::setSize", "width", size.width(), "heig ht", size.height()); 82 TRACE_EVENT2("blink", "PinchViewport::setSize", "width", size.width(), "heig ht", size.height());
82 m_size = size; 83 m_size = size;
83 84
84 clampToBoundaries();
85
86 if (m_innerViewportContainerLayer) { 85 if (m_innerViewportContainerLayer) {
87 m_innerViewportContainerLayer->setSize(m_size); 86 m_innerViewportContainerLayer->setSize(m_size);
88 87
89 // Need to re-compute sizes for the overlay scrollbars. 88 // Need to re-compute sizes for the overlay scrollbars.
90 setupScrollbar(WebScrollbar::Horizontal); 89 setupScrollbar(WebScrollbar::Horizontal);
91 setupScrollbar(WebScrollbar::Vertical); 90 setupScrollbar(WebScrollbar::Vertical);
92 } 91 }
93 } 92 }
94 93
95 void PinchViewport::reset() 94 void PinchViewport::reset()
96 { 95 {
97 setScaleAndLocation(1, FloatPoint()); 96 setScaleAndLocation(1, FloatPoint());
98 } 97 }
99 98
100 void PinchViewport::mainFrameDidChangeSize() 99 void PinchViewport::mainFrameDidChangeSize()
101 { 100 {
102 TRACE_EVENT0("blink", "PinchViewport::mainFrameDidChangeSize"); 101 TRACE_EVENT0("blink", "PinchViewport::mainFrameDidChangeSize");
103 102
104 // In unit tests we may not have initialized the layer tree. 103 // In unit tests we may not have initialized the layer tree.
105 if (m_innerViewportScrollLayer) 104 if (m_innerViewportScrollLayer)
106 m_innerViewportScrollLayer->setSize(contentsSize()); 105 m_innerViewportScrollLayer->setSize(contentsSize());
107 106
108 clampToBoundaries(); 107 clampToBoundaries();
109 } 108 }
110 109
111 FloatRect PinchViewport::visibleRect() const 110 FloatRect PinchViewport::visibleRect() const
112 { 111 {
113 FloatSize scaledSize(m_size); 112 FloatSize scaledSize(m_size);
113 scaledSize.expand(0, m_topControlsAdjustment);
114 scaledSize.scale(1 / m_scale); 114 scaledSize.scale(1 / m_scale);
115 return FloatRect(m_offset, scaledSize); 115 return FloatRect(m_offset, scaledSize);
116 } 116 }
117 117
118 FloatRect PinchViewport::visibleRectInDocument() const 118 FloatRect PinchViewport::visibleRectInDocument() const
119 { 119 {
120 if (!mainFrame() || !mainFrame()->view()) 120 if (!mainFrame() || !mainFrame()->view())
121 return FloatRect(); 121 return FloatRect();
122 122
123 FloatRect viewRect = mainFrame()->view()->visibleContentRect(); 123 FloatRect viewRect = mainFrame()->view()->visibleContentRect();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr ollDimensions.height(); 349 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr ollDimensions.height();
350 } 350 }
351 351
352 IntPoint PinchViewport::minimumScrollPosition() const 352 IntPoint PinchViewport::minimumScrollPosition() const
353 { 353 {
354 return IntPoint(); 354 return IntPoint();
355 } 355 }
356 356
357 IntPoint PinchViewport::maximumScrollPosition() const 357 IntPoint PinchViewport::maximumScrollPosition() const
358 { 358 {
359 return flooredIntPoint(FloatSize(contentsSize()) - visibleRect().size()); 359 FloatSize frameViewSize(contentsSize());
Rick Byers 2014/10/10 00:06:09 not necessarily for this CL (if it's non-trivial t
bokan 2014/10/10 14:39:56 Yes, I've been following the discussion. I'll keep
360
361 // The adjustment should only be non-zero in the case of a top controls offs et.
362 // It is made to keep the aspect ratio of the two viewports the same.
363 float aspectRatio = visibleRect().width() / visibleRect().height();
364 float adjustment = frameViewSize.width() / aspectRatio - frameViewSize.heigh t();
365 frameViewSize.expand(0, adjustment);
366
367 frameViewSize.scale(m_scale);
368 frameViewSize = flooredIntSize(frameViewSize);
369
370 FloatSize viewportSize(m_size);
371 viewportSize.expand(0, m_topControlsAdjustment);
372
373 FloatSize maxPosition = frameViewSize - viewportSize;
374 maxPosition.scale(1 / m_scale);
375
376 return flooredIntPoint(maxPosition);
360 } 377 }
361 378
362 IntPoint PinchViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float scale) 379 IntPoint PinchViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float scale)
363 { 380 {
364 if (!mainFrame() || !mainFrame()->view()) 381 if (!mainFrame() || !mainFrame()->view())
365 return IntPoint(); 382 return IntPoint();
366 383
367 FrameView* view = mainFrame()->view(); 384 FrameView* view = mainFrame()->view();
368 385
369 FloatSize scaledSize(m_size); 386 FloatSize scaledSize(m_size);
370 scaledSize.scale(1 / scale); 387 scaledSize.scale(1 / scale);
371 388
372 IntPoint pinchViewportMax = flooredIntPoint(FloatSize(contentsSize()) - scal edSize); 389 IntPoint pinchViewportMax = flooredIntPoint(FloatSize(contentsSize()) - scal edSize);
373 IntPoint max = view->maximumScrollPosition() + pinchViewportMax; 390 IntPoint max = view->maximumScrollPosition() + pinchViewportMax;
374 IntPoint min = view->minimumScrollPosition(); // PinchViewportMin should be (0, 0) 391 IntPoint min = view->minimumScrollPosition(); // PinchViewportMin should be (0, 0)
375 392
376 IntPoint clamped = offset; 393 IntPoint clamped = offset;
377 clamped = clamped.shrunkTo(max); 394 clamped = clamped.shrunkTo(max);
378 clamped = clamped.expandedTo(min); 395 clamped = clamped.expandedTo(min);
379 return clamped; 396 return clamped;
380 } 397 }
381 398
399 void PinchViewport::setTopControlsAdjustment(float adjustment)
400 {
401 m_topControlsAdjustment = adjustment;
402 }
403
382 IntRect PinchViewport::scrollableAreaBoundingBox() const 404 IntRect PinchViewport::scrollableAreaBoundingBox() const
383 { 405 {
384 // This method should return the bounding box in the parent view's coordinat e 406 // This method should return the bounding box in the parent view's coordinat e
385 // space; however, PinchViewport technically isn't a child of any Frames. 407 // space; however, PinchViewport technically isn't a child of any Frames.
386 // Nonetheless, the PinchViewport always occupies the entire main frame so j ust 408 // Nonetheless, the PinchViewport always occupies the entire main frame so j ust
387 // return that. 409 // return that.
388 LocalFrame* frame = mainFrame(); 410 LocalFrame* frame = mainFrame();
389 411
390 if (!frame || !frame->view()) 412 if (!frame || !frame->view())
391 return IntRect(); 413 return IntRect();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { 497 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) {
476 name = "Overlay Scrollbar Vertical Layer"; 498 name = "Overlay Scrollbar Vertical Layer";
477 } else { 499 } else {
478 ASSERT_NOT_REACHED(); 500 ASSERT_NOT_REACHED();
479 } 501 }
480 502
481 return name; 503 return name;
482 } 504 }
483 505
484 } // namespace blink 506 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698