Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: ash/rotator/screen_rotation_animator.h

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: Rebased to commit. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/observer_list.h"
12 #include "ui/display/display.h" 14 #include "ui/display/display.h"
13 15
16 namespace ui {
17 class Layer;
18 class LayerTreeOwner;
19 } // namespace ui
20
14 namespace ash { 21 namespace ash {
22 namespace test {
23 class ScreenRotationAnimatorTestApi;
24 } // namespace test
25
26 class ScreenRotationAnimatorObserver;
15 27
16 // Utility to perform a screen rotation with an animation. 28 // Utility to perform a screen rotation with an animation.
17 class ASH_EXPORT ScreenRotationAnimator { 29 class ASH_EXPORT ScreenRotationAnimator {
18 public: 30 public:
19 explicit ScreenRotationAnimator(int64_t display_id); 31 explicit ScreenRotationAnimator(int64_t display_id);
20 ~ScreenRotationAnimator(); 32 ~ScreenRotationAnimator();
21 33
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 34 // Rotates the display::Display specified by |display_id_| to the
29 // |new_rotation| 35 // |new_rotation| orientation, for the given |source|. The rotation will also
30 // orientation, for the given |source|. The rotation will also become active. 36 // become active. Should only be called when |display_id_| references a valid
31 // Clients should only call |Rotate()| if |CanAnimate()| returns true. 37 // display::Display. |screen_rotation_animator_observer_| will be notified
38 // when rotation is finished and there is no more pending rotation request.
39 // Otherwise, any ongoing animation will be stopped and progressed to the
40 // target position, followed by a new |Rotate()| call with the pending
41 // 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 AddScreenRotationAnimatorObserver(
48 ScreenRotationAnimatorObserver* observer);
49 void RemoveScreenRotationAnimatorObserver(
50 ScreenRotationAnimatorObserver* observer);
51
52 void OnLayerAnimationEnded();
53
54 void OnLayerAnimationAborted();
55
35 private: 56 private:
57 friend class ash::test::ScreenRotationAnimatorTestApi;
58 struct ScreenRotationRequest;
59
60 // Set the screen orientation to |new_rotation| and animate the change. The
61 // animation will rotate the initial orientation's layer towards the new
62 // orientation through |rotation_degrees| while fading out, and the new
63 // orientation's layer will be rotated in to the |new_orientation| through
64 // |rotation_degrees| arc.
65 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request);
66
67 // When screen rotation animation is ended or aborted, if the request queue is
68 // not empty, it will call |Rotate()| with the pending rotation request.
69 // Otherwise it will notify |screen_rotation_animator_observer_|.
70 void ProcessAnimationQueue();
71
72 void set_disable_animation_timers_for_test(bool disable_timers);
73
74 void StopAnimating();
75
36 // The id of the display to rotate. 76 // The id of the display to rotate.
37 int64_t display_id_; 77 int64_t display_id_;
78 bool is_rotating_;
79 // Only set in unittest to disable animation timers.
80 bool disable_animation_timers_for_test_;
81 base::ObserverList<ScreenRotationAnimatorObserver>
82 screen_rotation_animator_observers_;
83 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_;
84 std::unique_ptr<ScreenRotationRequest> last_pending_request_;
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_
OLDNEW
« no previous file with comments | « ash/display/display_configuration_controller_unittest.cc ('k') | ash/rotator/screen_rotation_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698