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

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

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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
« no previous file with comments | « ash/common/wm/lock_window_state.h ('k') | ash/common/wm/maximize_mode/OWNERS » ('j') | 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/common/wm/lock_window_state.h"
6
7 #include <utility>
8
9 #include "ash/common/wm/lock_layout_manager.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/common/wm_window.h"
18 #include "base/memory/ptr_util.h"
19 #include "ui/gfx/geometry/rect.h"
20 #include "ui/keyboard/keyboard_controller.h"
21 #include "ui/keyboard/keyboard_util.h"
22
23 namespace ash {
24
25 LockWindowState::LockWindowState(WmWindow* window)
26 : current_state_type_(window->GetWindowState()->GetStateType()) {}
27
28 LockWindowState::~LockWindowState() {}
29
30 void LockWindowState::OnWMEvent(wm::WindowState* window_state,
31 const wm::WMEvent* event) {
32 switch (event->type()) {
33 case wm::WM_EVENT_TOGGLE_FULLSCREEN:
34 ToggleFullScreen(window_state, window_state->delegate());
35 break;
36 case wm::WM_EVENT_FULLSCREEN:
37 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN);
38 break;
39 case wm::WM_EVENT_PIN:
40 case wm::WM_EVENT_TRUSTED_PIN:
41 NOTREACHED();
42 break;
43 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
44 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
45 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
46 case wm::WM_EVENT_TOGGLE_MAXIMIZE:
47 case wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT:
48 case wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT:
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 case wm::WM_EVENT_DOCK:
55 UpdateWindow(window_state,
56 GetMaximizedOrCenteredWindowType(window_state));
57 return;
58 case wm::WM_EVENT_MINIMIZE:
59 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED);
60 return;
61 case wm::WM_EVENT_SHOW_INACTIVE:
62 return;
63 case wm::WM_EVENT_SET_BOUNDS:
64 if (window_state->IsMaximized() || window_state->IsFullscreen()) {
65 UpdateBounds(window_state);
66 } else {
67 const ash::wm::SetBoundsEvent* bounds_event =
68 static_cast<const ash::wm::SetBoundsEvent*>(event);
69 window_state->SetBoundsConstrained(bounds_event->requested_bounds());
70 }
71 break;
72 case wm::WM_EVENT_ADDED_TO_WORKSPACE:
73 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
74 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
75 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
76 UpdateWindow(window_state,
77 GetMaximizedOrCenteredWindowType(window_state));
78 } else {
79 UpdateBounds(window_state);
80 }
81 break;
82 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED:
83 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED:
84 UpdateBounds(window_state);
85 break;
86 }
87 }
88
89 wm::WindowStateType LockWindowState::GetType() const {
90 return current_state_type_;
91 }
92
93 void LockWindowState::AttachState(wm::WindowState* window_state,
94 wm::WindowState::State* previous_state) {
95 current_state_type_ = previous_state->GetType();
96
97 // Initialize the state to a good preset.
98 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
99 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
100 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
101 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state));
102 }
103 }
104
105 void LockWindowState::DetachState(wm::WindowState* window_state) {}
106
107 // static
108 wm::WindowState* LockWindowState::SetLockWindowState(WmWindow* window) {
109 std::unique_ptr<wm::WindowState::State> lock_state =
110 base::MakeUnique<LockWindowState>(window);
111 std::unique_ptr<wm::WindowState::State> old_state(
112 window->GetWindowState()->SetStateObject(std::move(lock_state)));
113 return window->GetWindowState();
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 window_state->window()->SetVisibilityAnimationType(
130 wm::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()->GetTargetVisibility() ||
151 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
152 !window_state->window()->GetLayer()->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 if (!window_state->IsMaximized() && !window_state->IsFullscreen())
167 return;
168
169 keyboard::KeyboardController* keyboard_controller =
170 keyboard::KeyboardController::GetInstance();
171 gfx::Rect keyboard_bounds;
172
173 if (keyboard_controller && !keyboard::IsKeyboardOverscrollEnabled() &&
174 keyboard_controller->keyboard_visible()) {
175 keyboard_bounds = keyboard_controller->current_keyboard_bounds();
176 }
177 gfx::Rect bounds = wm::GetDisplayBoundsWithShelf(window_state->window());
178 bounds.set_height(bounds.height() - keyboard_bounds.height());
179
180 VLOG(1) << "Updating window bounds to: " << bounds.ToString();
181 window_state->SetBoundsDirect(bounds);
182 }
183
184 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/lock_window_state.h ('k') | ash/common/wm/maximize_mode/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698