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

Unified Diff: cc/trees/layer_tree_host_impl.cc

Issue 361143002: Impl thread smooth scrolling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better way to detect animation finished. Created 6 years, 5 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 | « cc/trees/layer_tree_host_impl.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_impl.cc
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index caa380ec8623f26c387539b3067298a87da5a698..69b08f68482c2c20afefde5382e9578c8c8e7ef0 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -13,6 +13,8 @@
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
+#include "cc/animation/animation_id_provider.h"
+#include "cc/animation/scroll_offset_animation_curve.h"
#include "cc/animation/scrollbar_animation_controller.h"
#include "cc/animation/timing_function.h"
#include "cc/base/latency_info_swap_promise_monitor.h"
@@ -2262,6 +2264,57 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
return ScrollIgnored;
}
+InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated(
+ const gfx::Point& viewport_point,
+ const gfx::Vector2dF& scroll_delta) {
+ if (CurrentlyScrollingLayer()) {
+ // TODO(skobes): Update the target of the existing animation.
+ return ScrollIgnored;
+ }
+ InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel);
+ if (scroll_status == ScrollStarted) {
+ for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl;
+ layer_impl = layer_impl->parent()) {
+ if (!layer_impl->scrollable())
+ continue;
+
+ gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset();
+ gfx::Vector2dF target_offset = current_offset + scroll_delta;
+ target_offset.SetToMax(gfx::Vector2dF());
+ target_offset.SetToMin(layer_impl->MaxScrollOffset());
+ gfx::Vector2dF actual_delta = target_offset - current_offset;
+
+ const float kEpsilon = 0.1f;
+ bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon ||
+ std::abs(actual_delta.y()) > kEpsilon);
ajuma 2014/07/08 14:44:49 If actual_delta is less than kEpsilon but non-zero
skobes 2014/07/08 17:49:12 I based this on the logic in ScrollBy, I think the
ajuma 2014/07/08 18:45:32 It looks like ScrollBy actually performs the scrol
skobes 2014/07/08 21:21:58 Fair point, done.
+
+ if (!can_layer_scroll)
+ continue;
+
+ active_tree_->SetCurrentlyScrollingLayer(layer_impl);
+
+ scoped_ptr<ScrollOffsetAnimationCurve> curve =
+ ScrollOffsetAnimationCurve::Create(target_offset,
+ EaseInOutTimingFunction::Create());
+ curve->SetInitialValue(current_offset);
+
+ scoped_ptr<Animation> animation =
+ Animation::Create(curve->Clone().Pass(),
+ AnimationIdProvider::NextAnimationId(),
+ AnimationIdProvider::NextGroupId(),
+ Animation::ScrollOffset);
+ animation->set_is_impl_only(true);
+
+ layer_impl->layer_animation_controller()->AddAnimation(animation.Pass());
+
+ SetNeedsAnimate();
+ return ScrollStarted;
+ }
+ }
+ ScrollEnd();
+ return scroll_status;
+}
+
gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta(
LayerImpl* layer_impl,
float scale_from_viewport_to_screen_space,
@@ -2886,6 +2939,10 @@ void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) {
(*iter).second->UpdateState(start_ready_animations, events.get());
if (!events->empty()) {
+ if (std::find_if(events->begin(),
+ events->end(),
+ IsScrollOffsetAnimationFinished()) != events->end())
+ ScrollEnd();
ajuma 2014/07/08 14:44:49 I think a better approach would be to modify Layer
skobes 2014/07/08 17:49:12 Done.
client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass());
}
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698