Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/TopControls.h" | 5 #include "core/frame/TopControls.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameHost.h" | 7 #include "core/frame/FrameHost.h" |
| 8 #include "core/page/ChromeClient.h" | 8 #include "core/page/ChromeClient.h" |
| 9 #include "platform/geometry/FloatSize.h" | 9 #include "platform/geometry/FloatSize.h" |
| 10 #include <algorithm> // for std::min and std::max | 10 #include <algorithm> // for std::min and std::max |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 visitor->trace(m_frameHost); | 31 visitor->trace(m_frameHost); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void TopControls::scrollBegin() | 34 void TopControls::scrollBegin() |
| 35 { | 35 { |
| 36 resetBaseline(); | 36 resetBaseline(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 FloatSize TopControls::scrollBy(FloatSize pendingDelta) | 39 FloatSize TopControls::scrollBy(FloatSize pendingDelta) |
| 40 { | 40 { |
| 41 if ((m_permittedState == WebTopControlsShown && pendingDelta.height() < 0) | | (m_permittedState == WebTopControlsHidden && pendingDelta.height() > 0)) | 41 if ((m_permittedState == WebTopControlsShown && pendingDelta.height() > 0) | | (m_permittedState == WebTopControlsHidden && pendingDelta.height() < 0)) |
| 42 return pendingDelta; | 42 return pendingDelta; |
| 43 | 43 |
| 44 if (m_height == 0) | 44 if (m_height == 0) |
| 45 return pendingDelta; | 45 return pendingDelta; |
| 46 | 46 |
| 47 float oldOffset = contentOffset(); | 47 float oldOffset = contentOffset(); |
| 48 float pageScale = m_frameHost->visualViewport().scale(); | 48 float pageScale = m_frameHost->visualViewport().scale(); |
| 49 | 49 |
| 50 // Update accumulated vertical scroll and apply it to top controls | 50 // Update accumulated vertical scroll and apply it to top controls |
| 51 // Compute scroll delta in viewport space by applying page scale | 51 // Compute scroll delta in viewport space by applying page scale |
| 52 m_accumulatedScrollDelta += pendingDelta.height() * pageScale; | 52 m_accumulatedScrollDelta += pendingDelta.height() * pageScale; |
| 53 | 53 |
| 54 float newContentOffset = m_baselineContentOffset + m_accumulatedScrollDelta; | 54 float newContentOffset = m_baselineContentOffset - m_accumulatedScrollDelta; |
| 55 | 55 |
| 56 setShownRatio(newContentOffset / m_height); | 56 setShownRatio(newContentOffset / m_height); |
| 57 | 57 |
| 58 // Reset baseline when controls are fully visible | 58 // Reset baseline when controls are fully visible |
| 59 if (m_shownRatio == 1) | 59 if (m_shownRatio == 1) |
| 60 resetBaseline(); | 60 resetBaseline(); |
| 61 | 61 |
| 62 // Clamp and use the expected content offset so that we don't return | 62 // Clamp and use the expected content offset so that we don't return |
| 63 // spurrious remaining scrolls due to the imprecision of the shownRatio. | 63 // spurrious remaining scrolls due to the imprecision of the shownRatio. |
| 64 newContentOffset = std::min(newContentOffset, m_height); | 64 newContentOffset = std::min(newContentOffset, m_height); |
| 65 newContentOffset = std::max(newContentOffset, 0.f); | 65 newContentOffset = std::max(newContentOffset, 0.f); |
| 66 | 66 |
| 67 FloatSize appliedDelta(0, (newContentOffset - oldOffset) / pageScale); | 67 // We negate the different because scrolling down (positive delta) causes |
| 68 // top controls to hide (negative offset difference). | |
|
tdresser
2016/03/01 19:24:09
Would it be clearer to just take oldOffset - newCo
bokan
2016/03/01 19:40:57
Done. Ugh, I'm a typo machine...
| |
| 69 FloatSize appliedDelta(0, -(newContentOffset - oldOffset) / pageScale); | |
| 68 return pendingDelta - appliedDelta; | 70 return pendingDelta - appliedDelta; |
| 69 } | 71 } |
| 70 | 72 |
| 71 void TopControls::resetBaseline() | 73 void TopControls::resetBaseline() |
| 72 { | 74 { |
| 73 m_accumulatedScrollDelta = 0; | 75 m_accumulatedScrollDelta = 0; |
| 74 m_baselineContentOffset = contentOffset(); | 76 m_baselineContentOffset = contentOffset(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 float TopControls::layoutHeight() | 79 float TopControls::layoutHeight() |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 105 { | 107 { |
| 106 if (m_height == height && m_shrinkViewport == shrinkViewport) | 108 if (m_height == height && m_shrinkViewport == shrinkViewport) |
| 107 return; | 109 return; |
| 108 | 110 |
| 109 m_height = height; | 111 m_height = height; |
| 110 m_shrinkViewport = shrinkViewport; | 112 m_shrinkViewport = shrinkViewport; |
| 111 m_frameHost->chromeClient().didUpdateTopControls(); | 113 m_frameHost->chromeClient().didUpdateTopControls(); |
| 112 } | 114 } |
| 113 | 115 |
| 114 } // namespace blink | 116 } // namespace blink |
| OLD | NEW |