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

Side by Side Diff: ash/wm/tablet_mode/tablet_mode_window_state.cc

Issue 2906803002: Rename MaximizeMode to TabletMode (Closed)
Patch Set: updated filter Created 3 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" 5 #include "ash/wm/tablet_mode/tablet_mode_window_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
13 #include "ash/wm/screen_pinning_controller.h" 12 #include "ash/wm/screen_pinning_controller.h"
13 #include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
14 #include "ash/wm/window_animation_types.h" 14 #include "ash/wm/window_animation_types.h"
15 #include "ash/wm/window_properties.h" 15 #include "ash/wm/window_properties.h"
16 #include "ash/wm/window_state_util.h" 16 #include "ash/wm/window_state_util.h"
17 #include "ash/wm/wm_event.h" 17 #include "ash/wm/wm_event.h"
18 #include "ash/wm_window.h" 18 #include "ash/wm_window.h"
19 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
20 #include "ui/aura/window_delegate.h" 20 #include "ui/aura/window_delegate.h"
21 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
22 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
23 23
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen(); 95 gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen();
96 if (!restore_bounds.IsEmpty()) 96 if (!restore_bounds.IsEmpty())
97 return restore_bounds; 97 return restore_bounds;
98 } 98 }
99 return window_state->window()->GetBoundsInScreen(); 99 return window_state->window()->GetBoundsInScreen();
100 } 100 }
101 101
102 } // namespace 102 } // namespace
103 103
104 // static 104 // static
105 void MaximizeModeWindowState::UpdateWindowPosition( 105 void TabletModeWindowState::UpdateWindowPosition(
106 wm::WindowState* window_state) { 106 wm::WindowState* window_state) {
107 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); 107 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state);
108 if (bounds_in_parent == window_state->window()->bounds()) 108 if (bounds_in_parent == window_state->window()->bounds())
109 return; 109 return;
110 window_state->SetBoundsDirect(bounds_in_parent); 110 window_state->SetBoundsDirect(bounds_in_parent);
111 } 111 }
112 112
113 MaximizeModeWindowState::MaximizeModeWindowState( 113 TabletModeWindowState::TabletModeWindowState(aura::Window* window,
114 aura::Window* window, 114 TabletModeWindowManager* creator)
115 MaximizeModeWindowManager* creator)
116 : window_(window), 115 : window_(window),
117 creator_(creator), 116 creator_(creator),
118 current_state_type_(wm::GetWindowState(window)->GetStateType()), 117 current_state_type_(wm::GetWindowState(window)->GetStateType()),
119 defer_bounds_updates_(false) { 118 defer_bounds_updates_(false) {
120 old_state_.reset(wm::GetWindowState(window) 119 old_state_.reset(wm::GetWindowState(window)
121 ->SetStateObject(std::unique_ptr<State>(this)) 120 ->SetStateObject(std::unique_ptr<State>(this))
122 .release()); 121 .release());
123 } 122 }
124 123
125 MaximizeModeWindowState::~MaximizeModeWindowState() { 124 TabletModeWindowState::~TabletModeWindowState() {
126 creator_->WindowStateDestroyed(window_); 125 creator_->WindowStateDestroyed(window_);
127 } 126 }
128 127
129 void MaximizeModeWindowState::LeaveMaximizeMode(wm::WindowState* window_state) { 128 void TabletModeWindowState::LeaveTabletMode(wm::WindowState* window_state) {
130 // Note: When we return we will destroy ourselves with the |our_reference|. 129 // Note: When we return we will destroy ourselves with the |our_reference|.
131 std::unique_ptr<wm::WindowState::State> our_reference = 130 std::unique_ptr<wm::WindowState::State> our_reference =
132 window_state->SetStateObject(std::move(old_state_)); 131 window_state->SetStateObject(std::move(old_state_));
133 } 132 }
134 133
135 void MaximizeModeWindowState::SetDeferBoundsUpdates(bool defer_bounds_updates) { 134 void TabletModeWindowState::SetDeferBoundsUpdates(bool defer_bounds_updates) {
136 if (defer_bounds_updates_ == defer_bounds_updates) 135 if (defer_bounds_updates_ == defer_bounds_updates)
137 return; 136 return;
138 137
139 defer_bounds_updates_ = defer_bounds_updates; 138 defer_bounds_updates_ = defer_bounds_updates;
140 if (!defer_bounds_updates_) 139 if (!defer_bounds_updates_)
141 UpdateBounds(wm::GetWindowState(window_), true); 140 UpdateBounds(wm::GetWindowState(window_), true);
142 } 141 }
143 142
144 void MaximizeModeWindowState::OnWMEvent(wm::WindowState* window_state, 143 void TabletModeWindowState::OnWMEvent(wm::WindowState* window_state,
145 const wm::WMEvent* event) { 144 const wm::WMEvent* event) {
146 // Ignore events that are sent during the exit transition. 145 // Ignore events that are sent during the exit transition.
147 if (ignore_wm_events_) { 146 if (ignore_wm_events_) {
148 return; 147 return;
149 } 148 }
150 149
151 switch (event->type()) { 150 switch (event->type()) {
152 case wm::WM_EVENT_TOGGLE_FULLSCREEN: 151 case wm::WM_EVENT_TOGGLE_FULLSCREEN:
153 ToggleFullScreen(window_state, window_state->delegate()); 152 ToggleFullScreen(window_state, window_state->delegate());
154 break; 153 break;
155 case wm::WM_EVENT_FULLSCREEN: 154 case wm::WM_EVENT_FULLSCREEN:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 UpdateBounds(window_state, true); 221 UpdateBounds(window_state, true);
223 break; 222 break;
224 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED: 223 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED:
225 // Don't animate on a screen rotation - just snap to new size. 224 // Don't animate on a screen rotation - just snap to new size.
226 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) 225 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED)
227 UpdateBounds(window_state, false); 226 UpdateBounds(window_state, false);
228 break; 227 break;
229 } 228 }
230 } 229 }
231 230
232 wm::WindowStateType MaximizeModeWindowState::GetType() const { 231 wm::WindowStateType TabletModeWindowState::GetType() const {
233 return current_state_type_; 232 return current_state_type_;
234 } 233 }
235 234
236 void MaximizeModeWindowState::AttachState( 235 void TabletModeWindowState::AttachState(
237 wm::WindowState* window_state, 236 wm::WindowState* window_state,
238 wm::WindowState::State* previous_state) { 237 wm::WindowState::State* previous_state) {
239 current_state_type_ = previous_state->GetType(); 238 current_state_type_ = previous_state->GetType();
240 239
241 gfx::Rect restore_bounds = GetRestoreBounds(window_state); 240 gfx::Rect restore_bounds = GetRestoreBounds(window_state);
242 if (!restore_bounds.IsEmpty()) { 241 if (!restore_bounds.IsEmpty()) {
243 // We do not want to do a session restore to our window states. Therefore 242 // We do not want to do a session restore to our window states. Therefore
244 // we tell the window to use the current default states instead. 243 // we tell the window to use the current default states instead.
245 SetWindowRestoreOverrides(window_state->window(), restore_bounds, 244 SetWindowRestoreOverrides(window_state->window(), restore_bounds,
246 window_state->GetShowState()); 245 window_state->GetShowState());
247 } 246 }
248 247
249 // Initialize the state to a good preset. 248 // Initialize the state to a good preset.
250 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 249 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
251 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && 250 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
252 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && 251 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN &&
253 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && 252 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED &&
254 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { 253 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) {
255 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), 254 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state),
256 true); 255 true);
257 } 256 }
258 257
259 window_state->set_can_be_dragged(false); 258 window_state->set_can_be_dragged(false);
260 } 259 }
261 260
262 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { 261 void TabletModeWindowState::DetachState(wm::WindowState* window_state) {
263 // From now on, we can use the default session restore mechanism again. 262 // From now on, we can use the default session restore mechanism again.
264 SetWindowRestoreOverrides(window_state->window(), gfx::Rect(), 263 SetWindowRestoreOverrides(window_state->window(), gfx::Rect(),
265 ui::SHOW_STATE_NORMAL); 264 ui::SHOW_STATE_NORMAL);
266 window_state->set_can_be_dragged(true); 265 window_state->set_can_be_dragged(true);
267 } 266 }
268 267
269 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, 268 void TabletModeWindowState::UpdateWindow(wm::WindowState* window_state,
270 wm::WindowStateType target_state, 269 wm::WindowStateType target_state,
271 bool animated) { 270 bool animated) {
272 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || 271 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
273 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || 272 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
274 target_state == wm::WINDOW_STATE_TYPE_PINNED || 273 target_state == wm::WINDOW_STATE_TYPE_PINNED ||
275 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || 274 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED ||
276 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && 275 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
277 !window_state->CanMaximize()) || 276 !window_state->CanMaximize()) ||
278 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); 277 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN);
279 278
280 if (current_state_type_ == target_state) { 279 if (current_state_type_ == target_state) {
281 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) 280 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED)
(...skipping 30 matching lines...) Expand all
312 311
313 if ((window_state->window()->layer()->GetTargetVisibility() || 312 if ((window_state->window()->layer()->GetTargetVisibility() ||
314 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && 313 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
315 !window_state->window()->layer()->visible()) { 314 !window_state->window()->layer()->visible()) {
316 // The layer may be hidden if the window was previously minimized. Make 315 // The layer may be hidden if the window was previously minimized. Make
317 // sure it's visible. 316 // sure it's visible.
318 window_state->window()->Show(); 317 window_state->window()->Show();
319 } 318 }
320 } 319 }
321 320
322 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( 321 wm::WindowStateType TabletModeWindowState::GetMaximizedOrCenteredWindowType(
323 wm::WindowState* window_state) { 322 wm::WindowState* window_state) {
324 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED 323 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED
325 : wm::WINDOW_STATE_TYPE_NORMAL; 324 : wm::WINDOW_STATE_TYPE_NORMAL;
326 } 325 }
327 326
328 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, 327 void TabletModeWindowState::UpdateBounds(wm::WindowState* window_state,
329 bool animated) { 328 bool animated) {
330 if (defer_bounds_updates_) 329 if (defer_bounds_updates_)
331 return; 330 return;
332 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); 331 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state);
333 // If we have a target bounds rectangle, we center it and set it 332 // If we have a target bounds rectangle, we center it and set it
334 // accordingly. 333 // accordingly.
335 if (!bounds_in_parent.IsEmpty() && 334 if (!bounds_in_parent.IsEmpty() &&
336 bounds_in_parent != window_state->window()->bounds()) { 335 bounds_in_parent != window_state->window()->bounds()) {
337 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || 336 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED ||
338 !window_state->window()->IsVisible() || !animated) { 337 !window_state->window()->IsVisible() || !animated) {
339 window_state->SetBoundsDirect(bounds_in_parent); 338 window_state->SetBoundsDirect(bounds_in_parent);
340 } else { 339 } else {
341 // If we animate (to) maximized mode, we want to use the cross fade to 340 // If we animate (to) tablet mode, we want to use the cross fade to
342 // avoid flashing. 341 // avoid flashing.
343 if (window_state->IsMaximized()) 342 if (window_state->IsMaximized())
344 window_state->SetBoundsDirectCrossFade(bounds_in_parent); 343 window_state->SetBoundsDirectCrossFade(bounds_in_parent);
345 else 344 else
346 window_state->SetBoundsDirectAnimated(bounds_in_parent); 345 window_state->SetBoundsDirectAnimated(bounds_in_parent);
347 } 346 }
348 } 347 }
349 } 348 }
350 349
351 } // namespace ash 350 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698