Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: ash/wm/lock_window_state.cc

Issue 254673004: Add LockLayoutManager responsible for lock container (login/lock). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cl Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 namespace {
26 } // namespace
27
28 LockWindowState::LockWindowState(aura::Window* window)
29 : window_(window),
30 current_state_type_(wm::GetWindowState(window)->GetStateType()) {
31 wm::GetWindowState(window)->SetStateObject(scoped_ptr<State>(this));
32 }
33
34 LockWindowState::~LockWindowState() {
35 }
36
37 void LockWindowState::OnWMEvent(wm::WindowState* window_state,
38 const wm::WMEvent* event) {
39 aura::Window* window = window_state->window();
40 gfx::Rect bounds = window->bounds();
41
42 switch (event->type()) {
43 case wm::WM_EVENT_TOGGLE_FULLSCREEN:
44 ToggleFullScreen(window_state, window_state->delegate());
45 break;
46 case wm::WM_EVENT_FULLSCREEN:
47 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN);
48 break;
49 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
50 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
51 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
52 case wm::WM_EVENT_TOGGLE_MAXIMIZE:
53 case wm::WM_EVENT_CENTER:
54 case wm::WM_EVENT_SNAP_LEFT:
55 case wm::WM_EVENT_SNAP_RIGHT:
56 case wm::WM_EVENT_NORMAL:
57 case wm::WM_EVENT_MAXIMIZE:
58 UpdateWindow(window_state,
59 GetMaximizedOrCenteredWindowType(window_state));
60 return;
61 case wm::WM_EVENT_MINIMIZE:
62 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED);
63 return;
64 case wm::WM_EVENT_SHOW_INACTIVE:
65 return;
66 case wm::WM_EVENT_SET_BOUNDS:
67 UpdateBounds(window_state);
68 break;
69 case wm::WM_EVENT_ADDED_TO_WORKSPACE:
70 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
71 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
72 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
73 UpdateWindow(window_state,
74 GetMaximizedOrCenteredWindowType(window_state));
75 }
76 break;
77 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED:
78 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED:
79 UpdateBounds(window_state);
80 break;
81 }
82 }
83
84 wm::WindowStateType LockWindowState::GetType() const {
85 return current_state_type_;
86 }
87
88 void LockWindowState::AttachState(wm::WindowState* window_state,
89 wm::WindowState::State* previous_state) {
90 current_state_type_ = previous_state->GetType();
91
92 // Initialize the state to a good preset.
93 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
94 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
95 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
96 UpdateWindow(window_state,
97 GetMaximizedOrCenteredWindowType(window_state));
98 }
99 window_state->set_can_be_dragged(false);
100 }
101
102 void LockWindowState::DetachState(wm::WindowState* window_state) {
103 window_state->set_can_be_dragged(true);
104 }
105
106 void LockWindowState::UpdateWindow(wm::WindowState* window_state,
107 wm::WindowStateType target_state) {
108 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
109 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
110 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
111 !window_state->CanMaximize()) ||
112 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN);
113
114 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) {
115 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED)
116 return;
117
118 current_state_type_ = target_state;
119 ::wm::SetWindowVisibilityAnimationType(
120 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
121 window_state->window()->Hide();
122 if (window_state->IsActive())
123 window_state->Deactivate();
124 return;
125 }
126
127 if (current_state_type_ == target_state) {
128 // If the state type did not change, update it accordingly.
129 UpdateBounds(window_state);
130 return;
131 }
132
133 const wm::WindowStateType old_state_type = current_state_type_;
134 current_state_type_ = target_state;
135 window_state->UpdateWindowShowStateFromStateType();
136 window_state->NotifyPreStateTypeChange(old_state_type);
137 UpdateBounds(window_state);
138 window_state->NotifyPostStateTypeChange(old_state_type);
139
140 if ((window_state->window()->TargetVisibility() ||
141 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
142 !window_state->window()->layer()->visible()) {
143 // The layer may be hidden if the window was previously minimized. Make
144 // sure it's visible.
145 window_state->window()->Show();
146 }
147 }
148
149 wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType(
150 wm::WindowState* window_state) {
151 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED :
152 wm::WINDOW_STATE_TYPE_NORMAL;
153 }
154
155 void LockWindowState::UpdateBounds(wm::WindowState* window_state) {
156 keyboard::KeyboardController* keyboard_controller =
157 keyboard::KeyboardController::GetInstance();
158 gfx::Rect keyboard_bounds;
159
160 if (keyboard_controller && !keyboard::IsKeyboardOverscrollEnabled())
161 keyboard_bounds = keyboard_controller->current_keyboard_bounds();
162
163 gfx::Rect bounds =
164 ScreenUtil::GetDisplayBoundsInParent(window_state->window());
165 bounds.set_height(bounds.height() - keyboard_bounds.height());
166 window_state->SetBoundsDirect(bounds);
167 }
168
169 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698