blob: 91ee69f39d3e3a3165177c76b082a93c005d16ae [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]1a2145b2012-03-13 21:09:1717#include "base/observer_list.h"
[email protected]0c4011b2012-02-11 02:10:4218#include "ui/gfx/size.h"
[email protected]1a2145b2012-03-13 21:09:1719#include "ui/gfx/insets.h"
[email protected]87b0d82e2011-10-07 21:02:5920
[email protected]b0639282011-12-22 21:12:2721class CommandLine;
[email protected]e70cf0ed2012-03-15 16:24:4722class SkBitmap;
[email protected]b0639282011-12-22 21:12:2723
[email protected]87b0d82e2011-10-07 21:02:5924namespace aura {
[email protected]e29014c2011-11-16 18:25:5125class EventFilter;
[email protected]e050ef142012-03-21 01:04:2426class Monitor;
[email protected]35304ce2011-12-14 23:21:0127class RootWindow;
[email protected]87b0d82e2011-10-07 21:02:5928class Window;
29}
[email protected]2b99f8c2011-10-11 19:42:2430namespace gfx {
[email protected]b5f30602012-01-30 15:16:5731class Point;
[email protected]cac10fc62011-10-07 23:22:5632class Rect;
33}
[email protected]a8bd1cb2012-02-17 23:05:5434namespace ui {
35class Layer;
36}
[email protected]57b8bb352012-01-11 05:11:4637namespace views {
38class NonClientFrameView;
39class Widget;
40}
[email protected]87b0d82e2011-10-07 21:02:5941
[email protected]55f593352011-12-24 05:42:4642namespace ash {
[email protected]87b0d82e2011-10-07 21:02:5943
[email protected]2f744282011-12-23 22:40:5244class AcceleratorController;
[email protected]e70cf0ed2012-03-15 16:24:4745class DesktopBackgroundController;
[email protected]671a2ae2011-10-13 21:53:2346class Launcher;
[email protected]8f80db0f2012-02-07 14:44:5347class NestedDispatcherController;
[email protected]e0d22e82012-01-04 00:46:5748class PowerButtonController;
[email protected]1a2145b2012-03-13 21:09:1749class ScreenAsh;
[email protected]2b99f8c2011-10-11 19:42:2450class ShellDelegate;
[email protected]1a2145b2012-03-13 21:09:1751class ShellObserver;
[email protected]bfb411312012-02-27 20:59:2752class SystemTrayDelegate;
53class SystemTray;
[email protected]6aa614a2012-01-19 22:13:3854class VideoDetector;
[email protected]40c4cbb2012-01-10 23:26:0755class WindowCycleController;
[email protected]60fa9bba2011-10-28 21:21:5156
57namespace internal {
[email protected]9fc206d2011-12-13 00:05:3358class ActivationController;
[email protected]2f744282011-12-23 22:40:5259class AcceleratorFilter;
[email protected]ae4987d2011-11-21 22:52:4460class AppList;
[email protected]084b6bb2011-11-17 05:18:1661class DragDropController;
[email protected]3d29912a2012-02-07 07:41:5162class FocusCycler;
[email protected]2c456102011-12-26 06:26:3463class InputMethodEventFilter;
[email protected]e050ef142012-03-21 01:04:2464class MonitorController;
[email protected]0b0b0742012-02-16 13:23:4565class PartialScreenshotEventFilter;
[email protected]e4a181cc2012-03-17 02:20:5766class ResizeShadowController;
[email protected]627a62f2012-02-14 22:59:1467class RootWindowEventFilter;
[email protected]b0079a92012-01-25 20:13:3868class RootWindowLayoutManager;
[email protected]a54e65b2011-11-21 22:03:3469class ShadowController;
[email protected]4e437632012-02-13 22:39:4070class ShelfLayoutManager;
[email protected]ee1e1a22011-12-15 01:51:1071class StackingController;
[email protected]862deef2011-12-15 22:07:3372class TooltipController;
[email protected]ddd91e92012-01-27 16:03:4873class VisibilityController;
[email protected]80373572012-01-06 23:14:3074class WindowModalityController;
[email protected]60fa9bba2011-10-28 21:21:5175class WorkspaceController;
76}
[email protected]2b99f8c2011-10-11 19:42:2477
[email protected]87b0d82e2011-10-07 21:02:5978// Shell is a singleton object that presents the Shell API and implements the
[email protected]99f07e02011-12-07 00:02:5979// RootWindow's delegate interface.
[email protected]b0079a92012-01-25 20:13:3880//
81// Upon creation, the Shell sets itself as the RootWindow's delegate, which
82// takes ownership of the Shell.
[email protected]e050ef142012-03-21 01:04:2483class ASH_EXPORT Shell {
[email protected]87b0d82e2011-10-07 21:02:5984 public:
[email protected]3d29912a2012-02-07 07:41:5185 enum Direction {
86 FORWARD,
87 BACKWARD
88 };
89
[email protected]2b4cd302012-02-24 20:21:1390 // Accesses private data from a Shell for testing.
91 class ASH_EXPORT TestApi {
92 public:
93 explicit TestApi(Shell* shell);
94
[email protected]2b4cd302012-02-24 20:21:1395 internal::RootWindowLayoutManager* root_window_layout();
[email protected]db9131602012-02-29 19:06:3296 internal::InputMethodEventFilter* input_method_event_filter();
97 internal::WorkspaceController* workspace_controller();
[email protected]2b4cd302012-02-24 20:21:1398
99 private:
100 Shell* shell_; // not owned
101
102 DISALLOW_COPY_AND_ASSIGN(TestApi);
103 };
104
[email protected]3266c2b92011-11-14 00:06:08105 // A shell must be explicitly created so that it can call |Init()| with the
106 // delegate set. |delegate| can be NULL (if not required for initialization).
107 static Shell* CreateInstance(ShellDelegate* delegate);
108
109 // Should never be called before |CreateInstance()|.
[email protected]cac10fc62011-10-07 23:22:56110 static Shell* GetInstance();
[email protected]3266c2b92011-11-14 00:06:08111
[email protected]b3b7bcd2012-03-06 19:35:45112 // Returns true if the ash shell has been instantiated.
113 static bool HasInstance();
114
[email protected]ef589af2011-12-03 01:07:15115 static void DeleteInstance();
[email protected]cac10fc62011-10-07 23:22:56116
[email protected]63ef21592012-03-21 01:15:40117 // Get the singleton RootWindow used by the Shell.
[email protected]e73bd7802012-02-17 20:10:34118 static aura::RootWindow* GetRootWindow();
119
[email protected]e70cf0ed2012-03-15 16:24:47120 internal::RootWindowLayoutManager* root_window_layout() const {
121 return root_window_layout_;
[email protected]a8bd1cb2012-02-17 23:05:54122 }
123
[email protected]87b0d82e2011-10-07 21:02:59124 aura::Window* GetContainer(int container_id);
125 const aura::Window* GetContainer(int container_id) const;
126
[email protected]99f07e02011-12-07 00:02:59127 // Adds or removes |filter| from the RootWindowEventFilter.
128 void AddRootWindowEventFilter(aura::EventFilter* filter);
129 void RemoveRootWindowEventFilter(aura::EventFilter* filter);
[email protected]2c456102011-12-26 06:26:34130 size_t GetRootWindowEventFilterCount() const;
[email protected]e29014c2011-11-16 18:25:51131
[email protected]b5f30602012-01-30 15:16:57132 // Shows the background menu over |widget|.
133 void ShowBackgroundMenu(views::Widget* widget, const gfx::Point& location);
[email protected]cac10fc62011-10-07 23:22:56134
[email protected]ae4987d2011-11-21 22:52:44135 // Toggles app list.
136 void ToggleAppList();
137
[email protected]f7eb89c2011-12-13 09:48:54138 // Returns true if the screen is locked.
139 bool IsScreenLocked() const;
140
[email protected]40c4cbb2012-01-10 23:26:07141 // Returns true if a modal dialog window is currently open.
142 bool IsModalWindowOpen() const;
143
[email protected]57b8bb352012-01-11 05:11:46144 // Creates a default views::NonClientFrameView for use by windows in the
145 // Ash environment.
146 views::NonClientFrameView* CreateDefaultNonClientFrameView(
147 views::Widget* widget);
148
[email protected]63ef21592012-03-21 01:15:40149 // Rotate focus through containers that can receive focus.
[email protected]3d29912a2012-02-07 07:41:51150 void RotateFocus(Direction direction);
151
[email protected]8a45c972012-03-14 18:22:44152 // Sets the work area insets of the monitor that contains |window|,
153 // this notifies observers too.
[email protected]27f6af62012-03-21 05:34:40154 // TODO(sky): this no longer really replicates what happens and is unreliable.
155 // Remove this.
[email protected]8a45c972012-03-14 18:22:44156 void SetMonitorWorkAreaInsets(aura::Window* window,
157 const gfx::Insets& insets);
[email protected]1a2145b2012-03-13 21:09:17158
[email protected]63ef21592012-03-21 01:15:40159 // Add/remove observer.
[email protected]1a2145b2012-03-13 21:09:17160 void AddShellObserver(ShellObserver* observer);
161 void RemoveShellObserver(ShellObserver* observer);
162
[email protected]6e9f6aa2012-02-09 04:16:20163#if !defined(OS_MACOSX)
[email protected]2f744282011-12-23 22:40:52164 AcceleratorController* accelerator_controller() {
[email protected]745816be2011-11-22 05:08:30165 return accelerator_controller_.get();
166 }
[email protected]6e9f6aa2012-02-09 04:16:20167#endif // !defined(OS_MACOSX)
168
[email protected]627a62f2012-02-14 22:59:14169 internal::RootWindowEventFilter* root_filter() {
170 return root_filter_;
171 }
[email protected]862deef2011-12-15 22:07:33172 internal::TooltipController* tooltip_controller() {
173 return tooltip_controller_.get();
[email protected]4a229e902011-12-01 21:21:11174 }
[email protected]0b0b0742012-02-16 13:23:45175 internal::PartialScreenshotEventFilter* partial_screenshot_filter() {
176 return partial_screenshot_filter_.get();
177 }
[email protected]e70cf0ed2012-03-15 16:24:47178 DesktopBackgroundController* desktop_background_controller() {
179 return desktop_background_controller_.get();
180 }
[email protected]e0d22e82012-01-04 00:46:57181 PowerButtonController* power_button_controller() {
182 return power_button_controller_.get();
183 }
[email protected]6aa614a2012-01-19 22:13:38184 VideoDetector* video_detector() {
185 return video_detector_.get();
186 }
[email protected]40c4cbb2012-01-10 23:26:07187 WindowCycleController* window_cycle_controller() {
188 return window_cycle_controller_.get();
189 }
[email protected]2d511542012-03-07 09:13:34190 internal::FocusCycler* focus_cycler() {
191 return focus_cycler_.get();
192 }
[email protected]4a229e902011-12-01 21:21:11193
[email protected]3266c2b92011-11-14 00:06:08194 ShellDelegate* delegate() { return delegate_.get(); }
[email protected]bfb411312012-02-27 20:59:27195 SystemTrayDelegate* tray_delegate() { return tray_delegate_.get(); }
[email protected]35304ce2011-12-14 23:21:01196
[email protected]671a2ae2011-10-13 21:53:23197 Launcher* launcher() { return launcher_.get(); }
198
[email protected]1a2145b2012-03-13 21:09:17199 const ScreenAsh* screen() { return screen_; }
200
[email protected]4e437632012-02-13 22:39:40201 internal::ShelfLayoutManager* shelf() const { return shelf_; }
202
[email protected]bfb411312012-02-27 20:59:27203 SystemTray* tray() const { return tray_.get(); }
204
[email protected]85d43f02012-03-14 21:11:19205 // Returns the size of the grid.
206 int GetGridSize() const;
207
[email protected]9488d4d2012-02-29 18:32:37208 static void set_initially_hide_cursor(bool hide) {
209 initially_hide_cursor_ = hide;
210 }
211
[email protected]e4a181cc2012-03-17 02:20:57212 internal::ResizeShadowController* resize_shadow_controller() {
213 return resize_shadow_controller_.get();
214 }
215
[email protected]a54e65b2011-11-21 22:03:34216 // Made available for tests.
217 internal::ShadowController* shadow_controller() {
218 return shadow_controller_.get();
219 }
220
[email protected]2b4cd302012-02-24 20:21:13221 private:
[email protected]ad0c8722012-03-02 20:17:45222 FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, MouseEventCursors);
223 FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, TransformActivate);
224
[email protected]cac10fc62011-10-07 23:22:56225 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
226
[email protected]3266c2b92011-11-14 00:06:08227 explicit Shell(ShellDelegate* delegate);
228 virtual ~Shell();
229
230 void Init();
[email protected]b0639282011-12-22 21:12:27231
[email protected]c73d1332012-03-08 17:11:04232 // Initializes the layout managers and event filters.
233 void InitLayoutManagers();
[email protected]1b62b892012-01-17 17:08:15234
[email protected]ad0c8722012-03-02 20:17:45235 // Disables the workspace grid layout.
236 void DisableWorkspaceGridLayout();
237
[email protected]cac10fc62011-10-07 23:22:56238 static Shell* instance_;
239
[email protected]9488d4d2012-02-29 18:32:37240 // If set before the Shell is initialized, the mouse cursor will be hidden
241 // when the screen is initially created.
242 static bool initially_hide_cursor_;
243
[email protected]58482fa2012-03-02 14:57:39244 scoped_ptr<aura::RootWindow> root_window_;
[email protected]1a2145b2012-03-13 21:09:17245 ScreenAsh* screen_;
[email protected]58482fa2012-03-02 14:57:39246
[email protected]627a62f2012-02-14 22:59:14247 internal::RootWindowEventFilter* root_filter_; // not owned
248
[email protected]cac10fc62011-10-07 23:22:56249 std::vector<WindowAndBoundsPair> to_restore_;
250
[email protected]6e9f6aa2012-02-09 04:16:20251#if !defined(OS_MACOSX)
[email protected]8f80db0f2012-02-07 14:44:53252 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
253
[email protected]2f744282011-12-23 22:40:52254 scoped_ptr<AcceleratorController> accelerator_controller_;
[email protected]6e9f6aa2012-02-09 04:16:20255#endif // !defined(OS_MACOSX)
[email protected]745816be2011-11-22 05:08:30256
[email protected]2b99f8c2011-10-11 19:42:24257 scoped_ptr<ShellDelegate> delegate_;
[email protected]bfb411312012-02-27 20:59:27258 scoped_ptr<SystemTrayDelegate> tray_delegate_;
[email protected]2b99f8c2011-10-11 19:42:24259
[email protected]671a2ae2011-10-13 21:53:23260 scoped_ptr<Launcher> launcher_;
261
[email protected]ae4987d2011-11-21 22:52:44262 scoped_ptr<internal::AppList> app_list_;
263
[email protected]ee1e1a22011-12-15 01:51:10264 scoped_ptr<internal::StackingController> stacking_controller_;
[email protected]9fc206d2011-12-13 00:05:33265 scoped_ptr<internal::ActivationController> activation_controller_;
[email protected]80373572012-01-06 23:14:30266 scoped_ptr<internal::WindowModalityController> window_modality_controller_;
[email protected]084b6bb2011-11-17 05:18:16267 scoped_ptr<internal::DragDropController> drag_drop_controller_;
[email protected]60fa9bba2011-10-28 21:21:51268 scoped_ptr<internal::WorkspaceController> workspace_controller_;
[email protected]e4a181cc2012-03-17 02:20:57269 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
[email protected]a54e65b2011-11-21 22:03:34270 scoped_ptr<internal::ShadowController> shadow_controller_;
[email protected]862deef2011-12-15 22:07:33271 scoped_ptr<internal::TooltipController> tooltip_controller_;
[email protected]ddd91e92012-01-27 16:03:48272 scoped_ptr<internal::VisibilityController> visibility_controller_;
[email protected]e70cf0ed2012-03-15 16:24:47273 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
[email protected]e0d22e82012-01-04 00:46:57274 scoped_ptr<PowerButtonController> power_button_controller_;
[email protected]6aa614a2012-01-19 22:13:38275 scoped_ptr<VideoDetector> video_detector_;
[email protected]40c4cbb2012-01-10 23:26:07276 scoped_ptr<WindowCycleController> window_cycle_controller_;
[email protected]3d29912a2012-02-07 07:41:51277 scoped_ptr<internal::FocusCycler> focus_cycler_;
[email protected]e050ef142012-03-21 01:04:24278 scoped_ptr<internal::MonitorController> monitor_controller_;
[email protected]ae18b9112011-11-07 16:59:13279
[email protected]2c456102011-12-26 06:26:34280 // An event filter that pre-handles all key events to send them to an IME.
281 scoped_ptr<internal::InputMethodEventFilter> input_method_filter_;
[email protected]6e9f6aa2012-02-09 04:16:20282
[email protected]0b0b0742012-02-16 13:23:45283 // An event filter that pre-handles key events while the partial
284 // screenshot UI is active.
285 scoped_ptr<internal::PartialScreenshotEventFilter> partial_screenshot_filter_;
286
[email protected]6e9f6aa2012-02-09 04:16:20287#if !defined(OS_MACOSX)
[email protected]745816be2011-11-22 05:08:30288 // An event filter that pre-handles global accelerators.
[email protected]2f744282011-12-23 22:40:52289 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
[email protected]6e9f6aa2012-02-09 04:16:20290#endif
[email protected]745816be2011-11-22 05:08:30291
[email protected]4e437632012-02-13 22:39:40292 // The shelf for managing the launcher and the status widget in non-compact
293 // mode. Shell does not own the shelf. Instead, it is owned by container of
294 // the status area.
295 internal::ShelfLayoutManager* shelf_;
296
[email protected]1a2145b2012-03-13 21:09:17297 ObserverList<ShellObserver> observers_;
298
[email protected]b0079a92012-01-25 20:13:38299 // Owned by aura::RootWindow, cached here for type safety.
300 internal::RootWindowLayoutManager* root_window_layout_;
301
302 // Status area with clock, Wi-Fi signal, etc.
303 views::Widget* status_widget_;
304
[email protected]bfb411312012-02-27 20:59:27305 // System tray with clock, Wi-Fi signal, etc. (a replacement in progress for
306 // |status_widget_|).
307 scoped_ptr<SystemTray> tray_;
308
[email protected]87b0d82e2011-10-07 21:02:59309 DISALLOW_COPY_AND_ASSIGN(Shell);
310};
311
[email protected]55f593352011-12-24 05:42:46312} // namespace ash
[email protected]87b0d82e2011-10-07 21:02:59313
[email protected]b65bdda2011-12-23 23:35:31314#endif // ASH_SHELL_H_