Add ICU message format support
[chromium-blink-merge.git] / content / browser / android / overscroll_refresh.cc
blobc2a1453bc1750eea5e49f337c65f9601f7fe1667
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/android/overscroll_refresh.h"
7 #include "base/logging.h"
9 namespace content {
10 namespace {
12 // Experimentally determined constant used to allow activation even if touch
13 // release results in a small upward fling (quite common during a slow scroll).
14 const float kMinFlingVelocityForActivation = -500.f;
16 } // namespace
18 OverscrollRefresh::OverscrollRefresh(OverscrollRefreshHandler* handler)
19 : scrolled_to_top_(true),
20 overflow_y_hidden_(false),
21 scroll_consumption_state_(DISABLED),
22 handler_(handler) {
23 DCHECK(handler);
26 OverscrollRefresh::~OverscrollRefresh() {
29 void OverscrollRefresh::Reset() {
30 scroll_consumption_state_ = DISABLED;
31 handler_->PullReset();
34 void OverscrollRefresh::OnScrollBegin() {
35 ReleaseWithoutActivation();
36 if (scrolled_to_top_ && !overflow_y_hidden_)
37 scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK;
40 void OverscrollRefresh::OnScrollEnd(const gfx::Vector2dF& scroll_velocity) {
41 bool allow_activation = scroll_velocity.y() > kMinFlingVelocityForActivation;
42 Release(allow_activation);
45 void OverscrollRefresh::OnScrollUpdateAck(bool was_consumed) {
46 if (scroll_consumption_state_ != AWAITING_SCROLL_UPDATE_ACK)
47 return;
49 if (was_consumed) {
50 scroll_consumption_state_ = DISABLED;
51 return;
54 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED;
57 bool OverscrollRefresh::WillHandleScrollUpdate(
58 const gfx::Vector2dF& scroll_delta) {
59 switch (scroll_consumption_state_) {
60 case DISABLED:
61 return false;
63 case AWAITING_SCROLL_UPDATE_ACK:
64 // If the initial scroll motion is downward, never allow activation.
65 if (scroll_delta.y() <= 0)
66 scroll_consumption_state_ = DISABLED;
67 return false;
69 case ENABLED:
70 handler_->PullUpdate(scroll_delta.y());
71 return true;
74 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_;
75 return false;
78 void OverscrollRefresh::ReleaseWithoutActivation() {
79 bool allow_activation = false;
80 Release(allow_activation);
83 bool OverscrollRefresh::IsActive() const {
84 return scroll_consumption_state_ == ENABLED;
87 bool OverscrollRefresh::IsAwaitingScrollUpdateAck() const {
88 return scroll_consumption_state_ == AWAITING_SCROLL_UPDATE_ACK;
91 void OverscrollRefresh::OnFrameUpdated(
92 const gfx::Vector2dF& content_scroll_offset,
93 bool root_overflow_y_hidden) {
94 scrolled_to_top_ = content_scroll_offset.y() == 0;
95 overflow_y_hidden_ = root_overflow_y_hidden;
98 void OverscrollRefresh::Release(bool allow_refresh) {
99 if (scroll_consumption_state_ == ENABLED)
100 handler_->PullRelease(allow_refresh);
101 scroll_consumption_state_ = DISABLED;
104 } // namespace content