blob: db60bae3b9cce6618089345cfec1ea5a1c62c201 [file] [log] [blame]
[email protected]e0d22e82012-01-04 00:46:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]87b0d82e2011-10-07 21:02:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b65bdda2011-12-23 23:35:315#ifndef ASH_SHELL_H_
6#define ASH_SHELL_H_
[email protected]87b0d82e2011-10-07 21:02:597#pragma once
8
[email protected]cac10fc62011-10-07 23:22:569#include <utility>
10#include <vector>
11
[email protected]b65bdda2011-12-23 23:35:3112#include "ash/ash_export.h"
[email protected]87b0d82e2011-10-07 21:02:5913#include "base/basictypes.h"
[email protected]c45fdc72012-02-22 22:59:1214#include "base/compiler_specific.h"
[email protected]b0639282011-12-22 21:12:2715#include "base/gtest_prod_util.h"
[email protected]2b99f8c2011-10-11 19:42:2416#include "base/memory/scoped_ptr.h"
[email protected]0c4011b2012-02-11 02:10:4217#include "ui/gfx/size.h"
[email protected]87b0d82e2011-10-07 21:02:5918
[email protected]b0639282011-12-22 21:12:2719class CommandLine;
20
[email protected]87b0d82e2011-10-07 21:02:5921namespace aura {
[email protected]e29014c2011-11-16 18:25:5122class EventFilter;
[email protected]35304ce2011-12-14 23:21:0123class RootWindow;
[email protected]87b0d82e2011-10-07 21:02:5924class Window;
25}
[email protected]2b99f8c2011-10-11 19:42:2426namespace gfx {
[email protected]b5f30602012-01-30 15:16:5727class Point;
[email protected]cac10fc62011-10-07 23:22:5628class Rect;
29}
[email protected]a8bd1cb2012-02-17 23:05:5430namespace ui {
31class Layer;
32}
[email protected]57b8bb352012-01-11 05:11:4633namespace views {
34class NonClientFrameView;
35class Widget;
36}
[email protected]87b0d82e2011-10-07 21:02:5937
[email protected]55f593352011-12-24 05:42:4638namespace ash {
[email protected]87b0d82e2011-10-07 21:02:5939
[email protected]2f744282011-12-23 22:40:5240class AcceleratorController;
[email protected]671a2ae2011-10-13 21:53:2341class Launcher;
[email protected]8f80db0f2012-02-07 14:44:5342class NestedDispatcherController;
[email protected]e0d22e82012-01-04 00:46:5743class PowerButtonController;
[email protected]2b99f8c2011-10-11 19:42:2444class ShellDelegate;
[email protected]6aa614a2012-01-19 22:13:3845class VideoDetector;
[email protected]40c4cbb2012-01-10 23:26:0746class WindowCycleController;
[email protected]60fa9bba2011-10-28 21:21:5147
48namespace internal {
[email protected]9fc206d2011-12-13 00:05:3349class ActivationController;
[email protected]2f744282011-12-23 22:40:5250class AcceleratorFilter;
[email protected]ae4987d2011-11-21 22:52:4451class AppList;
[email protected]084b6bb2011-11-17 05:18:1652class DragDropController;
[email protected]3d29912a2012-02-07 07:41:5153class FocusCycler;
[email protected]2c456102011-12-26 06:26:3454class InputMethodEventFilter;
[email protected]0b0b0742012-02-16 13:23:4555class PartialScreenshotEventFilter;
[email protected]627a62f2012-02-14 22:59:1456class RootWindowEventFilter;
[email protected]b0079a92012-01-25 20:13:3857class RootWindowLayoutManager;
[email protected]a54e65b2011-11-21 22:03:3458class ShadowController;
[email protected]4e437632012-02-13 22:39:4059class ShelfLayoutManager;
[email protected]ee1e1a22011-12-15 01:51:1060class StackingController;
[email protected]862deef2011-12-15 22:07:3361class TooltipController;
[email protected]ddd91e92012-01-27 16:03:4862class VisibilityController;
[email protected]80373572012-01-06 23:14:3063class WindowModalityController;
[email protected]60fa9bba2011-10-28 21:21:5164class WorkspaceController;
65}
[email protected]2b99f8c2011-10-11 19:42:2466
[email protected]87b0d82e2011-10-07 21:02:5967// Shell is a singleton object that presents the Shell API and implements the
[email protected]99f07e02011-12-07 00:02:5968// RootWindow's delegate interface.
[email protected]b0079a92012-01-25 20:13:3869//
70// Upon creation, the Shell sets itself as the RootWindow's delegate, which
71// takes ownership of the Shell.
[email protected]b65bdda2011-12-23 23:35:3172class ASH_EXPORT Shell {
[email protected]87b0d82e2011-10-07 21:02:5973 public:
[email protected]b0079a92012-01-25 20:13:3874 // In compact window mode we fill the screen with a single maximized window,
[email protected]d2840ef2012-02-01 05:10:3675 // similar to ChromeOS R17 and earlier. In overlapping mode we have draggable
76 // windows. In managed mode the workspace arranges windows for the user.
[email protected]b0079a92012-01-25 20:13:3877 enum WindowMode {
[email protected]d2840ef2012-02-01 05:10:3678 MODE_COMPACT,
79 MODE_MANAGED,
80 MODE_OVERLAPPING,
[email protected]b0079a92012-01-25 20:13:3881 };
[email protected]87b0d82e2011-10-07 21:02:5982
[email protected]a8bd1cb2012-02-17 23:05:5483 enum BackgroundMode {
84 BACKGROUND_IMAGE,
85 BACKGROUND_SOLID_COLOR
86 };
87
[email protected]3d29912a2012-02-07 07:41:5188 enum Direction {
89 FORWARD,
90 BACKWARD
91 };
92
[email protected]2b4cd302012-02-24 20:21:1393 // Accesses private data from a Shell for testing.
94 class ASH_EXPORT TestApi {
95 public:
96 explicit TestApi(Shell* shell);
97
98 WindowMode ComputeWindowMode(CommandLine* cmd) const;
99 internal::RootWindowLayoutManager* root_window_layout();
100
101 private:
102 Shell* shell_; // not owned
103
104 DISALLOW_COPY_AND_ASSIGN(TestApi);
105 };
106
[email protected]3266c2b92011-11-14 00:06:08107 // A shell must be explicitly created so that it can call |Init()| with the
108 // delegate set. |delegate| can be NULL (if not required for initialization).
109 static Shell* CreateInstance(ShellDelegate* delegate);
110
111 // Should never be called before |CreateInstance()|.
[email protected]cac10fc62011-10-07 23:22:56112 static Shell* GetInstance();
[email protected]3266c2b92011-11-14 00:06:08113
[email protected]ef589af2011-12-03 01:07:15114 static void DeleteInstance();
[email protected]cac10fc62011-10-07 23:22:56115
[email protected]e73bd7802012-02-17 20:10:34116 // Get the singleton RootWindow used by the Shell.
117 static aura::RootWindow* GetRootWindow();
118
[email protected]0c4011b2012-02-11 02:10:42119 const gfx::Size& compact_status_area_offset() const {
120 return compact_status_area_offset_;
121 }
122
[email protected]a8bd1cb2012-02-17 23:05:54123 BackgroundMode desktop_background_mode() const {
124 return desktop_background_mode_;
125 }
126
[email protected]87b0d82e2011-10-07 21:02:59127 aura::Window* GetContainer(int container_id);
128 const aura::Window* GetContainer(int container_id) const;
129
[email protected]99f07e02011-12-07 00:02:59130 // Adds or removes |filter| from the RootWindowEventFilter.
131 void AddRootWindowEventFilter(aura::EventFilter* filter);
132 void RemoveRootWindowEventFilter(aura::EventFilter* filter);
[email protected]2c456102011-12-26 06:26:34133 size_t GetRootWindowEventFilterCount() const;
[email protected]e29014c2011-11-16 18:25:51134
[email protected]b5f30602012-01-30 15:16:57135 // Shows the background menu over |widget|.
136 void ShowBackgroundMenu(views::Widget* widget, const gfx::Point& location);
[email protected]cac10fc62011-10-07 23:22:56137
[email protected]ae4987d2011-11-21 22:52:44138 // Toggles app list.
139 void ToggleAppList();
140
[email protected]a8bd1cb2012-02-17 23:05:54141 // Sets the desktop background mode.
142 void SetDesktopBackgroundMode(BackgroundMode mode);
143
[email protected]f7eb89c2011-12-13 09:48:54144 // Returns true if the screen is locked.
145 bool IsScreenLocked() const;
146
[email protected]40c4cbb2012-01-10 23:26:07147 // Returns true if a modal dialog window is currently open.
148 bool IsModalWindowOpen() const;
149
[email protected]9c66adc2012-01-05 02:10:16150 // See enum WindowMode for details.
[email protected]d2840ef2012-02-01 05:10:36151 bool IsWindowModeCompact() const { return window_mode_ == MODE_COMPACT; }
[email protected]9c66adc2012-01-05 02:10:16152
[email protected]0c4011b2012-02-11 02:10:42153 // Sets the offset between the corner of the status area and the corner of the
154 // screen when we're using the compact window mode.
155 void SetCompactStatusAreaOffset(gfx::Size& offset);
156
[email protected]57b8bb352012-01-11 05:11:46157 // Creates a default views::NonClientFrameView for use by windows in the
158 // Ash environment.
159 views::NonClientFrameView* CreateDefaultNonClientFrameView(
160 views::Widget* widget);
161
[email protected]3d29912a2012-02-07 07:41:51162 // Rotate focus through containers that can recieve focus.
163 void RotateFocus(Direction direction);
164
[email protected]6e9f6aa2012-02-09 04:16:20165#if !defined(OS_MACOSX)
[email protected]2f744282011-12-23 22:40:52166 AcceleratorController* accelerator_controller() {
[email protected]745816be2011-11-22 05:08:30167 return accelerator_controller_.get();
168 }
[email protected]6e9f6aa2012-02-09 04:16:20169#endif // !defined(OS_MACOSX)
170
[email protected]627a62f2012-02-14 22:59:14171 internal::RootWindowEventFilter* root_filter() {
172 return root_filter_;
173 }
[email protected]862deef2011-12-15 22:07:33174 internal::TooltipController* tooltip_controller() {
175 return tooltip_controller_.get();
[email protected]4a229e902011-12-01 21:21:11176 }
[email protected]0b0b0742012-02-16 13:23:45177 internal::PartialScreenshotEventFilter* partial_screenshot_filter() {
178 return partial_screenshot_filter_.get();
179 }
[email protected]e0d22e82012-01-04 00:46:57180 PowerButtonController* power_button_controller() {
181 return power_button_controller_.get();
182 }
[email protected]6aa614a2012-01-19 22:13:38183 VideoDetector* video_detector() {
184 return video_detector_.get();
185 }
[email protected]40c4cbb2012-01-10 23:26:07186 WindowCycleController* window_cycle_controller() {
187 return window_cycle_controller_.get();
188 }
[email protected]4a229e902011-12-01 21:21:11189
[email protected]3266c2b92011-11-14 00:06:08190 ShellDelegate* delegate() { return delegate_.get(); }
[email protected]35304ce2011-12-14 23:21:01191
[email protected]671a2ae2011-10-13 21:53:23192 Launcher* launcher() { return launcher_.get(); }
193
[email protected]4e437632012-02-13 22:39:40194 internal::ShelfLayoutManager* shelf() const { return shelf_; }
195
[email protected]a54e65b2011-11-21 22:03:34196 // Made available for tests.
197 internal::ShadowController* shadow_controller() {
198 return shadow_controller_.get();
199 }
200
[email protected]2b4cd302012-02-24 20:21:13201 static void set_compact_window_mode_for_test(bool compact) {
202 compact_window_mode_for_test_ = compact;
203 }
[email protected]b0639282011-12-22 21:12:27204
[email protected]2b4cd302012-02-24 20:21:13205 private:
[email protected]cac10fc62011-10-07 23:22:56206 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
207
[email protected]3266c2b92011-11-14 00:06:08208 explicit Shell(ShellDelegate* delegate);
209 virtual ~Shell();
210
211 void Init();
[email protected]b0639282011-12-22 21:12:27212
[email protected]2b4cd302012-02-24 20:21:13213 // Returns the appropriate window mode to use based on the |command_line|
214 // and |compact_window_mode_for_test_|.
215 WindowMode ComputeWindowMode(CommandLine* command_line) const;
[email protected]b0639282011-12-22 21:12:27216
[email protected]b0079a92012-01-25 20:13:38217 // Initializes or re-initializes the layout managers and event filters needed
218 // to support a given window mode and cleans up the unneeded ones.
219 void SetupCompactWindowMode();
[email protected]d2840ef2012-02-01 05:10:36220 void SetupNonCompactWindowMode();
[email protected]46ca3632011-11-03 03:33:42221
[email protected]1b62b892012-01-17 17:08:15222 // Sets the LayoutManager of the container with the specified id to NULL. This
223 // has the effect of deleting the current LayoutManager.
224 void ResetLayoutManager(int container_id);
225
[email protected]cac10fc62011-10-07 23:22:56226 static Shell* instance_;
227
[email protected]2b4cd302012-02-24 20:21:13228 // Window mode is computed at shell initialization time, so allow it to be
229 // overridden without modifying the global command line.
230 static bool compact_window_mode_for_test_;
231
[email protected]627a62f2012-02-14 22:59:14232 internal::RootWindowEventFilter* root_filter_; // not owned
233
[email protected]cac10fc62011-10-07 23:22:56234 std::vector<WindowAndBoundsPair> to_restore_;
235
[email protected]6e9f6aa2012-02-09 04:16:20236#if !defined(OS_MACOSX)
[email protected]8f80db0f2012-02-07 14:44:53237 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
238
[email protected]2f744282011-12-23 22:40:52239 scoped_ptr<AcceleratorController> accelerator_controller_;
[email protected]6e9f6aa2012-02-09 04:16:20240#endif // !defined(OS_MACOSX)
[email protected]745816be2011-11-22 05:08:30241
[email protected]2b99f8c2011-10-11 19:42:24242 scoped_ptr<ShellDelegate> delegate_;
243
[email protected]671a2ae2011-10-13 21:53:23244 scoped_ptr<Launcher> launcher_;
245
[email protected]ae4987d2011-11-21 22:52:44246 scoped_ptr<internal::AppList> app_list_;
247
[email protected]ee1e1a22011-12-15 01:51:10248 scoped_ptr<internal::StackingController> stacking_controller_;
[email protected]9fc206d2011-12-13 00:05:33249 scoped_ptr<internal::ActivationController> activation_controller_;
[email protected]80373572012-01-06 23:14:30250 scoped_ptr<internal::WindowModalityController> window_modality_controller_;
[email protected]084b6bb2011-11-17 05:18:16251 scoped_ptr<internal::DragDropController> drag_drop_controller_;
[email protected]60fa9bba2011-10-28 21:21:51252 scoped_ptr<internal::WorkspaceController> workspace_controller_;
[email protected]a54e65b2011-11-21 22:03:34253 scoped_ptr<internal::ShadowController> shadow_controller_;
[email protected]862deef2011-12-15 22:07:33254 scoped_ptr<internal::TooltipController> tooltip_controller_;
[email protected]ddd91e92012-01-27 16:03:48255 scoped_ptr<internal::VisibilityController> visibility_controller_;
[email protected]e0d22e82012-01-04 00:46:57256 scoped_ptr<PowerButtonController> power_button_controller_;
[email protected]6aa614a2012-01-19 22:13:38257 scoped_ptr<VideoDetector> video_detector_;
[email protected]40c4cbb2012-01-10 23:26:07258 scoped_ptr<WindowCycleController> window_cycle_controller_;
[email protected]3d29912a2012-02-07 07:41:51259 scoped_ptr<internal::FocusCycler> focus_cycler_;
[email protected]ae18b9112011-11-07 16:59:13260
[email protected]2c456102011-12-26 06:26:34261 // An event filter that pre-handles all key events to send them to an IME.
262 scoped_ptr<internal::InputMethodEventFilter> input_method_filter_;
[email protected]6e9f6aa2012-02-09 04:16:20263
[email protected]0b0b0742012-02-16 13:23:45264 // An event filter that pre-handles key events while the partial
265 // screenshot UI is active.
266 scoped_ptr<internal::PartialScreenshotEventFilter> partial_screenshot_filter_;
267
[email protected]6e9f6aa2012-02-09 04:16:20268#if !defined(OS_MACOSX)
[email protected]745816be2011-11-22 05:08:30269 // An event filter that pre-handles global accelerators.
[email protected]2f744282011-12-23 22:40:52270 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
[email protected]6e9f6aa2012-02-09 04:16:20271#endif
[email protected]745816be2011-11-22 05:08:30272
[email protected]4e437632012-02-13 22:39:40273 // The shelf for managing the launcher and the status widget in non-compact
274 // mode. Shell does not own the shelf. Instead, it is owned by container of
275 // the status area.
276 internal::ShelfLayoutManager* shelf_;
277
[email protected]2b4cd302012-02-24 20:21:13278 // Does not change after Init().
[email protected]9c66adc2012-01-05 02:10:16279 WindowMode window_mode_;
[email protected]4a229e902011-12-01 21:21:11280
[email protected]a8bd1cb2012-02-17 23:05:54281 // Can change at runtime.
282 BackgroundMode desktop_background_mode_;
283
[email protected]b0079a92012-01-25 20:13:38284 // Owned by aura::RootWindow, cached here for type safety.
285 internal::RootWindowLayoutManager* root_window_layout_;
286
287 // Status area with clock, Wi-Fi signal, etc.
288 views::Widget* status_widget_;
289
[email protected]0c4011b2012-02-11 02:10:42290 // Offset between the corner of the status area and the corner of the screen
291 // when in the compact window mode.
292 gfx::Size compact_status_area_offset_;
293
[email protected]87b0d82e2011-10-07 21:02:59294 DISALLOW_COPY_AND_ASSIGN(Shell);
295};
296
[email protected]55f593352011-12-24 05:42:46297} // namespace ash
[email protected]87b0d82e2011-10-07 21:02:59298
[email protected]b65bdda2011-12-23 23:35:31299#endif // ASH_SHELL_H_