| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/frame/BrowserControls.h" | 5 #include "core/frame/BrowserControls.h" |
| 6 | 6 |
| 7 #include <algorithm> // for std::min and std::max | 7 #include <algorithm> // for std::min and std::max |
| 8 | 8 |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "core/frame/VisualViewport.h" | 10 #include "core/frame/VisualViewport.h" |
| 11 #include "core/page/ChromeClient.h" | 11 #include "core/page/ChromeClient.h" |
| 12 #include "core/page/Page.h" | 12 #include "core/page/Page.h" |
| 13 #include "platform/geometry/FloatSize.h" | 13 #include "platform/geometry/FloatSize.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 BrowserControls::BrowserControls(const FrameHost& frameHost) | 17 BrowserControls::BrowserControls(const Page& page) |
| 18 : m_frameHost(&frameHost), | 18 : m_page(&page), |
| 19 m_height(0), | 19 m_height(0), |
| 20 m_shownRatio(0), | 20 m_shownRatio(0), |
| 21 m_baselineContentOffset(0), | 21 m_baselineContentOffset(0), |
| 22 m_accumulatedScrollDelta(0), | 22 m_accumulatedScrollDelta(0), |
| 23 m_shrinkViewport(false), | 23 m_shrinkViewport(false), |
| 24 m_permittedState(WebBrowserControlsBoth) {} | 24 m_permittedState(WebBrowserControlsBoth) {} |
| 25 | 25 |
| 26 DEFINE_TRACE(BrowserControls) { | 26 DEFINE_TRACE(BrowserControls) { |
| 27 visitor->trace(m_frameHost); | 27 visitor->trace(m_page); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void BrowserControls::scrollBegin() { | 30 void BrowserControls::scrollBegin() { |
| 31 resetBaseline(); | 31 resetBaseline(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 FloatSize BrowserControls::scrollBy(FloatSize pendingDelta) { | 34 FloatSize BrowserControls::scrollBy(FloatSize pendingDelta) { |
| 35 if ((m_permittedState == WebBrowserControlsShown && | 35 if ((m_permittedState == WebBrowserControlsShown && |
| 36 pendingDelta.height() > 0) || | 36 pendingDelta.height() > 0) || |
| 37 (m_permittedState == WebBrowserControlsHidden && | 37 (m_permittedState == WebBrowserControlsHidden && |
| 38 pendingDelta.height() < 0)) | 38 pendingDelta.height() < 0)) |
| 39 return pendingDelta; | 39 return pendingDelta; |
| 40 | 40 |
| 41 if (m_height == 0) | 41 if (m_height == 0) |
| 42 return pendingDelta; | 42 return pendingDelta; |
| 43 | 43 |
| 44 float oldOffset = contentOffset(); | 44 float oldOffset = contentOffset(); |
| 45 float pageScale = m_frameHost->visualViewport().scale(); | 45 float pageScale = m_page->frameHost().visualViewport().scale(); |
| 46 | 46 |
| 47 // Update accumulated vertical scroll and apply it to browser controls | 47 // Update accumulated vertical scroll and apply it to browser controls |
| 48 // Compute scroll delta in viewport space by applying page scale | 48 // Compute scroll delta in viewport space by applying page scale |
| 49 m_accumulatedScrollDelta += pendingDelta.height() * pageScale; | 49 m_accumulatedScrollDelta += pendingDelta.height() * pageScale; |
| 50 | 50 |
| 51 float newContentOffset = m_baselineContentOffset - m_accumulatedScrollDelta; | 51 float newContentOffset = m_baselineContentOffset - m_accumulatedScrollDelta; |
| 52 | 52 |
| 53 setShownRatio(newContentOffset / m_height); | 53 setShownRatio(newContentOffset / m_height); |
| 54 | 54 |
| 55 // Reset baseline when controls are fully visible | 55 // Reset baseline when controls are fully visible |
| (...skipping 25 matching lines...) Expand all Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 void BrowserControls::setShownRatio(float shownRatio) { | 83 void BrowserControls::setShownRatio(float shownRatio) { |
| 84 shownRatio = std::min(shownRatio, 1.f); | 84 shownRatio = std::min(shownRatio, 1.f); |
| 85 shownRatio = std::max(shownRatio, 0.f); | 85 shownRatio = std::max(shownRatio, 0.f); |
| 86 | 86 |
| 87 if (m_shownRatio == shownRatio) | 87 if (m_shownRatio == shownRatio) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 m_shownRatio = shownRatio; | 90 m_shownRatio = shownRatio; |
| 91 m_frameHost->page().chromeClient().didUpdateBrowserControls(); | 91 m_page->chromeClient().didUpdateBrowserControls(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void BrowserControls::updateConstraintsAndState( | 94 void BrowserControls::updateConstraintsAndState( |
| 95 WebBrowserControlsState constraints, | 95 WebBrowserControlsState constraints, |
| 96 WebBrowserControlsState current, | 96 WebBrowserControlsState current, |
| 97 bool animate) { | 97 bool animate) { |
| 98 m_permittedState = constraints; | 98 m_permittedState = constraints; |
| 99 | 99 |
| 100 DCHECK(!(constraints == WebBrowserControlsShown && | 100 DCHECK(!(constraints == WebBrowserControlsShown && |
| 101 current == WebBrowserControlsHidden)); | 101 current == WebBrowserControlsHidden)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 118 else | 118 else |
| 119 setShownRatio(1.f); | 119 setShownRatio(1.f); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void BrowserControls::setHeight(float height, bool shrinkViewport) { | 122 void BrowserControls::setHeight(float height, bool shrinkViewport) { |
| 123 if (m_height == height && m_shrinkViewport == shrinkViewport) | 123 if (m_height == height && m_shrinkViewport == shrinkViewport) |
| 124 return; | 124 return; |
| 125 | 125 |
| 126 m_height = height; | 126 m_height = height; |
| 127 m_shrinkViewport = shrinkViewport; | 127 m_shrinkViewport = shrinkViewport; |
| 128 m_frameHost->page().chromeClient().didUpdateBrowserControls(); | 128 m_page->chromeClient().didUpdateBrowserControls(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace blink | 131 } // namespace blink |
| OLD | NEW |