OLD | NEW |
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/common/wm/maximize_mode/maximize_mode_window_state.h" | 5 #include "ash/common/wm/maximize_mode/maximize_mode_window_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
10 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 case wm::WM_EVENT_TOGGLE_FULLSCREEN: | 135 case wm::WM_EVENT_TOGGLE_FULLSCREEN: |
136 ToggleFullScreen(window_state, window_state->delegate()); | 136 ToggleFullScreen(window_state, window_state->delegate()); |
137 break; | 137 break; |
138 case wm::WM_EVENT_FULLSCREEN: | 138 case wm::WM_EVENT_FULLSCREEN: |
139 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN, true); | 139 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN, true); |
140 break; | 140 break; |
141 case wm::WM_EVENT_PIN: | 141 case wm::WM_EVENT_PIN: |
142 if (!WmShell::Get()->IsPinned()) | 142 if (!WmShell::Get()->IsPinned()) |
143 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_PINNED, true); | 143 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_PINNED, true); |
144 break; | 144 break; |
| 145 case wm::WM_EVENT_TRUSTED_PIN: |
| 146 if (!WmShell::Get()->IsPinned()) |
| 147 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_TRUSTED_PINNED, true); |
| 148 break; |
145 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 149 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
146 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: | 150 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
147 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 151 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
148 case wm::WM_EVENT_TOGGLE_MAXIMIZE: | 152 case wm::WM_EVENT_TOGGLE_MAXIMIZE: |
149 case wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT: | 153 case wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT: |
150 case wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: | 154 case wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: |
151 case wm::WM_EVENT_CENTER: | 155 case wm::WM_EVENT_CENTER: |
152 case wm::WM_EVENT_SNAP_LEFT: | 156 case wm::WM_EVENT_SNAP_LEFT: |
153 case wm::WM_EVENT_SNAP_RIGHT: | 157 case wm::WM_EVENT_SNAP_RIGHT: |
154 case wm::WM_EVENT_NORMAL: | 158 case wm::WM_EVENT_NORMAL: |
(...skipping 14 matching lines...) Expand all Loading... |
169 } else if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { | 173 } else if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { |
170 // Having a maximized window, it could have been created with an empty | 174 // Having a maximized window, it could have been created with an empty |
171 // size and the caller should get his size upon leaving the maximized | 175 // size and the caller should get his size upon leaving the maximized |
172 // mode. As such we set the restore bounds to the requested bounds. | 176 // mode. As such we set the restore bounds to the requested bounds. |
173 gfx::Rect bounds_in_parent = | 177 gfx::Rect bounds_in_parent = |
174 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); | 178 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); |
175 if (!bounds_in_parent.IsEmpty()) | 179 if (!bounds_in_parent.IsEmpty()) |
176 window_state->SetRestoreBoundsInParent(bounds_in_parent); | 180 window_state->SetRestoreBoundsInParent(bounds_in_parent); |
177 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && | 181 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
178 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && | 182 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
179 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED) { | 183 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && |
| 184 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
180 // In all other cases (except for minimized windows) we respect the | 185 // In all other cases (except for minimized windows) we respect the |
181 // requested bounds and center it to a fully visible area on the screen. | 186 // requested bounds and center it to a fully visible area on the screen. |
182 gfx::Rect bounds_in_parent = | 187 gfx::Rect bounds_in_parent = |
183 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); | 188 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); |
184 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); | 189 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); |
185 if (bounds_in_parent != window_state->window()->GetBounds()) { | 190 if (bounds_in_parent != window_state->window()->GetBounds()) { |
186 if (window_state->window()->IsVisible()) | 191 if (window_state->window()->IsVisible()) |
187 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 192 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
188 else | 193 else |
189 window_state->SetBoundsDirect(bounds_in_parent); | 194 window_state->SetBoundsDirect(bounds_in_parent); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // We do not want to do a session restore to our window states. Therefore | 230 // We do not want to do a session restore to our window states. Therefore |
226 // we tell the window to use the current default states instead. | 231 // we tell the window to use the current default states instead. |
227 window_state->window()->SetRestoreOverrides(restore_bounds, | 232 window_state->window()->SetRestoreOverrides(restore_bounds, |
228 window_state->GetShowState()); | 233 window_state->GetShowState()); |
229 } | 234 } |
230 | 235 |
231 // Initialize the state to a good preset. | 236 // Initialize the state to a good preset. |
232 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && | 237 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
233 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && | 238 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
234 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && | 239 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
235 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED) { | 240 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && |
| 241 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
236 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), | 242 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), |
237 true); | 243 true); |
238 } | 244 } |
239 | 245 |
240 window_state->set_can_be_dragged(false); | 246 window_state->set_can_be_dragged(false); |
241 } | 247 } |
242 | 248 |
243 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { | 249 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { |
244 // From now on, we can use the default session restore mechanism again. | 250 // From now on, we can use the default session restore mechanism again. |
245 window_state->window()->SetRestoreOverrides(gfx::Rect(), | 251 window_state->window()->SetRestoreOverrides(gfx::Rect(), |
246 ui::SHOW_STATE_NORMAL); | 252 ui::SHOW_STATE_NORMAL); |
247 window_state->set_can_be_dragged(true); | 253 window_state->set_can_be_dragged(true); |
248 } | 254 } |
249 | 255 |
250 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, | 256 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, |
251 wm::WindowStateType target_state, | 257 wm::WindowStateType target_state, |
252 bool animated) { | 258 bool animated) { |
253 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || | 259 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
254 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || | 260 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
255 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 261 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
| 262 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
256 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && | 263 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
257 !window_state->CanMaximize()) || | 264 !window_state->CanMaximize()) || |
258 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); | 265 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); |
259 | 266 |
260 if (current_state_type_ == target_state) { | 267 if (current_state_type_ == target_state) { |
261 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) | 268 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) |
262 return; | 269 return; |
263 // If the state type did not change, update it accordingly. | 270 // If the state type did not change, update it accordingly. |
264 UpdateBounds(window_state, animated); | 271 UpdateBounds(window_state, animated); |
265 return; | 272 return; |
(...skipping 10 matching lines...) Expand all Loading... |
276 window_state->window()->Hide(); | 283 window_state->window()->Hide(); |
277 if (window_state->IsActive()) | 284 if (window_state->IsActive()) |
278 window_state->Deactivate(); | 285 window_state->Deactivate(); |
279 } else { | 286 } else { |
280 UpdateBounds(window_state, animated); | 287 UpdateBounds(window_state, animated); |
281 } | 288 } |
282 | 289 |
283 window_state->NotifyPostStateTypeChange(old_state_type); | 290 window_state->NotifyPostStateTypeChange(old_state_type); |
284 | 291 |
285 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || | 292 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || |
286 target_state == wm::WINDOW_STATE_TYPE_PINNED) { | 293 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
| 294 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
| 295 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
287 WmShell::Get()->SetPinnedWindow(window_state->window()); | 296 WmShell::Get()->SetPinnedWindow(window_state->window()); |
288 } | 297 } |
289 | 298 |
290 if ((window_state->window()->GetTargetVisibility() || | 299 if ((window_state->window()->GetTargetVisibility() || |
291 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && | 300 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && |
292 !window_state->window()->GetLayer()->visible()) { | 301 !window_state->window()->GetLayer()->visible()) { |
293 // The layer may be hidden if the window was previously minimized. Make | 302 // The layer may be hidden if the window was previously minimized. Make |
294 // sure it's visible. | 303 // sure it's visible. |
295 window_state->window()->Show(); | 304 window_state->window()->Show(); |
296 } | 305 } |
(...skipping 22 matching lines...) Expand all Loading... |
319 // avoid flashing. | 328 // avoid flashing. |
320 if (window_state->IsMaximized()) | 329 if (window_state->IsMaximized()) |
321 window_state->SetBoundsDirectCrossFade(bounds_in_parent); | 330 window_state->SetBoundsDirectCrossFade(bounds_in_parent); |
322 else | 331 else |
323 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 332 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
324 } | 333 } |
325 } | 334 } |
326 } | 335 } |
327 | 336 |
328 } // namespace ash | 337 } // namespace ash |
OLD | NEW |