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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } | 77 } |
77 | 78 |
78 void PinchViewport::trace(Visitor* visitor) | 79 void PinchViewport::trace(Visitor* visitor) |
79 { | 80 { |
80 visitor->trace(m_frameHost); | 81 visitor->trace(m_frameHost); |
81 } | 82 } |
82 | 83 |
83 void PinchViewport::setSize(const IntSize& size) | 84 void PinchViewport::setSize(const IntSize& size) |
84 { | 85 { |
85 if (m_size == size) | 86 if (m_size == size) |
86 return; | 87 return; |
87 | 88 |
88 TRACE_EVENT2("blink", "PinchViewport::setSize", "width", size.width(), "heig
ht", size.height()); | 89 TRACE_EVENT2("blink", "PinchViewport::setSize", "width", size.width(), "heig
ht", size.height()); |
89 m_size = size; | 90 m_size = size; |
90 | 91 |
91 clampToBoundaries(); | |
92 | |
93 if (m_innerViewportContainerLayer) { | 92 if (m_innerViewportContainerLayer) { |
94 m_innerViewportContainerLayer->setSize(m_size); | 93 m_innerViewportContainerLayer->setSize(m_size); |
95 | 94 |
96 // Need to re-compute sizes for the overlay scrollbars. | 95 // Need to re-compute sizes for the overlay scrollbars. |
97 setupScrollbar(WebScrollbar::Horizontal); | 96 setupScrollbar(WebScrollbar::Horizontal); |
98 setupScrollbar(WebScrollbar::Vertical); | 97 setupScrollbar(WebScrollbar::Vertical); |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
102 void PinchViewport::reset() | 101 void PinchViewport::reset() |
103 { | 102 { |
104 setScaleAndLocation(1, FloatPoint()); | 103 setScaleAndLocation(1, FloatPoint()); |
105 } | 104 } |
106 | 105 |
107 void PinchViewport::mainFrameDidChangeSize() | 106 void PinchViewport::mainFrameDidChangeSize() |
108 { | 107 { |
109 TRACE_EVENT0("blink", "PinchViewport::mainFrameDidChangeSize"); | 108 TRACE_EVENT0("blink", "PinchViewport::mainFrameDidChangeSize"); |
110 | 109 |
111 // In unit tests we may not have initialized the layer tree. | 110 // In unit tests we may not have initialized the layer tree. |
112 if (m_innerViewportScrollLayer) | 111 if (m_innerViewportScrollLayer) |
113 m_innerViewportScrollLayer->setSize(contentsSize()); | 112 m_innerViewportScrollLayer->setSize(contentsSize()); |
114 | 113 |
115 clampToBoundaries(); | 114 clampToBoundaries(); |
116 } | 115 } |
117 | 116 |
118 FloatRect PinchViewport::visibleRect() const | 117 FloatRect PinchViewport::visibleRect() const |
119 { | 118 { |
120 FloatSize scaledSize(m_size); | 119 FloatSize scaledSize(m_size); |
| 120 scaledSize.expand(0, m_topControlsAdjustment); |
121 scaledSize.scale(1 / m_scale); | 121 scaledSize.scale(1 / m_scale); |
122 return FloatRect(m_offset, scaledSize); | 122 return FloatRect(m_offset, scaledSize); |
123 } | 123 } |
124 | 124 |
125 FloatRect PinchViewport::visibleRectInDocument() const | 125 FloatRect PinchViewport::visibleRectInDocument() const |
126 { | 126 { |
127 if (!mainFrame() || !mainFrame()->view()) | 127 if (!mainFrame() || !mainFrame()->view()) |
128 return FloatRect(); | 128 return FloatRect(); |
129 | 129 |
130 FloatRect viewRect = mainFrame()->view()->visibleContentRect(); | 130 FloatRect viewRect = mainFrame()->view()->visibleContentRect(); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr
ollDimensions.height(); | 358 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr
ollDimensions.height(); |
359 } | 359 } |
360 | 360 |
361 IntPoint PinchViewport::minimumScrollPosition() const | 361 IntPoint PinchViewport::minimumScrollPosition() const |
362 { | 362 { |
363 return IntPoint(); | 363 return IntPoint(); |
364 } | 364 } |
365 | 365 |
366 IntPoint PinchViewport::maximumScrollPosition() const | 366 IntPoint PinchViewport::maximumScrollPosition() const |
367 { | 367 { |
368 return flooredIntPoint(FloatSize(contentsSize()) - visibleRect().size()); | 368 // FIXME: We probably shouldn't be storing the bounds in a float. crbug.com/
422331. |
| 369 FloatSize frameViewSize(contentsSize()); |
| 370 |
| 371 if (m_topControlsAdjustment) { |
| 372 float aspectRatio = visibleRect().width() / visibleRect().height(); |
| 373 float adjustment = frameViewSize.width() / aspectRatio - frameViewSize.h
eight(); |
| 374 frameViewSize.expand(0, adjustment); |
| 375 } |
| 376 |
| 377 frameViewSize.scale(m_scale); |
| 378 frameViewSize = flooredIntSize(frameViewSize); |
| 379 |
| 380 FloatSize viewportSize(m_size); |
| 381 viewportSize.expand(0, m_topControlsAdjustment); |
| 382 |
| 383 FloatSize maxPosition = frameViewSize - viewportSize; |
| 384 maxPosition.scale(1 / m_scale); |
| 385 |
| 386 return flooredIntPoint(maxPosition); |
369 } | 387 } |
370 | 388 |
371 IntPoint PinchViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float
scale) | 389 IntPoint PinchViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float
scale) |
372 { | 390 { |
373 if (!mainFrame() || !mainFrame()->view()) | 391 if (!mainFrame() || !mainFrame()->view()) |
374 return IntPoint(); | 392 return IntPoint(); |
375 | 393 |
376 FrameView* view = mainFrame()->view(); | 394 FrameView* view = mainFrame()->view(); |
377 | 395 |
378 FloatSize scaledSize(m_size); | 396 FloatSize scaledSize(m_size); |
379 scaledSize.scale(1 / scale); | 397 scaledSize.scale(1 / scale); |
380 | 398 |
381 IntPoint pinchViewportMax = flooredIntPoint(FloatSize(contentsSize()) - scal
edSize); | 399 IntPoint pinchViewportMax = flooredIntPoint(FloatSize(contentsSize()) - scal
edSize); |
382 IntPoint max = view->maximumScrollPosition() + pinchViewportMax; | 400 IntPoint max = view->maximumScrollPosition() + pinchViewportMax; |
383 IntPoint min = view->minimumScrollPosition(); // PinchViewportMin should be
(0, 0) | 401 IntPoint min = view->minimumScrollPosition(); // PinchViewportMin should be
(0, 0) |
384 | 402 |
385 IntPoint clamped = offset; | 403 IntPoint clamped = offset; |
386 clamped = clamped.shrunkTo(max); | 404 clamped = clamped.shrunkTo(max); |
387 clamped = clamped.expandedTo(min); | 405 clamped = clamped.expandedTo(min); |
388 return clamped; | 406 return clamped; |
389 } | 407 } |
390 | 408 |
| 409 void PinchViewport::setTopControlsAdjustment(float adjustment) |
| 410 { |
| 411 m_topControlsAdjustment = adjustment; |
| 412 } |
| 413 |
391 IntRect PinchViewport::scrollableAreaBoundingBox() const | 414 IntRect PinchViewport::scrollableAreaBoundingBox() const |
392 { | 415 { |
393 // This method should return the bounding box in the parent view's coordinat
e | 416 // This method should return the bounding box in the parent view's coordinat
e |
394 // space; however, PinchViewport technically isn't a child of any Frames. | 417 // space; however, PinchViewport technically isn't a child of any Frames. |
395 // Nonetheless, the PinchViewport always occupies the entire main frame so j
ust | 418 // Nonetheless, the PinchViewport always occupies the entire main frame so j
ust |
396 // return that. | 419 // return that. |
397 LocalFrame* frame = mainFrame(); | 420 LocalFrame* frame = mainFrame(); |
398 | 421 |
399 if (!frame || !frame->view()) | 422 if (!frame || !frame->view()) |
400 return IntRect(); | 423 return IntRect(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { | 507 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { |
485 name = "Overlay Scrollbar Vertical Layer"; | 508 name = "Overlay Scrollbar Vertical Layer"; |
486 } else { | 509 } else { |
487 ASSERT_NOT_REACHED(); | 510 ASSERT_NOT_REACHED(); |
488 } | 511 } |
489 | 512 |
490 return name; | 513 return name; |
491 } | 514 } |
492 | 515 |
493 } // namespace blink | 516 } // namespace blink |
OLD | NEW |