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 "ui/compositor/layer_tree_owner.h" | |
| 12 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
| 13 | 14 |
| 14 namespace ash { | 15 namespace ash { |
| 15 | 16 |
| 16 // Utility to perform a screen rotation with an animation. | 17 // Utility to perform a screen rotation with an animation. |
| 17 class ASH_EXPORT ScreenRotationAnimator { | 18 class ASH_EXPORT ScreenRotationAnimator { |
| 18 public: | 19 public: |
| 20 class ASH_EXPORT ScreenRotationAnimatorObserver { | |
| 21 public: | |
| 22 ScreenRotationAnimatorObserver(); | |
| 23 virtual void OnEndedOrAbortedAnimation(ScreenRotationAnimator* animator); | |
| 24 | |
| 25 protected: | |
| 26 ~ScreenRotationAnimatorObserver(); | |
|
bruthig
2017/03/08 22:35:59
This should be virtual because you expect classes
wutao
2017/03/09 22:09:19
Done.
| |
| 27 }; | |
| 28 | |
| 29 struct ScreenRotationRequest { | |
| 30 ScreenRotationAnimator* animator; | |
| 31 int64_t display_id; | |
| 32 display::Display::Rotation initial_rotation; | |
| 33 display::Display::Rotation new_rotation; | |
| 34 display::Display::RotationSource source; | |
| 35 }; | |
| 36 | |
| 19 explicit ScreenRotationAnimator(int64_t display_id); | 37 explicit ScreenRotationAnimator(int64_t display_id); |
| 20 ~ScreenRotationAnimator(); | 38 ~ScreenRotationAnimator(); |
| 21 | 39 |
| 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 | 40 // Rotates the display::Display specified by |display_id_| to the |
| 29 // |new_rotation| | 41 // |new_rotation| |
| 30 // orientation, for the given |source|. The rotation will also become active. | 42 // orientation, for the given |source|. The rotation will also become active. |
| 31 // Clients should only call |Rotate()| if |CanAnimate()| returns true. | 43 // Clients should only call |Rotate()| if |CanAnimate()| returns true. |
| 32 void Rotate(display::Display::Rotation new_rotation, | 44 void Rotate(display::Display::Rotation new_rotation, |
| 33 display::Display::RotationSource source); | 45 display::Display::RotationSource source); |
| 34 | 46 |
| 47 int64_t display_id() const { return display_id_; }; | |
| 48 | |
| 49 bool is_rotating() const { return is_rotating_; }; | |
| 50 void set_is_rotating(bool rotating) { is_rotating_ = rotating; }; | |
|
bruthig
2017/03/08 22:35:59
|is_rotating_| seems to me that it should be inter
wutao
2017/03/09 22:09:19
(3) is almost close to what I implemented for the
| |
| 51 | |
| 52 ScreenRotationRequest* last_pending_request() const { | |
| 53 return last_pending_request_.get(); | |
| 54 }; | |
| 55 | |
| 56 ScreenRotationAnimatorObserver* observer() const { return observer_; }; | |
| 57 void SetObserver(ScreenRotationAnimatorObserver* observer) { | |
| 58 observer_ = observer; | |
| 59 }; | |
| 60 void RemoveObserver() { observer_ = nullptr; }; | |
| 61 | |
| 62 ui::LayerTreeOwner* old_layer_tree_owner() const { | |
| 63 return old_layer_tree_owner_.get(); | |
| 64 }; | |
| 65 void reset_old_layer_tree_owner() { old_layer_tree_owner_.reset(); }; | |
| 66 void set_old_layer_tree_owner(ui::LayerTreeOwner* layer_tree_owner) { | |
| 67 old_layer_tree_owner_.reset(layer_tree_owner); | |
| 68 }; | |
| 69 | |
| 35 private: | 70 private: |
| 36 // The id of the display to rotate. | 71 // The id of the display to rotate. |
| 37 int64_t display_id_; | 72 int64_t display_id_; |
| 73 bool is_rotating_; | |
| 74 ScreenRotationAnimatorObserver* observer_; | |
| 75 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | |
| 76 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | |
| 38 | 77 |
| 39 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 78 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
| 40 }; | 79 }; |
| 41 | 80 |
| 42 } // namespace ash | 81 } // namespace ash |
| 43 | 82 |
| 44 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 83 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
| OLD | NEW |