1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_DISPLAY_DISPLAY_CONTROLLER_H_
6 #define ASH_DISPLAY_DISPLAY_CONTROLLER_H_
11 #include "ash/ash_export.h"
12 #include "ash/display/display_manager.h"
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/observer_list.h"
18 #include "base/time/time.h"
19 #include "ui/aura/root_window_observer.h"
20 #include "ui/aura/window.h"
21 #include "ui/gfx/display_observer.h"
22 #include "ui/gfx/point.h"
31 template <typename T
> class JSONValueConverter
;
43 class FocusActivationStore
;
44 class MirrorWindowController
;
45 class RootWindowController
;
46 class VirtualKeyboardWindowController
;
49 // DisplayController owns and maintains RootWindows for each attached
50 // display, keeping them in sync with display configuration changes.
51 class ASH_EXPORT DisplayController
: public gfx::DisplayObserver
,
52 public aura::RootWindowObserver
,
53 public internal::DisplayManager::Delegate
{
55 class ASH_EXPORT Observer
{
57 // Invoked when the display configuration change is requested,
58 // but before the change is applied to aura/ash.
59 virtual void OnDisplayConfigurationChanging() {}
61 // Invoked when the all display configuration changes
63 virtual void OnDisplayConfigurationChanged() {};
66 virtual ~Observer() {}
70 virtual ~DisplayController();
75 // Returns primary display's ID.
76 // TODO(oshima): Move this out from DisplayController;
77 static int64
GetPrimaryDisplayId();
79 internal::MirrorWindowController
* mirror_window_controller() {
80 return mirror_window_controller_
.get();
83 internal::VirtualKeyboardWindowController
*
84 virtual_keyboard_window_controller() {
85 return virtual_keyboard_window_controller_
.get();
88 // Initializes primary display.
89 void InitPrimaryDisplay();
91 // Initialize secondary displays.
92 void InitSecondaryDisplays();
94 // Add/Remove observers.
95 void AddObserver(Observer
* observer
);
96 void RemoveObserver(Observer
* observer
);
98 // Returns the root window for primary display.
99 aura::Window
* GetPrimaryRootWindow();
101 // Returns the root window for |display_id|.
102 aura::Window
* GetRootWindowForDisplayId(int64 id
);
104 // Toggle mirror mode.
105 void ToggleMirrorMode();
107 // Swap primary and secondary display.
108 void SwapPrimaryDisplay();
110 // Sets the ID of the primary display. If the display is not connected, it
111 // will switch the primary display when connected.
112 void SetPrimaryDisplayId(int64 id
);
114 // Sets primary display. This re-assigns the current root
115 // window to given |display|.
116 void SetPrimaryDisplay(const gfx::Display
& display
);
118 // Closes all child windows in the all root windows.
119 void CloseChildWindows();
121 // Returns all root windows. In non extended desktop mode, this
122 // returns the primary root window only.
123 aura::Window::Windows
GetAllRootWindows();
125 // Returns all oot window controllers. In non extended desktop
126 // mode, this return a RootWindowController for the primary root window only.
127 std::vector
<internal::RootWindowController
*> GetAllRootWindowControllers();
129 // Gets/Sets/Clears the overscan insets for the specified |display_id|. See
130 // display_manager.h for the details.
131 gfx::Insets
GetOverscanInsets(int64 display_id
) const;
132 void SetOverscanInsets(int64 display_id
, const gfx::Insets
& insets_in_dip
);
134 // Checks if the mouse pointer is on one of displays, and moves to
135 // the center of the nearest display if it's outside of all displays.
136 void EnsurePointerInDisplays();
138 // Sets the work area's |insets| to the display assigned to |window|.
139 bool UpdateWorkAreaOfDisplayNearestWindow(const aura::Window
* window
,
140 const gfx::Insets
& insets
);
141 // aura::DisplayObserver overrides:
142 virtual void OnDisplayBoundsChanged(
143 const gfx::Display
& display
) OVERRIDE
;
144 virtual void OnDisplayAdded(const gfx::Display
& display
) OVERRIDE
;
145 virtual void OnDisplayRemoved(const gfx::Display
& display
) OVERRIDE
;
147 // RootWindowObserver overrides:
148 virtual void OnWindowTreeHostResized(const aura::RootWindow
* root
) OVERRIDE
;
150 // aura::DisplayManager::Delegate overrides:
151 virtual void CreateOrUpdateNonDesktopDisplay(
152 const internal::DisplayInfo
& info
) OVERRIDE
;
153 virtual void CloseNonDesktopDisplay() OVERRIDE
;
154 virtual void PreDisplayConfigurationChange(bool clear_focus
) OVERRIDE
;
155 virtual void PostDisplayConfigurationChange() OVERRIDE
;
158 FRIEND_TEST_ALL_PREFIXES(DisplayControllerTest
, BoundsUpdated
);
159 FRIEND_TEST_ALL_PREFIXES(DisplayControllerTest
, SecondaryDisplayLayout
);
160 friend class internal::DisplayManager
;
161 friend class internal::MirrorWindowController
;
163 // Creates a root window for |display| and stores it in the |root_windows_|
165 aura::RootWindow
* AddRootWindowForDisplay(const gfx::Display
& display
);
167 void OnFadeOutForSwapDisplayFinished();
169 void UpdateHostWindowNames();
171 class DisplayChangeLimiter
{
173 DisplayChangeLimiter();
175 // Sets how long the throttling should last.
176 void SetThrottleTimeout(int64 throttle_ms
);
178 bool IsThrottled() const;
181 // The time when the throttling ends.
182 base::Time throttle_timeout_
;
184 DISALLOW_COPY_AND_ASSIGN(DisplayChangeLimiter
);
187 // The limiter to throttle how fast a user can
188 // change the display configuration.
189 scoped_ptr
<DisplayChangeLimiter
> limiter_
;
191 // The mapping from display ID to its root window.
192 std::map
<int64
, aura::Window
*> root_windows_
;
194 ObserverList
<Observer
> observers_
;
196 // Store the primary root window temporarily while replacing
198 aura::Window
* primary_root_window_for_replace_
;
200 scoped_ptr
<internal::FocusActivationStore
> focus_activation_store_
;
202 scoped_ptr
<internal::MirrorWindowController
> mirror_window_controller_
;
203 scoped_ptr
<internal::VirtualKeyboardWindowController
>
204 virtual_keyboard_window_controller_
;
206 // Stores the curent cursor location (in native coordinates) used to
207 // restore the cursor location when display configuration
209 gfx::Point cursor_location_in_native_coords_for_restore_
;
211 DISALLOW_COPY_AND_ASSIGN(DisplayController
);
216 #endif // ASH_DISPLAY_DISPLAY_CONTROLLER_H_