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

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

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: 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 "ui/compositor/layer_tree_owner.h"
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 virtual void OnEndedOrAbortedAnimation(
25 base::WeakPtr<ScreenRotationAnimator> animator);
26
27 protected:
28 ~ScreenRotationAnimatorObserver();
29 };
30
31 struct ScreenRotationRequest {
32 ScreenRotationAnimator* animator;
33 int64_t display_id;
34 display::Display::Rotation initial_rotation;
35 display::Display::Rotation new_rotation;
36 display::Display::RotationSource source;
37 };
38
19 explicit ScreenRotationAnimator(int64_t display_id); 39 explicit ScreenRotationAnimator(int64_t display_id);
20 ~ScreenRotationAnimator(); 40 ~ScreenRotationAnimator();
21 41
22 // Returns true if the screen rotation animation can be completed 42 display::Display::Rotation GetCurrentRotation() const;
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 43
28 // Rotates the display::Display specified by |display_id_| to the 44 // Rotates the display::Display specified by |display_id_| to the
29 // |new_rotation| 45 // |new_rotation|
30 // orientation, for the given |source|. The rotation will also become active. 46 // orientation, for the given |source|. The rotation will also become active.
31 // Clients should only call |Rotate()| if |CanAnimate()| returns true. 47 // Clients should only call |Rotate()| if |CanAnimate()| returns true.
32 void Rotate(display::Display::Rotation new_rotation, 48 void Rotate(display::Display::Rotation new_rotation,
33 display::Display::RotationSource source); 49 display::Display::RotationSource source);
34 50
51 int64_t display_id() const;
bruthig 2017/03/02 18:25:45 You should inline the definition of simple getters
wutao 2017/03/03 02:45:52 I move the simple getters and setters in the .h.
52
53 bool is_animating() const;
54 void set_is_animating(bool rotating);
bruthig 2017/03/02 18:25:45 I think it is very odd that clients of the animato
wutao 2017/03/03 02:45:52 I was debating myself where is the best to reset i
55
56 ScreenRotationAnimatorObserver* observer() const;
57 void SetObserver(ScreenRotationAnimatorObserver* observer);
58 void RemoveObserver();
59
60 ui::LayerTreeOwner* old_layer_tree_owner() const;
61 void reset_old_layer_tree_owner();
62 void set_old_layer_tree_owner(ui::LayerTreeOwner* layer_tree_owner);
63
64 ScreenRotationRequest* last_pending_request() const;
65 void reset_last_pending_request();
66
67 base::WeakPtr<ScreenRotationAnimator> WeakPtr();
68
35 private: 69 private:
36 // The id of the display to rotate. 70 // The id of the display to rotate.
37 int64_t display_id_; 71 int64_t display_id_;
72 bool is_animating_;
73 ScreenRotationAnimatorObserver* observer_;
74 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_;
75 std::unique_ptr<ScreenRotationRequest> last_pending_request_;
76 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698