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/default_state.h" | 5 #include "ash/common/wm/default_state.h" |
6 | 6 |
7 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 7 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
8 #include "ash/common/wm/window_animation_types.h" | 8 #include "ash/common/wm/window_animation_types.h" |
9 #include "ash/common/wm/window_parenting_utils.h" | 9 #include "ash/common/wm/window_parenting_utils.h" |
10 #include "ash/common/wm/window_positioning_utils.h" | 10 #include "ash/common/wm/window_positioning_utils.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 | 159 |
160 } // namespace | 160 } // namespace |
161 | 161 |
162 DefaultState::DefaultState(WindowStateType initial_state_type) | 162 DefaultState::DefaultState(WindowStateType initial_state_type) |
163 : state_type_(initial_state_type), stored_window_state_(nullptr) {} | 163 : state_type_(initial_state_type), stored_window_state_(nullptr) {} |
164 DefaultState::~DefaultState() {} | 164 DefaultState::~DefaultState() {} |
165 | 165 |
166 void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) { | 166 void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) { |
167 if (ProcessWorkspaceEvents(window_state, event)) | 167 if (ProcessWorkspaceEvents(window_state, event)) |
168 return; | 168 return; |
169 | 169 |
oshima
2016/12/21 01:38:58
It's probably safer to reject all request in the f
hidehiko
2016/12/21 06:57:30
Done.
| |
170 if (ProcessCompoundEvents(window_state, event)) | 170 if (ProcessCompoundEvents(window_state, event)) |
171 return; | 171 return; |
172 | 172 |
173 WindowStateType current_state_type = window_state->GetStateType(); | 173 WindowStateType current_state_type = window_state->GetStateType(); |
174 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL; | 174 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL; |
175 switch (event->type()) { | 175 switch (event->type()) { |
176 case WM_EVENT_NORMAL: | 176 case WM_EVENT_NORMAL: |
177 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED | 177 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED |
178 ? WINDOW_STATE_TYPE_DOCKED | 178 ? WINDOW_STATE_TYPE_DOCKED |
179 : WINDOW_STATE_TYPE_NORMAL; | 179 : WINDOW_STATE_TYPE_NORMAL; |
180 break; | 180 break; |
181 case WM_EVENT_MAXIMIZE: | 181 case WM_EVENT_MAXIMIZE: |
182 if (window_state->IsTrustedPinned()) | |
183 return; | |
182 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED; | 184 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED; |
183 break; | 185 break; |
184 case WM_EVENT_MINIMIZE: | 186 case WM_EVENT_MINIMIZE: |
187 if (window_state->IsTrustedPinned()) | |
188 return; | |
185 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED | 189 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED |
186 ? WINDOW_STATE_TYPE_DOCKED_MINIMIZED | 190 ? WINDOW_STATE_TYPE_DOCKED_MINIMIZED |
187 : WINDOW_STATE_TYPE_MINIMIZED; | 191 : WINDOW_STATE_TYPE_MINIMIZED; |
188 break; | 192 break; |
189 case WM_EVENT_FULLSCREEN: | 193 case WM_EVENT_FULLSCREEN: |
194 if (window_state->IsTrustedPinned()) | |
195 return; | |
190 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN; | 196 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN; |
191 break; | 197 break; |
192 case WM_EVENT_SNAP_LEFT: | 198 case WM_EVENT_SNAP_LEFT: |
193 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED; | 199 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED; |
194 break; | 200 break; |
195 case WM_EVENT_SNAP_RIGHT: | 201 case WM_EVENT_SNAP_RIGHT: |
196 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED; | 202 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED; |
197 break; | 203 break; |
198 case WM_EVENT_DOCK: | 204 case WM_EVENT_DOCK: |
199 next_state_type = WINDOW_STATE_TYPE_DOCKED; | 205 next_state_type = WINDOW_STATE_TYPE_DOCKED; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 stored_display_state_ = window_state->window()->GetDisplayNearestWindow(); | 292 stored_display_state_ = window_state->window()->GetDisplayNearestWindow(); |
287 } | 293 } |
288 | 294 |
289 // static | 295 // static |
290 bool DefaultState::ProcessCompoundEvents(WindowState* window_state, | 296 bool DefaultState::ProcessCompoundEvents(WindowState* window_state, |
291 const WMEvent* event) { | 297 const WMEvent* event) { |
292 WmWindow* window = window_state->window(); | 298 WmWindow* window = window_state->window(); |
293 | 299 |
294 switch (event->type()) { | 300 switch (event->type()) { |
295 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 301 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
302 if (window_state->IsTrustedPinned()) | |
303 return true; | |
296 if (window_state->IsFullscreen()) { | 304 if (window_state->IsFullscreen()) { |
297 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 305 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
298 window_state->OnWMEvent(&event); | 306 window_state->OnWMEvent(&event); |
299 } else if (window_state->IsMaximized()) { | 307 } else if (window_state->IsMaximized()) { |
300 window_state->Restore(); | 308 window_state->Restore(); |
301 } else if (window_state->IsNormalOrSnapped()) { | 309 } else if (window_state->IsNormalOrSnapped()) { |
302 if (window_state->CanMaximize()) | 310 if (window_state->CanMaximize()) |
303 window_state->Maximize(); | 311 window_state->Maximize(); |
304 } | 312 } |
305 return true; | 313 return true; |
306 case WM_EVENT_TOGGLE_MAXIMIZE: | 314 case WM_EVENT_TOGGLE_MAXIMIZE: |
315 if (window_state->IsTrustedPinned()) | |
316 return true; | |
307 if (window_state->IsFullscreen()) { | 317 if (window_state->IsFullscreen()) { |
308 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 318 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
309 window_state->OnWMEvent(&event); | 319 window_state->OnWMEvent(&event); |
310 } else if (window_state->IsMaximized()) { | 320 } else if (window_state->IsMaximized()) { |
311 window_state->Restore(); | 321 window_state->Restore(); |
312 } else if (window_state->CanMaximize()) { | 322 } else if (window_state->CanMaximize()) { |
313 window_state->Maximize(); | 323 window_state->Maximize(); |
314 } | 324 } |
315 return true; | 325 return true; |
316 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: { | 326 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: { |
327 if (window_state->IsTrustedPinned()) | |
328 return true; | |
317 gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window); | 329 gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window); |
318 | 330 |
319 // Maximize vertically if: | 331 // Maximize vertically if: |
320 // - The window does not have a max height defined. | 332 // - The window does not have a max height defined. |
321 // - The window has the normal state type. Snapped windows are excluded | 333 // - The window has the normal state type. Snapped windows are excluded |
322 // because they are already maximized vertically and reverting to the | 334 // because they are already maximized vertically and reverting to the |
323 // restored bounds looks weird. | 335 // restored bounds looks weird. |
324 if (window->GetMaximumSize().height() != 0 || | 336 if (window->GetMaximumSize().height() != 0 || |
325 !window_state->IsNormalStateType()) { | 337 !window_state->IsNormalStateType()) { |
326 return true; | 338 return true; |
327 } | 339 } |
328 if (window_state->HasRestoreBounds() && | 340 if (window_state->HasRestoreBounds() && |
329 (window->GetBounds().height() == work_area.height() && | 341 (window->GetBounds().height() == work_area.height() && |
330 window->GetBounds().y() == work_area.y())) { | 342 window->GetBounds().y() == work_area.y())) { |
331 window_state->SetAndClearRestoreBounds(); | 343 window_state->SetAndClearRestoreBounds(); |
332 } else { | 344 } else { |
333 window_state->SaveCurrentBoundsForRestore(); | 345 window_state->SaveCurrentBoundsForRestore(); |
334 window->SetBounds(gfx::Rect(window->GetBounds().x(), work_area.y(), | 346 window->SetBounds(gfx::Rect(window->GetBounds().x(), work_area.y(), |
335 window->GetBounds().width(), | 347 window->GetBounds().width(), |
336 work_area.height())); | 348 work_area.height())); |
337 } | 349 } |
338 return true; | 350 return true; |
339 } | 351 } |
340 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: { | 352 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: { |
353 if (window_state->IsTrustedPinned()) | |
354 return true; | |
355 | |
341 // Maximize horizontally if: | 356 // Maximize horizontally if: |
342 // - The window does not have a max width defined. | 357 // - The window does not have a max width defined. |
343 // - The window is snapped or has the normal state type. | 358 // - The window is snapped or has the normal state type. |
344 if (window->GetMaximumSize().width() != 0) | 359 if (window->GetMaximumSize().width() != 0) |
345 return true; | 360 return true; |
346 if (!window_state->IsNormalOrSnapped()) | 361 if (!window_state->IsNormalOrSnapped()) |
347 return true; | 362 return true; |
348 gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window); | 363 gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window); |
349 if (window_state->IsNormalStateType() && | 364 if (window_state->IsNormalStateType() && |
350 window_state->HasRestoreBounds() && | 365 window_state->HasRestoreBounds() && |
(...skipping 13 matching lines...) Expand all Loading... | |
364 // which match the workspace bounds exactly so it is necessary to set | 379 // which match the workspace bounds exactly so it is necessary to set |
365 // the bounds again below. | 380 // the bounds again below. |
366 } | 381 } |
367 | 382 |
368 window_state->SetRestoreBoundsInParent(restore_bounds); | 383 window_state->SetRestoreBoundsInParent(restore_bounds); |
369 window->SetBounds(new_bounds); | 384 window->SetBounds(new_bounds); |
370 } | 385 } |
371 return true; | 386 return true; |
372 } | 387 } |
373 case WM_EVENT_TOGGLE_FULLSCREEN: | 388 case WM_EVENT_TOGGLE_FULLSCREEN: |
389 if (window_state->IsTrustedPinned()) | |
390 return true; | |
374 ToggleFullScreen(window_state, window_state->delegate()); | 391 ToggleFullScreen(window_state, window_state->delegate()); |
375 return true; | 392 return true; |
376 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: | 393 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: |
377 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: | 394 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: |
378 CycleSnapDock(window_state, event->type()); | 395 CycleSnapDock(window_state, event->type()); |
379 return true; | 396 return true; |
380 case WM_EVENT_CENTER: | 397 case WM_EVENT_CENTER: |
381 CenterWindow(window_state); | 398 CenterWindow(window_state); |
382 return true; | 399 return true; |
383 case WM_EVENT_NORMAL: | 400 case WM_EVENT_NORMAL: |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); | 785 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); |
769 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); | 786 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); |
770 window_state->SetBoundsDirectAnimated(center_in_parent); | 787 window_state->SetBoundsDirectAnimated(center_in_parent); |
771 } | 788 } |
772 // Centering window is treated as if a user moved and resized the window. | 789 // Centering window is treated as if a user moved and resized the window. |
773 window_state->set_bounds_changed_by_user(true); | 790 window_state->set_bounds_changed_by_user(true); |
774 } | 791 } |
775 | 792 |
776 } // namespace wm | 793 } // namespace wm |
777 } // namespace ash | 794 } // namespace ash |
OLD | NEW |