[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 5 | #ifndef ASH_SHELL_H_ |
| 6 | #define ASH_SHELL_H_ |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 7 | #pragma once |
| 8 | |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 9 | #include <utility> |
| 10 | #include <vector> |
| 11 | |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 12 | #include "ash/ash_export.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 13 | #include "base/basictypes.h" |
[email protected] | b063928 | 2011-12-22 21:12:27 | [diff] [blame] | 14 | #include "base/gtest_prod_util.h" |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 15 | #include "base/memory/scoped_ptr.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
[email protected] | f296be7 | 2011-10-11 15:40:00 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 18 | |
[email protected] | b063928 | 2011-12-22 21:12:27 | [diff] [blame] | 19 | class CommandLine; |
| 20 | |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 21 | namespace aura { |
[email protected] | e29014c | 2011-11-16 18:25:51 | [diff] [blame] | 22 | class EventFilter; |
[email protected] | 35304ce | 2011-12-14 23:21:01 | [diff] [blame] | 23 | class RootWindow; |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 24 | class Window; |
| 25 | } |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 26 | namespace gfx { |
[email protected] | b5f3060 | 2012-01-30 15:16:57 | [diff] [blame] | 27 | class Point; |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 28 | class Rect; |
[email protected] | b063928 | 2011-12-22 21:12:27 | [diff] [blame] | 29 | class Size; |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 30 | } |
[email protected] | 57b8bb35 | 2012-01-11 05:11:46 | [diff] [blame] | 31 | namespace views { |
| 32 | class NonClientFrameView; |
| 33 | class Widget; |
| 34 | } |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 35 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 36 | namespace ash { |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 37 | |
[email protected] | 2f74428 | 2011-12-23 22:40:52 | [diff] [blame] | 38 | class AcceleratorController; |
[email protected] | 671a2ae | 2011-10-13 21:53:23 | [diff] [blame] | 39 | class Launcher; |
[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 40 | class PowerButtonController; |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 41 | class ShellDelegate; |
[email protected] | 6aa614a | 2012-01-19 22:13:38 | [diff] [blame] | 42 | class VideoDetector; |
[email protected] | 40c4cbb | 2012-01-10 23:26:07 | [diff] [blame] | 43 | class WindowCycleController; |
[email protected] | 60fa9bba | 2011-10-28 21:21:51 | [diff] [blame] | 44 | |
| 45 | namespace internal { |
[email protected] | 9fc206d | 2011-12-13 00:05:33 | [diff] [blame] | 46 | class ActivationController; |
[email protected] | 2f74428 | 2011-12-23 22:40:52 | [diff] [blame] | 47 | class AcceleratorFilter; |
[email protected] | ae4987d | 2011-11-21 22:52:44 | [diff] [blame] | 48 | class AppList; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 49 | class DragDropController; |
[email protected] | 3d29912a | 2012-02-07 07:41:51 | [diff] [blame^] | 50 | class FocusCycler; |
[email protected] | 2c45610 | 2011-12-26 06:26:34 | [diff] [blame] | 51 | class InputMethodEventFilter; |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 52 | class RootWindowLayoutManager; |
[email protected] | a54e65b | 2011-11-21 22:03:34 | [diff] [blame] | 53 | class ShadowController; |
[email protected] | ee1e1a2 | 2011-12-15 01:51:10 | [diff] [blame] | 54 | class StackingController; |
[email protected] | 862deef | 2011-12-15 22:07:33 | [diff] [blame] | 55 | class TooltipController; |
[email protected] | ddd91e9 | 2012-01-27 16:03:48 | [diff] [blame] | 56 | class VisibilityController; |
[email protected] | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 57 | class WindowModalityController; |
[email protected] | 60fa9bba | 2011-10-28 21:21:51 | [diff] [blame] | 58 | class WorkspaceController; |
| 59 | } |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 60 | |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 61 | // Shell is a singleton object that presents the Shell API and implements the |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 62 | // RootWindow's delegate interface. |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 63 | // |
| 64 | // Upon creation, the Shell sets itself as the RootWindow's delegate, which |
| 65 | // takes ownership of the Shell. |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 66 | class ASH_EXPORT Shell { |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 67 | public: |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 68 | // In compact window mode we fill the screen with a single maximized window, |
[email protected] | d2840ef | 2012-02-01 05:10:36 | [diff] [blame] | 69 | // 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] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 71 | enum WindowMode { |
[email protected] | d2840ef | 2012-02-01 05:10:36 | [diff] [blame] | 72 | MODE_COMPACT, |
| 73 | MODE_MANAGED, |
| 74 | MODE_OVERLAPPING, |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 75 | }; |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 76 | |
[email protected] | 3d29912a | 2012-02-07 07:41:51 | [diff] [blame^] | 77 | enum Direction { |
| 78 | FORWARD, |
| 79 | BACKWARD |
| 80 | }; |
| 81 | |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 82 | // 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] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 87 | static Shell* GetInstance(); |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 88 | |
[email protected] | ef589af | 2011-12-03 01:07:15 | [diff] [blame] | 89 | static void DeleteInstance(); |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 90 | |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 91 | aura::Window* GetContainer(int container_id); |
| 92 | const aura::Window* GetContainer(int container_id) const; |
| 93 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 94 | // Adds or removes |filter| from the RootWindowEventFilter. |
| 95 | void AddRootWindowEventFilter(aura::EventFilter* filter); |
| 96 | void RemoveRootWindowEventFilter(aura::EventFilter* filter); |
[email protected] | 2c45610 | 2011-12-26 06:26:34 | [diff] [blame] | 97 | size_t GetRootWindowEventFilterCount() const; |
[email protected] | e29014c | 2011-11-16 18:25:51 | [diff] [blame] | 98 | |
[email protected] | b5f3060 | 2012-01-30 15:16:57 | [diff] [blame] | 99 | // Shows the background menu over |widget|. |
| 100 | void ShowBackgroundMenu(views::Widget* widget, const gfx::Point& location); |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 101 | |
[email protected] | ae4987d | 2011-11-21 22:52:44 | [diff] [blame] | 102 | // Toggles app list. |
| 103 | void ToggleAppList(); |
| 104 | |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 105 | // 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] | 615922f | 2012-02-07 02:41:15 | [diff] [blame] | 110 | // Sets an appropriate window mode for the given screen resolution. |
| 111 | void SetWindowModeForMonitorSize(const gfx::Size& monitor_size); |
| 112 | |
[email protected] | f7eb89c | 2011-12-13 09:48:54 | [diff] [blame] | 113 | // Returns true if the screen is locked. |
| 114 | bool IsScreenLocked() const; |
| 115 | |
[email protected] | 40c4cbb | 2012-01-10 23:26:07 | [diff] [blame] | 116 | // Returns true if a modal dialog window is currently open. |
| 117 | bool IsModalWindowOpen() const; |
| 118 | |
[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 119 | // See enum WindowMode for details. |
[email protected] | d2840ef | 2012-02-01 05:10:36 | [diff] [blame] | 120 | bool IsWindowModeCompact() const { return window_mode_ == MODE_COMPACT; } |
[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 121 | |
[email protected] | 57b8bb35 | 2012-01-11 05:11:46 | [diff] [blame] | 122 | // 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] | 3d29912a | 2012-02-07 07:41:51 | [diff] [blame^] | 127 | // Rotate focus through containers that can recieve focus. |
| 128 | void RotateFocus(Direction direction); |
| 129 | |
[email protected] | 2f74428 | 2011-12-23 22:40:52 | [diff] [blame] | 130 | AcceleratorController* accelerator_controller() { |
[email protected] | 745816be | 2011-11-22 05:08:30 | [diff] [blame] | 131 | return accelerator_controller_.get(); |
| 132 | } |
[email protected] | 862deef | 2011-12-15 22:07:33 | [diff] [blame] | 133 | internal::TooltipController* tooltip_controller() { |
| 134 | return tooltip_controller_.get(); |
[email protected] | 4a229e90 | 2011-12-01 21:21:11 | [diff] [blame] | 135 | } |
[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 136 | PowerButtonController* power_button_controller() { |
| 137 | return power_button_controller_.get(); |
| 138 | } |
[email protected] | 6aa614a | 2012-01-19 22:13:38 | [diff] [blame] | 139 | VideoDetector* video_detector() { |
| 140 | return video_detector_.get(); |
| 141 | } |
[email protected] | 40c4cbb | 2012-01-10 23:26:07 | [diff] [blame] | 142 | WindowCycleController* window_cycle_controller() { |
| 143 | return window_cycle_controller_.get(); |
| 144 | } |
[email protected] | 4a229e90 | 2011-12-01 21:21:11 | [diff] [blame] | 145 | |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 146 | ShellDelegate* delegate() { return delegate_.get(); } |
[email protected] | 35304ce | 2011-12-14 23:21:01 | [diff] [blame] | 147 | |
[email protected] | 671a2ae | 2011-10-13 21:53:23 | [diff] [blame] | 148 | Launcher* launcher() { return launcher_.get(); } |
| 149 | |
[email protected] | a54e65b | 2011-11-21 22:03:34 | [diff] [blame] | 150 | // Made available for tests. |
| 151 | internal::ShadowController* shadow_controller() { |
| 152 | return shadow_controller_.get(); |
| 153 | } |
| 154 | |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 155 | private: |
[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 156 | FRIEND_TEST_ALL_PREFIXES(ShellTest, ComputeWindowMode); |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 157 | FRIEND_TEST_ALL_PREFIXES(ShellTest, ChangeWindowMode); |
[email protected] | b063928 | 2011-12-22 21:12:27 | [diff] [blame] | 158 | |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 159 | typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; |
| 160 | |
[email protected] | 3266c2b9 | 2011-11-14 00:06:08 | [diff] [blame] | 161 | explicit Shell(ShellDelegate* delegate); |
| 162 | virtual ~Shell(); |
| 163 | |
| 164 | void Init(); |
[email protected] | b063928 | 2011-12-22 21:12:27 | [diff] [blame] | 165 | |
[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 166 | // 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] | b063928 | 2011-12-22 21:12:27 | [diff] [blame] | 170 | |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 171 | // 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] | d2840ef | 2012-02-01 05:10:36 | [diff] [blame] | 174 | void SetupNonCompactWindowMode(); |
[email protected] | 46ca363 | 2011-11-03 03:33:42 | [diff] [blame] | 175 | |
[email protected] | 1b62b89 | 2012-01-17 17:08:15 | [diff] [blame] | 176 | // 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] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 180 | static Shell* instance_; |
| 181 | |
| 182 | std::vector<WindowAndBoundsPair> to_restore_; |
| 183 | |
[email protected] | f296be7 | 2011-10-11 15:40:00 | [diff] [blame] | 184 | base::WeakPtrFactory<Shell> method_factory_; |
[email protected] | cac10fc6 | 2011-10-07 23:22:56 | [diff] [blame] | 185 | |
[email protected] | 2f74428 | 2011-12-23 22:40:52 | [diff] [blame] | 186 | scoped_ptr<AcceleratorController> accelerator_controller_; |
[email protected] | 745816be | 2011-11-22 05:08:30 | [diff] [blame] | 187 | |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 188 | scoped_ptr<ShellDelegate> delegate_; |
| 189 | |
[email protected] | 671a2ae | 2011-10-13 21:53:23 | [diff] [blame] | 190 | scoped_ptr<Launcher> launcher_; |
| 191 | |
[email protected] | ae4987d | 2011-11-21 22:52:44 | [diff] [blame] | 192 | scoped_ptr<internal::AppList> app_list_; |
| 193 | |
[email protected] | ee1e1a2 | 2011-12-15 01:51:10 | [diff] [blame] | 194 | scoped_ptr<internal::StackingController> stacking_controller_; |
[email protected] | 9fc206d | 2011-12-13 00:05:33 | [diff] [blame] | 195 | scoped_ptr<internal::ActivationController> activation_controller_; |
[email protected] | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 196 | scoped_ptr<internal::WindowModalityController> window_modality_controller_; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 197 | scoped_ptr<internal::DragDropController> drag_drop_controller_; |
[email protected] | 60fa9bba | 2011-10-28 21:21:51 | [diff] [blame] | 198 | scoped_ptr<internal::WorkspaceController> workspace_controller_; |
[email protected] | a54e65b | 2011-11-21 22:03:34 | [diff] [blame] | 199 | scoped_ptr<internal::ShadowController> shadow_controller_; |
[email protected] | 862deef | 2011-12-15 22:07:33 | [diff] [blame] | 200 | scoped_ptr<internal::TooltipController> tooltip_controller_; |
[email protected] | ddd91e9 | 2012-01-27 16:03:48 | [diff] [blame] | 201 | scoped_ptr<internal::VisibilityController> visibility_controller_; |
[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 202 | scoped_ptr<PowerButtonController> power_button_controller_; |
[email protected] | 6aa614a | 2012-01-19 22:13:38 | [diff] [blame] | 203 | scoped_ptr<VideoDetector> video_detector_; |
[email protected] | 40c4cbb | 2012-01-10 23:26:07 | [diff] [blame] | 204 | scoped_ptr<WindowCycleController> window_cycle_controller_; |
[email protected] | 3d29912a | 2012-02-07 07:41:51 | [diff] [blame^] | 205 | scoped_ptr<internal::FocusCycler> focus_cycler_; |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 206 | |
[email protected] | 2c45610 | 2011-12-26 06:26:34 | [diff] [blame] | 207 | // 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] | 745816be | 2011-11-22 05:08:30 | [diff] [blame] | 209 | // An event filter that pre-handles global accelerators. |
[email protected] | 2f74428 | 2011-12-23 22:40:52 | [diff] [blame] | 210 | scoped_ptr<internal::AcceleratorFilter> accelerator_filter_; |
[email protected] | 745816be | 2011-11-22 05:08:30 | [diff] [blame] | 211 | |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 212 | // Can change at runtime. |
[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 213 | WindowMode window_mode_; |
[email protected] | 4a229e90 | 2011-12-01 21:21:11 | [diff] [blame] | 214 | |
[email protected] | b0079a9 | 2012-01-25 20:13:38 | [diff] [blame] | 215 | // 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] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 221 | DISALLOW_COPY_AND_ASSIGN(Shell); |
| 222 | }; |
| 223 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 224 | } // namespace ash |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 225 | |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 226 | #endif // ASH_SHELL_H_ |