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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_
6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "ui/events/event_handler.h"
11 #include "ui/views/views_export.h"
18 class AppearAnimationObserver
;
19 class InkDropDelegate
;
22 // Controls an animation which can be associated to a ui::Layer backed View.
23 // It sets itself as the pre-target handler for the supplied view, providing
24 // animations for user interactions. The events will not be consumed.
26 // The supplied views::View will be forced to have a layer, and this controller
27 // will add child layers to that.
28 class VIEWS_EXPORT InkDropAnimationController
: public ui::EventHandler
{
30 explicit InkDropAnimationController(View
* view
);
31 ~InkDropAnimationController() override
;
34 // Starts the animation of a touch event.
35 void AnimateTapDown();
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.
42 // Starts the animation of a long press, and cancels hiding |ink_drop_layer_|
43 // until the long press has completed.
44 void AnimateLongPress();
46 // Starts the showing animation on |layer|, with a |duration| in milliseconds.
47 void AnimateShow(ui::Layer
* layer
,
48 AppearAnimationObserver
* observer
,
50 base::TimeDelta duration
);
52 // Sets the bounds for |layer|.
53 void SetLayerBounds(ui::Layer
* layer
, bool circle
, int width
, int height
);
55 // Initializes |layer| and attaches it to |parent|.
56 void SetupAnimationLayer(ui::Layer
* parent
,
58 InkDropDelegate
* delegate
);
61 void OnGestureEvent(ui::GestureEvent
* event
) override
;
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_
;
67 // ui::LayerDelegate responsible for painting to |ink_drop_layer_|.
68 scoped_ptr
<InkDropDelegate
> ink_drop_delegate_
;
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_
;
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_
;
78 // ui::LayerDelegate responsible for painting to |long_press_layer_|.
79 scoped_ptr
<InkDropDelegate
> long_press_delegate_
;
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_
;
85 // The View for which InkDropAnimationController is a PreTargetHandler.
88 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationController
);
93 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_