| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/ash_switches.h" | 8 #include "ash/common/ash_switches.h" |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h" |
| 11 #include "ash/common/wm/mru_window_tracker.h" | 12 #include "ash/common/wm/mru_window_tracker.h" |
| 12 #include "ash/common/wm/overview/window_selector_controller.h" | 13 #include "ash/common/wm/overview/window_selector_controller.h" |
| 13 #include "ash/common/wm/window_state.h" | 14 #include "ash/common/wm/window_state.h" |
| 14 #include "ash/common/wm/wm_event.h" | 15 #include "ash/common/wm/wm_event.h" |
| 15 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 16 #include "ash/root_window_controller.h" | 17 #include "ash/root_window_controller.h" |
| 17 #include "ash/shell.h" | 18 #include "ash/shell.h" |
| 18 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" | 19 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" |
| 19 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" | 20 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" |
| 20 #include "ash/wm/window_state_aura.h" | 21 #include "ash/wm/window_state_aura.h" |
| 21 #include "ash/wm/window_util.h" | 22 #include "ash/wm/window_util.h" |
| 22 #include "ash/wm/workspace_controller.h" | 23 #include "ash/wm/workspace_controller.h" |
| 23 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 24 #include "ui/aura/client/aura_constants.h" | 25 #include "ui/aura/client/aura_constants.h" |
| 25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 26 #include "ui/display/screen.h" | 27 #include "ui/display/screen.h" |
| 27 | 28 |
| 28 namespace ash { | 29 namespace ash { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // The height of the area in which a touch operation leads to exiting the | |
| 33 // full screen mode. | |
| 34 const int kLeaveFullScreenAreaHeightInPixel = 2; | |
| 35 | |
| 36 // Exits overview mode if it is currently active. | 33 // Exits overview mode if it is currently active. |
| 37 void CancelOverview() { | 34 void CancelOverview() { |
| 38 WindowSelectorController* controller = | 35 WindowSelectorController* controller = |
| 39 WmShell::Get()->window_selector_controller(); | 36 WmShell::Get()->window_selector_controller(); |
| 40 if (controller->IsSelecting()) | 37 if (controller->IsSelecting()) |
| 41 controller->OnSelectionEnded(); | 38 controller->OnSelectionEnded(); |
| 42 } | 39 } |
| 43 | 40 |
| 44 } // namespace | 41 } // namespace |
| 45 | 42 |
| 46 MaximizeModeWindowManager::~MaximizeModeWindowManager() { | 43 MaximizeModeWindowManager::~MaximizeModeWindowManager() { |
| 47 // Overview mode needs to be ended before exiting maximize mode to prevent | 44 // Overview mode needs to be ended before exiting maximize mode to prevent |
| 48 // transforming windows which are currently in | 45 // transforming windows which are currently in |
| 49 // overview: http://crbug.com/366605 | 46 // overview: http://crbug.com/366605 |
| 50 CancelOverview(); | 47 CancelOverview(); |
| 51 | 48 |
| 52 Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 53 WmShell::Get()->RemoveShellObserver(this); | 49 WmShell::Get()->RemoveShellObserver(this); |
| 54 display::Screen::GetScreen()->RemoveObserver(this); | 50 display::Screen::GetScreen()->RemoveObserver(this); |
| 55 EnableBackdropBehindTopWindowOnEachDisplay(false); | 51 EnableBackdropBehindTopWindowOnEachDisplay(false); |
| 56 RemoveWindowCreationObservers(); | 52 RemoveWindowCreationObservers(); |
| 57 RestoreAllWindows(); | 53 RestoreAllWindows(); |
| 58 } | 54 } |
| 59 | 55 |
| 60 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { | 56 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { |
| 61 return window_state_map_.size(); | 57 return window_state_map_.size(); |
| 62 } | 58 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 void MaximizeModeWindowManager::OnDisplayRemoved( | 155 void MaximizeModeWindowManager::OnDisplayRemoved( |
| 160 const display::Display& display) { | 156 const display::Display& display) { |
| 161 DisplayConfigurationChanged(); | 157 DisplayConfigurationChanged(); |
| 162 } | 158 } |
| 163 | 159 |
| 164 void MaximizeModeWindowManager::OnDisplayMetricsChanged(const display::Display&, | 160 void MaximizeModeWindowManager::OnDisplayMetricsChanged(const display::Display&, |
| 165 uint32_t) { | 161 uint32_t) { |
| 166 // Nothing to do here. | 162 // Nothing to do here. |
| 167 } | 163 } |
| 168 | 164 |
| 169 void MaximizeModeWindowManager::OnTouchEvent(ui::TouchEvent* event) { | |
| 170 const SessionStateDelegate* delegate = | |
| 171 Shell::GetInstance()->session_state_delegate(); | |
| 172 | |
| 173 if (delegate->IsScreenLocked()) | |
| 174 return; | |
| 175 | |
| 176 switch (delegate->GetSessionState()) { | |
| 177 case SessionStateDelegate::SESSION_STATE_LOGIN_PRIMARY: | |
| 178 return; | |
| 179 case SessionStateDelegate::SESSION_STATE_ACTIVE: | |
| 180 break; | |
| 181 case SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY: | |
| 182 return; | |
| 183 } | |
| 184 | |
| 185 if (event->type() != ui::ET_TOUCH_PRESSED) | |
| 186 return; | |
| 187 | |
| 188 // Find the active window (from the primary screen) to un-fullscreen. | |
| 189 aura::Window* window = wm::GetActiveWindow(); | |
| 190 if (!window) | |
| 191 return; | |
| 192 | |
| 193 wm::WindowState* window_state = wm::GetWindowState(window); | |
| 194 if (!window_state->IsFullscreen() || window_state->in_immersive_fullscreen()) | |
| 195 return; | |
| 196 | |
| 197 // Test that the touch happened in the top or bottom lines. | |
| 198 int y = event->y(); | |
| 199 if (y >= kLeaveFullScreenAreaHeightInPixel && | |
| 200 y < (window->bounds().height() - kLeaveFullScreenAreaHeightInPixel)) { | |
| 201 return; | |
| 202 } | |
| 203 | |
| 204 // Leave full screen mode. | |
| 205 event->StopPropagation(); | |
| 206 wm::WMEvent toggle_fullscreen(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
| 207 window_state->OnWMEvent(&toggle_fullscreen); | |
| 208 } | |
| 209 | |
| 210 MaximizeModeWindowManager::MaximizeModeWindowManager() | 165 MaximizeModeWindowManager::MaximizeModeWindowManager() |
| 211 : backdrops_hidden_(false) { | 166 : backdrops_hidden_(false) { |
| 212 // The overview mode needs to be ended before the maximize mode is started. To | 167 // The overview mode needs to be ended before the maximize mode is started. To |
| 213 // guarantee the proper order, it will be turned off from here. | 168 // guarantee the proper order, it will be turned off from here. |
| 214 CancelOverview(); | 169 CancelOverview(); |
| 215 | 170 |
| 216 MaximizeAllWindows(); | 171 MaximizeAllWindows(); |
| 217 AddWindowCreationObservers(); | 172 AddWindowCreationObservers(); |
| 218 EnableBackdropBehindTopWindowOnEachDisplay(true); | 173 EnableBackdropBehindTopWindowOnEachDisplay(true); |
| 219 display::Screen::GetScreen()->AddObserver(this); | 174 display::Screen::GetScreen()->AddObserver(this); |
| 220 WmShell::Get()->AddShellObserver(this); | 175 WmShell::Get()->AddShellObserver(this); |
| 221 Shell::GetInstance()->AddPreTargetHandler(this); | 176 event_handler_ = WmShell::Get()->CreateMaximizeModeEventHandler(); |
| 222 } | 177 } |
| 223 | 178 |
| 224 void MaximizeModeWindowManager::MaximizeAllWindows() { | 179 void MaximizeModeWindowManager::MaximizeAllWindows() { |
| 225 MruWindowTracker::WindowList windows = ash::Shell::GetInstance() | 180 MruWindowTracker::WindowList windows = ash::Shell::GetInstance() |
| 226 ->mru_window_tracker() | 181 ->mru_window_tracker() |
| 227 ->BuildWindowListIgnoreModal(); | 182 ->BuildWindowListIgnoreModal(); |
| 228 // Add all existing Mru windows. | 183 // Add all existing Mru windows. |
| 229 for (WmWindow* window : windows) | 184 for (WmWindow* window : windows) |
| 230 MaximizeAndTrackWindow(WmWindowAura::GetAuraWindow(window)); | 185 MaximizeAndTrackWindow(WmWindowAura::GetAuraWindow(window)); |
| 231 } | 186 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 aura::Window* container = Shell::GetContainer( | 299 aura::Window* container = Shell::GetContainer( |
| 345 controller->GetRootWindow(), kShellWindowId_DefaultContainer); | 300 controller->GetRootWindow(), kShellWindowId_DefaultContainer); |
| 346 controller->workspace_controller()->SetMaximizeBackdropDelegate( | 301 controller->workspace_controller()->SetMaximizeBackdropDelegate( |
| 347 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate>( | 302 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate>( |
| 348 enable ? new WorkspaceBackdropDelegate(WmWindowAura::Get(container)) | 303 enable ? new WorkspaceBackdropDelegate(WmWindowAura::Get(container)) |
| 349 : nullptr)); | 304 : nullptr)); |
| 350 } | 305 } |
| 351 } | 306 } |
| 352 | 307 |
| 353 } // namespace ash | 308 } // namespace ash |
| OLD | NEW |