OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/workspace/workspace_window_resizer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/metrics/user_metrics_action.h" | 12 #include "ash/metrics/user_metrics_action.h" |
13 #include "ash/public/cpp/shell_window_ids.h" | 13 #include "ash/public/cpp/shell_window_ids.h" |
14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/shell_port.h" |
16 #include "ash/wm/default_window_resizer.h" | 17 #include "ash/wm/default_window_resizer.h" |
17 #include "ash/wm/panels/panel_window_resizer.h" | 18 #include "ash/wm/panels/panel_window_resizer.h" |
18 #include "ash/wm/window_positioning_utils.h" | 19 #include "ash/wm/window_positioning_utils.h" |
19 #include "ash/wm/window_state.h" | 20 #include "ash/wm/window_state.h" |
20 #include "ash/wm/wm_event.h" | 21 #include "ash/wm/wm_event.h" |
21 #include "ash/wm/wm_screen_util.h" | 22 #include "ash/wm/wm_screen_util.h" |
22 #include "ash/wm/workspace/phantom_window_controller.h" | 23 #include "ash/wm/workspace/phantom_window_controller.h" |
23 #include "ash/wm/workspace/two_step_edge_cycler.h" | 24 #include "ash/wm/workspace/two_step_edge_cycler.h" |
24 #include "ash/wm_shell.h" | |
25 #include "ash/wm_window.h" | 25 #include "ash/wm_window.h" |
26 #include "base/memory/ptr_util.h" | 26 #include "base/memory/ptr_util.h" |
27 #include "base/memory/weak_ptr.h" | 27 #include "base/memory/weak_ptr.h" |
28 #include "ui/base/hit_test.h" | 28 #include "ui/base/hit_test.h" |
29 #include "ui/compositor/layer.h" | 29 #include "ui/compositor/layer.h" |
30 #include "ui/display/display.h" | 30 #include "ui/display/display.h" |
31 #include "ui/display/screen.h" | 31 #include "ui/display/screen.h" |
32 #include "ui/gfx/transform.h" | 32 #include "ui/gfx/transform.h" |
33 #include "ui/wm/public/window_types.h" | 33 #include "ui/wm/public/window_types.h" |
34 | 34 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const int parent_shell_window_id = | 74 const int parent_shell_window_id = |
75 window->GetParent() ? window->GetParent()->GetShellWindowId() : -1; | 75 window->GetParent() ? window->GetParent()->GetShellWindowId() : -1; |
76 if (window->GetParent() && | 76 if (window->GetParent() && |
77 (parent_shell_window_id == kShellWindowId_DefaultContainer || | 77 (parent_shell_window_id == kShellWindowId_DefaultContainer || |
78 parent_shell_window_id == kShellWindowId_PanelContainer)) { | 78 parent_shell_window_id == kShellWindowId_PanelContainer)) { |
79 window_resizer.reset( | 79 window_resizer.reset( |
80 WorkspaceWindowResizer::Create(window_state, std::vector<WmWindow*>())); | 80 WorkspaceWindowResizer::Create(window_state, std::vector<WmWindow*>())); |
81 } else { | 81 } else { |
82 window_resizer.reset(DefaultWindowResizer::Create(window_state)); | 82 window_resizer.reset(DefaultWindowResizer::Create(window_state)); |
83 } | 83 } |
84 window_resizer = window->GetShell()->CreateDragWindowResizer( | 84 window_resizer = ShellPort::Get()->CreateDragWindowResizer( |
85 std::move(window_resizer), window_state); | 85 std::move(window_resizer), window_state); |
86 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL) { | 86 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL) { |
87 window_resizer.reset( | 87 window_resizer.reset( |
88 PanelWindowResizer::Create(window_resizer.release(), window_state)); | 88 PanelWindowResizer::Create(window_resizer.release(), window_state)); |
89 } | 89 } |
90 return window_resizer; | 90 return window_resizer; |
91 } | 91 } |
92 | 92 |
93 namespace { | 93 namespace { |
94 | 94 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 | 299 |
300 private: | 300 private: |
301 int size_; | 301 int size_; |
302 int min_; | 302 int min_; |
303 int max_; | 303 int max_; |
304 }; | 304 }; |
305 | 305 |
306 WorkspaceWindowResizer::~WorkspaceWindowResizer() { | 306 WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
307 if (did_lock_cursor_) | 307 if (did_lock_cursor_) |
308 shell_->UnlockCursor(); | 308 ShellPort::Get()->UnlockCursor(); |
309 | 309 |
310 if (instance == this) | 310 if (instance == this) |
311 instance = NULL; | 311 instance = NULL; |
312 } | 312 } |
313 | 313 |
314 // static | 314 // static |
315 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( | 315 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( |
316 wm::WindowState* window_state, | 316 wm::WindowState* window_state, |
317 const std::vector<WmWindow*>& attached_windows) { | 317 const std::vector<WmWindow*>& attached_windows) { |
318 return new WorkspaceWindowResizer(window_state, attached_windows); | 318 return new WorkspaceWindowResizer(window_state, attached_windows); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 details().initial_bounds_in_parent); | 399 details().initial_bounds_in_parent); |
400 window_state()->SetRestoreBoundsInScreen( | 400 window_state()->SetRestoreBoundsInScreen( |
401 details().restore_bounds.IsEmpty() ? initial_bounds | 401 details().restore_bounds.IsEmpty() ? initial_bounds |
402 : details().restore_bounds); | 402 : details().restore_bounds); |
403 } | 403 } |
404 // TODO(oshima): Add event source type to WMEvent and move | 404 // TODO(oshima): Add event source type to WMEvent and move |
405 // metrics recording inside WindowState::OnWMEvent. | 405 // metrics recording inside WindowState::OnWMEvent. |
406 const wm::WMEvent event(snap_type_ == SNAP_LEFT ? wm::WM_EVENT_SNAP_LEFT | 406 const wm::WMEvent event(snap_type_ == SNAP_LEFT ? wm::WM_EVENT_SNAP_LEFT |
407 : wm::WM_EVENT_SNAP_RIGHT); | 407 : wm::WM_EVENT_SNAP_RIGHT); |
408 window_state()->OnWMEvent(&event); | 408 window_state()->OnWMEvent(&event); |
409 shell_->RecordUserMetricsAction(snap_type_ == SNAP_LEFT | 409 ShellPort::Get()->RecordUserMetricsAction(snap_type_ == SNAP_LEFT |
410 ? UMA_DRAG_MAXIMIZE_LEFT | 410 ? UMA_DRAG_MAXIMIZE_LEFT |
411 : UMA_DRAG_MAXIMIZE_RIGHT); | 411 : UMA_DRAG_MAXIMIZE_RIGHT); |
412 snapped = true; | 412 snapped = true; |
413 } | 413 } |
414 | 414 |
415 if (!snapped) { | 415 if (!snapped) { |
416 if (window_state()->IsSnapped()) { | 416 if (window_state()->IsSnapped()) { |
417 // Keep the window snapped if the user resizes the window such that the | 417 // Keep the window snapped if the user resizes the window such that the |
418 // window has valid bounds for a snapped window. Always unsnap the window | 418 // window has valid bounds for a snapped window. Always unsnap the window |
419 // if the user dragged the window via the caption area because doing this | 419 // if the user dragged the window via the caption area because doing this |
420 // is slightly less confusing. | 420 // is slightly less confusing. |
421 if (details().window_component == HTCAPTION || | 421 if (details().window_component == HTCAPTION || |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 last_y = attached_windows_[i]->GetBounds().bottom(); | 466 last_y = attached_windows_[i]->GetBounds().bottom(); |
467 } | 467 } |
468 } | 468 } |
469 } | 469 } |
470 | 470 |
471 WorkspaceWindowResizer::WorkspaceWindowResizer( | 471 WorkspaceWindowResizer::WorkspaceWindowResizer( |
472 wm::WindowState* window_state, | 472 wm::WindowState* window_state, |
473 const std::vector<WmWindow*>& attached_windows) | 473 const std::vector<WmWindow*>& attached_windows) |
474 : WindowResizer(window_state), | 474 : WindowResizer(window_state), |
475 attached_windows_(attached_windows), | 475 attached_windows_(attached_windows), |
476 shell_(window_state->window()->GetShell()), | |
477 did_lock_cursor_(false), | 476 did_lock_cursor_(false), |
478 did_move_or_resize_(false), | 477 did_move_or_resize_(false), |
479 initial_bounds_changed_by_user_(window_state_->bounds_changed_by_user()), | 478 initial_bounds_changed_by_user_(window_state_->bounds_changed_by_user()), |
480 total_min_(0), | 479 total_min_(0), |
481 total_initial_size_(0), | 480 total_initial_size_(0), |
482 snap_type_(SNAP_NONE), | 481 snap_type_(SNAP_NONE), |
483 num_mouse_moves_since_bounds_change_(0), | 482 num_mouse_moves_since_bounds_change_(0), |
484 magnetism_window_(NULL), | 483 magnetism_window_(NULL), |
485 weak_ptr_factory_(this) { | 484 weak_ptr_factory_(this) { |
486 DCHECK(details().is_resizable); | 485 DCHECK(details().is_resizable); |
487 | 486 |
488 // A mousemove should still show the cursor even if the window is | 487 // A mousemove should still show the cursor even if the window is |
489 // being moved or resized with touch, so do not lock the cursor. | 488 // being moved or resized with touch, so do not lock the cursor. |
490 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | 489 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) { |
491 shell_->LockCursor(); | 490 ShellPort::Get()->LockCursor(); |
492 did_lock_cursor_ = true; | 491 did_lock_cursor_ = true; |
493 } | 492 } |
494 | 493 |
495 // Only support attaching to the right/bottom. | 494 // Only support attaching to the right/bottom. |
496 DCHECK(attached_windows_.empty() || (details().window_component == HTRIGHT || | 495 DCHECK(attached_windows_.empty() || (details().window_component == HTRIGHT || |
497 details().window_component == HTBOTTOM)); | 496 details().window_component == HTBOTTOM)); |
498 | 497 |
499 // TODO: figure out how to deal with window going off the edge. | 498 // TODO: figure out how to deal with window going off the edge. |
500 | 499 |
501 // Calculate sizes so that we can maintain the ratios if we need to resize. | 500 // Calculate sizes so that we can maintain the ratios if we need to resize. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 } | 690 } |
692 window_tracker_.Remove(magnetism_window_->aura_window()); | 691 window_tracker_.Remove(magnetism_window_->aura_window()); |
693 magnetism_window_ = NULL; | 692 magnetism_window_ = NULL; |
694 } | 693 } |
695 | 694 |
696 // Avoid magnetically snapping windows that are not resizable. | 695 // Avoid magnetically snapping windows that are not resizable. |
697 // TODO(oshima): change this to window.type() == TYPE_NORMAL. | 696 // TODO(oshima): change this to window.type() == TYPE_NORMAL. |
698 if (!window_state()->CanResize()) | 697 if (!window_state()->CanResize()) |
699 return false; | 698 return false; |
700 | 699 |
701 for (WmWindow* root_window : shell_->GetAllRootWindows()) { | 700 for (WmWindow* root_window : ShellPort::Get()->GetAllRootWindows()) { |
702 // Test all children from the desktop in each root window. | 701 // Test all children from the desktop in each root window. |
703 const std::vector<WmWindow*> children = | 702 const std::vector<WmWindow*> children = |
704 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer) | 703 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer) |
705 ->GetChildren(); | 704 ->GetChildren(); |
706 for (auto i = children.rbegin(); | 705 for (auto i = children.rbegin(); |
707 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { | 706 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { |
708 wm::WindowState* other_state = (*i)->GetWindowState(); | 707 wm::WindowState* other_state = (*i)->GetWindowState(); |
709 if (other_state->window() == GetTarget() || | 708 if (other_state->window() == GetTarget() || |
710 !other_state->window()->IsVisible() || | 709 !other_state->window()->IsVisible() || |
711 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { | 710 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || | 948 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || |
950 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); | 949 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
951 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget()); | 950 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget()); |
952 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) | 951 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) |
953 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); | 952 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); |
954 snapped_bounds.set_width(bounds_in_parent.width()); | 953 snapped_bounds.set_width(bounds_in_parent.width()); |
955 return bounds_in_parent == snapped_bounds; | 954 return bounds_in_parent == snapped_bounds; |
956 } | 955 } |
957 | 956 |
958 } // namespace ash | 957 } // namespace ash |
OLD | NEW |