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

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

Issue 2354533004: Ports LockLayoutManager/LockWindowState to ash/common (Closed)
Patch Set: Created 4 years, 3 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
« ash/root_window_controller.cc ('K') | « ash/wm/lock_window_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility>
8
9 #include "ash/aura/wm_window_aura.h"
10 #include "ash/common/wm/window_animation_types.h"
11 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm/window_state_delegate.h"
13 #include "ash/common/wm/window_state_util.h"
14 #include "ash/common/wm/wm_event.h"
15 #include "ash/common/wm/wm_screen_util.h"
16 #include "ash/common/wm_shell.h"
17 #include "ash/display/display_manager.h"
18 #include "ash/shell.h"
19 #include "ash/wm/lock_layout_manager.h"
20 #include "ash/wm/window_animations.h"
21 #include "ash/wm/window_state_aura.h"
22 #include "ash/wm/window_util.h"
23 #include "ui/aura/window.h"
24 #include "ui/aura/window_delegate.h"
25 #include "ui/gfx/geometry/rect.h"
26 #include "ui/keyboard/keyboard_controller.h"
27 #include "ui/keyboard/keyboard_util.h"
28 #include "ui/wm/core/window_animations.h"
29
30 namespace ash {
31
32 LockWindowState::LockWindowState(aura::Window* window)
33 : current_state_type_(wm::GetWindowState(window)->GetStateType()) {}
34
35 LockWindowState::~LockWindowState() {}
36
37 void LockWindowState::OnWMEvent(wm::WindowState* window_state,
38 const wm::WMEvent* event) {
39 switch (event->type()) {
40 case wm::WM_EVENT_TOGGLE_FULLSCREEN:
41 ToggleFullScreen(window_state, window_state->delegate());
42 break;
43 case wm::WM_EVENT_FULLSCREEN:
44 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN);
45 break;
46 case wm::WM_EVENT_PIN:
47 case wm::WM_EVENT_TRUSTED_PIN:
48 NOTREACHED();
49 break;
50 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
51 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
52 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
53 case wm::WM_EVENT_TOGGLE_MAXIMIZE:
54 case wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT:
55 case wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT:
56 case wm::WM_EVENT_CENTER:
57 case wm::WM_EVENT_SNAP_LEFT:
58 case wm::WM_EVENT_SNAP_RIGHT:
59 case wm::WM_EVENT_NORMAL:
60 case wm::WM_EVENT_MAXIMIZE:
61 case wm::WM_EVENT_DOCK:
62 UpdateWindow(window_state,
63 GetMaximizedOrCenteredWindowType(window_state));
64 return;
65 case wm::WM_EVENT_MINIMIZE:
66 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED);
67 return;
68 case wm::WM_EVENT_SHOW_INACTIVE:
69 return;
70 case wm::WM_EVENT_SET_BOUNDS:
71 if (window_state->IsMaximized() || window_state->IsFullscreen()) {
72 UpdateBounds(window_state);
73 } else {
74 const ash::wm::SetBoundsEvent* bounds_event =
75 static_cast<const ash::wm::SetBoundsEvent*>(event);
76 window_state->SetBoundsConstrained(bounds_event->requested_bounds());
77 }
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 } else {
86 UpdateBounds(window_state);
87 }
88 break;
89 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED:
90 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED:
91 UpdateBounds(window_state);
92 break;
93 }
94 }
95
96 wm::WindowStateType LockWindowState::GetType() const {
97 return current_state_type_;
98 }
99
100 void LockWindowState::AttachState(wm::WindowState* window_state,
101 wm::WindowState::State* previous_state) {
102 current_state_type_ = previous_state->GetType();
103
104 // Initialize the state to a good preset.
105 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
106 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
107 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
108 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state));
109 }
110 }
111
112 void LockWindowState::DetachState(wm::WindowState* window_state) {}
113
114 // static
115 wm::WindowState* LockWindowState::SetLockWindowState(aura::Window* window) {
116 std::unique_ptr<wm::WindowState::State> lock_state(
117 new LockWindowState(window));
118 std::unique_ptr<wm::WindowState::State> old_state(
119 wm::GetWindowState(window)->SetStateObject(std::move(lock_state)));
120 return wm::GetWindowState(window);
121 }
122
123 void LockWindowState::UpdateWindow(wm::WindowState* window_state,
124 wm::WindowStateType target_state) {
125 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
126 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
127 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
128 !window_state->CanMaximize()) ||
129 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN);
130
131 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) {
132 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED)
133 return;
134
135 current_state_type_ = target_state;
136 window_state->window()->SetVisibilityAnimationType(
137 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
138 window_state->window()->Hide();
139 if (window_state->IsActive())
140 window_state->Deactivate();
141 return;
142 }
143
144 if (current_state_type_ == target_state) {
145 // If the state type did not change, update it accordingly.
146 UpdateBounds(window_state);
147 return;
148 }
149
150 const wm::WindowStateType old_state_type = current_state_type_;
151 current_state_type_ = target_state;
152 window_state->UpdateWindowShowStateFromStateType();
153 window_state->NotifyPreStateTypeChange(old_state_type);
154 UpdateBounds(window_state);
155 window_state->NotifyPostStateTypeChange(old_state_type);
156
157 if ((window_state->window()->GetTargetVisibility() ||
158 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
159 !window_state->window()->GetLayer()->visible()) {
160 // The layer may be hidden if the window was previously minimized. Make
161 // sure it's visible.
162 window_state->window()->Show();
163 }
164 }
165
166 wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType(
167 wm::WindowState* window_state) {
168 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED
169 : wm::WINDOW_STATE_TYPE_NORMAL;
170 }
171
172 gfx::Rect GetBoundsForLockWindow(aura::Window* window) {
173 if (WmShell::Get()->IsInUnifiedMode())
174 return WmShell::Get()->GetFirstDisplay().bounds();
175 return wm::GetDisplayBoundsInParent(WmWindowAura::Get(window));
176 }
177
178 void LockWindowState::UpdateBounds(wm::WindowState* window_state) {
179 if (!window_state->IsMaximized() && !window_state->IsFullscreen())
180 return;
181
182 keyboard::KeyboardController* keyboard_controller =
183 keyboard::KeyboardController::GetInstance();
184 gfx::Rect keyboard_bounds;
185
186 if (keyboard_controller && !keyboard::IsKeyboardOverscrollEnabled() &&
187 keyboard_controller->keyboard_visible()) {
188 keyboard_bounds = keyboard_controller->current_keyboard_bounds();
189 }
190 gfx::Rect bounds = wm::GetDisplayBoundsWithShelf(window_state->window());
191 bounds.set_height(bounds.height() - keyboard_bounds.height());
192
193 VLOG(1) << "Updating window bounds to: " << bounds.ToString();
194 window_state->SetBoundsDirect(bounds);
195 }
196
197 } // namespace ash
OLDNEW
« ash/root_window_controller.cc ('K') | « ash/wm/lock_window_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698