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

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: remove bug fix 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 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 window_state->set_can_be_dragged(false);
oshima 2014/06/05 15:27:26 you can remove this, and one in DetachState. they'
Nikita (slow) 2014/06/05 16:08:37 Done.
96 }
97
98 void LockWindowState::DetachState(wm::WindowState* window_state) {
99 window_state->set_can_be_dragged(true);
100 }
101
102 void LockWindowState::UpdateWindow(wm::WindowState* window_state,
103 wm::WindowStateType target_state) {
104 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
105 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
106 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
107 !window_state->CanMaximize()) ||
108 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN);
109
110 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) {
111 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED)
112 return;
113
114 current_state_type_ = target_state;
115 ::wm::SetWindowVisibilityAnimationType(
116 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
117 window_state->window()->Hide();
118 if (window_state->IsActive())
119 window_state->Deactivate();
120 return;
121 }
122
123 if (current_state_type_ == target_state) {
124 // If the state type did not change, update it accordingly.
125 UpdateBounds(window_state);
126 return;
127 }
128
129 const wm::WindowStateType old_state_type = current_state_type_;
130 current_state_type_ = target_state;
131 window_state->UpdateWindowShowStateFromStateType();
132 window_state->NotifyPreStateTypeChange(old_state_type);
133 UpdateBounds(window_state);
134 window_state->NotifyPostStateTypeChange(old_state_type);
135
136 if ((window_state->window()->TargetVisibility() ||
137 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
138 !window_state->window()->layer()->visible()) {
139 // The layer may be hidden if the window was previously minimized. Make
140 // sure it's visible.
141 window_state->window()->Show();
142 }
143 }
144
145 wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType(
146 wm::WindowState* window_state) {
147 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED :
148 wm::WINDOW_STATE_TYPE_NORMAL;
149 }
150
151 void LockWindowState::UpdateBounds(wm::WindowState* window_state) {
152 keyboard::KeyboardController* keyboard_controller =
153 keyboard::KeyboardController::GetInstance();
154 gfx::Rect keyboard_bounds;
155
156 if (keyboard_controller && !keyboard::IsKeyboardOverscrollEnabled())
157 keyboard_bounds = keyboard_controller->current_keyboard_bounds();
158
159 gfx::Rect bounds =
160 ScreenUtil::GetDisplayBoundsInParent(window_state->window());
161 bounds.set_height(bounds.height() - keyboard_bounds.height());
162 window_state->SetBoundsDirect(bounds);
163 }
164
165 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698