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

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

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: Fixes some nit. 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"
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.
bruthig 2017/03/16 20:41:58 nit: 'Clients should only call |Rotate()| when can
wutao 2017/03/17 00:01:03 Right, in the ProcessAnimationQueue, I will add a
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,
bruthig 2017/03/16 20:41:57 nit: 'ongoging' -> 'ongoing'
wutao 2017/03/17 00:01:03 Done.
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
35 private: 60 private:
61 friend class ash::test::ScreenRotationAnimatorTestApi;
62 struct ScreenRotationRequest;
63
64 // Set the screen orientation to |new_rotation| and animate the change. The
65 // animation will rotate the initial orientation's layer towards the new
66 // orientation through |rotation_degrees| while fading out, and the new
67 // orientation's layer will be rotated in to the |new_orientation| through
68 // |rotation_degrees| arc.
69 void AnimateRotation(const ScreenRotationRequest& rotation_request);
70
71 // Get the root layer of the old layer tree.
72 ui::Layer* GetOldLayerTreeRootLayer();
73
74 // When screen rotation animation is ended or aborted, if the request queue is
75 // not empty, it will call |Rotate()| with the pending rotation request.
76 // Otherwise it will notify |screen_rotation_animator_observer_|.
77 void ProcessAnimationQueue();
78
79 void set_disable_animation_timers_for_test(bool disable_timers);
80
81 void StopAnimating();
82
36 // The id of the display to rotate. 83 // The id of the display to rotate.
37 int64_t display_id_; 84 int64_t display_id_;
85 bool is_rotating_;
86 // Only set in unittest to disable animation timers.
87 bool disable_animation_timers_for_test_;
88 ScreenRotationAnimatorObserver* screen_rotation_animator_observer_;
oshima 2017/03/16 20:13:09 us ObserverList and follow the same pattern as oth
wutao 2017/03/17 00:01:03 Currently only one observer. I will change to Obse
89 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_;
90 std::unique_ptr<ScreenRotationRequest> last_pending_request_;
91 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_;
38 92
39 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); 93 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator);
40 }; 94 };
41 95
42 } // namespace ash 96 } // namespace ash
43 97
44 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ 98 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698