OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/lock_window_state.h" |
| 6 |
| 7 #include "ash/screen_util.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/wm/lock_layout_manager.h" |
| 10 #include "ash/wm/window_animations.h" |
| 11 #include "ash/wm/window_state.h" |
| 12 #include "ash/wm/window_state_delegate.h" |
| 13 #include "ash/wm/window_state_util.h" |
| 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/wm_event.h" |
| 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_delegate.h" |
| 18 #include "ui/gfx/rect.h" |
| 19 #include "ui/keyboard/keyboard_controller.h" |
| 20 #include "ui/wm/core/window_animations.h" |
| 21 |
| 22 namespace ash { |
| 23 |
| 24 namespace { |
| 25 } // namespace |
| 26 |
| 27 LockWindowState::LockWindowState( |
| 28 aura::Window* window, LockLayoutManager* creator) |
| 29 : window_(window), |
| 30 creator_(creator), |
| 31 current_state_type_(wm::GetWindowState(window)->GetStateType()) { |
| 32 old_state_.reset( |
| 33 wm::GetWindowState(window)->SetStateObject( |
| 34 scoped_ptr<State>(this).Pass()).release()); |
| 35 } |
| 36 |
| 37 LockWindowState::~LockWindowState() { |
| 38 creator_->WindowStateDestroyed(window_); |
| 39 } |
| 40 |
| 41 void LockWindowState::RestoreWindowState(wm::WindowState* window_state) { |
| 42 // Note: When we return we will destroy ourselves with the |our_reference|. |
| 43 scoped_ptr<wm::WindowState::State> our_reference = |
| 44 window_state->SetStateObject(old_state_.Pass()); |
| 45 } |
| 46 |
| 47 void LockWindowState::OnWMEvent(wm::WindowState* window_state, |
| 48 const wm::WMEvent* event) { |
| 49 aura::Window* window = window_state->window(); |
| 50 gfx::Rect bounds = window->bounds(); |
| 51 |
| 52 switch (event->type()) { |
| 53 case wm::WM_EVENT_TOGGLE_FULLSCREEN: |
| 54 ToggleFullScreen(window_state, window_state->delegate()); |
| 55 break; |
| 56 case wm::WM_EVENT_FULLSCREEN: |
| 57 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN); |
| 58 break; |
| 59 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
| 60 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
| 61 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
| 62 case wm::WM_EVENT_TOGGLE_MAXIMIZE: |
| 63 case wm::WM_EVENT_CENTER: |
| 64 case wm::WM_EVENT_SNAP_LEFT: |
| 65 case wm::WM_EVENT_SNAP_RIGHT: |
| 66 case wm::WM_EVENT_NORMAL: |
| 67 case wm::WM_EVENT_MAXIMIZE: |
| 68 UpdateWindow(window_state, |
| 69 GetMaximizedOrCenteredWindowType(window_state)); |
| 70 return; |
| 71 case wm::WM_EVENT_MINIMIZE: |
| 72 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED); |
| 73 return; |
| 74 case wm::WM_EVENT_SHOW_INACTIVE: |
| 75 return; |
| 76 case wm::WM_EVENT_SET_BOUNDS: |
| 77 UpdateBounds(window_state); |
| 78 break; |
| 79 case wm::WM_EVENT_ADDED_TO_WORKSPACE: |
| 80 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 81 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 82 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 83 UpdateWindow(window_state, |
| 84 GetMaximizedOrCenteredWindowType(window_state)); |
| 85 } |
| 86 break; |
| 87 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED: |
| 88 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED: |
| 89 UpdateBounds(window_state); |
| 90 break; |
| 91 } |
| 92 } |
| 93 |
| 94 wm::WindowStateType LockWindowState::GetType() const { |
| 95 return current_state_type_; |
| 96 } |
| 97 |
| 98 void LockWindowState::AttachState(wm::WindowState* window_state, |
| 99 wm::WindowState::State* previous_state) { |
| 100 current_state_type_ = previous_state->GetType(); |
| 101 |
| 102 // Initialize the state to a good preset. |
| 103 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 104 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 105 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 106 UpdateWindow(window_state, |
| 107 GetMaximizedOrCenteredWindowType(window_state)); |
| 108 } |
| 109 window_state->set_can_be_dragged(false); |
| 110 } |
| 111 |
| 112 void LockWindowState::DetachState(wm::WindowState* window_state) { |
| 113 window_state->set_can_be_dragged(true); |
| 114 } |
| 115 |
| 116 void LockWindowState::UpdateWindow(wm::WindowState* window_state, |
| 117 wm::WindowStateType target_state) { |
| 118 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
| 119 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
| 120 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
| 121 !window_state->CanMaximize()) || |
| 122 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); |
| 123 |
| 124 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { |
| 125 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED) |
| 126 return; |
| 127 |
| 128 current_state_type_ = target_state; |
| 129 ::wm::SetWindowVisibilityAnimationType( |
| 130 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
| 131 window_state->window()->Hide(); |
| 132 if (window_state->IsActive()) |
| 133 window_state->Deactivate(); |
| 134 return; |
| 135 } |
| 136 |
| 137 if (current_state_type_ == target_state) { |
| 138 // If the state type did not change, update it accordingly. |
| 139 UpdateBounds(window_state); |
| 140 return; |
| 141 } |
| 142 |
| 143 const wm::WindowStateType old_state_type = current_state_type_; |
| 144 current_state_type_ = target_state; |
| 145 window_state->UpdateWindowShowStateFromStateType(); |
| 146 window_state->NotifyPreStateTypeChange(old_state_type); |
| 147 UpdateBounds(window_state); |
| 148 window_state->NotifyPostStateTypeChange(old_state_type); |
| 149 |
| 150 if ((window_state->window()->TargetVisibility() || |
| 151 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && |
| 152 !window_state->window()->layer()->visible()) { |
| 153 // The layer may be hidden if the window was previously minimized. Make |
| 154 // sure it's visible. |
| 155 window_state->window()->Show(); |
| 156 } |
| 157 } |
| 158 |
| 159 wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType( |
| 160 wm::WindowState* window_state) { |
| 161 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED : |
| 162 wm::WINDOW_STATE_TYPE_NORMAL; |
| 163 } |
| 164 |
| 165 void LockWindowState::UpdateBounds(wm::WindowState* window_state) { |
| 166 keyboard::KeyboardController* keyboard_controller = |
| 167 keyboard::KeyboardController::GetInstance(); |
| 168 gfx::Rect keyboard_bounds; |
| 169 if (keyboard_controller) |
| 170 keyboard_bounds = keyboard_controller->current_keyboard_bounds(); |
| 171 |
| 172 // TODO(nkostylev): Currently (M36/M37) virtual keyboard overscroll is |
| 173 // disabled for login/lock screen. Add support for keyboard overscroll i.e. |
| 174 // don't take keyboard bounds into consideration. This requires additional |
| 175 // plumbing and will be done shortly after in M37. |
| 176 gfx::Rect bounds = |
| 177 ScreenUtil::GetDisplayBoundsInParent(window_state->window()); |
| 178 bounds.set_height(bounds.height() - keyboard_bounds.height()); |
| 179 window_state->SetBoundsDirect(bounds); |
| 180 } |
| 181 |
| 182 } // namespace ash |
OLD | NEW |