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 ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 5 #ifndef ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
| 6 #define ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 6 #define ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | |
| 12 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
| 13 | 14 |
| 15 namespace ui { | |
| 16 class Layer; | |
| 17 class LayerTreeOwner; | |
| 18 } // namespace ui | |
| 19 | |
| 14 namespace ash { | 20 namespace ash { |
| 21 namespace test { | |
| 22 class ScreenRotationAnimatorTestApi; | |
| 23 } // namespace test | |
| 24 | |
| 25 class ScreenRotationAnimatorObserver; | |
| 15 | 26 |
| 16 // Utility to perform a screen rotation with an animation. | 27 // Utility to perform a screen rotation with an animation. |
| 17 class ASH_EXPORT ScreenRotationAnimator { | 28 class ASH_EXPORT ScreenRotationAnimator { |
| 18 public: | 29 public: |
| 19 explicit ScreenRotationAnimator(int64_t display_id); | 30 explicit ScreenRotationAnimator(int64_t display_id); |
| 20 ~ScreenRotationAnimator(); | 31 ~ScreenRotationAnimator(); |
| 21 | 32 |
| 22 // Returns true if the screen rotation animation can be completed | |
| 23 // successfully. For example an animation is not possible if |display_id_| | |
| 24 // specifies a display::Display that is not currently active. See | |
| 25 // www.crbug.com/479503. | |
| 26 bool CanAnimate() const; | |
| 27 | |
| 28 // Rotates the display::Display specified by |display_id_| to the | 33 // Rotates the display::Display specified by |display_id_| to the |
| 29 // |new_rotation| | 34 // |new_rotation| orientation, for the given |source|. The rotation will also |
| 30 // orientation, for the given |source|. The rotation will also become active. | 35 // become active. Clients should only call |Rotate()| when can animate. For |
| 31 // Clients should only call |Rotate()| if |CanAnimate()| returns true. | 36 // example an animation is not possible if |display_id_| specifies a |
| 37 // display::Display that is not currently active. See www.crbug.com/479503. | |
| 38 // |screen_rotation_animator_observer_| will be notified when rotation is | |
| 39 // finished and there is no more pending rotation request. Otherwise, any | |
| 40 // ongoging animation will be stoped and progressed to the target position, | |
| 41 // followed by a new |Rotate()| call with the pending rotation request. | |
| 32 void Rotate(display::Display::Rotation new_rotation, | 42 void Rotate(display::Display::Rotation new_rotation, |
| 33 display::Display::RotationSource source); | 43 display::Display::RotationSource source); |
| 34 | 44 |
| 45 int64_t display_id() const { return display_id_; } | |
| 46 | |
| 47 void SetScreenRotationAnimatorObserver( | |
| 48 ScreenRotationAnimatorObserver* observer) { | |
| 49 screen_rotation_animator_observer_ = observer; | |
| 50 } | |
| 51 | |
| 52 void RemoveScreenRotationAnimatorObserver() { | |
| 53 screen_rotation_animator_observer_ = nullptr; | |
| 54 } | |
| 55 | |
| 56 void OnLayerAnimationEnded(); | |
| 57 | |
| 58 void OnLayerAnimationAborted(); | |
| 59 | |
| 60 base::WeakPtr<ScreenRotationAnimator> WeakPtr(); | |
|
bruthig
2017/03/15 23:12:38
Is this required or can you use weak_factory_.GetW
wutao
2017/03/16 07:37:59
I can use weak_factory_.GetWeakPtr().
| |
| 61 | |
| 35 private: | 62 private: |
| 63 friend class ash::test::ScreenRotationAnimatorTestApi; | |
| 64 | |
| 36 // The id of the display to rotate. | 65 // The id of the display to rotate. |
| 37 int64_t display_id_; | 66 int64_t display_id_; |
| 67 bool is_rotating_; | |
| 68 bool disable_animation_timers_for_test_; | |
|
bruthig
2017/03/15 23:12:37
This could use a doc.
wutao
2017/03/16 07:37:59
Done.
| |
| 69 ScreenRotationAnimatorObserver* screen_rotation_animator_observer_; | |
| 70 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | |
| 71 struct ScreenRotationRequest; | |
| 72 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | |
| 73 | |
| 74 void AnimateRotation(const ScreenRotationRequest& rotation_request); | |
|
bruthig
2017/03/15 23:12:37
Function declarations should go before member vari
wutao
2017/03/16 07:37:59
Done.
| |
| 75 | |
| 76 // Get the root layer of the old layer tree. | |
| 77 ui::Layer* GetOldLayerTreeRootLayer(); | |
| 78 | |
| 79 void ProcessAnimationQueue(); | |
|
bruthig
2017/03/15 23:12:37
Docs?
wutao
2017/03/16 07:37:59
Done.
| |
| 80 | |
| 81 void set_disable_animation_timers_for_test(bool disable_timers); | |
| 82 | |
| 83 void StopAnimating(); | |
| 84 | |
| 85 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | |
| 38 | 86 |
| 39 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 87 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
| 40 }; | 88 }; |
| 41 | 89 |
| 42 } // namespace ash | 90 } // namespace ash |
| 43 | 91 |
| 44 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 92 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
| OLD | NEW |