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

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

Issue 893683003: Implement top controls show/hide functionality for main thread scrolling (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address nitp Created 5 years, 10 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
(Empty)
1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "TopControls.h"
28
29 #include "core/frame/FrameHost.h"
30 #include "core/page/Chrome.h"
31 #include "core/page/ChromeClient.h"
32 #include "platform/geometry/FloatSize.h"
33 #include <algorithm> // for std::min and std::max
34
35 namespace blink {
36
37 TopControls::TopControls(const FrameHost& frameHost)
38 : m_frameHost(frameHost)
39 , m_height(0)
40 , m_shownRatio(0)
41 , m_baselineContentOffset(0)
42 , m_accumulatedScrollDelta(0)
43 , m_shrinkViewport(false)
44 , m_permittedState(WebTopControlsBoth)
45 {
46 }
47
48 void TopControls::scrollBegin()
49 {
50 resetBaseline();
51 }
52
53 FloatSize TopControls::scrollBy(FloatSize pendingDelta)
54 {
55 if ((m_permittedState == WebTopControlsShown && pendingDelta.height() < 0) | | (m_permittedState == WebTopControlsHidden && pendingDelta.height() > 0))
56 return pendingDelta;
57
58 if (m_height == 0)
59 return pendingDelta;
60
61 float oldOffset = contentOffset();
62
63 // Update accumulated vertical scroll and apply it to top controls
64 m_accumulatedScrollDelta += pendingDelta.height();
65 setShownRatio((m_baselineContentOffset + m_accumulatedScrollDelta) / m_heigh t);
66
67 // Reset baseline when controls are fully visible
68 if (m_shownRatio == 1)
69 resetBaseline();
70
71 FloatSize appliedDelta(0, contentOffset() - oldOffset);
72 return pendingDelta - appliedDelta;
73 }
74
75 void TopControls::resetBaseline()
76 {
77 m_accumulatedScrollDelta = 0;
78 m_baselineContentOffset = contentOffset();
79 }
80
81 float TopControls::layoutHeight()
82 {
83 return m_shrinkViewport ? m_height : 0;
84 }
85
86 float TopControls::contentOffset()
87 {
88 return m_shownRatio * m_height;
89 }
90
91 void TopControls::setShownRatio(float shownRatio)
92 {
93 shownRatio = std::min(shownRatio, 1.f);
94 shownRatio = std::max(shownRatio, 0.f);
95
96 if (m_shownRatio == shownRatio)
97 return;
98
99 m_shownRatio = shownRatio;
100 m_frameHost.chrome().client().didUpdateTopControls();
101 }
102
103 void TopControls::updateConstraints(WebTopControlsState constraints)
104 {
105 m_permittedState = constraints;
106 }
107
108 void TopControls::setHeight(float height, bool shrinkViewport)
109 {
110 if (m_height == height && m_shrinkViewport == shrinkViewport)
111 return;
112
113 m_height = height;
114 m_shrinkViewport = shrinkViewport;
115 m_frameHost.chrome().client().didUpdateTopControls();
116 }
117
118 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698