| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 
| 7 | 7 | 
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" | 
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" | 
|  | 10 #include "ui/compositor/layer_tree_owner.h" | 
| 10 #include "ui/events/event_handler.h" | 11 #include "ui/events/event_handler.h" | 
|  | 12 #include "ui/gfx/geometry/rect.h" | 
|  | 13 #include "ui/gfx/geometry/size.h" | 
| 11 #include "ui/views/views_export.h" | 14 #include "ui/views/views_export.h" | 
| 12 | 15 | 
| 13 namespace ui { | 16 namespace ui { | 
| 14 class Layer; | 17 class Layer; | 
| 15 } | 18 } | 
| 16 | 19 | 
| 17 namespace views { | 20 namespace views { | 
| 18 class AppearAnimationObserver; | 21 class AppearAnimationObserver; | 
| 19 class InkDropDelegate; | 22 class InkDropDelegate; | 
|  | 23 class InkDropHost; | 
| 20 class View; | 24 class View; | 
| 21 | 25 | 
| 22 // Controls an animation which can be associated to a ui::Layer backed View. | 26 // The different states that the ink drop animation can be animated to. | 
| 23 // It sets itself as the pre-target handler for the supplied view, providing | 27 enum class InkDropState { | 
| 24 // animations for user interactions. The events will not be consumed. | 28   // The ink drop is not visible. | 
| 25 // | 29   HIDDEN, | 
| 26 // The supplied views::View will be forced to have a layer, and this controller | 30   // The view is being interacted with but the action to be triggered has not | 
| 27 // will add child layers to that. | 31   // yet been determined. | 
| 28 class VIEWS_EXPORT InkDropAnimationController : public ui::EventHandler { | 32   ACTION_PENDING, | 
|  | 33   // The quick action for the view has been triggered. e.g. A tap gesture to | 
|  | 34   // click a button. | 
|  | 35   QUICK_ACTION, | 
|  | 36   // The slow action for the view has been triggered. e.g. A long press to bring | 
|  | 37   // up a menu. | 
|  | 38   SLOW_ACTION, | 
|  | 39   // An active state for a view that is no longer being interacted with. e.g. A | 
|  | 40   // pressed button that is showing a menu. | 
|  | 41   ACTIVATED | 
|  | 42 }; | 
|  | 43 | 
|  | 44 // Base class for an ink drop animation which is hosted by an InkDropHost. | 
|  | 45 class VIEWS_EXPORT InkDropAnimationController { | 
| 29  public: | 46  public: | 
| 30   explicit InkDropAnimationController(View* view); | 47   // Constructs an ink drop controller that will attach the ink drop to the | 
| 31   ~InkDropAnimationController() override; | 48   // given |ink_drop_host|. | 
|  | 49   explicit InkDropAnimationController(InkDropHost* ink_drop_host) {} | 
|  | 50   virtual ~InkDropAnimationController() {} | 
|  | 51 | 
|  | 52   // Animates from the current InkDropState to |state|. | 
|  | 53   virtual void AnimateToState(InkDropState state) = 0; | 
|  | 54 | 
|  | 55   // Set the size of the ink drop. | 
|  | 56   virtual void SetInkDropSize(const gfx::Size& size) = 0; | 
|  | 57 | 
|  | 58   // Returns the ink drop bounds. | 
|  | 59   virtual gfx::Rect GetInkDropBounds() const = 0; | 
|  | 60 | 
|  | 61   // Sets the bounds for the ink drop. |bounds| are in the coordinate space of | 
|  | 62   // the parent ui::Layer that the ink drop layer is added to. | 
|  | 63   virtual void SetInkDropBounds(const gfx::Rect& bounds) = 0; | 
| 32 | 64 | 
| 33  private: | 65  private: | 
| 34   // Starts the animation of a touch event. |  | 
| 35   void AnimateTapDown(); |  | 
| 36 |  | 
| 37   // Schedules the hide animation of |ink_drop_layer_| for once its current |  | 
| 38   // animation has completed. If |ink_drop_layer_| is not animating, the hide |  | 
| 39   // animation begins immediately. |  | 
| 40   void AnimateHide(); |  | 
| 41 |  | 
| 42   // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| |  | 
| 43   // until the long press has completed. |  | 
| 44   void AnimateLongPress(); |  | 
| 45 |  | 
| 46   // Starts the showing animation on |layer|, with a |duration| in milliseconds. |  | 
| 47   void AnimateShow(ui::Layer* layer, |  | 
| 48                    AppearAnimationObserver* observer, |  | 
| 49                    bool circle, |  | 
| 50                    base::TimeDelta duration); |  | 
| 51 |  | 
| 52   // Sets the bounds for |layer|. |  | 
| 53   void SetLayerBounds(ui::Layer* layer, bool circle, int width, int height); |  | 
| 54 |  | 
| 55   // Initializes |layer| and attaches it to |parent|. |  | 
| 56   void SetupAnimationLayer(ui::Layer* parent, |  | 
| 57                            ui::Layer* layer, |  | 
| 58                            InkDropDelegate* delegate); |  | 
| 59 |  | 
| 60   // ui::EventHandler: |  | 
| 61   void OnGestureEvent(ui::GestureEvent* event) override; |  | 
| 62 |  | 
| 63   // The layer for animating a user touch. Added as a child to |view_|'s layer. |  | 
| 64   // It will be stacked underneath. |  | 
| 65   scoped_ptr<ui::Layer> ink_drop_layer_; |  | 
| 66 |  | 
| 67   // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. |  | 
| 68   scoped_ptr<InkDropDelegate> ink_drop_delegate_; |  | 
| 69 |  | 
| 70   // ui::ImplicitAnimationObserver which observes |ink_drop_layer_| and can be |  | 
| 71   // used to automatically trigger a hide animation upon completion. |  | 
| 72   scoped_ptr<AppearAnimationObserver> appear_animation_observer_; |  | 
| 73 |  | 
| 74   // The layer for animating a long press. Added as a child to |view_|'s layer. |  | 
| 75   // It will be stacked underneath. |  | 
| 76   scoped_ptr<ui::Layer> long_press_layer_; |  | 
| 77 |  | 
| 78   // ui::LayerDelegate responsible for painting to |long_press_layer_|. |  | 
| 79   scoped_ptr<InkDropDelegate> long_press_delegate_; |  | 
| 80 |  | 
| 81   // ui::ImplicitAnimationObserver which observers |long_press_layer_| and can |  | 
| 82   // be used to automatically trigger a hide animation upon completion. |  | 
| 83   scoped_ptr<AppearAnimationObserver> long_press_animation_observer_; |  | 
| 84 |  | 
| 85   // The View for which InkDropAnimationController is a PreTargetHandler. |  | 
| 86   View* view_; |  | 
| 87 |  | 
| 88   DISALLOW_COPY_AND_ASSIGN(InkDropAnimationController); | 66   DISALLOW_COPY_AND_ASSIGN(InkDropAnimationController); | 
| 89 }; | 67 }; | 
| 90 | 68 | 
| 91 }  // namespace views | 69 }  // namespace views | 
| 92 | 70 | 
| 93 #endif  // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 71 #endif  // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 
| OLD | NEW | 
|---|