Chromium Code Reviews| 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 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 Loading... | |
| 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()); |
| 360 | |
| 361 if (m_topControlsAdjustment) { | |
|
aelias_OOO_until_Jul13
2014/10/09 22:58:53
Please remove this if() statement, it's unnecessar
bokan
2014/10/09 23:22:49
Done.
bokan
2014/10/10 14:39:56
Actually, the 'if' is needed, there are cases wher
| |
| 362 float aspectRatio = visibleRect().width() / visibleRect().height(); | |
| 363 float adjustment = frameViewSize.width() / aspectRatio - frameViewSize.h eight(); | |
| 364 frameViewSize.expand(0, adjustment); | |
| 365 } | |
| 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 Loading... | |
| 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 |
| OLD | NEW |