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" | |
| 13 #include "ui/compositor/layer_tree_owner.h" | |
|
bruthig
2017/03/10 22:34:08
nit: Can you forward declare this instead?
wutao
2017/03/14 16:46:38
Done.
| |
| 12 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
| 13 | 15 |
| 14 namespace ash { | 16 namespace ash { |
| 15 | 17 |
| 16 // Utility to perform a screen rotation with an animation. | 18 // Utility to perform a screen rotation with an animation. |
| 17 class ASH_EXPORT ScreenRotationAnimator { | 19 class ASH_EXPORT ScreenRotationAnimator { |
| 18 public: | 20 public: |
| 21 class ASH_EXPORT ScreenRotationAnimatorObserver { | |
| 22 public: | |
| 23 ScreenRotationAnimatorObserver(); | |
| 24 | |
| 25 virtual void OnEndedOrAbortedScreenRotationAnimation( | |
| 26 ScreenRotationAnimator* animator); | |
| 27 | |
| 28 protected: | |
| 29 virtual ~ScreenRotationAnimatorObserver(); | |
| 30 }; | |
| 31 | |
| 32 struct ScreenRotationRequest { | |
|
bruthig
2017/03/10 22:34:08
If you make Rotate() a member function, I think yo
wutao
2017/03/14 16:46:38
It is already in ScreenRotationAnimator class :)
I
| |
| 33 ScreenRotationAnimator* animator; | |
| 34 int64_t display_id; | |
| 35 display::Display::Rotation initial_rotation; | |
| 36 display::Display::Rotation new_rotation; | |
| 37 display::Display::RotationSource source; | |
| 38 }; | |
| 39 | |
| 19 explicit ScreenRotationAnimator(int64_t display_id); | 40 explicit ScreenRotationAnimator(int64_t display_id); |
| 20 ~ScreenRotationAnimator(); | 41 ~ScreenRotationAnimator(); |
| 21 | 42 |
| 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 | 43 // Rotates the display::Display specified by |display_id_| to the |
| 29 // |new_rotation| | 44 // |new_rotation| |
| 30 // orientation, for the given |source|. The rotation will also become active. | 45 // orientation, for the given |source|. The rotation will also become active. |
| 31 // Clients should only call |Rotate()| if |CanAnimate()| returns true. | 46 // Clients should only call |Rotate()| if |CanAnimate()| returns true. |
| 32 void Rotate(display::Display::Rotation new_rotation, | 47 void Rotate(display::Display::Rotation new_rotation, |
|
bruthig
2017/03/10 22:34:08
Can you document when the |observer_| will and wil
wutao
2017/03/14 16:46:38
Done.
| |
| 33 display::Display::RotationSource source); | 48 display::Display::RotationSource source); |
| 34 | 49 |
| 50 int64_t display_id() const { return display_id_; } | |
| 51 | |
| 52 void SetScreenRotationAnimatorObserver( | |
| 53 ScreenRotationAnimatorObserver* observer) { | |
| 54 screen_rotation_animator_observer_ = observer; | |
| 55 } | |
| 56 | |
| 57 void RemoveScreenRotationAnimatorObserver() { | |
| 58 screen_rotation_animator_observer_ = nullptr; | |
| 59 } | |
| 60 | |
| 61 void set_old_layer_tree_owner(ui::LayerTreeOwner* layer_tree_owner) { | |
|
bruthig
2017/03/10 22:34:08
Instead of making set_old_layer_tree_owner() and G
wutao
2017/03/14 16:46:38
Done.
| |
| 62 old_layer_tree_owner_.reset(layer_tree_owner); | |
| 63 } | |
| 64 | |
| 65 // Get the root layer of the old layer tree. | |
| 66 ui::Layer* GetOldLayerTreeRootLayer(); | |
| 67 | |
| 68 void OnLayerAnimationEnded(); | |
| 69 | |
| 70 void OnLayerAnimationAborted(); | |
| 71 | |
| 72 bool is_rotating_for_test() const { return is_rotating_; } | |
| 73 | |
| 74 base::WeakPtr<ScreenRotationAnimator> WeakPtr() { | |
| 75 return weak_factory_.GetWeakPtr(); | |
| 76 } | |
| 77 | |
| 35 private: | 78 private: |
| 36 // The id of the display to rotate. | 79 // The id of the display to rotate. |
| 37 int64_t display_id_; | 80 int64_t display_id_; |
| 81 bool is_rotating_; | |
| 82 ScreenRotationAnimatorObserver* screen_rotation_animator_observer_; | |
| 83 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | |
| 84 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | |
| 85 | |
| 86 void ContinueOrCleanUp(); | |
|
bruthig
2017/03/10 22:34:08
Some docs here would be helpful or a rename of Pro
wutao
2017/03/14 16:46:38
Renamed. A doc will be a little redundant when I a
| |
| 87 | |
| 88 // Aborts the active animations of the layer, and recurses upon its child | |
| 89 // layers. | |
| 90 void AbortAnimations(ui::Layer* layer); | |
| 91 | |
| 92 void StopAnimating(); | |
| 93 | |
| 94 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | |
| 38 | 95 |
| 39 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 96 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
| 40 }; | 97 }; |
| 41 | 98 |
| 42 } // namespace ash | 99 } // namespace ash |
| 43 | 100 |
| 44 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 101 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
| OLD | NEW |