Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/android/overscroll_controller_android.h" | 5 #include "content/browser/android/overscroll_controller_android.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 switches::kDisablePullToRefreshEffect)) { | 89 switches::kDisablePullToRefreshEffect)) { |
| 90 return nullptr; | 90 return nullptr; |
| 91 } | 91 } |
| 92 | 92 |
| 93 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler); | 93 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 OverscrollControllerAndroid::OverscrollControllerAndroid( | 98 OverscrollControllerAndroid::OverscrollControllerAndroid( |
| 99 ui::WindowAndroidCompositor* compositor, | |
| 100 float dpi_scale, | |
| 101 ui::OverscrollGlow* glow_effect, | |
| 102 ui::OverscrollRefresh* refresh_effect) | |
| 103 : compositor_(compositor), | |
| 104 dpi_scale_(dpi_scale), | |
| 105 enabled_(true), | |
| 106 scroll_update_consumed_(false), | |
| 107 glow_effect_(glow_effect), | |
| 108 refresh_effect_(refresh_effect) { | |
| 109 DCHECK(compositor_); | |
| 110 } | |
| 111 | |
| 112 OverscrollControllerAndroid::OverscrollControllerAndroid( | |
| 99 ui::OverscrollRefreshHandler* overscroll_refresh_handler, | 113 ui::OverscrollRefreshHandler* overscroll_refresh_handler, |
| 100 ui::WindowAndroidCompositor* compositor, | 114 ui::WindowAndroidCompositor* compositor, |
| 101 float dpi_scale) | 115 float dpi_scale) |
| 102 : compositor_(compositor), | 116 : compositor_(compositor), dpi_scale_(dpi_scale) { |
| 103 dpi_scale_(dpi_scale), | 117 OverscrollControllerAndroid( |
|
majidvp
2017/07/20 13:26:55
This is not the correct way to do delegating const
sunyunjia
2017/07/21 13:52:23
Done.
| |
| 104 enabled_(true), | 118 compositor, dpi_scale, CreateGlowEffect(this, dpi_scale_).get(), |
| 105 glow_effect_(CreateGlowEffect(this, dpi_scale_)), | 119 CreateRefreshEffect(overscroll_refresh_handler).get()); |
| 106 refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) { | |
| 107 DCHECK(compositor_); | |
| 108 } | 120 } |
| 109 | 121 |
| 110 OverscrollControllerAndroid::~OverscrollControllerAndroid() { | 122 OverscrollControllerAndroid::~OverscrollControllerAndroid() { |
| 111 } | 123 } |
| 112 | 124 |
| 113 bool OverscrollControllerAndroid::WillHandleGestureEvent( | 125 bool OverscrollControllerAndroid::WillHandleGestureEvent( |
| 114 const blink::WebGestureEvent& event) { | 126 const blink::WebGestureEvent& event) { |
| 115 if (!enabled_) | 127 if (!enabled_) |
| 116 return false; | 128 return false; |
| 117 | 129 |
| 118 if (!refresh_effect_) | 130 if (!refresh_effect_) |
| 119 return false; | 131 return false; |
| 120 | 132 |
| 121 // Suppress refresh detection if the glow effect is still prominent. | 133 // Suppress refresh detection if the glow effect is still prominent. |
| 122 if (glow_effect_ && glow_effect_->IsActive()) { | 134 if (glow_effect_ && glow_effect_->IsActive()) { |
| 123 if (glow_effect_->GetVisibleAlpha() > MinGlowAlphaToDisableRefresh()) | 135 if (glow_effect_->GetVisibleAlpha() > MinGlowAlphaToDisableRefresh()) |
| 124 return false; | 136 return false; |
| 125 } | 137 } |
| 126 | 138 |
| 127 bool handled = false; | 139 bool handled = false; |
| 128 switch (event.GetType()) { | 140 switch (event.GetType()) { |
| 129 case blink::WebInputEvent::kGestureScrollBegin: | 141 case blink::WebInputEvent::kGestureScrollBegin: |
| 130 refresh_effect_->OnScrollBegin(); | 142 refresh_effect_->OnScrollBegin(); |
| 143 scroll_update_consumed_ = false; | |
| 131 break; | 144 break; |
| 132 | 145 |
| 133 case blink::WebInputEvent::kGestureScrollUpdate: { | 146 case blink::WebInputEvent::kGestureScrollUpdate: { |
| 134 gfx::Vector2dF scroll_delta(event.data.scroll_update.delta_x, | 147 gfx::Vector2dF scroll_delta(event.data.scroll_update.delta_x, |
| 135 event.data.scroll_update.delta_y); | 148 event.data.scroll_update.delta_y); |
| 136 scroll_delta.Scale(dpi_scale_); | 149 scroll_delta.Scale(dpi_scale_); |
| 137 handled = refresh_effect_->WillHandleScrollUpdate(scroll_delta); | 150 handled = refresh_effect_->WillHandleScrollUpdate(scroll_delta); |
| 138 } break; | 151 } break; |
| 139 | 152 |
| 140 case blink::WebInputEvent::kGestureScrollEnd: | 153 case blink::WebInputEvent::kGestureScrollEnd: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // sent from the renderer compositor. | 195 // sent from the renderer compositor. |
| 183 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd || | 196 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd || |
| 184 event.GetType() == blink::WebInputEvent::kGestureFlingStart) { | 197 event.GetType() == blink::WebInputEvent::kGestureFlingStart) { |
| 185 OnOverscrolled(DidOverscrollParams()); | 198 OnOverscrolled(DidOverscrollParams()); |
| 186 } | 199 } |
| 187 | 200 |
| 188 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate && | 201 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate && |
| 189 refresh_effect_) { | 202 refresh_effect_) { |
| 190 // The effect should only be allowed if both the causal touch events go | 203 // The effect should only be allowed if both the causal touch events go |
| 191 // unconsumed and the generated scroll events go unconsumed. | 204 // unconsumed and the generated scroll events go unconsumed. |
| 192 bool consumed = | 205 scroll_update_consumed_ = |
| 193 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED || | 206 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED || |
| 194 event.data.scroll_update.previous_update_in_sequence_prevented; | 207 event.data.scroll_update.previous_update_in_sequence_prevented; |
| 195 refresh_effect_->OnScrollUpdateAck(consumed); | |
| 196 } | 208 } |
| 197 } | 209 } |
| 198 | 210 |
| 199 void OverscrollControllerAndroid::OnOverscrolled( | 211 void OverscrollControllerAndroid::OnOverscrolled( |
| 200 const DidOverscrollParams& params) { | 212 const DidOverscrollParams& params) { |
| 201 if (!enabled_) | 213 if (!enabled_) |
| 202 return; | 214 return; |
| 203 | 215 |
| 204 if (refresh_effect_ && (refresh_effect_->IsActive() || | 216 if (refresh_effect_) { |
| 205 refresh_effect_->IsAwaitingScrollUpdateAck())) { | 217 bool can_navigate = |
| 206 // An active (or potentially active) refresh effect should always pre-empt | 218 (!scroll_update_consumed_) && |
| 207 // the passive glow effect. | 219 (params.scroll_boundary_behavior.y == |
| 208 return; | 220 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType:: |
| 221 kScrollBoundaryBehaviorTypeAuto); | |
| 222 refresh_effect_->OnOverscrolled(can_navigate); | |
| 223 | |
| 224 if (refresh_effect_->IsActive() || | |
| 225 refresh_effect_->IsAwaitingScrollUpdateAck()) { | |
| 226 // An active (or potentially active) refresh effect should always pre-empt | |
| 227 // the passive glow effect. | |
| 228 return; | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 gfx::Vector2dF accumulated_overscroll = | |
| 233 gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_); | |
| 234 gfx::Vector2dF latest_overscroll_delta = | |
| 235 gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_); | |
| 236 gfx::Vector2dF current_fling_velocity = | |
| 237 gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_); | |
| 238 | |
| 239 if (params.scroll_boundary_behavior.x == | |
| 240 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType:: | |
| 241 kScrollBoundaryBehaviorTypeNone) { | |
| 242 accumulated_overscroll.set_x(0); | |
| 243 latest_overscroll_delta.set_x(0); | |
| 244 current_fling_velocity.set_x(0); | |
| 245 } | |
| 246 | |
| 247 if (params.scroll_boundary_behavior.y == | |
| 248 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType:: | |
| 249 kScrollBoundaryBehaviorTypeNone) { | |
| 250 accumulated_overscroll.set_y(0); | |
| 251 latest_overscroll_delta.set_y(0); | |
| 252 current_fling_velocity.set_y(0); | |
| 209 } | 253 } |
| 210 | 254 |
| 211 if (glow_effect_ && | 255 if (glow_effect_ && |
| 212 glow_effect_->OnOverscrolled( | 256 glow_effect_->OnOverscrolled( |
| 213 base::TimeTicks::Now(), | 257 base::TimeTicks::Now(), accumulated_overscroll, |
| 214 gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_), | 258 latest_overscroll_delta, current_fling_velocity, |
| 215 gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_), | |
| 216 gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_), | |
| 217 gfx::ScaleVector2d( | 259 gfx::ScaleVector2d( |
| 218 params.causal_event_viewport_point.OffsetFromOrigin(), | 260 params.causal_event_viewport_point.OffsetFromOrigin(), |
| 219 dpi_scale_))) { | 261 dpi_scale_))) { |
|
majidvp
2017/07/20 13:26:55
Although the last argument is not modified like ot
sunyunjia
2017/07/21 13:52:23
Done.
| |
| 220 SetNeedsAnimate(); | 262 SetNeedsAnimate(); |
| 221 } | 263 } |
| 222 } | 264 } |
| 223 | 265 |
| 224 bool OverscrollControllerAndroid::Animate(base::TimeTicks current_time, | 266 bool OverscrollControllerAndroid::Animate(base::TimeTicks current_time, |
| 225 cc::Layer* parent_layer) { | 267 cc::Layer* parent_layer) { |
| 226 DCHECK(parent_layer); | 268 DCHECK(parent_layer); |
| 227 if (!enabled_ || !glow_effect_) | 269 if (!enabled_ || !glow_effect_) |
| 228 return false; | 270 return false; |
| 229 | 271 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 std::unique_ptr<EdgeEffectBase> | 316 std::unique_ptr<EdgeEffectBase> |
| 275 OverscrollControllerAndroid::CreateEdgeEffect() { | 317 OverscrollControllerAndroid::CreateEdgeEffect() { |
| 276 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); | 318 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); |
| 277 } | 319 } |
| 278 | 320 |
| 279 void OverscrollControllerAndroid::SetNeedsAnimate() { | 321 void OverscrollControllerAndroid::SetNeedsAnimate() { |
| 280 compositor_->SetNeedsAnimate(); | 322 compositor_->SetNeedsAnimate(); |
| 281 } | 323 } |
| 282 | 324 |
| 283 } // namespace content | 325 } // namespace content |
| OLD | NEW |