blob: 62d08d351be7528aa6d24d9f17fcd3b0c5d03f60 [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]b0639282011-12-22 21:12:2714#include "base/gtest_prod_util.h"
[email protected]2b99f8c2011-10-11 19:42:2415#include "base/memory/scoped_ptr.h"
[email protected]87b0d82e2011-10-07 21:02:5916#include "base/compiler_specific.h"
[email protected]f296be72011-10-11 15:40:0017#include "base/memory/weak_ptr.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;
[email protected]b0639282011-12-22 21:12:2729class Size;
[email protected]cac10fc62011-10-07 23:22:5630}
[email protected]57b8bb352012-01-11 05:11:4631namespace views {
32class NonClientFrameView;
33class Widget;
34}
[email protected]87b0d82e2011-10-07 21:02:5935
[email protected]55f593352011-12-24 05:42:4636namespace ash {
[email protected]87b0d82e2011-10-07 21:02:5937
[email protected]2f744282011-12-23 22:40:5238class AcceleratorController;
[email protected]671a2ae2011-10-13 21:53:2339class Launcher;
[email protected]8f80db0f2012-02-07 14:44:5340class NestedDispatcherController;
[email protected]e0d22e82012-01-04 00:46:5741class PowerButtonController;
[email protected]2b99f8c2011-10-11 19:42:2442class ShellDelegate;
[email protected]6aa614a2012-01-19 22:13:3843class VideoDetector;
[email protected]40c4cbb2012-01-10 23:26:0744class WindowCycleController;
[email protected]60fa9bba2011-10-28 21:21:5145
46namespace internal {
[email protected]9fc206d2011-12-13 00:05:3347class ActivationController;
[email protected]2f744282011-12-23 22:40:5248class AcceleratorFilter;
[email protected]ae4987d2011-11-21 22:52:4449class AppList;
[email protected]084b6bb2011-11-17 05:18:1650class DragDropController;
[email protected]3d29912a2012-02-07 07:41:5151class FocusCycler;
[email protected]2c456102011-12-26 06:26:3452class InputMethodEventFilter;
[email protected]b0079a92012-01-25 20:13:3853class RootWindowLayoutManager;
[email protected]a54e65b2011-11-21 22:03:3454class ShadowController;
[email protected]ee1e1a22011-12-15 01:51:1055class StackingController;
[email protected]862deef2011-12-15 22:07:3356class TooltipController;
[email protected]ddd91e92012-01-27 16:03:4857class VisibilityController;
[email protected]80373572012-01-06 23:14:3058class WindowModalityController;
[email protected]60fa9bba2011-10-28 21:21:5159class WorkspaceController;
60}
[email protected]2b99f8c2011-10-11 19:42:2461
[email protected]87b0d82e2011-10-07 21:02:5962// Shell is a singleton object that presents the Shell API and implements the
[email protected]99f07e02011-12-07 00:02:5963// RootWindow's delegate interface.
[email protected]b0079a92012-01-25 20:13:3864//
65// Upon creation, the Shell sets itself as the RootWindow's delegate, which
66// takes ownership of the Shell.
[email protected]b65bdda2011-12-23 23:35:3167class ASH_EXPORT Shell {
[email protected]87b0d82e2011-10-07 21:02:5968 public:
[email protected]b0079a92012-01-25 20:13:3869 // In compact window mode we fill the screen with a single maximized window,
[email protected]d2840ef2012-02-01 05:10:3670 // similar to ChromeOS R17 and earlier. In overlapping mode we have draggable
71 // windows. In managed mode the workspace arranges windows for the user.
[email protected]b0079a92012-01-25 20:13:3872 enum WindowMode {
[email protected]d2840ef2012-02-01 05:10:3673 MODE_COMPACT,
74 MODE_MANAGED,
75 MODE_OVERLAPPING,
[email protected]b0079a92012-01-25 20:13:3876 };
[email protected]87b0d82e2011-10-07 21:02:5977
[email protected]3d29912a2012-02-07 07:41:5178 enum Direction {
79 FORWARD,
80 BACKWARD
81 };
82
[email protected]3266c2b92011-11-14 00:06:0883 // A shell must be explicitly created so that it can call |Init()| with the
84 // delegate set. |delegate| can be NULL (if not required for initialization).
85 static Shell* CreateInstance(ShellDelegate* delegate);
86
87 // Should never be called before |CreateInstance()|.
[email protected]cac10fc62011-10-07 23:22:5688 static Shell* GetInstance();
[email protected]3266c2b92011-11-14 00:06:0889
[email protected]ef589af2011-12-03 01:07:1590 static void DeleteInstance();
[email protected]cac10fc62011-10-07 23:22:5691
[email protected]87b0d82e2011-10-07 21:02:5992 aura::Window* GetContainer(int container_id);
93 const aura::Window* GetContainer(int container_id) const;
94
[email protected]99f07e02011-12-07 00:02:5995 // Adds or removes |filter| from the RootWindowEventFilter.
96 void AddRootWindowEventFilter(aura::EventFilter* filter);
97 void RemoveRootWindowEventFilter(aura::EventFilter* filter);
[email protected]2c456102011-12-26 06:26:3498 size_t GetRootWindowEventFilterCount() const;
[email protected]e29014c2011-11-16 18:25:5199
[email protected]b5f30602012-01-30 15:16:57100 // Shows the background menu over |widget|.
101 void ShowBackgroundMenu(views::Widget* widget, const gfx::Point& location);
[email protected]cac10fc62011-10-07 23:22:56102
[email protected]ae4987d2011-11-21 22:52:44103 // Toggles app list.
104 void ToggleAppList();
105
[email protected]b0079a92012-01-25 20:13:38106 // Changes the current window mode, which will cause all the open windows
107 // to be laid out in the new mode and layout managers and event filters to be
108 // installed or removed.
109 void ChangeWindowMode(WindowMode mode);
110
[email protected]615922f2012-02-07 02:41:15111 // Sets an appropriate window mode for the given screen resolution.
112 void SetWindowModeForMonitorSize(const gfx::Size& monitor_size);
113
[email protected]f7eb89c2011-12-13 09:48:54114 // Returns true if the screen is locked.
115 bool IsScreenLocked() const;
116
[email protected]40c4cbb2012-01-10 23:26:07117 // Returns true if a modal dialog window is currently open.
118 bool IsModalWindowOpen() const;
119
[email protected]9c66adc2012-01-05 02:10:16120 // See enum WindowMode for details.
[email protected]d2840ef2012-02-01 05:10:36121 bool IsWindowModeCompact() const { return window_mode_ == MODE_COMPACT; }
[email protected]9c66adc2012-01-05 02:10:16122
[email protected]57b8bb352012-01-11 05:11:46123 // Creates a default views::NonClientFrameView for use by windows in the
124 // Ash environment.
125 views::NonClientFrameView* CreateDefaultNonClientFrameView(
126 views::Widget* widget);
127
[email protected]3d29912a2012-02-07 07:41:51128 // Rotate focus through containers that can recieve focus.
129 void RotateFocus(Direction direction);
130
[email protected]6e9f6aa2012-02-09 04:16:20131#if !defined(OS_MACOSX)
[email protected]2f744282011-12-23 22:40:52132 AcceleratorController* accelerator_controller() {
[email protected]745816be2011-11-22 05:08:30133 return accelerator_controller_.get();
134 }
[email protected]6e9f6aa2012-02-09 04:16:20135#endif // !defined(OS_MACOSX)
136
[email protected]862deef2011-12-15 22:07:33137 internal::TooltipController* tooltip_controller() {
138 return tooltip_controller_.get();
[email protected]4a229e902011-12-01 21:21:11139 }
[email protected]e0d22e82012-01-04 00:46:57140 PowerButtonController* power_button_controller() {
141 return power_button_controller_.get();
142 }
[email protected]6aa614a2012-01-19 22:13:38143 VideoDetector* video_detector() {
144 return video_detector_.get();
145 }
[email protected]40c4cbb2012-01-10 23:26:07146 WindowCycleController* window_cycle_controller() {
147 return window_cycle_controller_.get();
148 }
[email protected]4a229e902011-12-01 21:21:11149
[email protected]3266c2b92011-11-14 00:06:08150 ShellDelegate* delegate() { return delegate_.get(); }
[email protected]35304ce2011-12-14 23:21:01151
[email protected]671a2ae2011-10-13 21:53:23152 Launcher* launcher() { return launcher_.get(); }
153
[email protected]a54e65b2011-11-21 22:03:34154 // Made available for tests.
155 internal::ShadowController* shadow_controller() {
156 return shadow_controller_.get();
157 }
158
[email protected]cac10fc62011-10-07 23:22:56159 private:
[email protected]9c66adc2012-01-05 02:10:16160 FRIEND_TEST_ALL_PREFIXES(ShellTest, ComputeWindowMode);
[email protected]b0079a92012-01-25 20:13:38161 FRIEND_TEST_ALL_PREFIXES(ShellTest, ChangeWindowMode);
[email protected]b0639282011-12-22 21:12:27162
[email protected]cac10fc62011-10-07 23:22:56163 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
164
[email protected]3266c2b92011-11-14 00:06:08165 explicit Shell(ShellDelegate* delegate);
166 virtual ~Shell();
167
168 void Init();
[email protected]b0639282011-12-22 21:12:27169
[email protected]9c66adc2012-01-05 02:10:16170 // Returns the appropriate window mode to use based on the primary monitor's
171 // |monitor_size| and the user's |command_line|.
172 WindowMode ComputeWindowMode(const gfx::Size& monitor_size,
173 CommandLine* command_line) const;
[email protected]b0639282011-12-22 21:12:27174
[email protected]b0079a92012-01-25 20:13:38175 // Initializes or re-initializes the layout managers and event filters needed
176 // to support a given window mode and cleans up the unneeded ones.
177 void SetupCompactWindowMode();
[email protected]d2840ef2012-02-01 05:10:36178 void SetupNonCompactWindowMode();
[email protected]46ca3632011-11-03 03:33:42179
[email protected]1b62b892012-01-17 17:08:15180 // Sets the LayoutManager of the container with the specified id to NULL. This
181 // has the effect of deleting the current LayoutManager.
182 void ResetLayoutManager(int container_id);
183
[email protected]cac10fc62011-10-07 23:22:56184 static Shell* instance_;
185
186 std::vector<WindowAndBoundsPair> to_restore_;
187
[email protected]f296be72011-10-11 15:40:00188 base::WeakPtrFactory<Shell> method_factory_;
[email protected]cac10fc62011-10-07 23:22:56189
[email protected]6e9f6aa2012-02-09 04:16:20190#if !defined(OS_MACOSX)
[email protected]8f80db0f2012-02-07 14:44:53191 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
192
[email protected]2f744282011-12-23 22:40:52193 scoped_ptr<AcceleratorController> accelerator_controller_;
[email protected]6e9f6aa2012-02-09 04:16:20194#endif // !defined(OS_MACOSX)
[email protected]745816be2011-11-22 05:08:30195
[email protected]2b99f8c2011-10-11 19:42:24196 scoped_ptr<ShellDelegate> delegate_;
197
[email protected]671a2ae2011-10-13 21:53:23198 scoped_ptr<Launcher> launcher_;
199
[email protected]ae4987d2011-11-21 22:52:44200 scoped_ptr<internal::AppList> app_list_;
201
[email protected]ee1e1a22011-12-15 01:51:10202 scoped_ptr<internal::StackingController> stacking_controller_;
[email protected]9fc206d2011-12-13 00:05:33203 scoped_ptr<internal::ActivationController> activation_controller_;
[email protected]80373572012-01-06 23:14:30204 scoped_ptr<internal::WindowModalityController> window_modality_controller_;
[email protected]084b6bb2011-11-17 05:18:16205 scoped_ptr<internal::DragDropController> drag_drop_controller_;
[email protected]60fa9bba2011-10-28 21:21:51206 scoped_ptr<internal::WorkspaceController> workspace_controller_;
[email protected]a54e65b2011-11-21 22:03:34207 scoped_ptr<internal::ShadowController> shadow_controller_;
[email protected]862deef2011-12-15 22:07:33208 scoped_ptr<internal::TooltipController> tooltip_controller_;
[email protected]ddd91e92012-01-27 16:03:48209 scoped_ptr<internal::VisibilityController> visibility_controller_;
[email protected]e0d22e82012-01-04 00:46:57210 scoped_ptr<PowerButtonController> power_button_controller_;
[email protected]6aa614a2012-01-19 22:13:38211 scoped_ptr<VideoDetector> video_detector_;
[email protected]40c4cbb2012-01-10 23:26:07212 scoped_ptr<WindowCycleController> window_cycle_controller_;
[email protected]3d29912a2012-02-07 07:41:51213 scoped_ptr<internal::FocusCycler> focus_cycler_;
[email protected]ae18b9112011-11-07 16:59:13214
[email protected]2c456102011-12-26 06:26:34215 // An event filter that pre-handles all key events to send them to an IME.
216 scoped_ptr<internal::InputMethodEventFilter> input_method_filter_;
[email protected]6e9f6aa2012-02-09 04:16:20217
218#if !defined(OS_MACOSX)
[email protected]745816be2011-11-22 05:08:30219 // An event filter that pre-handles global accelerators.
[email protected]2f744282011-12-23 22:40:52220 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
[email protected]6e9f6aa2012-02-09 04:16:20221#endif
[email protected]745816be2011-11-22 05:08:30222
[email protected]b0079a92012-01-25 20:13:38223 // Can change at runtime.
[email protected]9c66adc2012-01-05 02:10:16224 WindowMode window_mode_;
[email protected]4a229e902011-12-01 21:21:11225
[email protected]b0079a92012-01-25 20:13:38226 // Owned by aura::RootWindow, cached here for type safety.
227 internal::RootWindowLayoutManager* root_window_layout_;
228
229 // Status area with clock, Wi-Fi signal, etc.
230 views::Widget* status_widget_;
231
[email protected]87b0d82e2011-10-07 21:02:59232 DISALLOW_COPY_AND_ASSIGN(Shell);
233};
234
[email protected]55f593352011-12-24 05:42:46235} // namespace ash
[email protected]87b0d82e2011-10-07 21:02:59236
[email protected]b65bdda2011-12-23 23:35:31237#endif // ASH_SHELL_H_