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

Side by Side Diff: ash/common/wm/workspace/workspace_window_resizer.cc

Issue 2035543004: Shuffles and renames ash/common/wm classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: random changes for chrome tests Created 4 years, 6 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 (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/common/wm/workspace/workspace_window_resizer.h" 5 #include "ash/common/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/common/shell_window_ids.h" 12 #include "ash/common/shell_window_ids.h"
13 #include "ash/common/wm/default_window_resizer.h" 13 #include "ash/common/wm/default_window_resizer.h"
14 #include "ash/common/wm/dock/docked_window_layout_manager.h" 14 #include "ash/common/wm/dock/docked_window_layout_manager.h"
15 #include "ash/common/wm/dock/docked_window_resizer.h" 15 #include "ash/common/wm/dock/docked_window_resizer.h"
16 #include "ash/common/wm/panels/panel_window_resizer.h" 16 #include "ash/common/wm/panels/panel_window_resizer.h"
17 #include "ash/common/wm/window_positioning_utils.h" 17 #include "ash/common/wm/window_positioning_utils.h"
18 #include "ash/common/wm/window_state.h" 18 #include "ash/common/wm/window_state.h"
19 #include "ash/common/wm/wm_event.h" 19 #include "ash/common/wm/wm_event.h"
20 #include "ash/common/wm/wm_globals.h"
21 #include "ash/common/wm/wm_lookup.h"
22 #include "ash/common/wm/wm_root_window_controller.h"
23 #include "ash/common/wm/wm_screen_util.h" 20 #include "ash/common/wm/wm_screen_util.h"
24 #include "ash/common/wm/wm_user_metrics_action.h" 21 #include "ash/common/wm/wm_user_metrics_action.h"
25 #include "ash/common/wm/wm_window.h"
26 #include "ash/common/wm/workspace/phantom_window_controller.h" 22 #include "ash/common/wm/workspace/phantom_window_controller.h"
27 #include "ash/common/wm/workspace/two_step_edge_cycler.h" 23 #include "ash/common/wm/workspace/two_step_edge_cycler.h"
24 #include "ash/common/wm_lookup.h"
25 #include "ash/common/wm_root_window_controller.h"
26 #include "ash/common/wm_shell.h"
27 #include "ash/common/wm_window.h"
28 #include "base/memory/ptr_util.h" 28 #include "base/memory/ptr_util.h"
29 #include "base/memory/weak_ptr.h" 29 #include "base/memory/weak_ptr.h"
30 #include "ui/base/hit_test.h" 30 #include "ui/base/hit_test.h"
31 #include "ui/compositor/layer.h" 31 #include "ui/compositor/layer.h"
32 #include "ui/display/display.h" 32 #include "ui/display/display.h"
33 #include "ui/display/screen.h" 33 #include "ui/display/screen.h"
34 #include "ui/gfx/transform.h" 34 #include "ui/gfx/transform.h"
35 #include "ui/wm/public/window_types.h" 35 #include "ui/wm/public/window_types.h"
36 36
37 namespace ash { 37 namespace ash {
38 38
39 std::unique_ptr<WindowResizer> CreateWindowResizer( 39 std::unique_ptr<WindowResizer> CreateWindowResizer(
40 wm::WmWindow* window, 40 WmWindow* window,
41 const gfx::Point& point_in_parent, 41 const gfx::Point& point_in_parent,
42 int window_component, 42 int window_component,
43 aura::client::WindowMoveSource source) { 43 aura::client::WindowMoveSource source) {
44 DCHECK(window); 44 DCHECK(window);
45 wm::WindowState* window_state = window->GetWindowState(); 45 wm::WindowState* window_state = window->GetWindowState();
46 // No need to return a resizer when the window cannot get resized or when a 46 // No need to return a resizer when the window cannot get resized or when a
47 // resizer already exists for this window. 47 // resizer already exists for this window.
48 if ((!window_state->CanResize() && window_component != HTCAPTION) || 48 if ((!window_state->CanResize() && window_component != HTCAPTION) ||
49 window_state->drag_details()) { 49 window_state->drag_details()) {
50 return nullptr; 50 return nullptr;
(...skipping 23 matching lines...) Expand all
74 if (bounds_change == WindowResizer::kBoundsChangeDirection_None) 74 if (bounds_change == WindowResizer::kBoundsChangeDirection_None)
75 return std::unique_ptr<WindowResizer>(); 75 return std::unique_ptr<WindowResizer>();
76 76
77 window_state->CreateDragDetails(point_in_parent, window_component, source); 77 window_state->CreateDragDetails(point_in_parent, window_component, source);
78 const int parent_shell_window_id = 78 const int parent_shell_window_id =
79 window->GetParent() ? window->GetParent()->GetShellWindowId() : -1; 79 window->GetParent() ? window->GetParent()->GetShellWindowId() : -1;
80 if (window->GetParent() && 80 if (window->GetParent() &&
81 (parent_shell_window_id == kShellWindowId_DefaultContainer || 81 (parent_shell_window_id == kShellWindowId_DefaultContainer ||
82 parent_shell_window_id == kShellWindowId_DockedContainer || 82 parent_shell_window_id == kShellWindowId_DockedContainer ||
83 parent_shell_window_id == kShellWindowId_PanelContainer)) { 83 parent_shell_window_id == kShellWindowId_PanelContainer)) {
84 window_resizer.reset(WorkspaceWindowResizer::Create( 84 window_resizer.reset(
85 window_state, std::vector<wm::WmWindow*>())); 85 WorkspaceWindowResizer::Create(window_state, std::vector<WmWindow*>()));
86 } else { 86 } else {
87 window_resizer.reset(DefaultWindowResizer::Create(window_state)); 87 window_resizer.reset(DefaultWindowResizer::Create(window_state));
88 } 88 }
89 window_resizer = window->GetGlobals()->CreateDragWindowResizer( 89 window_resizer = window->GetShell()->CreateDragWindowResizer(
90 std::move(window_resizer), window_state); 90 std::move(window_resizer), window_state);
91 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL) 91 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL)
92 window_resizer.reset( 92 window_resizer.reset(
93 PanelWindowResizer::Create(window_resizer.release(), window_state)); 93 PanelWindowResizer::Create(window_resizer.release(), window_state));
94 if (window_resizer && window->GetParent() && !window->GetTransientParent() && 94 if (window_resizer && window->GetParent() && !window->GetTransientParent() &&
95 (parent_shell_window_id == kShellWindowId_DefaultContainer || 95 (parent_shell_window_id == kShellWindowId_DefaultContainer ||
96 parent_shell_window_id == kShellWindowId_DockedContainer || 96 parent_shell_window_id == kShellWindowId_DockedContainer ||
97 parent_shell_window_id == kShellWindowId_PanelContainer)) { 97 parent_shell_window_id == kShellWindowId_PanelContainer)) {
98 window_resizer.reset( 98 window_resizer.reset(
99 DockedWindowResizer::Create(window_resizer.release(), window_state)); 99 DockedWindowResizer::Create(window_resizer.release(), window_state));
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 309 }
310 310
311 private: 311 private:
312 int size_; 312 int size_;
313 int min_; 313 int min_;
314 int max_; 314 int max_;
315 }; 315 };
316 316
317 WorkspaceWindowResizer::~WorkspaceWindowResizer() { 317 WorkspaceWindowResizer::~WorkspaceWindowResizer() {
318 if (did_lock_cursor_) 318 if (did_lock_cursor_)
319 globals_->UnlockCursor(); 319 shell_->UnlockCursor();
320 320
321 if (instance == this) 321 if (instance == this)
322 instance = NULL; 322 instance = NULL;
323 } 323 }
324 324
325 // static 325 // static
326 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( 326 WorkspaceWindowResizer* WorkspaceWindowResizer::Create(
327 wm::WindowState* window_state, 327 wm::WindowState* window_state,
328 const std::vector<wm::WmWindow*>& attached_windows) { 328 const std::vector<WmWindow*>& attached_windows) {
329 return new WorkspaceWindowResizer(window_state, attached_windows); 329 return new WorkspaceWindowResizer(window_state, attached_windows);
330 } 330 }
331 331
332 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, 332 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent,
333 int event_flags) { 333 int event_flags) {
334 last_mouse_location_ = location_in_parent; 334 last_mouse_location_ = location_in_parent;
335 335
336 int sticky_size; 336 int sticky_size;
337 if (event_flags & ui::EF_CONTROL_DOWN) { 337 if (event_flags & ui::EF_CONTROL_DOWN) {
338 sticky_size = 0; 338 sticky_size = 0;
(...skipping 12 matching lines...) Expand all
351 if (!details().restore_bounds.IsEmpty()) 351 if (!details().restore_bounds.IsEmpty())
352 window_state()->ClearRestoreBounds(); 352 window_state()->ClearRestoreBounds();
353 RestackWindows(); 353 RestackWindows();
354 } 354 }
355 did_move_or_resize_ = true; 355 did_move_or_resize_ = true;
356 } 356 }
357 357
358 gfx::Point location_in_screen = 358 gfx::Point location_in_screen =
359 GetTarget()->GetParent()->ConvertPointToScreen(location_in_parent); 359 GetTarget()->GetParent()->ConvertPointToScreen(location_in_parent);
360 360
361 wm::WmWindow* root = nullptr; 361 WmWindow* root = nullptr;
362 display::Display display = 362 display::Display display =
363 display::Screen::GetScreen()->GetDisplayNearestPoint(location_in_screen); 363 display::Screen::GetScreen()->GetDisplayNearestPoint(location_in_screen);
364 // Track the last screen that the pointer was on to keep the snap phantom 364 // Track the last screen that the pointer was on to keep the snap phantom
365 // window there. 365 // window there.
366 if (display.bounds().Contains(location_in_screen)) { 366 if (display.bounds().Contains(location_in_screen)) {
367 root = wm::WmLookup::Get() 367 root = WmLookup::Get()
368 ->GetRootWindowControllerWithDisplayId(display.id()) 368 ->GetRootWindowControllerWithDisplayId(display.id())
369 ->GetWindow(); 369 ->GetWindow();
370 } 370 }
371 if (!attached_windows_.empty()) 371 if (!attached_windows_.empty())
372 LayoutAttachedWindows(&bounds); 372 LayoutAttachedWindows(&bounds);
373 if (bounds != GetTarget()->GetBounds()) { 373 if (bounds != GetTarget()->GetBounds()) {
374 // SetBounds needs to be called to update the layout which affects where the 374 // SetBounds needs to be called to update the layout which affects where the
375 // phantom window is drawn. Keep track if the window was destroyed during 375 // phantom window is drawn. Keep track if the window was destroyed during
376 // the drag and quit early if so. 376 // the drag and quit early if so.
377 base::WeakPtr<WorkspaceWindowResizer> resizer( 377 base::WeakPtr<WorkspaceWindowResizer> resizer(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 details().restore_bounds.IsEmpty() ? initial_bounds 414 details().restore_bounds.IsEmpty() ? initial_bounds
415 : details().restore_bounds); 415 : details().restore_bounds);
416 } 416 }
417 if (!dock_layout_->is_dragged_window_docked()) { 417 if (!dock_layout_->is_dragged_window_docked()) {
418 // TODO(oshima): Add event source type to WMEvent and move 418 // TODO(oshima): Add event source type to WMEvent and move
419 // metrics recording inside WindowState::OnWMEvent. 419 // metrics recording inside WindowState::OnWMEvent.
420 const wm::WMEvent event(snap_type_ == SNAP_LEFT 420 const wm::WMEvent event(snap_type_ == SNAP_LEFT
421 ? wm::WM_EVENT_SNAP_LEFT 421 ? wm::WM_EVENT_SNAP_LEFT
422 : wm::WM_EVENT_SNAP_RIGHT); 422 : wm::WM_EVENT_SNAP_RIGHT);
423 window_state()->OnWMEvent(&event); 423 window_state()->OnWMEvent(&event);
424 globals_->RecordUserMetricsAction( 424 shell_->RecordUserMetricsAction(
425 snap_type_ == SNAP_LEFT 425 snap_type_ == SNAP_LEFT
426 ? wm::WmUserMetricsAction::DRAG_MAXIMIZE_LEFT 426 ? wm::WmUserMetricsAction::DRAG_MAXIMIZE_LEFT
427 : wm::WmUserMetricsAction::DRAG_MAXIMIZE_RIGHT); 427 : wm::WmUserMetricsAction::DRAG_MAXIMIZE_RIGHT);
428 snapped = true; 428 snapped = true;
429 } 429 }
430 } 430 }
431 431
432 if (!snapped) { 432 if (!snapped) {
433 if (window_state()->IsSnapped()) { 433 if (window_state()->IsSnapped()) {
434 // Keep the window snapped if the user resizes the window such that the 434 // Keep the window snapped if the user resizes the window such that the
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 bounds.set_y(last_y); 485 bounds.set_y(last_y);
486 bounds.set_height(initial_size_[i]); 486 bounds.set_height(initial_size_[i]);
487 attached_windows_[i]->SetBounds(bounds); 487 attached_windows_[i]->SetBounds(bounds);
488 last_y = attached_windows_[i]->GetBounds().bottom(); 488 last_y = attached_windows_[i]->GetBounds().bottom();
489 } 489 }
490 } 490 }
491 } 491 }
492 492
493 WorkspaceWindowResizer::WorkspaceWindowResizer( 493 WorkspaceWindowResizer::WorkspaceWindowResizer(
494 wm::WindowState* window_state, 494 wm::WindowState* window_state,
495 const std::vector<wm::WmWindow*>& attached_windows) 495 const std::vector<WmWindow*>& attached_windows)
496 : WindowResizer(window_state), 496 : WindowResizer(window_state),
497 attached_windows_(attached_windows), 497 attached_windows_(attached_windows),
498 globals_(window_state->window()->GetGlobals()), 498 shell_(window_state->window()->GetShell()),
499 did_lock_cursor_(false), 499 did_lock_cursor_(false),
500 did_move_or_resize_(false), 500 did_move_or_resize_(false),
501 initial_bounds_changed_by_user_(window_state_->bounds_changed_by_user()), 501 initial_bounds_changed_by_user_(window_state_->bounds_changed_by_user()),
502 total_min_(0), 502 total_min_(0),
503 total_initial_size_(0), 503 total_initial_size_(0),
504 snap_type_(SNAP_NONE), 504 snap_type_(SNAP_NONE),
505 num_mouse_moves_since_bounds_change_(0), 505 num_mouse_moves_since_bounds_change_(0),
506 magnetism_window_(NULL), 506 magnetism_window_(NULL),
507 weak_ptr_factory_(this) { 507 weak_ptr_factory_(this) {
508 DCHECK(details().is_resizable); 508 DCHECK(details().is_resizable);
509 509
510 // A mousemove should still show the cursor even if the window is 510 // A mousemove should still show the cursor even if the window is
511 // being moved or resized with touch, so do not lock the cursor. 511 // being moved or resized with touch, so do not lock the cursor.
512 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 512 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
513 globals_->LockCursor(); 513 shell_->LockCursor();
514 did_lock_cursor_ = true; 514 did_lock_cursor_ = true;
515 } 515 }
516 516
517 dock_layout_ = DockedWindowLayoutManager::Get(GetTarget()); 517 dock_layout_ = DockedWindowLayoutManager::Get(GetTarget());
518 518
519 // Only support attaching to the right/bottom. 519 // Only support attaching to the right/bottom.
520 DCHECK(attached_windows_.empty() || (details().window_component == HTRIGHT || 520 DCHECK(attached_windows_.empty() || (details().window_component == HTRIGHT ||
521 details().window_component == HTBOTTOM)); 521 details().window_component == HTBOTTOM));
522 522
523 // TODO: figure out how to deal with window going off the edge. 523 // TODO: figure out how to deal with window going off the edge.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 715 }
716 window_tracker_.Remove(magnetism_window_); 716 window_tracker_.Remove(magnetism_window_);
717 magnetism_window_ = NULL; 717 magnetism_window_ = NULL;
718 } 718 }
719 719
720 // Avoid magnetically snapping windows that are not resizable. 720 // Avoid magnetically snapping windows that are not resizable.
721 // TODO(oshima): change this to window.type() == TYPE_NORMAL. 721 // TODO(oshima): change this to window.type() == TYPE_NORMAL.
722 if (!window_state()->CanResize()) 722 if (!window_state()->CanResize())
723 return false; 723 return false;
724 724
725 for (wm::WmWindow* root_window : globals_->GetAllRootWindows()) { 725 for (WmWindow* root_window : shell_->GetAllRootWindows()) {
726 // Test all children from the desktop in each root window. 726 // Test all children from the desktop in each root window.
727 const std::vector<wm::WmWindow*> children = 727 const std::vector<WmWindow*> children =
728 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer) 728 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer)
729 ->GetChildren(); 729 ->GetChildren();
730 for (auto i = children.rbegin(); 730 for (auto i = children.rbegin();
731 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { 731 i != children.rend() && !matcher.AreEdgesObscured(); ++i) {
732 wm::WindowState* other_state = (*i)->GetWindowState(); 732 wm::WindowState* other_state = (*i)->GetWindowState();
733 if (other_state->window() == GetTarget() || 733 if (other_state->window() == GetTarget() ||
734 !other_state->window()->IsVisible() || 734 !other_state->window()->IsVisible() ||
735 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { 735 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) {
736 continue; 736 continue;
737 } 737 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 } 941 }
942 snap_phantom_window_controller_->Show( 942 snap_phantom_window_controller_->Show(
943 GetTarget()->GetParent()->ConvertRectToScreen(phantom_bounds)); 943 GetTarget()->GetParent()->ConvertRectToScreen(phantom_bounds));
944 } 944 }
945 945
946 void WorkspaceWindowResizer::RestackWindows() { 946 void WorkspaceWindowResizer::RestackWindows() {
947 if (attached_windows_.empty()) 947 if (attached_windows_.empty())
948 return; 948 return;
949 // Build a map from index in children to window, returning if there is a 949 // Build a map from index in children to window, returning if there is a
950 // window with a different parent. 950 // window with a different parent.
951 using IndexToWindowMap = std::map<size_t, wm::WmWindow*>; 951 using IndexToWindowMap = std::map<size_t, WmWindow*>;
952 IndexToWindowMap map; 952 IndexToWindowMap map;
953 wm::WmWindow* parent = GetTarget()->GetParent(); 953 WmWindow* parent = GetTarget()->GetParent();
954 const std::vector<wm::WmWindow*> windows(parent->GetChildren()); 954 const std::vector<WmWindow*> windows(parent->GetChildren());
955 map[std::find(windows.begin(), windows.end(), GetTarget()) - 955 map[std::find(windows.begin(), windows.end(), GetTarget()) -
956 windows.begin()] = GetTarget(); 956 windows.begin()] = GetTarget();
957 for (auto i = attached_windows_.begin(); i != attached_windows_.end(); ++i) { 957 for (auto i = attached_windows_.begin(); i != attached_windows_.end(); ++i) {
958 if ((*i)->GetParent() != parent) 958 if ((*i)->GetParent() != parent)
959 return; 959 return;
960 size_t index = 960 size_t index =
961 std::find(windows.begin(), windows.end(), *i) - windows.begin(); 961 std::find(windows.begin(), windows.end(), *i) - windows.begin();
962 map[index] = *i; 962 map[index] = *i;
963 } 963 }
964 964
965 // Reorder the windows starting at the topmost. 965 // Reorder the windows starting at the topmost.
966 parent->StackChildAtTop(map.rbegin()->second); 966 parent->StackChildAtTop(map.rbegin()->second);
967 for (auto i = map.rbegin(); i != map.rend();) { 967 for (auto i = map.rbegin(); i != map.rend();) {
968 wm::WmWindow* window = i->second; 968 WmWindow* window = i->second;
969 ++i; 969 ++i;
970 if (i != map.rend()) 970 if (i != map.rend())
971 parent->StackChildBelow(i->second, window); 971 parent->StackChildBelow(i->second, window);
972 } 972 }
973 } 973 }
974 974
975 WorkspaceWindowResizer::SnapType WorkspaceWindowResizer::GetSnapType( 975 WorkspaceWindowResizer::SnapType WorkspaceWindowResizer::GetSnapType(
976 const gfx::Point& location) const { 976 const gfx::Point& location) const {
977 // TODO: this likely only wants total display area, not the area of a single 977 // TODO: this likely only wants total display area, not the area of a single
978 // display. 978 // display.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || 1016 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ||
1017 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); 1017 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED);
1018 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget()); 1018 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget());
1019 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) 1019 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED)
1020 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); 1020 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width());
1021 snapped_bounds.set_width(bounds_in_parent.width()); 1021 snapped_bounds.set_width(bounds_in_parent.width());
1022 return bounds_in_parent == snapped_bounds; 1022 return bounds_in_parent == snapped_bounds;
1023 } 1023 }
1024 1024
1025 } // namespace ash 1025 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698