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.
12 #include "ash/ash_export.h"
13 #include "base/basictypes.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/compiler_specific.h"
17 #include "base/memory/weak_ptr.h"
18 #include "ui/gfx/size.h"
32 class NonClientFrameView
;
38 class AcceleratorController
;
40 class NestedDispatcherController
;
41 class PowerButtonController
;
44 class WindowCycleController
;
47 class ActivationController
;
48 class AcceleratorFilter
;
50 class DragDropController
;
52 class InputMethodEventFilter
;
53 class RootWindowEventFilter
;
54 class RootWindowLayoutManager
;
55 class ShadowController
;
56 class ShelfLayoutManager
;
57 class StackingController
;
58 class TooltipController
;
59 class VisibilityController
;
60 class WindowModalityController
;
61 class WorkspaceController
;
64 // Shell is a singleton object that presents the Shell API and implements the
65 // RootWindow's delegate interface.
67 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
68 // takes ownership of the Shell.
69 class ASH_EXPORT Shell
{
71 // In compact window mode we fill the screen with a single maximized window,
72 // similar to ChromeOS R17 and earlier. In overlapping mode we have draggable
73 // windows. In managed mode the workspace arranges windows for the user.
85 // A shell must be explicitly created so that it can call |Init()| with the
86 // delegate set. |delegate| can be NULL (if not required for initialization).
87 static Shell
* CreateInstance(ShellDelegate
* delegate
);
89 // Should never be called before |CreateInstance()|.
90 static Shell
* GetInstance();
92 static void DeleteInstance();
94 const gfx::Size
& compact_status_area_offset() const {
95 return compact_status_area_offset_
;
98 aura::Window
* GetContainer(int container_id
);
99 const aura::Window
* GetContainer(int container_id
) const;
101 // Adds or removes |filter| from the RootWindowEventFilter.
102 void AddRootWindowEventFilter(aura::EventFilter
* filter
);
103 void RemoveRootWindowEventFilter(aura::EventFilter
* filter
);
104 size_t GetRootWindowEventFilterCount() const;
106 // Shows the background menu over |widget|.
107 void ShowBackgroundMenu(views::Widget
* widget
, const gfx::Point
& location
);
110 void ToggleAppList();
112 // Dynamic window mode chooses between MODE_OVERLAPPING and MODE_COMPACT
113 // based on screen resolution and dynamically changes modes when the screen
114 // resolution changes (e.g. plugging in a monitor).
115 void set_dynamic_window_mode(bool value
) { dynamic_window_mode_
= value
; }
117 // Changes the current window mode, which will cause all the open windows
118 // to be laid out in the new mode and layout managers and event filters to be
119 // installed or removed.
120 void ChangeWindowMode(WindowMode mode
);
122 // Sets an appropriate window mode for the given screen resolution.
123 void SetWindowModeForMonitorSize(const gfx::Size
& monitor_size
);
125 // Returns true if the screen is locked.
126 bool IsScreenLocked() const;
128 // Returns true if a modal dialog window is currently open.
129 bool IsModalWindowOpen() const;
131 // See enum WindowMode for details.
132 bool IsWindowModeCompact() const { return window_mode_
== MODE_COMPACT
; }
134 // Sets the offset between the corner of the status area and the corner of the
135 // screen when we're using the compact window mode.
136 void SetCompactStatusAreaOffset(gfx::Size
& offset
);
138 // Creates a default views::NonClientFrameView for use by windows in the
140 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
141 views::Widget
* widget
);
143 // Rotate focus through containers that can recieve focus.
144 void RotateFocus(Direction direction
);
146 #if !defined(OS_MACOSX)
147 AcceleratorController
* accelerator_controller() {
148 return accelerator_controller_
.get();
150 #endif // !defined(OS_MACOSX)
152 internal::RootWindowEventFilter
* root_filter() {
155 internal::TooltipController
* tooltip_controller() {
156 return tooltip_controller_
.get();
158 PowerButtonController
* power_button_controller() {
159 return power_button_controller_
.get();
161 VideoDetector
* video_detector() {
162 return video_detector_
.get();
164 WindowCycleController
* window_cycle_controller() {
165 return window_cycle_controller_
.get();
168 ShellDelegate
* delegate() { return delegate_
.get(); }
170 Launcher
* launcher() { return launcher_
.get(); }
172 internal::ShelfLayoutManager
* shelf() const { return shelf_
; }
174 // Made available for tests.
175 internal::ShadowController
* shadow_controller() {
176 return shadow_controller_
.get();
180 FRIEND_TEST_ALL_PREFIXES(ShellTest
, ComputeWindowMode
);
181 FRIEND_TEST_ALL_PREFIXES(ShellTest
, ChangeWindowMode
);
183 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
185 explicit Shell(ShellDelegate
* delegate
);
190 // Returns the appropriate window mode to use based on the primary monitor's
191 // |monitor_size| and the user's |command_line|.
192 WindowMode
ComputeWindowMode(const gfx::Size
& monitor_size
,
193 CommandLine
* command_line
) const;
195 // Initializes or re-initializes the layout managers and event filters needed
196 // to support a given window mode and cleans up the unneeded ones.
197 void SetupCompactWindowMode();
198 void SetupNonCompactWindowMode();
200 // Sets the LayoutManager of the container with the specified id to NULL. This
201 // has the effect of deleting the current LayoutManager.
202 void ResetLayoutManager(int container_id
);
204 static Shell
* instance_
;
206 internal::RootWindowEventFilter
* root_filter_
; // not owned
208 std::vector
<WindowAndBoundsPair
> to_restore_
;
210 base::WeakPtrFactory
<Shell
> method_factory_
;
212 #if !defined(OS_MACOSX)
213 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
215 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
216 #endif // !defined(OS_MACOSX)
218 scoped_ptr
<ShellDelegate
> delegate_
;
220 scoped_ptr
<Launcher
> launcher_
;
222 scoped_ptr
<internal::AppList
> app_list_
;
224 scoped_ptr
<internal::StackingController
> stacking_controller_
;
225 scoped_ptr
<internal::ActivationController
> activation_controller_
;
226 scoped_ptr
<internal::WindowModalityController
> window_modality_controller_
;
227 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
228 scoped_ptr
<internal::WorkspaceController
> workspace_controller_
;
229 scoped_ptr
<internal::ShadowController
> shadow_controller_
;
230 scoped_ptr
<internal::TooltipController
> tooltip_controller_
;
231 scoped_ptr
<internal::VisibilityController
> visibility_controller_
;
232 scoped_ptr
<PowerButtonController
> power_button_controller_
;
233 scoped_ptr
<VideoDetector
> video_detector_
;
234 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
235 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
237 // An event filter that pre-handles all key events to send them to an IME.
238 scoped_ptr
<internal::InputMethodEventFilter
> input_method_filter_
;
240 #if !defined(OS_MACOSX)
241 // An event filter that pre-handles global accelerators.
242 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
245 // The shelf for managing the launcher and the status widget in non-compact
246 // mode. Shell does not own the shelf. Instead, it is owned by container of
248 internal::ShelfLayoutManager
* shelf_
;
250 // Change window mode based on screen resolution.
251 bool dynamic_window_mode_
;
253 // Can change at runtime.
254 WindowMode window_mode_
;
256 // Owned by aura::RootWindow, cached here for type safety.
257 internal::RootWindowLayoutManager
* root_window_layout_
;
259 // Status area with clock, Wi-Fi signal, etc.
260 views::Widget
* status_widget_
;
262 // Offset between the corner of the status area and the corner of the screen
263 // when in the compact window mode.
264 gfx::Size compact_status_area_offset_
;
266 DISALLOW_COPY_AND_ASSIGN(Shell
);
271 #endif // ASH_SHELL_H_