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