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

Side by Side Diff: ash/display/display_configuration_controller.h

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: Make ScreenRotationAnimator handle its own internal states. 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ 5 #ifndef ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_
6 #define ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ 6 #define ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/ash_export.h" 10 #include "ash/ash_export.h"
11 #include "ash/display/window_tree_host_manager.h" 11 #include "ash/display/window_tree_host_manager.h"
12 #include "ash/rotator/screen_rotation_animator.h"
bruthig 2017/03/10 22:34:07 super-nit: If ScreenRotationAnimatorObserver was i
wutao 2017/03/14 16:46:37 Moved ScreenRotationAnimatorObserver to it's own .
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
14 #include "ui/display/display.h" 15 #include "ui/display/display.h"
15 16
16 namespace display { 17 namespace display {
17 class DisplayLayout; 18 class DisplayLayout;
18 class DisplayManager; 19 class DisplayManager;
19 } 20 }
20 21
21 namespace ash { 22 namespace ash {
22 23
23 namespace test { 24 namespace test {
24 class ShellTestApi; 25 class DisplayConfigurationControllerTestApi;
25 } // namespace test 26 } // namespace test
26 27
27 class DisplayAnimator; 28 class DisplayAnimator;
28 29
29 // This class controls Display related configuration. Specifically it: 30 // This class controls Display related configuration. Specifically it:
30 // * Handles animated transitions where appropriate. 31 // * Handles animated transitions where appropriate.
31 // * Limits the frequency of certain operations. 32 // * Limits the frequency of certain operations.
32 // * Provides a single interface for UI and API classes. 33 // * Provides a single interface for UI and API classes.
33 // * TODO: Forwards display configuration changed events to UI and API classes. 34 // * TODO: Forwards display configuration changed events to UI and API classes.
34 class ASH_EXPORT DisplayConfigurationController 35 class ASH_EXPORT DisplayConfigurationController
35 : public WindowTreeHostManager::Observer { 36 : public WindowTreeHostManager::Observer,
37 public ScreenRotationAnimator::ScreenRotationAnimatorObserver {
36 public: 38 public:
37 DisplayConfigurationController( 39 DisplayConfigurationController(
38 display::DisplayManager* display_manager, 40 display::DisplayManager* display_manager,
39 WindowTreeHostManager* window_tree_host_manager); 41 WindowTreeHostManager* window_tree_host_manager);
40 ~DisplayConfigurationController() override; 42 ~DisplayConfigurationController() override;
41 43
42 // Sets the layout for the current displays with a fade in/out 44 // Sets the layout for the current displays with a fade in/out
43 // animation. Currently |display_id| is assumed to be the secondary 45 // animation. Currently |display_id| is assumed to be the secondary
44 // display. TODO(oshima/stevenjb): Support 3+ displays. 46 // display. TODO(oshima/stevenjb): Support 3+ displays.
45 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout, 47 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout,
46 bool user_action); 48 bool user_action);
47 49
48 // Sets the mirror mode with a fade-in/fade-out animation. Affects all 50 // Sets the mirror mode with a fade-in/fade-out animation. Affects all
49 // displays. 51 // displays.
50 void SetMirrorMode(bool mirror, bool user_action); 52 void SetMirrorMode(bool mirror, bool user_action);
51 53
52 // Sets the display's rotation with animation if available. 54 // Sets the display's rotation with animation if available.
53 void SetDisplayRotation(int64_t display_id, 55 void SetDisplayRotation(int64_t display_id,
54 display::Display::Rotation rotation, 56 display::Display::Rotation rotation,
55 display::Display::RotationSource source); 57 display::Display::RotationSource source);
56 58
57 // Sets the primary display id. 59 // Sets the primary display id.
58 void SetPrimaryDisplayId(int64_t display_id, bool user_action); 60 void SetPrimaryDisplayId(int64_t display_id, bool user_action);
59 61
60 // WindowTreeHostManager::Observer 62 // WindowTreeHostManager::Observer
61 void OnDisplayConfigurationChanged() override; 63 void OnDisplayConfigurationChanged() override;
62 64
65 // ScreenRotationAnimator::ScreenRotationAnimatorObserver
66 void OnEndedOrAbortedScreenRotationAnimation(
67 ScreenRotationAnimator* animator) override;
68
63 protected: 69 protected:
64 friend class ash::test::ShellTestApi; 70 friend class ash::test::DisplayConfigurationControllerTestApi;
65 71
66 // Allow tests to skip animations. 72 // Allow tests to skip animations.
67 void ResetAnimatorForTest(); 73 void ResetAnimatorForTest();
68 74
69 private: 75 private:
70 class DisplayChangeLimiter; 76 class DisplayChangeLimiter;
71 77
72 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this 78 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this
73 // *before* starting any animations. 79 // *before* starting any animations.
74 void SetThrottleTimeout(int64_t throttle_ms); 80 void SetThrottleTimeout(int64_t throttle_ms);
75 bool IsLimited(); 81 bool IsLimited();
76 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); 82 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout);
77 void SetMirrorModeImpl(bool mirror); 83 void SetMirrorModeImpl(bool mirror);
78 void SetPrimaryDisplayIdImpl(int64_t display_id); 84 void SetPrimaryDisplayIdImpl(int64_t display_id);
79 85
86 // Returns true if the screen rotation animation can be completed
87 // successfully. For example an animation is not possible if |display_id_|
88 // specifies a display::Display that is not currently active. See
89 // www.crbug.com/479503.
90 bool CanAnimateScreenRotation(int64_t display_id) const;
91
92 // Returns the currently active rotation for the display with |display_id|. If
93 // an animation is in progress, the target rotation will be returned.
94 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) const;
95
96 ScreenRotationAnimator* GetScreenRotationAnimatorForDisplay(
bruthig 2017/03/10 22:34:07 nit: Can you doc this method that it creates one i
wutao 2017/03/14 16:46:37 Done.
97 int64_t display_id);
98
80 display::DisplayManager* display_manager_; // weak ptr 99 display::DisplayManager* display_manager_; // weak ptr
81 WindowTreeHostManager* window_tree_host_manager_; // weak ptr 100 WindowTreeHostManager* window_tree_host_manager_; // weak ptr
82 std::unique_ptr<DisplayAnimator> display_animator_; 101 std::unique_ptr<DisplayAnimator> display_animator_;
83 std::unique_ptr<DisplayChangeLimiter> limiter_; 102 std::unique_ptr<DisplayChangeLimiter> limiter_;
84 103
104 // Tracks |display_id| to ScreenRotationAnimator mappings. The
105 // |rotation_animator_map_| is populated on demand the first time a
106 // ScreenRotationAnimator is needed for a given |display_id|.
107 // On animation ended or aborted, the animator may be deleted if there is no
108 // more pending rotation request.
109 std::unordered_map<int64_t, std::unique_ptr<ScreenRotationAnimator>>
110 rotation_animator_map_;
111
85 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; 112 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_;
86 113
87 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); 114 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController);
88 }; 115 };
89 116
90 } // namespace ash 117 } // namespace ash
91 118
92 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ 119 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698