blob: 374015d00b96f051a79e2c1d42431a58d10b4f38 [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]e0d22e82012-01-04 00:46:5740class PowerButtonController;
[email protected]2b99f8c2011-10-11 19:42:2441class ShellDelegate;
[email protected]6aa614a2012-01-19 22:13:3842class VideoDetector;
[email protected]40c4cbb2012-01-10 23:26:0743class WindowCycleController;
[email protected]60fa9bba2011-10-28 21:21:5144
45namespace internal {
[email protected]9fc206d2011-12-13 00:05:3346class ActivationController;
[email protected]2f744282011-12-23 22:40:5247class AcceleratorFilter;
[email protected]ae4987d2011-11-21 22:52:4448class AppList;
[email protected]084b6bb2011-11-17 05:18:1649class DragDropController;
[email protected]3d29912a2012-02-07 07:41:5150class FocusCycler;
[email protected]2c456102011-12-26 06:26:3451class InputMethodEventFilter;
[email protected]b0079a92012-01-25 20:13:3852class RootWindowLayoutManager;
[email protected]a54e65b2011-11-21 22:03:3453class ShadowController;
[email protected]ee1e1a22011-12-15 01:51:1054class StackingController;
[email protected]862deef2011-12-15 22:07:3355class TooltipController;
[email protected]ddd91e92012-01-27 16:03:4856class VisibilityController;
[email protected]80373572012-01-06 23:14:3057class WindowModalityController;
[email protected]60fa9bba2011-10-28 21:21:5158class WorkspaceController;
59}
[email protected]2b99f8c2011-10-11 19:42:2460
[email protected]87b0d82e2011-10-07 21:02:5961// Shell is a singleton object that presents the Shell API and implements the
[email protected]99f07e02011-12-07 00:02:5962// RootWindow's delegate interface.
[email protected]b0079a92012-01-25 20:13:3863//
64// Upon creation, the Shell sets itself as the RootWindow's delegate, which
65// takes ownership of the Shell.
[email protected]b65bdda2011-12-23 23:35:3166class ASH_EXPORT Shell {
[email protected]87b0d82e2011-10-07 21:02:5967 public:
[email protected]b0079a92012-01-25 20:13:3868 // In compact window mode we fill the screen with a single maximized window,
[email protected]d2840ef2012-02-01 05:10:3669 // similar to ChromeOS R17 and earlier. In overlapping mode we have draggable
70 // windows. In managed mode the workspace arranges windows for the user.
[email protected]b0079a92012-01-25 20:13:3871 enum WindowMode {
[email protected]d2840ef2012-02-01 05:10:3672 MODE_COMPACT,
73 MODE_MANAGED,
74 MODE_OVERLAPPING,
[email protected]b0079a92012-01-25 20:13:3875 };
[email protected]87b0d82e2011-10-07 21:02:5976
[email protected]3d29912a2012-02-07 07:41:5177 enum Direction {
78 FORWARD,
79 BACKWARD
80 };
81
[email protected]3266c2b92011-11-14 00:06:0882 // A shell must be explicitly created so that it can call |Init()| with the
83 // delegate set. |delegate| can be NULL (if not required for initialization).
84 static Shell* CreateInstance(ShellDelegate* delegate);
85
86 // Should never be called before |CreateInstance()|.
[email protected]cac10fc62011-10-07 23:22:5687 static Shell* GetInstance();
[email protected]3266c2b92011-11-14 00:06:0888
[email protected]ef589af2011-12-03 01:07:1589 static void DeleteInstance();
[email protected]cac10fc62011-10-07 23:22:5690
[email protected]87b0d82e2011-10-07 21:02:5991 aura::Window* GetContainer(int container_id);
92 const aura::Window* GetContainer(int container_id) const;
93
[email protected]99f07e02011-12-07 00:02:5994 // Adds or removes |filter| from the RootWindowEventFilter.
95 void AddRootWindowEventFilter(aura::EventFilter* filter);
96 void RemoveRootWindowEventFilter(aura::EventFilter* filter);
[email protected]2c456102011-12-26 06:26:3497 size_t GetRootWindowEventFilterCount() const;
[email protected]e29014c2011-11-16 18:25:5198
[email protected]b5f30602012-01-30 15:16:5799 // Shows the background menu over |widget|.
100 void ShowBackgroundMenu(views::Widget* widget, const gfx::Point& location);
[email protected]cac10fc62011-10-07 23:22:56101
[email protected]ae4987d2011-11-21 22:52:44102 // Toggles app list.
103 void ToggleAppList();
104
[email protected]b0079a92012-01-25 20:13:38105 // Changes the current window mode, which will cause all the open windows
106 // to be laid out in the new mode and layout managers and event filters to be
107 // installed or removed.
108 void ChangeWindowMode(WindowMode mode);
109
[email protected]615922f2012-02-07 02:41:15110 // Sets an appropriate window mode for the given screen resolution.
111 void SetWindowModeForMonitorSize(const gfx::Size& monitor_size);
112
[email protected]f7eb89c2011-12-13 09:48:54113 // Returns true if the screen is locked.
114 bool IsScreenLocked() const;
115
[email protected]40c4cbb2012-01-10 23:26:07116 // Returns true if a modal dialog window is currently open.
117 bool IsModalWindowOpen() const;
118
[email protected]9c66adc2012-01-05 02:10:16119 // See enum WindowMode for details.
[email protected]d2840ef2012-02-01 05:10:36120 bool IsWindowModeCompact() const { return window_mode_ == MODE_COMPACT; }
[email protected]9c66adc2012-01-05 02:10:16121
[email protected]57b8bb352012-01-11 05:11:46122 // Creates a default views::NonClientFrameView for use by windows in the
123 // Ash environment.
124 views::NonClientFrameView* CreateDefaultNonClientFrameView(
125 views::Widget* widget);
126
[email protected]3d29912a2012-02-07 07:41:51127 // Rotate focus through containers that can recieve focus.
128 void RotateFocus(Direction direction);
129
[email protected]2f744282011-12-23 22:40:52130 AcceleratorController* accelerator_controller() {
[email protected]745816be2011-11-22 05:08:30131 return accelerator_controller_.get();
132 }
[email protected]862deef2011-12-15 22:07:33133 internal::TooltipController* tooltip_controller() {
134 return tooltip_controller_.get();
[email protected]4a229e902011-12-01 21:21:11135 }
[email protected]e0d22e82012-01-04 00:46:57136 PowerButtonController* power_button_controller() {
137 return power_button_controller_.get();
138 }
[email protected]6aa614a2012-01-19 22:13:38139 VideoDetector* video_detector() {
140 return video_detector_.get();
141 }
[email protected]40c4cbb2012-01-10 23:26:07142 WindowCycleController* window_cycle_controller() {
143 return window_cycle_controller_.get();
144 }
[email protected]4a229e902011-12-01 21:21:11145
[email protected]3266c2b92011-11-14 00:06:08146 ShellDelegate* delegate() { return delegate_.get(); }
[email protected]35304ce2011-12-14 23:21:01147
[email protected]671a2ae2011-10-13 21:53:23148 Launcher* launcher() { return launcher_.get(); }
149
[email protected]a54e65b2011-11-21 22:03:34150 // Made available for tests.
151 internal::ShadowController* shadow_controller() {
152 return shadow_controller_.get();
153 }
154
[email protected]cac10fc62011-10-07 23:22:56155 private:
[email protected]9c66adc2012-01-05 02:10:16156 FRIEND_TEST_ALL_PREFIXES(ShellTest, ComputeWindowMode);
[email protected]b0079a92012-01-25 20:13:38157 FRIEND_TEST_ALL_PREFIXES(ShellTest, ChangeWindowMode);
[email protected]b0639282011-12-22 21:12:27158
[email protected]cac10fc62011-10-07 23:22:56159 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
160
[email protected]3266c2b92011-11-14 00:06:08161 explicit Shell(ShellDelegate* delegate);
162 virtual ~Shell();
163
164 void Init();
[email protected]b0639282011-12-22 21:12:27165
[email protected]9c66adc2012-01-05 02:10:16166 // Returns the appropriate window mode to use based on the primary monitor's
167 // |monitor_size| and the user's |command_line|.
168 WindowMode ComputeWindowMode(const gfx::Size& monitor_size,
169 CommandLine* command_line) const;
[email protected]b0639282011-12-22 21:12:27170
[email protected]b0079a92012-01-25 20:13:38171 // Initializes or re-initializes the layout managers and event filters needed
172 // to support a given window mode and cleans up the unneeded ones.
173 void SetupCompactWindowMode();
[email protected]d2840ef2012-02-01 05:10:36174 void SetupNonCompactWindowMode();
[email protected]46ca3632011-11-03 03:33:42175
[email protected]1b62b892012-01-17 17:08:15176 // Sets the LayoutManager of the container with the specified id to NULL. This
177 // has the effect of deleting the current LayoutManager.
178 void ResetLayoutManager(int container_id);
179
[email protected]cac10fc62011-10-07 23:22:56180 static Shell* instance_;
181
182 std::vector<WindowAndBoundsPair> to_restore_;
183
[email protected]f296be72011-10-11 15:40:00184 base::WeakPtrFactory<Shell> method_factory_;
[email protected]cac10fc62011-10-07 23:22:56185
[email protected]2f744282011-12-23 22:40:52186 scoped_ptr<AcceleratorController> accelerator_controller_;
[email protected]745816be2011-11-22 05:08:30187
[email protected]2b99f8c2011-10-11 19:42:24188 scoped_ptr<ShellDelegate> delegate_;
189
[email protected]671a2ae2011-10-13 21:53:23190 scoped_ptr<Launcher> launcher_;
191
[email protected]ae4987d2011-11-21 22:52:44192 scoped_ptr<internal::AppList> app_list_;
193
[email protected]ee1e1a22011-12-15 01:51:10194 scoped_ptr<internal::StackingController> stacking_controller_;
[email protected]9fc206d2011-12-13 00:05:33195 scoped_ptr<internal::ActivationController> activation_controller_;
[email protected]80373572012-01-06 23:14:30196 scoped_ptr<internal::WindowModalityController> window_modality_controller_;
[email protected]084b6bb2011-11-17 05:18:16197 scoped_ptr<internal::DragDropController> drag_drop_controller_;
[email protected]60fa9bba2011-10-28 21:21:51198 scoped_ptr<internal::WorkspaceController> workspace_controller_;
[email protected]a54e65b2011-11-21 22:03:34199 scoped_ptr<internal::ShadowController> shadow_controller_;
[email protected]862deef2011-12-15 22:07:33200 scoped_ptr<internal::TooltipController> tooltip_controller_;
[email protected]ddd91e92012-01-27 16:03:48201 scoped_ptr<internal::VisibilityController> visibility_controller_;
[email protected]e0d22e82012-01-04 00:46:57202 scoped_ptr<PowerButtonController> power_button_controller_;
[email protected]6aa614a2012-01-19 22:13:38203 scoped_ptr<VideoDetector> video_detector_;
[email protected]40c4cbb2012-01-10 23:26:07204 scoped_ptr<WindowCycleController> window_cycle_controller_;
[email protected]3d29912a2012-02-07 07:41:51205 scoped_ptr<internal::FocusCycler> focus_cycler_;
[email protected]ae18b9112011-11-07 16:59:13206
[email protected]2c456102011-12-26 06:26:34207 // An event filter that pre-handles all key events to send them to an IME.
208 scoped_ptr<internal::InputMethodEventFilter> input_method_filter_;
[email protected]745816be2011-11-22 05:08:30209 // An event filter that pre-handles global accelerators.
[email protected]2f744282011-12-23 22:40:52210 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
[email protected]745816be2011-11-22 05:08:30211
[email protected]b0079a92012-01-25 20:13:38212 // Can change at runtime.
[email protected]9c66adc2012-01-05 02:10:16213 WindowMode window_mode_;
[email protected]4a229e902011-12-01 21:21:11214
[email protected]b0079a92012-01-25 20:13:38215 // Owned by aura::RootWindow, cached here for type safety.
216 internal::RootWindowLayoutManager* root_window_layout_;
217
218 // Status area with clock, Wi-Fi signal, etc.
219 views::Widget* status_widget_;
220
[email protected]87b0d82e2011-10-07 21:02:59221 DISALLOW_COPY_AND_ASSIGN(Shell);
222};
223
[email protected]55f593352011-12-24 05:42:46224} // namespace ash
[email protected]87b0d82e2011-10-07 21:02:59225
[email protected]b65bdda2011-12-23 23:35:31226#endif // ASH_SHELL_H_