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/keyboard/keyboard_util.h" |
| 21 #include "ui/wm/core/window_animations.h" |
| 22 |
| 23 namespace ash { |
| 24 |
| 25 LockWindowState::LockWindowState(aura::Window* window) |
| 26 : current_state_type_(wm::GetWindowState(window)->GetStateType()) { |
| 27 wm::GetWindowState(window)->SetStateObject(scoped_ptr<State>(this)); |
| 28 } |
| 29 |
| 30 LockWindowState::~LockWindowState() { |
| 31 } |
| 32 |
| 33 void LockWindowState::OnWMEvent(wm::WindowState* window_state, |
| 34 const wm::WMEvent* event) { |
| 35 aura::Window* window = window_state->window(); |
| 36 gfx::Rect bounds = window->bounds(); |
| 37 |
| 38 switch (event->type()) { |
| 39 case wm::WM_EVENT_TOGGLE_FULLSCREEN: |
| 40 ToggleFullScreen(window_state, window_state->delegate()); |
| 41 break; |
| 42 case wm::WM_EVENT_FULLSCREEN: |
| 43 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN); |
| 44 break; |
| 45 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
| 46 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
| 47 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
| 48 case wm::WM_EVENT_TOGGLE_MAXIMIZE: |
| 49 case wm::WM_EVENT_CENTER: |
| 50 case wm::WM_EVENT_SNAP_LEFT: |
| 51 case wm::WM_EVENT_SNAP_RIGHT: |
| 52 case wm::WM_EVENT_NORMAL: |
| 53 case wm::WM_EVENT_MAXIMIZE: |
| 54 UpdateWindow(window_state, |
| 55 GetMaximizedOrCenteredWindowType(window_state)); |
| 56 return; |
| 57 case wm::WM_EVENT_MINIMIZE: |
| 58 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED); |
| 59 return; |
| 60 case wm::WM_EVENT_SHOW_INACTIVE: |
| 61 return; |
| 62 case wm::WM_EVENT_SET_BOUNDS: |
| 63 UpdateBounds(window_state); |
| 64 break; |
| 65 case wm::WM_EVENT_ADDED_TO_WORKSPACE: |
| 66 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 67 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 68 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 69 UpdateWindow(window_state, |
| 70 GetMaximizedOrCenteredWindowType(window_state)); |
| 71 } |
| 72 break; |
| 73 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED: |
| 74 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED: |
| 75 UpdateBounds(window_state); |
| 76 break; |
| 77 } |
| 78 } |
| 79 |
| 80 wm::WindowStateType LockWindowState::GetType() const { |
| 81 return current_state_type_; |
| 82 } |
| 83 |
| 84 void LockWindowState::AttachState(wm::WindowState* window_state, |
| 85 wm::WindowState::State* previous_state) { |
| 86 current_state_type_ = previous_state->GetType(); |
| 87 |
| 88 // Initialize the state to a good preset. |
| 89 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 90 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 91 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 92 UpdateWindow(window_state, |
| 93 GetMaximizedOrCenteredWindowType(window_state)); |
| 94 } |
| 95 } |
| 96 |
| 97 void LockWindowState::DetachState(wm::WindowState* window_state) { |
| 98 } |
| 99 |
| 100 // static |
| 101 wm::WindowState* LockWindowState::SetLockWindowState(aura::Window* window) { |
| 102 wm::WindowState* window_state = wm::GetWindowState(window); |
| 103 scoped_ptr<wm::WindowState::State> lock_state(new LockWindowState(window)); |
| 104 window_state->SetStateObject(lock_state.Pass()); |
| 105 return window_state; |
| 106 } |
| 107 |
| 108 void LockWindowState::UpdateWindow(wm::WindowState* window_state, |
| 109 wm::WindowStateType target_state) { |
| 110 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
| 111 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
| 112 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
| 113 !window_state->CanMaximize()) || |
| 114 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); |
| 115 |
| 116 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { |
| 117 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED) |
| 118 return; |
| 119 |
| 120 current_state_type_ = target_state; |
| 121 ::wm::SetWindowVisibilityAnimationType( |
| 122 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
| 123 window_state->window()->Hide(); |
| 124 if (window_state->IsActive()) |
| 125 window_state->Deactivate(); |
| 126 return; |
| 127 } |
| 128 |
| 129 if (current_state_type_ == target_state) { |
| 130 // If the state type did not change, update it accordingly. |
| 131 UpdateBounds(window_state); |
| 132 return; |
| 133 } |
| 134 |
| 135 const wm::WindowStateType old_state_type = current_state_type_; |
| 136 current_state_type_ = target_state; |
| 137 window_state->UpdateWindowShowStateFromStateType(); |
| 138 window_state->NotifyPreStateTypeChange(old_state_type); |
| 139 UpdateBounds(window_state); |
| 140 window_state->NotifyPostStateTypeChange(old_state_type); |
| 141 |
| 142 if ((window_state->window()->TargetVisibility() || |
| 143 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && |
| 144 !window_state->window()->layer()->visible()) { |
| 145 // The layer may be hidden if the window was previously minimized. Make |
| 146 // sure it's visible. |
| 147 window_state->window()->Show(); |
| 148 } |
| 149 } |
| 150 |
| 151 wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType( |
| 152 wm::WindowState* window_state) { |
| 153 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED : |
| 154 wm::WINDOW_STATE_TYPE_NORMAL; |
| 155 } |
| 156 |
| 157 void LockWindowState::UpdateBounds(wm::WindowState* window_state) { |
| 158 keyboard::KeyboardController* keyboard_controller = |
| 159 keyboard::KeyboardController::GetInstance(); |
| 160 gfx::Rect keyboard_bounds; |
| 161 |
| 162 if (keyboard_controller && !keyboard::IsKeyboardOverscrollEnabled()) |
| 163 keyboard_bounds = keyboard_controller->current_keyboard_bounds(); |
| 164 |
| 165 gfx::Rect bounds = |
| 166 ScreenUtil::GetDisplayBoundsInParent(window_state->window()); |
| 167 bounds.set_height(bounds.height() - keyboard_bounds.height()); |
| 168 window_state->SetBoundsDirect(bounds); |
| 169 } |
| 170 |
| 171 } // namespace ash |
OLD | NEW |