| 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 // Controls 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   void AnimateToState(InkDropState state); | 
|  | 54 | 
|  | 55   // Set the size of the ink drop. | 
|  | 56   void SetSize(const gfx::Size& size); | 
|  | 57 | 
|  | 58   gfx::Rect bounds() const { return bounds_; } | 
|  | 59 | 
|  | 60   // Sets the bounds for the ink drop. |bounds| are in the coordinate space of | 
|  | 61   // the parent ui::Layer that the ink drop layer is added to. | 
|  | 62   void SetBounds(const gfx::Rect& bounds); | 
| 32 | 63 | 
| 33  private: | 64  private: | 
| 34   // Starts the animation of a touch event. | 65   // Starts the animation of a touch event. | 
| 35   void AnimateTapDown(); | 66   void AnimateTapDown(); | 
| 36 | 67 | 
| 37   // Schedules the hide animation of |ink_drop_layer_| for once its current | 68   // 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 | 69   // animation has completed. If |ink_drop_layer_| is not animating, the hide | 
| 39   // animation begins immediately. | 70   // animation begins immediately. | 
| 40   void AnimateHide(); | 71   void AnimateHide(); | 
| 41 | 72 | 
| 42   // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| | 73   // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| | 
| 43   // until the long press has completed. | 74   // until the long press has completed. | 
| 44   void AnimateLongPress(); | 75   void AnimateLongPress(); | 
| 45 | 76 | 
| 46   // Starts the showing animation on |layer|, with a |duration| in milliseconds. | 77   // Starts the showing animation on |layer|, with a |duration| in milliseconds. | 
| 47   void AnimateShow(ui::Layer* layer, | 78   void AnimateShow(ui::Layer* layer, | 
| 48                    AppearAnimationObserver* observer, | 79                    AppearAnimationObserver* observer, | 
| 49                    bool circle, |  | 
| 50                    base::TimeDelta duration); | 80                    base::TimeDelta duration); | 
| 51 | 81 | 
| 52   // Sets the bounds for |layer|. | 82   // Sets the bounds for |layer|. | 
| 53   void SetLayerBounds(ui::Layer* layer, bool circle, int width, int height); | 83   void SetLayerBounds(ui::Layer* layer); | 
| 54 | 84 | 
| 55   // Initializes |layer| and attaches it to |parent|. | 85   // Initializes |layer|'s properties. | 
| 56   void SetupAnimationLayer(ui::Layer* parent, | 86   void SetupAnimationLayer(ui::Layer* layer, InkDropDelegate* delegate); | 
| 57                            ui::Layer* layer, |  | 
| 58                            InkDropDelegate* delegate); |  | 
| 59 | 87 | 
| 60   // ui::EventHandler: | 88   InkDropHost* ink_drop_host_; | 
| 61   void OnGestureEvent(ui::GestureEvent* event) override; |  | 
| 62 | 89 | 
| 63   // The layer for animating a user touch. Added as a child to |view_|'s layer. | 90   // Owns the ink drop layer tree. | 
| 64   // It will be stacked underneath. | 91   ui::LayerTreeOwner layer_tree_; | 
| 65   scoped_ptr<ui::Layer> ink_drop_layer_; | 92 | 
|  | 93   // The layer for animating a user touch. It will be stacked behind | 
|  | 94   // |long_press_layer_| in the |layer_tree_|. | 
|  | 95   ui::Layer* ink_drop_layer_; | 
| 66 | 96 | 
| 67   // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. | 97   // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. | 
| 68   scoped_ptr<InkDropDelegate> ink_drop_delegate_; | 98   scoped_ptr<InkDropDelegate> ink_drop_delegate_; | 
| 69 | 99 | 
| 70   // ui::ImplicitAnimationObserver which observes |ink_drop_layer_| and can be | 100   // ui::ImplicitAnimationObserver which observes |ink_drop_layer_| and can be | 
| 71   // used to automatically trigger a hide animation upon completion. | 101   // used to automatically trigger a hide animation upon completion. | 
| 72   scoped_ptr<AppearAnimationObserver> appear_animation_observer_; | 102   scoped_ptr<AppearAnimationObserver> appear_animation_observer_; | 
| 73 | 103 | 
| 74   // The layer for animating a long press. Added as a child to |view_|'s layer. | 104   // The layer for animating a long press. It will be stacked in front of the | 
| 75   // It will be stacked underneath. | 105   // |ink_drop_layer_| in the |layer_tree_|. | 
| 76   scoped_ptr<ui::Layer> long_press_layer_; | 106   ui::Layer* long_press_layer_; | 
| 77 | 107 | 
| 78   // ui::LayerDelegate responsible for painting to |long_press_layer_|. | 108   // ui::LayerDelegate responsible for painting to |long_press_layer_|. | 
| 79   scoped_ptr<InkDropDelegate> long_press_delegate_; | 109   scoped_ptr<InkDropDelegate> long_press_delegate_; | 
| 80 | 110 | 
| 81   // ui::ImplicitAnimationObserver which observers |long_press_layer_| and can | 111   // ui::ImplicitAnimationObserver which observers |long_press_layer_| and can | 
| 82   // be used to automatically trigger a hide animation upon completion. | 112   // be used to automatically trigger a hide animation upon completion. | 
| 83   scoped_ptr<AppearAnimationObserver> long_press_animation_observer_; | 113   scoped_ptr<AppearAnimationObserver> long_press_animation_observer_; | 
| 84 | 114 | 
| 85   // The View for which InkDropAnimationController is a PreTargetHandler. | 115   // The bounds of the ink drop layers. Defined in the coordinate space of the | 
| 86   View* view_; | 116   // parent ui::Layer that the ink drop layers were added to. | 
|  | 117   gfx::Rect bounds_; | 
| 87 | 118 | 
| 88   DISALLOW_COPY_AND_ASSIGN(InkDropAnimationController); | 119   DISALLOW_COPY_AND_ASSIGN(InkDropAnimationController); | 
| 89 }; | 120 }; | 
| 90 | 121 | 
| 91 }  // namespace views | 122 }  // namespace views | 
| 92 | 123 | 
| 93 #endif  // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 124 #endif  // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 
| OLD | NEW | 
|---|