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

Unified Diff: content/browser/android/overscroll_controller_android.cc

Issue 894193005: [Android] Use the platform SwipeRefreshLayout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/android/overscroll_controller_android.h ('k') | content/browser/android/overscroll_glow.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/android/overscroll_controller_android.cc
diff --git a/content/browser/android/overscroll_controller_android.cc b/content/browser/android/overscroll_controller_android.cc
index 4548cf33ce20fba36a0dd46aecc0d50726730678..02e2c01383eb6ac8df2773b62e5b6a614db82343 100644
--- a/content/browser/android/overscroll_controller_android.cc
+++ b/content/browser/android/overscroll_controller_android.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "cc/layers/layer.h"
#include "cc/output/compositor_frame_metadata.h"
+#include "content/browser/android/content_view_core_impl.h"
#include "content/browser/android/edge_effect.h"
#include "content/browser/android/edge_effect_l.h"
#include "content/browser/web_contents/web_contents_impl.h"
@@ -17,6 +18,7 @@
#include "content/public/common/content_switches.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/android/resources/resource_manager.h"
+#include "ui/android/window_android.h"
#include "ui/android/window_android_compositor.h"
#include "ui/base/l10n/l10n_util_android.h"
@@ -26,10 +28,6 @@ namespace {
// Used for conditional creation of EdgeEffect types for the overscroll glow.
const int kAndroidLSDKVersion = 21;
-// Default offset in dips from the top of the view beyond which the refresh
-// action will be activated.
-const int kDefaultRefreshDragTargetDips = 64;
-
// If the glow effect alpha is greater than this value, the refresh effect will
// be suppressed. This value was experimentally determined to provide a
// reasonable balance between avoiding accidental refresh activation and
@@ -79,37 +77,26 @@ scoped_ptr<OverscrollGlow> CreateGlowEffect(OverscrollGlowClient* client,
}
scoped_ptr<OverscrollRefresh> CreateRefreshEffect(
- ui::WindowAndroidCompositor* compositor,
- OverscrollRefreshClient* client,
- float dpi_scale) {
+ OverscrollRefreshHandler* handler) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisablePullToRefreshEffect)) {
return nullptr;
}
- return make_scoped_ptr(new OverscrollRefresh(
- &compositor->GetResourceManager(), client,
- kDefaultRefreshDragTargetDips * dpi_scale, l10n_util::IsLayoutRtl()));
+ return make_scoped_ptr(new OverscrollRefresh(handler));
}
} // namespace
OverscrollControllerAndroid::OverscrollControllerAndroid(
- WebContents* web_contents,
- ui::WindowAndroidCompositor* compositor,
- float dpi_scale)
- : compositor_(compositor),
- dpi_scale_(dpi_scale),
+ ContentViewCoreImpl* content_view_core)
+ : compositor_(content_view_core->GetWindowAndroid()->GetCompositor()),
+ dpi_scale_(content_view_core->GetDpiScale()),
enabled_(true),
- glow_effect_(CreateGlowEffect(this, dpi_scale)),
- refresh_effect_(CreateRefreshEffect(compositor, this, dpi_scale)),
- triggered_refresh_active_(false),
- is_fullscreen_(static_cast<WebContentsImpl*>(web_contents)
- ->IsFullscreenForCurrentTab()) {
- DCHECK(web_contents);
- DCHECK(compositor);
- if (refresh_effect_)
- Observe(web_contents);
+ glow_effect_(CreateGlowEffect(this, dpi_scale_)),
+ refresh_effect_(CreateRefreshEffect(content_view_core)),
+ is_fullscreen_(false) {
+ DCHECK(compositor_);
}
OverscrollControllerAndroid::~OverscrollControllerAndroid() {
@@ -134,7 +121,6 @@ bool OverscrollControllerAndroid::WillHandleGestureEvent(
}
bool handled = false;
- bool maybe_needs_animate = false;
switch (event.type) {
case blink::WebInputEvent::GestureScrollBegin:
refresh_effect_->OnScrollBegin();
@@ -144,21 +130,19 @@ bool OverscrollControllerAndroid::WillHandleGestureEvent(
gfx::Vector2dF scroll_delta(event.data.scrollUpdate.deltaX,
event.data.scrollUpdate.deltaY);
scroll_delta.Scale(dpi_scale_);
- maybe_needs_animate = true;
handled = refresh_effect_->WillHandleScrollUpdate(scroll_delta);
} break;
case blink::WebInputEvent::GestureScrollEnd:
refresh_effect_->OnScrollEnd(gfx::Vector2dF());
- maybe_needs_animate = true;
break;
case blink::WebInputEvent::GestureFlingStart: {
- gfx::Vector2dF scroll_velocity(event.data.flingStart.velocityX,
- event.data.flingStart.velocityY);
- scroll_velocity.Scale(dpi_scale_);
- refresh_effect_->OnScrollEnd(scroll_velocity);
if (refresh_effect_->IsActive()) {
+ gfx::Vector2dF scroll_velocity(event.data.flingStart.velocityX,
+ event.data.flingStart.velocityY);
+ scroll_velocity.Scale(dpi_scale_);
+ refresh_effect_->OnScrollEnd(scroll_velocity);
// TODO(jdduke): Figure out a cleaner way of suppressing a fling.
// It's important that the any downstream code sees a scroll-ending
// event (in this case GestureFlingStart) if it has seen a scroll begin.
@@ -171,7 +155,6 @@ bool OverscrollControllerAndroid::WillHandleGestureEvent(
modified_event.data.flingStart.velocityX = .01f;
modified_event.data.flingStart.velocityY = .01f;
}
- maybe_needs_animate = true;
} break;
case blink::WebInputEvent::GesturePinchBegin:
@@ -182,9 +165,6 @@ bool OverscrollControllerAndroid::WillHandleGestureEvent(
break;
}
- if (maybe_needs_animate && refresh_effect_->IsActive())
- SetNeedsAnimate();
-
return handled;
}
@@ -242,12 +222,7 @@ bool OverscrollControllerAndroid::Animate(base::TimeTicks current_time,
if (!enabled_)
return false;
- bool needs_animate = false;
- if (refresh_effect_)
- needs_animate |= refresh_effect_->Animate(current_time, parent_layer);
- if (glow_effect_)
- needs_animate |= glow_effect_->Animate(current_time, parent_layer);
- return needs_animate;
+ return glow_effect_->Animate(current_time, parent_layer);
}
void OverscrollControllerAndroid::OnFrameMetadataUpdated(
@@ -265,13 +240,13 @@ void OverscrollControllerAndroid::OnFrameMetadataUpdated(
gfx::ScaleVector2d(frame_metadata.root_scroll_offset, scale_factor);
if (refresh_effect_) {
- refresh_effect_->UpdateDisplay(viewport_size, content_scroll_offset,
- frame_metadata.root_overflow_y_hidden);
+ refresh_effect_->OnFrameUpdated(content_scroll_offset,
+ frame_metadata.root_overflow_y_hidden);
}
if (glow_effect_) {
- glow_effect_->UpdateDisplay(viewport_size, content_size,
- content_scroll_offset);
+ glow_effect_->OnFrameUpdated(viewport_size, content_size,
+ content_scroll_offset);
}
}
@@ -291,15 +266,6 @@ void OverscrollControllerAndroid::Disable() {
}
}
-void OverscrollControllerAndroid::DidNavigateMainFrame(
- const LoadCommittedDetails& details,
- const FrameNavigateParams& params) {
- // Once the main frame has navigated, there's little need to further animate
- // the reload effect. Note that the effect will naturally time out should the
- // reload be interruped for any reason.
- triggered_refresh_active_ = false;
-}
-
void OverscrollControllerAndroid::DidToggleFullscreenModeForTab(
bool entered_fullscreen) {
if (is_fullscreen_ == entered_fullscreen)
@@ -309,20 +275,6 @@ void OverscrollControllerAndroid::DidToggleFullscreenModeForTab(
refresh_effect_->ReleaseWithoutActivation();
}
-void OverscrollControllerAndroid::TriggerRefresh() {
- triggered_refresh_active_ = false;
- if (!web_contents())
- return;
-
- triggered_refresh_active_ = true;
- RecordAction(base::UserMetricsAction("MobilePullGestureReload"));
- web_contents()->GetController().Reload(true);
-}
-
-bool OverscrollControllerAndroid::IsStillRefreshing() const {
- return triggered_refresh_active_;
-}
-
scoped_ptr<EdgeEffectBase> OverscrollControllerAndroid::CreateEdgeEffect() {
return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_);
}
« no previous file with comments | « content/browser/android/overscroll_controller_android.h ('k') | content/browser/android/overscroll_glow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698