Simplify the mapping between scroll layer and scrollbars.

1) I removed all scrollbar-related state and code from LayerImpl and put
it into LTI/LTHI instead.  LTHI now owns the
ScrollbarAnimationControllers instead of holding short-lived references
to them.  In LTI::DidUpdateScrollState, I made explicit the mechanism of
clip-layer (or inner-scroll-layer) notifications being associated with
the primary scroll layer before getting reforwarded to the scrollbars
(this has always been the case, but used to be implied in a fairly
subtle way).

2) I deleted the scrollbar registration logic in tree_synchronizer.cc and
SetScrollAndClipLayerById.  This all existed purely to handle the
special case of the root viewport layers, and I replaced it with a few
lines of explicit special case logic (which became straightforward to
write after the code was moved to LTI).  This makes the scrollbar
layer's pointer to the clip layer unneeded for anything, so I also
deleted that.

3) To eliminate the clumsy argument passing of "bool on_resize" (which
is there to make scrollbar fades longer during page load), I compute the
value at the last minute by checking whether state changed on the
scrollbar layer.  This required reformulating scrollbar state from
"maximum+visible ratio" to "scroll layer length+clip layer length".

NOTRY=true
BUG=476553
TEST=LayerTreeHostImplTest.ScrollbarRegistration
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1353883005

Cr-Commit-Position: refs/heads/master@{#352984}
diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h
index f2d5dfaa..ed724b3 100644
--- a/cc/trees/layer_tree_host_impl.h
+++ b/cc/trees/layer_tree_host_impl.h
@@ -298,6 +298,11 @@
 
   size_t SourceAnimationFrameNumberForTesting() const;
 
+  void RegisterScrollbarAnimationController(int scroll_layer_id);
+  void UnregisterScrollbarAnimationController(int scroll_layer_id);
+  ScrollbarAnimationController* ScrollbarAnimationControllerForId(
+      int scroll_layer_id) const;
+
   DrawMode GetDrawMode() const;
 
   // Viewport size in draw space: this size is in physical pixels and is used
@@ -323,13 +328,11 @@
   void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override;
 
   // ScrollbarAnimationControllerClient implementation.
-  void StartAnimatingScrollbarAnimationController(
-      ScrollbarAnimationController* controller) override;
-  void StopAnimatingScrollbarAnimationController(
-      ScrollbarAnimationController* controller) override;
   void PostDelayedScrollbarAnimationTask(const base::Closure& task,
                                          base::TimeDelta delay) override;
+  void SetNeedsAnimateForScrollbarAnimation() override;
   void SetNeedsRedrawForScrollbarAnimation() override;
+  ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override;
 
   // VideoBeginFrameSource implementation.
   void AddVideoFrameController(VideoFrameController* controller) override;
@@ -652,8 +655,7 @@
 
   void ClearCurrentlyScrollingLayer();
 
-  bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
-                                const gfx::PointF& device_viewport_point);
+  void HandleMouseOverScrollbar(LayerImpl* layer_impl);
 
   LayerImpl* FindScrollLayerForDeviceViewportPoint(
       const gfx::PointF& device_viewport_point,
@@ -783,9 +785,13 @@
 
   scoped_ptr<AnimationRegistrar> animation_registrar_;
   scoped_ptr<AnimationHost> animation_host_;
-  std::set<ScrollbarAnimationController*> scrollbar_animation_controllers_;
   std::set<VideoFrameController*> video_frame_controllers_;
 
+  // Map from scroll layer ID to scrollbar animation controller.
+  // There is one animation controller per pair of overlay scrollbars.
+  base::ScopedPtrHashMap<int, scoped_ptr<ScrollbarAnimationController>>
+      scrollbar_animation_controllers_;
+
   RenderingStatsInstrumentation* rendering_stats_instrumentation_;
   MicroBenchmarkControllerImpl micro_benchmark_controller_;
   scoped_ptr<TaskGraphRunner> single_thread_synchronous_task_graph_runner_;