Update scrollbar layer property tree opacity when it becomes active
[chromium-blink-merge.git] / ash / display / window_tree_host_manager.h
blob5d276992e05f452f043a90ecd038159a6f3def47
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_
8 #include <map>
9 #include <vector>
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/memory/weak_ptr.h"
18 #include "base/observer_list.h"
19 #include "base/time/time.h"
20 #include "ui/aura/window.h"
21 #include "ui/aura/window_tree_host_observer.h"
22 #include "ui/base/ime/input_method.h"
23 #include "ui/base/ime/input_method_delegate.h"
24 #include "ui/gfx/display_observer.h"
25 #include "ui/gfx/geometry/point.h"
27 namespace aura {
28 class Display;
29 class WindowTreeHost;
32 namespace base {
33 class Value;
34 template <typename T>
35 class JSONValueConverter;
38 namespace gfx {
39 class Display;
40 class Insets;
43 namespace ash {
44 class AshWindowTreeHost;
45 struct AshWindowTreeHostInitParams;
46 class CursorWindowController;
47 class DisplayInfo;
48 class DisplayManager;
49 class FocusActivationStore;
50 class InputMethodEventHandler;
51 class MirrorWindowController;
52 class RootWindowController;
54 // WindowTreeHostManager owns and maintains RootWindows for each attached
55 // display, keeping them in sync with display configuration changes.
56 class ASH_EXPORT WindowTreeHostManager
57 : public gfx::DisplayObserver,
58 public aura::WindowTreeHostObserver,
59 public DisplayManager::Delegate,
60 public ui::internal::InputMethodDelegate {
61 public:
62 // TODO(oshima): Consider moving this to gfx::DisplayObserver.
63 class ASH_EXPORT Observer {
64 public:
65 // Invoked only once after all displays are initialized
66 // after startup.
67 virtual void OnDisplaysInitialized() {}
69 // Invoked when the display configuration change is requested,
70 // but before the change is applied to aura/ash.
71 virtual void OnDisplayConfigurationChanging() {}
73 // Invoked when the all display configuration changes
74 // have been applied.
75 virtual void OnDisplayConfigurationChanged(){};
77 protected:
78 virtual ~Observer() {}
81 WindowTreeHostManager();
82 ~WindowTreeHostManager() override;
84 void Start();
85 void Shutdown();
87 // Returns primary display's ID.
88 // TODO(oshima): Move this out from WindowTreeHostManager;
89 static int64 GetPrimaryDisplayId();
91 CursorWindowController* cursor_window_controller() {
92 return cursor_window_controller_.get();
95 MirrorWindowController* mirror_window_controller() {
96 return mirror_window_controller_.get();
99 // Create a WindowTreeHost for the primary display. This replaces
100 // |initial_bounds| in |init_params|.
101 void CreatePrimaryHost(const AshWindowTreeHostInitParams& init_params);
103 // Initializes all WindowTreeHosts.
104 void InitHosts();
106 // Add/Remove observers.
107 void AddObserver(Observer* observer);
108 void RemoveObserver(Observer* observer);
110 // Returns the root window for primary display.
111 aura::Window* GetPrimaryRootWindow();
113 // Returns the root window for |display_id|.
114 aura::Window* GetRootWindowForDisplayId(int64 id);
116 // Returns AshWTH for given display |id|. Call results in CHECK failure
117 // if the WTH does not exist.
118 AshWindowTreeHost* GetAshWindowTreeHostForDisplayId(int64 id);
120 // Toggle mirror mode.
121 void ToggleMirrorMode();
123 // Swap primary and secondary display.
124 void SwapPrimaryDisplay();
126 // Sets the ID of the primary display. If the display is not connected, it
127 // will switch the primary display when connected.
128 void SetPrimaryDisplayId(int64 id);
130 // Sets primary display. This re-assigns the current root
131 // window to given |display|.
132 void SetPrimaryDisplay(const gfx::Display& display);
134 // Closes all child windows in the all root windows.
135 void CloseChildWindows();
137 // Returns all root windows. In non extended desktop mode, this
138 // returns the primary root window only.
139 aura::Window::Windows GetAllRootWindows();
141 // Returns all oot window controllers. In non extended desktop
142 // mode, this return a RootWindowController for the primary root window only.
143 std::vector<RootWindowController*> GetAllRootWindowControllers();
145 // Gets/Sets/Clears the overscan insets for the specified |display_id|. See
146 // display_manager.h for the details.
147 gfx::Insets GetOverscanInsets(int64 display_id) const;
148 void SetOverscanInsets(int64 display_id, const gfx::Insets& insets_in_dip);
150 // Checks if the mouse pointer is on one of displays, and moves to
151 // the center of the nearest display if it's outside of all displays.
152 void UpdateMouseLocationAfterDisplayChange();
154 // Sets the work area's |insets| to the display assigned to |window|.
155 bool UpdateWorkAreaOfDisplayNearestWindow(const aura::Window* window,
156 const gfx::Insets& insets);
158 ui::InputMethod* input_method() { return input_method_.get(); }
160 // gfx::DisplayObserver overrides:
161 void OnDisplayAdded(const gfx::Display& display) override;
162 void OnDisplayRemoved(const gfx::Display& display) override;
163 void OnDisplayMetricsChanged(const gfx::Display& display,
164 uint32_t metrics) override;
166 // aura::WindowTreeHostObserver overrides:
167 void OnHostResized(const aura::WindowTreeHost* host) override;
169 // aura::DisplayManager::Delegate overrides:
170 void CreateOrUpdateMirroringDisplay(
171 const DisplayInfoList& info_list) override;
172 void CloseMirroringDisplayIfNotNecessary() override;
173 void PreDisplayConfigurationChange(bool clear_focus) override;
174 void PostDisplayConfigurationChange() override;
176 // ui::internal::InputMethodDelegate overrides:
177 ui::EventDispatchDetails DispatchKeyEventPostIME(
178 ui::KeyEvent* event) override;
180 InputMethodEventHandler* input_method_event_handler() {
181 return input_method_event_handler_.get();
184 private:
185 FRIEND_TEST_ALL_PREFIXES(WindowTreeHostManagerTest, BoundsUpdated);
186 FRIEND_TEST_ALL_PREFIXES(WindowTreeHostManagerTest, SecondaryDisplayLayout);
187 friend class DisplayManager;
188 friend class MirrorWindowController;
190 // Creates a WindowTreeHost for |display| and stores it in the
191 // |window_tree_hosts_| map.
192 AshWindowTreeHost* AddWindowTreeHostForDisplay(
193 const gfx::Display& display,
194 const AshWindowTreeHostInitParams& params);
196 void OnFadeOutForSwapDisplayFinished();
198 void SetMirrorModeAfterAnimation(bool mirror);
200 // Delete the AsWindowTreeHost. This does not remove the entry from
201 // |window_tree_hosts_|. Caller has to explicitly remove it.
202 void DeleteHost(AshWindowTreeHost* host_to_delete);
204 class DisplayChangeLimiter {
205 public:
206 DisplayChangeLimiter();
208 // Sets how long the throttling should last.
209 void SetThrottleTimeout(int64 throttle_ms);
211 bool IsThrottled() const;
213 private:
214 // The time when the throttling ends.
215 base::Time throttle_timeout_;
217 DISALLOW_COPY_AND_ASSIGN(DisplayChangeLimiter);
220 // The limiter to throttle how fast a user can
221 // change the display configuration.
222 scoped_ptr<DisplayChangeLimiter> limiter_;
224 typedef std::map<int64, AshWindowTreeHost*> WindowTreeHostMap;
225 // The mapping from display ID to its window tree host.
226 WindowTreeHostMap window_tree_hosts_;
228 base::ObserverList<Observer> observers_;
230 // Store the primary window tree host temporarily while replacing
231 // display.
232 AshWindowTreeHost* primary_tree_host_for_replace_;
234 scoped_ptr<FocusActivationStore> focus_activation_store_;
236 scoped_ptr<CursorWindowController> cursor_window_controller_;
237 scoped_ptr<MirrorWindowController> mirror_window_controller_;
239 scoped_ptr<ui::InputMethod> input_method_;
240 scoped_ptr<InputMethodEventHandler> input_method_event_handler_;
242 // Stores the current cursor location (in native coordinates and screen
243 // coordinates respectively). The locations are used to restore the cursor
244 // location when the display configuration changes and to determine whether
245 // the mouse should be moved after a display configuration change.
246 gfx::Point cursor_location_in_native_coords_for_restore_;
247 gfx::Point cursor_location_in_screen_coords_for_restore_;
249 // Stores the cursor's display. The id is used to determine whether the mouse
250 // should be moved after a display configuration change.
251 int64 cursor_display_id_for_restore_;
253 base::WeakPtrFactory<WindowTreeHostManager> weak_ptr_factory_;
255 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostManager);
258 } // namespace ash
260 #endif // ASH_DISPLAY_DISPLAY_CONTROLLER_H_