Home | History | Annotate | Download | only in input
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CC_INPUT_TOP_CONTROLS_MANAGER_H_
      6 #define CC_INPUT_TOP_CONTROLS_MANAGER_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/memory/weak_ptr.h"
     10 #include "cc/input/top_controls_state.h"
     11 #include "cc/layers/layer_impl.h"
     12 #include "ui/gfx/size.h"
     13 #include "ui/gfx/vector2d_f.h"
     14 
     15 namespace base {
     16 class TimeTicks;
     17 }
     18 
     19 namespace cc {
     20 
     21 class KeyframedFloatAnimationCurve;
     22 class LayerTreeImpl;
     23 class TopControlsManagerClient;
     24 
     25 // Manages the position of the top controls.
     26 class CC_EXPORT TopControlsManager
     27     : public base::SupportsWeakPtr<TopControlsManager> {
     28  public:
     29   enum AnimationDirection {
     30     NO_ANIMATION,
     31     SHOWING_CONTROLS,
     32     HIDING_CONTROLS
     33   };
     34 
     35   static scoped_ptr<TopControlsManager> Create(
     36       TopControlsManagerClient* client,
     37       float top_controls_height,
     38       float top_controls_show_threshold,
     39       float top_controls_hide_threshold);
     40   virtual ~TopControlsManager();
     41 
     42   float controls_top_offset() { return controls_top_offset_; }
     43   float content_top_offset() {
     44     return controls_top_offset_ + top_controls_height_;
     45   }
     46   KeyframedFloatAnimationCurve* animation() {
     47     return top_controls_animation_.get();
     48   }
     49   AnimationDirection animation_direction() { return animation_direction_; }
     50 
     51   void UpdateTopControlsState(TopControlsState constraints,
     52                               TopControlsState current,
     53                               bool animate);
     54 
     55   void ScrollBegin();
     56   gfx::Vector2dF ScrollBy(const gfx::Vector2dF pending_delta);
     57   void ScrollEnd();
     58 
     59   gfx::Vector2dF Animate(base::TimeTicks monotonic_time);
     60 
     61  protected:
     62   TopControlsManager(TopControlsManagerClient* client,
     63                      float top_controls_height,
     64                      float top_controls_show_threshold,
     65                      float top_controls_hide_threshold);
     66 
     67  private:
     68   void SetControlsTopOffset(float offset);
     69   void ResetAnimations();
     70   void SetupAnimation(AnimationDirection direction);
     71   void StartAnimationIfNecessary();
     72   bool IsAnimationCompleteAtTime(base::TimeTicks time);
     73 
     74   TopControlsManagerClient* client_;  // The client manages the lifecycle of
     75                                       // this.
     76 
     77   scoped_ptr<KeyframedFloatAnimationCurve> top_controls_animation_;
     78   AnimationDirection animation_direction_;
     79   TopControlsState permitted_state_;
     80   float controls_top_offset_;
     81   float top_controls_height_;
     82 
     83   float current_scroll_delta_;
     84   float controls_scroll_begin_offset_;
     85 
     86   // The height of the visible top control such that it must be shown when
     87   // the user stops the scroll.
     88   float top_controls_show_height_;
     89 
     90   // The height of the visible top control such that it must be hidden when
     91   // the user stops the scroll.
     92   float top_controls_hide_height_;
     93 
     94   DISALLOW_COPY_AND_ASSIGN(TopControlsManager);
     95 };
     96 
     97 }  // namespace cc
     98 
     99 #endif  // CC_INPUT_TOP_CONTROLS_MANAGER_H_
    100