Chromium Code Reviews| 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_IMPL_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_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_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" | |
| 14 #include "ui/views/animation/ink_drop_animation_controller.h" | |
| 11 #include "ui/views/views_export.h" | 15 #include "ui/views/views_export.h" |
| 12 | 16 |
| 13 namespace ui { | 17 namespace ui { |
| 14 class Layer; | 18 class Layer; |
| 15 } | 19 } |
| 16 | 20 |
| 17 namespace views { | 21 namespace views { |
| 18 class AppearAnimationObserver; | 22 class AppearAnimationObserver; |
| 19 class InkDropDelegate; | 23 class InkDropDelegate; |
| 24 class InkDropHost; | |
| 20 class View; | 25 class View; |
| 21 | 26 |
| 22 // Controls an animation which can be associated to a ui::Layer backed View. | 27 // Controls an ink drop animation which is hosted by an InkDropHost. |
| 23 // It sets itself as the pre-target handler for the supplied view, providing | 28 class VIEWS_EXPORT InkDropAnimationControllerImpl |
| 24 // animations for user interactions. The events will not be consumed. | 29 : public InkDropAnimationController { |
| 25 // | |
| 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 { | |
| 29 public: | 30 public: |
| 30 explicit InkDropAnimationController(View* view); | 31 // Constructs an ink drop controller that will attach the ink drop to the |
| 31 ~InkDropAnimationController() override; | 32 // given |ink_drop_host|. |
| 33 explicit InkDropAnimationControllerImpl(InkDropHost* ink_drop_host); | |
| 34 ~InkDropAnimationControllerImpl() override; | |
| 35 | |
| 36 // InkDropAnimationController: | |
| 37 void AnimateToState(InkDropState state) override; | |
| 38 void SetInkDropSize(const gfx::Size& size) override; | |
| 39 gfx::Rect GetInkDropBounds() const override; | |
| 40 void SetInkDropBounds(const gfx::Rect& bounds) override; | |
| 32 | 41 |
| 33 private: | 42 private: |
| 34 // Starts the animation of a touch event. | 43 // Starts the animation of a touch event. |
| 35 void AnimateTapDown(); | 44 void AnimateTapDown(); |
| 36 | 45 |
| 37 // Schedules the hide animation of |ink_drop_layer_| for once its current | 46 // 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 | 47 // animation has completed. If |ink_drop_layer_| is not animating, the hide |
| 39 // animation begins immediately. | 48 // animation begins immediately. |
| 40 void AnimateHide(); | 49 void AnimateHide(); |
| 41 | 50 |
| 42 // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| | 51 // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| |
| 43 // until the long press has completed. | 52 // until the long press has completed. |
| 44 void AnimateLongPress(); | 53 void AnimateLongPress(); |
| 45 | 54 |
| 46 // Starts the showing animation on |layer|, with a |duration| in milliseconds. | 55 // Starts the showing animation on |layer|, with a |duration| in milliseconds. |
| 47 void AnimateShow(ui::Layer* layer, | 56 void AnimateShow(ui::Layer* layer, |
| 48 AppearAnimationObserver* observer, | 57 AppearAnimationObserver* observer, |
| 49 bool circle, | |
| 50 base::TimeDelta duration); | 58 base::TimeDelta duration); |
| 51 | 59 |
| 52 // Sets the bounds for |layer|. | 60 // Sets the bounds for |layer|. |
| 53 void SetLayerBounds(ui::Layer* layer, bool circle, int width, int height); | 61 void SetLayerBounds(ui::Layer* layer); |
| 54 | 62 |
| 55 // Initializes |layer| and attaches it to |parent|. | 63 // Initializes |layer|'s properties. |
| 56 void SetupAnimationLayer(ui::Layer* parent, | 64 void SetupAnimationLayer(ui::Layer* layer, InkDropDelegate* delegate); |
| 57 ui::Layer* layer, | |
| 58 InkDropDelegate* delegate); | |
| 59 | 65 |
| 60 // ui::EventHandler: | 66 InkDropHost* ink_drop_host_; |
| 61 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 62 | 67 |
| 63 // The layer for animating a user touch. Added as a child to |view_|'s layer. | 68 // Owner of the root layer that parents the animating layers. |
| 64 // It will be stacked underneath. | 69 ui::LayerOwner root_layer_owner_; |
| 65 scoped_ptr<ui::Layer> ink_drop_layer_; | 70 |
| 71 // Owner of the layer used for animating a user touch. | |
| 72 ui::LayerOwner ink_drop_layer_owner_; | |
| 66 | 73 |
| 67 // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. | 74 // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. |
| 68 scoped_ptr<InkDropDelegate> ink_drop_delegate_; | 75 scoped_ptr<InkDropDelegate> ink_drop_delegate_; |
| 69 | 76 |
| 70 // ui::ImplicitAnimationObserver which observes |ink_drop_layer_| and can be | 77 // ui::ImplicitAnimationObserver which observes |ink_drop_layer_| and can be |
| 71 // used to automatically trigger a hide animation upon completion. | 78 // used to automatically trigger a hide animation upon completion. |
| 72 scoped_ptr<AppearAnimationObserver> appear_animation_observer_; | 79 scoped_ptr<AppearAnimationObserver> appear_animation_observer_; |
| 73 | 80 |
| 74 // The layer for animating a long press. Added as a child to |view_|'s layer. | 81 // Owner of the layer used for animating a long press. |
| 75 // It will be stacked underneath. | 82 ui::LayerOwner long_press_layer_owner_; |
|
sadrul
2015/08/18 17:51:49
Is there a reason to not use scoped_ptr<Layer> for
bruthig
2015/08/18 19:04:38
Yes, ScreenRotationAnimator creates a copy of all
sadrul
2015/08/18 19:52:38
That sounds odd (and a buggy behaviour; ScreenRota
bruthig
2015/08/18 20:58:04
Hmm, you are right, I was mistaken. I've changed
| |
| 76 scoped_ptr<ui::Layer> long_press_layer_; | |
| 77 | 83 |
| 78 // ui::LayerDelegate responsible for painting to |long_press_layer_|. | 84 // ui::LayerDelegate responsible for painting to |long_press_layer_|. |
| 79 scoped_ptr<InkDropDelegate> long_press_delegate_; | 85 scoped_ptr<InkDropDelegate> long_press_delegate_; |
| 80 | 86 |
| 81 // ui::ImplicitAnimationObserver which observers |long_press_layer_| and can | 87 // ui::ImplicitAnimationObserver which observers |long_press_layer_| and can |
| 82 // be used to automatically trigger a hide animation upon completion. | 88 // be used to automatically trigger a hide animation upon completion. |
| 83 scoped_ptr<AppearAnimationObserver> long_press_animation_observer_; | 89 scoped_ptr<AppearAnimationObserver> long_press_animation_observer_; |
| 84 | 90 |
| 85 // The View for which InkDropAnimationController is a PreTargetHandler. | 91 // The bounds of the ink drop layers. Defined in the coordinate space of the |
| 86 View* view_; | 92 // parent ui::Layer that the ink drop layers were added to. |
| 93 gfx::Rect ink_drop_bounds_; | |
| 87 | 94 |
| 88 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationController); | 95 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerImpl); |
| 89 }; | 96 }; |
| 90 | 97 |
| 91 } // namespace views | 98 } // namespace views |
| 92 | 99 |
| 93 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_H_ | 100 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_H_ |
| OLD | NEW |