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

Unified Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 14268004: Add overscroll edge effect animations for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and layer attachment fixes Created 7 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/renderer_host/render_widget_host_view_android.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_widget_host_view_android.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index e247e3b7b9dcda1813adbbe7c0c1a4f9d9cc33a5..10266d13b1dfaae16be29aeb54535602af349c94 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -7,6 +7,7 @@
#include <android/bitmap.h>
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
@@ -15,6 +16,7 @@
#include "cc/output/compositor_frame.h"
#include "cc/output/compositor_frame_ack.h"
#include "content/browser/android/content_view_core_impl.h"
+#include "content/browser/android/overscroll_glow.h"
#include "content/browser/gpu/gpu_surface_tracker.h"
#include "content/browser/renderer_host/compositor_impl_android.h"
#include "content/browser/renderer_host/image_transport_factory_android.h"
@@ -23,6 +25,7 @@
#include "content/common/gpu/client/gl_helper.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/view_messages.h"
+#include "content/public/common/content_switches.h"
#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureLayer.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
@@ -39,6 +42,8 @@ namespace content {
namespace {
+static const int kDesiredAnimationIntervalInMs = 16;
+
void InsertSyncPointAndAckForGpu(
int gpu_host_id, int route_id, const std::string& return_mailbox) {
uint32 sync_point =
@@ -73,7 +78,7 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
RenderWidgetHostImpl* widget_host,
ContentViewCoreImpl* content_view_core)
: host_(widget_host),
- is_layer_attached_(true),
+ are_layers_attached_(true),
content_view_core_(NULL),
ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
cached_background_color_(SK_ColorWHITE),
@@ -89,6 +94,11 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
layer_->SetContentsOpaque(true);
layer_->SetIsDrawable(true);
+ if (CommandLine::ForCurrentProcess()->
+ HasSwitch(switches::kEnableOverscrollEdgeEffect)) {
+ overscroll_effect_ = OverscrollGlow::Create();
+ }
+
host_->SetView(this);
SetContentViewCore(content_view_core);
}
@@ -289,28 +299,26 @@ bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
}
void RenderWidgetHostViewAndroid::Show() {
- if (is_layer_attached_)
+ if (are_layers_attached_)
return;
- is_layer_attached_ = true;
- if (content_view_core_)
- content_view_core_->AttachLayer(layer_);
+ are_layers_attached_ = true;
+ AttachLayers();
}
void RenderWidgetHostViewAndroid::Hide() {
- if (!is_layer_attached_)
+ if (!are_layers_attached_)
return;
- is_layer_attached_ = false;
- if (content_view_core_)
- content_view_core_->RemoveLayer(layer_);
+ are_layers_attached_ = false;
+ RemoveLayers();
}
bool RenderWidgetHostViewAndroid::IsShowing() {
// ContentViewCoreImpl represents the native side of the Java
// ContentViewCore. It being NULL means that it is not attached
// to the View system yet, so we treat this RWHVA as hidden.
- return is_layer_attached_ && content_view_core_;
+ return are_layers_attached_ && content_view_core_;
}
gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
@@ -413,10 +421,10 @@ void RenderWidgetHostViewAndroid::RenderViewGone(
}
void RenderWidgetHostViewAndroid::Destroy() {
- if (content_view_core_) {
- content_view_core_->RemoveLayer(layer_);
- content_view_core_ = NULL;
- }
+ RemoveLayers();
+ content_view_core_ = NULL;
+
+ overscroll_effect_.reset();
// The RenderWidgetHost's destruction led here, so don't call it.
host_ = NULL;
@@ -547,6 +555,17 @@ void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
content_size,
callback);
+ if (overscroll_effect_) {
+ // Disable left/right edge effects when fully zoomed out.
+ const cc::CompositorFrameMetadata& metadata = frame->metadata;
+ bool horizontal_scrolling_possible =
+ metadata.page_scale_factor != metadata.min_page_scale_factor &&
+ metadata.root_layer_size.width() != metadata.viewport_size.width();
+
+ overscroll_effect_->set_horizontal_overscroll_enabled(
+ horizontal_scrolling_possible);
+ overscroll_effect_->set_size(content_size);
+ }
}
void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped(
@@ -618,6 +637,42 @@ void RenderWidgetHostViewAndroid::BuffersSwapped(
ack_callback.Run();
}
+void RenderWidgetHostViewAndroid::AttachLayers() {
+ if (!content_view_core_)
+ return;
+
+ content_view_core_->AttachLayer(layer_);
+
+ if (overscroll_effect_)
+ overscroll_effect_->set_parent_layer(content_view_core_->GetLayer());
+}
+
+void RenderWidgetHostViewAndroid::RemoveLayers() {
+ if (!content_view_core_)
+ return;
+
+ if (overscroll_effect_)
+ overscroll_effect_->set_parent_layer(NULL);
+
+ content_view_core_->RemoveLayer(layer_);
+}
+
+void RenderWidgetHostViewAndroid::AnimationCallback() {
+ if (overscroll_effect_ && overscroll_effect_->Animate(base::TimeTicks::Now()))
+ ScheduleAnimation();
+}
+
+void RenderWidgetHostViewAndroid::ScheduleAnimation() {
+ if (animation_timer_.IsRunning() || !overscroll_effect_)
+ return;
+
+ const base::TimeDelta animationInterval
+ = base::TimeDelta::FromMilliseconds(kDesiredAnimationIntervalInMs);
+
+ animation_timer_.Start(FROM_HERE, animationInterval, this,
mkosiba (inactive) 2013/04/22 16:24:53 I'm not familiar with how animations work, so I ap
jdduke (slow) 2013/04/22 17:18:16 It's not synchronized :) The timer hack was really
+ &RenderWidgetHostViewAndroid::AnimationCallback);
+}
+
void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer(
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
int gpu_host_id) {
@@ -755,14 +810,25 @@ SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
return cached_background_color_;
}
+void RenderWidgetHostViewAndroid::OnOverscrolled(
+ const gfx::Vector2dF& accumulated_overscroll,
+ const gfx::Vector2dF& current_fling_velocity) {
+ if (overscroll_effect_) {
+ overscroll_effect_->OnOverscrolled(base::TimeTicks::Now(),
+ accumulated_overscroll,
+ current_fling_velocity);
+ ScheduleAnimation();
+ }
+}
+
void RenderWidgetHostViewAndroid::SetContentViewCore(
ContentViewCoreImpl* content_view_core) {
- if (content_view_core_ && is_layer_attached_)
- content_view_core_->RemoveLayer(layer_);
+ if (are_layers_attached_)
+ RemoveLayers();
content_view_core_ = content_view_core;
- if (content_view_core_ && is_layer_attached_)
- content_view_core_->AttachLayer(layer_);
+ if (are_layers_attached_)
+ AttachLayers();
}
void RenderWidgetHostViewAndroid::HasTouchEventHandlers(
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698