| 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 11 matching lines...) Expand all Loading... |
| 22 #include "ui/base/l10n/l10n_util_android.h" | 22 #include "ui/base/l10n/l10n_util_android.h" |
| 23 #include "ui/events/blink/did_overscroll_params.h" | 23 #include "ui/events/blink/did_overscroll_params.h" |
| 24 | 24 |
| 25 using ui::DidOverscrollParams; | 25 using ui::DidOverscrollParams; |
| 26 using ui::EdgeEffect; | 26 using ui::EdgeEffect; |
| 27 using ui::EdgeEffectBase; | 27 using ui::EdgeEffectBase; |
| 28 using ui::EdgeEffectL; | 28 using ui::EdgeEffectL; |
| 29 using ui::OverscrollGlow; | 29 using ui::OverscrollGlow; |
| 30 using ui::OverscrollGlowClient; | 30 using ui::OverscrollGlowClient; |
| 31 using ui::OverscrollRefresh; | 31 using ui::OverscrollRefresh; |
| 32 using ui::OverscrollRefreshHandler; | |
| 33 | 32 |
| 34 namespace content { | 33 namespace content { |
| 35 namespace { | 34 namespace { |
| 36 | 35 |
| 37 // Used for conditional creation of EdgeEffect types for the overscroll glow. | 36 // Used for conditional creation of EdgeEffect types for the overscroll glow. |
| 38 const int kAndroidLSDKVersion = 21; | 37 const int kAndroidLSDKVersion = 21; |
| 39 | 38 |
| 40 // If the glow effect alpha is greater than this value, the refresh effect will | 39 // If the glow effect alpha is greater than this value, the refresh effect will |
| 41 // be suppressed. This value was experimentally determined to provide a | 40 // be suppressed. This value was experimentally determined to provide a |
| 42 // reasonable balance between avoiding accidental refresh activation and | 41 // reasonable balance between avoiding accidental refresh activation and |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 float dpi_scale) { | 78 float dpi_scale) { |
| 80 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 79 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 81 switches::kDisableOverscrollEdgeEffect)) { | 80 switches::kDisableOverscrollEdgeEffect)) { |
| 82 return nullptr; | 81 return nullptr; |
| 83 } | 82 } |
| 84 | 83 |
| 85 return base::MakeUnique<OverscrollGlow>(client); | 84 return base::MakeUnique<OverscrollGlow>(client); |
| 86 } | 85 } |
| 87 | 86 |
| 88 std::unique_ptr<OverscrollRefresh> CreateRefreshEffect( | 87 std::unique_ptr<OverscrollRefresh> CreateRefreshEffect( |
| 89 OverscrollRefreshHandler* handler) { | 88 const base::android::JavaRef<jobject>& overscroll_refresh_handler) { |
| 89 if (overscroll_refresh_handler.is_null()) |
| 90 return nullptr; |
| 91 |
| 90 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 92 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 91 switches::kDisablePullToRefreshEffect)) { | 93 switches::kDisablePullToRefreshEffect)) { |
| 92 return nullptr; | 94 return nullptr; |
| 93 } | 95 } |
| 94 | 96 |
| 95 return base::MakeUnique<OverscrollRefresh>(handler); | 97 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler); |
| 96 } | 98 } |
| 97 | 99 |
| 98 } // namespace | 100 } // namespace |
| 99 | 101 |
| 100 OverscrollControllerAndroid::OverscrollControllerAndroid( | 102 OverscrollControllerAndroid::OverscrollControllerAndroid( |
| 101 ContentViewCoreImpl* content_view_core, | 103 const base::android::JavaRef<jobject>& overscroll_refresh_handler, |
| 104 ui::WindowAndroidCompositor* compositor, |
| 102 float dpi_scale) | 105 float dpi_scale) |
| 103 : compositor_(content_view_core->GetWindowAndroid()->GetCompositor()), | 106 : compositor_(compositor), |
| 104 dpi_scale_(dpi_scale), | 107 dpi_scale_(dpi_scale), |
| 105 enabled_(true), | 108 enabled_(true), |
| 106 glow_effect_(CreateGlowEffect(this, dpi_scale_)), | 109 glow_effect_(CreateGlowEffect(this, dpi_scale_)), |
| 107 refresh_effect_(CreateRefreshEffect(content_view_core)) { | 110 refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) { |
| 108 DCHECK(compositor_); | 111 DCHECK(compositor_); |
| 109 } | 112 } |
| 110 | 113 |
| 111 OverscrollControllerAndroid::~OverscrollControllerAndroid() { | 114 OverscrollControllerAndroid::~OverscrollControllerAndroid() { |
| 112 } | 115 } |
| 113 | 116 |
| 114 bool OverscrollControllerAndroid::WillHandleGestureEvent( | 117 bool OverscrollControllerAndroid::WillHandleGestureEvent( |
| 115 const blink::WebGestureEvent& event) { | 118 const blink::WebGestureEvent& event) { |
| 116 if (!enabled_) | 119 if (!enabled_) |
| 117 return false; | 120 return false; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 std::unique_ptr<EdgeEffectBase> | 277 std::unique_ptr<EdgeEffectBase> |
| 275 OverscrollControllerAndroid::CreateEdgeEffect() { | 278 OverscrollControllerAndroid::CreateEdgeEffect() { |
| 276 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); | 279 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); |
| 277 } | 280 } |
| 278 | 281 |
| 279 void OverscrollControllerAndroid::SetNeedsAnimate() { | 282 void OverscrollControllerAndroid::SetNeedsAnimate() { |
| 280 compositor_->SetNeedsAnimate(); | 283 compositor_->SetNeedsAnimate(); |
| 281 } | 284 } |
| 282 | 285 |
| 283 } // namespace content | 286 } // namespace content |
| OLD | NEW |