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

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

Issue 1913473002: Makes WorkspaceWindowResizer use ash/wm/common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@root_controller_observer
Patch Set: fix exo again Created 4 years, 8 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/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/display/window_tree_host_manager.h"
13 #include "ash/metrics/user_metrics_recorder.h" 12 #include "ash/metrics/user_metrics_recorder.h"
14 #include "ash/root_window_controller.h"
15 #include "ash/screen_util.h"
16 #include "ash/shell.h"
17 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
18 #include "ash/wm/common/window_positioning_utils.h" 14 #include "ash/wm/common/window_positioning_utils.h"
19 #include "ash/wm/common/wm_event.h" 15 #include "ash/wm/common/wm_event.h"
16 #include "ash/wm/common/wm_globals.h"
17 #include "ash/wm/common/wm_root_window_controller.h"
18 #include "ash/wm/common/wm_screen_util.h"
20 #include "ash/wm/default_window_resizer.h" 19 #include "ash/wm/default_window_resizer.h"
21 #include "ash/wm/dock/docked_window_layout_manager.h" 20 #include "ash/wm/dock/docked_window_layout_manager.h"
22 #include "ash/wm/dock/docked_window_resizer.h" 21 #include "ash/wm/dock/docked_window_resizer.h"
23 #include "ash/wm/drag_window_resizer.h" 22 #include "ash/wm/drag_window_resizer.h"
24 #include "ash/wm/panels/panel_window_resizer.h" 23 #include "ash/wm/panels/panel_window_resizer.h"
25 #include "ash/wm/window_state.h" 24 #include "ash/wm/window_state.h"
26 #include "ash/wm/window_state_aura.h"
27 #include "ash/wm/window_util.h"
28 #include "ash/wm/workspace/phantom_window_controller.h" 25 #include "ash/wm/workspace/phantom_window_controller.h"
29 #include "ash/wm/workspace/two_step_edge_cycler.h" 26 #include "ash/wm/workspace/two_step_edge_cycler.h"
30 #include "base/command_line.h"
31 #include "base/memory/ptr_util.h" 27 #include "base/memory/ptr_util.h"
32 #include "base/memory/weak_ptr.h" 28 #include "base/memory/weak_ptr.h"
33 #include "ui/aura/client/aura_constants.h"
34 #include "ui/aura/client/screen_position_client.h"
35 #include "ui/aura/window.h"
36 #include "ui/aura/window_delegate.h"
37 #include "ui/aura/window_event_dispatcher.h"
38 #include "ui/base/hit_test.h" 29 #include "ui/base/hit_test.h"
39 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
40 #include "ui/gfx/screen.h" 31 #include "ui/gfx/screen.h"
41 #include "ui/gfx/transform.h" 32 #include "ui/gfx/transform.h"
42 #include "ui/wm/core/coordinate_conversion.h"
43 #include "ui/wm/core/window_util.h"
44 #include "ui/wm/public/window_types.h" 33 #include "ui/wm/public/window_types.h"
45 34
46 namespace ash { 35 namespace ash {
47 36
48 std::unique_ptr<WindowResizer> CreateWindowResizer( 37 std::unique_ptr<WindowResizer> CreateWindowResizer(
49 aura::Window* window, 38 wm::WmWindow* window,
50 const gfx::Point& point_in_parent, 39 const gfx::Point& point_in_parent,
51 int window_component, 40 int window_component,
52 aura::client::WindowMoveSource source) { 41 aura::client::WindowMoveSource source) {
53 DCHECK(window); 42 DCHECK(window);
54 wm::WindowState* window_state = wm::GetWindowState(window); 43 wm::WindowState* window_state = window->GetWindowState();
55 // No need to return a resizer when the window cannot get resized or when a 44 // No need to return a resizer when the window cannot get resized or when a
56 // resizer already exists for this window. 45 // resizer already exists for this window.
57 if ((!window_state->CanResize() && window_component != HTCAPTION) || 46 if ((!window_state->CanResize() && window_component != HTCAPTION) ||
58 window_state->drag_details()) { 47 window_state->drag_details()) {
59 return std::unique_ptr<WindowResizer>(); 48 return nullptr;
60 } 49 }
61 50
62 if (window_component == HTCAPTION && !window_state->can_be_dragged()) 51 if (window_component == HTCAPTION && !window_state->can_be_dragged())
63 return std::unique_ptr<WindowResizer>(); 52 return nullptr;
64 53
65 // TODO(varkha): The chaining of window resizers causes some of the logic 54 // TODO(varkha): The chaining of window resizers causes some of the logic
66 // to be repeated and the logic flow difficult to control. With some windows 55 // to be repeated and the logic flow difficult to control. With some windows
67 // classes using reparenting during drag operations it becomes challenging to 56 // classes using reparenting during drag operations it becomes challenging to
68 // implement proper transition from one resizer to another during or at the 57 // implement proper transition from one resizer to another during or at the
69 // end of the drag. This also causes http://crbug.com/247085. 58 // end of the drag. This also causes http://crbug.com/247085.
70 // It seems the only thing the panel or dock resizer needs to do is notify the 59 // It seems the only thing the panel or dock resizer needs to do is notify the
71 // layout manager when a docked window is being dragged. We should have a 60 // layout manager when a docked window is being dragged. We should have a
72 // better way of doing this, perhaps by having a way of observing drags or 61 // better way of doing this, perhaps by having a way of observing drags or
73 // having a generic drag window wrapper which informs a layout manager that a 62 // having a generic drag window wrapper which informs a layout manager that a
74 // drag has started or stopped. 63 // drag has started or stopped.
75 // It may be possible to refactor and eliminate chaining. 64 // It may be possible to refactor and eliminate chaining.
76 WindowResizer* window_resizer = NULL; 65 std::unique_ptr<WindowResizer> window_resizer;
77 66
78 if (!window_state->IsNormalOrSnapped() && !window_state->IsDocked()) 67 if (!window_state->IsNormalOrSnapped() && !window_state->IsDocked())
79 return std::unique_ptr<WindowResizer>(); 68 return std::unique_ptr<WindowResizer>();
80 69
81 int bounds_change = WindowResizer::GetBoundsChangeForWindowComponent( 70 int bounds_change = WindowResizer::GetBoundsChangeForWindowComponent(
82 window_component); 71 window_component);
83 if (bounds_change == WindowResizer::kBoundsChangeDirection_None) 72 if (bounds_change == WindowResizer::kBoundsChangeDirection_None)
84 return std::unique_ptr<WindowResizer>(); 73 return std::unique_ptr<WindowResizer>();
85 74
86 window_state->CreateDragDetails(point_in_parent, window_component, source); 75 window_state->CreateDragDetails(point_in_parent, window_component, source);
87 if (window->parent() && 76 const int parent_shell_window_id =
88 (window->parent()->id() == kShellWindowId_DefaultContainer || 77 window->GetParent() ? window->GetParent()->GetShellWindowId() : -1;
89 window->parent()->id() == kShellWindowId_DockedContainer || 78 if (window->GetParent() &&
90 window->parent()->id() == kShellWindowId_PanelContainer)) { 79 (parent_shell_window_id == kShellWindowId_DefaultContainer ||
91 window_resizer = WorkspaceWindowResizer::Create( 80 parent_shell_window_id == kShellWindowId_DockedContainer ||
92 window_state, std::vector<aura::Window*>()); 81 parent_shell_window_id == kShellWindowId_PanelContainer)) {
82 window_resizer.reset(WorkspaceWindowResizer::Create(
83 window_state, std::vector<wm::WmWindow*>()));
93 } else { 84 } else {
94 window_resizer = DefaultWindowResizer::Create(window_state); 85 window_resizer.reset(DefaultWindowResizer::Create(window_state));
95 } 86 }
96 window_resizer = DragWindowResizer::Create(window_resizer, window_state); 87 window_resizer.reset(
97 if (window->type() == ui::wm::WINDOW_TYPE_PANEL) 88 DragWindowResizer::Create(window_resizer.release(), window_state));
98 window_resizer = PanelWindowResizer::Create(window_resizer, window_state); 89 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL)
99 if (window_resizer && window->parent() && 90 window_resizer.reset(
100 !::wm::GetTransientParent(window) && 91 PanelWindowResizer::Create(window_resizer.release(), window_state));
101 (window->parent()->id() == kShellWindowId_DefaultContainer || 92 if (window_resizer && window->GetParent() && !window->GetTransientParent() &&
102 window->parent()->id() == kShellWindowId_DockedContainer || 93 (parent_shell_window_id == kShellWindowId_DefaultContainer ||
103 window->parent()->id() == kShellWindowId_PanelContainer)) { 94 parent_shell_window_id == kShellWindowId_DockedContainer ||
104 window_resizer = DockedWindowResizer::Create(window_resizer, window_state); 95 parent_shell_window_id == kShellWindowId_PanelContainer)) {
96 window_resizer.reset(
97 DockedWindowResizer::Create(window_resizer.release(), window_state));
105 } 98 }
106 return base::WrapUnique<WindowResizer>(window_resizer); 99 return window_resizer;
107 } 100 }
108 101
109 namespace { 102 namespace {
110 103
111 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset 104 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset
112 // when resizing a window using touchscreen. 105 // when resizing a window using touchscreen.
113 const int kScreenEdgeInsetForTouchDrag = 32; 106 const int kScreenEdgeInsetForTouchDrag = 32;
114 107
115 // Current instance for use by the WorkspaceWindowResizerTest. 108 // Current instance for use by the WorkspaceWindowResizerTest.
116 WorkspaceWindowResizer* instance = NULL; 109 WorkspaceWindowResizer* instance = NULL;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 return 0; 321 return 0;
329 } 322 }
330 323
331 private: 324 private:
332 int size_; 325 int size_;
333 int min_; 326 int min_;
334 int max_; 327 int max_;
335 }; 328 };
336 329
337 WorkspaceWindowResizer::~WorkspaceWindowResizer() { 330 WorkspaceWindowResizer::~WorkspaceWindowResizer() {
338 if (did_lock_cursor_) { 331 if (did_lock_cursor_)
339 Shell* shell = Shell::GetInstance(); 332 globals_->UnlockCursor();
340 shell->cursor_manager()->UnlockCursor(); 333
341 }
342 if (instance == this) 334 if (instance == this)
343 instance = NULL; 335 instance = NULL;
344 } 336 }
345 337
346 // static 338 // static
347 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( 339 WorkspaceWindowResizer* WorkspaceWindowResizer::Create(
348 wm::WindowState* window_state, 340 wm::WindowState* window_state,
349 const std::vector<aura::Window*>& attached_windows) { 341 const std::vector<wm::WmWindow*>& attached_windows) {
350 return new WorkspaceWindowResizer(window_state, attached_windows); 342 return new WorkspaceWindowResizer(window_state, attached_windows);
351 } 343 }
352 344
353 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, 345 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent,
354 int event_flags) { 346 int event_flags) {
355 last_mouse_location_ = location_in_parent; 347 last_mouse_location_ = location_in_parent;
356 348
357 int sticky_size; 349 int sticky_size;
358 if (event_flags & ui::EF_CONTROL_DOWN) { 350 if (event_flags & ui::EF_CONTROL_DOWN) {
359 sticky_size = 0; 351 sticky_size = 0;
360 } else if ((details().bounds_change & kBoundsChange_Resizes) && 352 } else if ((details().bounds_change & kBoundsChange_Resizes) &&
361 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 353 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
362 sticky_size = kScreenEdgeInsetForTouchDrag; 354 sticky_size = kScreenEdgeInsetForTouchDrag;
363 } else { 355 } else {
364 sticky_size = kScreenEdgeInset; 356 sticky_size = kScreenEdgeInset;
365 } 357 }
366 // |bounds| is in |GetTarget()->parent()|'s coordinates. 358 // |bounds| is in |GetTarget()->parent()|'s coordinates.
367 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent); 359 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent);
368 AdjustBoundsForMainWindow(sticky_size, &bounds); 360 AdjustBoundsForMainWindow(sticky_size, &bounds);
369 361
370 if (bounds != GetAuraTarget()->bounds()) { 362 if (bounds != GetTarget()->GetBounds()) {
371 if (!did_move_or_resize_) { 363 if (!did_move_or_resize_) {
372 if (!details().restore_bounds.IsEmpty()) 364 if (!details().restore_bounds.IsEmpty())
373 window_state()->ClearRestoreBounds(); 365 window_state()->ClearRestoreBounds();
374 RestackWindows(); 366 RestackWindows();
375 } 367 }
376 did_move_or_resize_ = true; 368 did_move_or_resize_ = true;
377 } 369 }
378 370
379 gfx::Point location_in_screen = location_in_parent; 371 gfx::Point location_in_screen =
380 ::wm::ConvertPointToScreen(GetAuraTarget()->parent(), &location_in_screen); 372 GetTarget()->GetParent()->ConvertPointToScreen(location_in_parent);
381 373
382 aura::Window* root = NULL; 374 wm::WmWindow* root = nullptr;
383 gfx::Display display = 375 gfx::Display display =
384 ScreenUtil::FindDisplayContainingPoint(location_in_screen); 376 gfx::Screen::GetScreen()->GetDisplayNearestPoint(location_in_screen);
385 // Track the last screen that the pointer was on to keep the snap phantom 377 // Track the last screen that the pointer was on to keep the snap phantom
386 // window there. 378 // window there.
387 if (display.is_valid()) { 379 if (display.bounds().Contains(location_in_screen)) {
388 root = Shell::GetInstance() 380 root =
389 ->window_tree_host_manager() 381 wm::WmRootWindowController::GetWithDisplayId(display.id())->GetWindow();
390 ->GetRootWindowForDisplayId(display.id());
391 } 382 }
392 if (!attached_windows_.empty()) 383 if (!attached_windows_.empty())
393 LayoutAttachedWindows(&bounds); 384 LayoutAttachedWindows(&bounds);
394 if (bounds != GetAuraTarget()->bounds()) { 385 if (bounds != GetTarget()->GetBounds()) {
395 // SetBounds needs to be called to update the layout which affects where the 386 // SetBounds needs to be called to update the layout which affects where the
396 // phantom window is drawn. Keep track if the window was destroyed during 387 // phantom window is drawn. Keep track if the window was destroyed during
397 // the drag and quit early if so. 388 // the drag and quit early if so.
398 base::WeakPtr<WorkspaceWindowResizer> resizer( 389 base::WeakPtr<WorkspaceWindowResizer> resizer(
399 weak_ptr_factory_.GetWeakPtr()); 390 weak_ptr_factory_.GetWeakPtr());
400 GetAuraTarget()->SetBounds(bounds); 391 GetTarget()->SetBounds(bounds);
401 if (!resizer) 392 if (!resizer)
402 return; 393 return;
403 } 394 }
404 const bool in_original_root = 395 const bool in_original_root = !root || root == GetTarget()->GetRootWindow();
405 !root || root == GetAuraTarget()->GetRootWindow();
406 // Hide a phantom window for snapping if the cursor is in another root window. 396 // Hide a phantom window for snapping if the cursor is in another root window.
407 if (in_original_root) { 397 if (in_original_root) {
408 UpdateSnapPhantomWindow(location_in_parent, bounds); 398 UpdateSnapPhantomWindow(location_in_parent, bounds);
409 } else { 399 } else {
410 snap_type_ = SNAP_NONE; 400 snap_type_ = SNAP_NONE;
411 snap_phantom_window_controller_.reset(); 401 snap_phantom_window_controller_.reset();
412 edge_cycler_.reset(); 402 edge_cycler_.reset();
413 SetDraggedWindowDocked(false); 403 SetDraggedWindowDocked(false);
414 } 404 }
415 } 405 }
416 406
417 void WorkspaceWindowResizer::CompleteDrag() { 407 void WorkspaceWindowResizer::CompleteDrag() {
418 if (!did_move_or_resize_) 408 if (!did_move_or_resize_)
419 return; 409 return;
420 410
421 window_state()->set_bounds_changed_by_user(true); 411 window_state()->set_bounds_changed_by_user(true);
422 snap_phantom_window_controller_.reset(); 412 snap_phantom_window_controller_.reset();
423 413
424 // If the window's state type changed over the course of the drag do not snap 414 // If the window's state type changed over the course of the drag do not snap
425 // the window. This happens when the user minimizes or maximizes the window 415 // the window. This happens when the user minimizes or maximizes the window
426 // using a keyboard shortcut while dragging it. 416 // using a keyboard shortcut while dragging it.
427 if (window_state()->GetStateType() != details().initial_state_type) 417 if (window_state()->GetStateType() != details().initial_state_type)
428 return; 418 return;
429 419
430 bool snapped = false; 420 bool snapped = false;
431 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { 421 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) {
432 if (!window_state()->HasRestoreBounds()) { 422 if (!window_state()->HasRestoreBounds()) {
433 gfx::Rect initial_bounds = ScreenUtil::ConvertRectToScreen( 423 gfx::Rect initial_bounds = GetTarget()->GetParent()->ConvertRectToScreen(
434 GetAuraTarget()->parent(), details().initial_bounds_in_parent); 424 details().initial_bounds_in_parent);
435 window_state()->SetRestoreBoundsInScreen( 425 window_state()->SetRestoreBoundsInScreen(
436 details().restore_bounds.IsEmpty() ? 426 details().restore_bounds.IsEmpty() ?
437 initial_bounds : 427 initial_bounds :
438 details().restore_bounds); 428 details().restore_bounds);
439 } 429 }
440 if (!dock_layout_->is_dragged_window_docked()) { 430 if (!dock_layout_->is_dragged_window_docked()) {
441 UserMetricsRecorder* metrics = Shell::GetInstance()->metrics(); 431 UserMetricsRecorder* metrics = globals_->GetUserMetricsRecorder();
442 // TODO(oshima): Add event source type to WMEvent and move 432 // TODO(oshima): Add event source type to WMEvent and move
443 // metrics recording inside WindowState::OnWMEvent. 433 // metrics recording inside WindowState::OnWMEvent.
444 const wm::WMEvent event(snap_type_ == SNAP_LEFT ? 434 const wm::WMEvent event(snap_type_ == SNAP_LEFT ?
445 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); 435 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
446 window_state()->OnWMEvent(&event); 436 window_state()->OnWMEvent(&event);
447 metrics->RecordUserMetricsAction( 437 metrics->RecordUserMetricsAction(
448 snap_type_ == SNAP_LEFT ? 438 snap_type_ == SNAP_LEFT ?
449 UMA_DRAG_MAXIMIZE_LEFT : UMA_DRAG_MAXIMIZE_RIGHT); 439 UMA_DRAG_MAXIMIZE_LEFT : UMA_DRAG_MAXIMIZE_RIGHT);
450 snapped = true; 440 snapped = true;
451 } 441 }
452 } 442 }
453 443
454 if (!snapped) { 444 if (!snapped) {
455 if (window_state()->IsSnapped()) { 445 if (window_state()->IsSnapped()) {
456 // Keep the window snapped if the user resizes the window such that the 446 // Keep the window snapped if the user resizes the window such that the
457 // window has valid bounds for a snapped window. Always unsnap the window 447 // window has valid bounds for a snapped window. Always unsnap the window
458 // if the user dragged the window via the caption area because doing this 448 // if the user dragged the window via the caption area because doing this
459 // is slightly less confusing. 449 // is slightly less confusing.
460 if (details().window_component == HTCAPTION || 450 if (details().window_component == HTCAPTION ||
461 !AreBoundsValidSnappedBounds(window_state()->GetStateType(), 451 !AreBoundsValidSnappedBounds(window_state()->GetStateType(),
462 GetAuraTarget()->bounds())) { 452 GetTarget()->GetBounds())) {
463 // Set the window to WINDOW_STATE_TYPE_NORMAL but keep the 453 // Set the window to WINDOW_STATE_TYPE_NORMAL but keep the
464 // window at the bounds that the user has moved/resized the 454 // window at the bounds that the user has moved/resized the
465 // window to. ClearRestoreBounds() is used instead of 455 // window to. ClearRestoreBounds() is used instead of
466 // SaveCurrentBoundsForRestore() because most of the restore 456 // SaveCurrentBoundsForRestore() because most of the restore
467 // logic is skipped because we are still in the middle of a 457 // logic is skipped because we are still in the middle of a
468 // drag. TODO(pkotwicz): Fix this and use 458 // drag. TODO(pkotwicz): Fix this and use
469 // SaveCurrentBoundsForRestore(). 459 // SaveCurrentBoundsForRestore().
470 window_state()->ClearRestoreBounds(); 460 window_state()->ClearRestoreBounds();
471 window_state()->Restore(); 461 window_state()->Restore();
472 } 462 }
473 } else if (!dock_layout_->is_dragged_window_docked()) { 463 } else if (!dock_layout_->is_dragged_window_docked()) {
474 // The window was not snapped and is not snapped. This is a user 464 // The window was not snapped and is not snapped. This is a user
475 // resize/drag and so the current bounds should be maintained, clearing 465 // resize/drag and so the current bounds should be maintained, clearing
476 // any prior restore bounds. When the window is docked the restore bound 466 // any prior restore bounds. When the window is docked the restore bound
477 // must be kept so the docked state can be reverted properly. 467 // must be kept so the docked state can be reverted properly.
478 window_state()->ClearRestoreBounds(); 468 window_state()->ClearRestoreBounds();
479 } 469 }
480 } 470 }
481 } 471 }
482 472
483 void WorkspaceWindowResizer::RevertDrag() { 473 void WorkspaceWindowResizer::RevertDrag() {
484 window_state()->set_bounds_changed_by_user(initial_bounds_changed_by_user_); 474 window_state()->set_bounds_changed_by_user(initial_bounds_changed_by_user_);
485 snap_phantom_window_controller_.reset(); 475 snap_phantom_window_controller_.reset();
486 476
487 if (!did_move_or_resize_) 477 if (!did_move_or_resize_)
488 return; 478 return;
489 479
490 GetAuraTarget()->SetBounds(details().initial_bounds_in_parent); 480 GetTarget()->SetBounds(details().initial_bounds_in_parent);
491 if (!details().restore_bounds.IsEmpty()) { 481 if (!details().restore_bounds.IsEmpty())
492 window_state()->SetRestoreBoundsInScreen(details().restore_bounds); 482 window_state()->SetRestoreBoundsInScreen(details().restore_bounds);
493 }
494 483
495 if (details().window_component == HTRIGHT) { 484 if (details().window_component == HTRIGHT) {
496 int last_x = details().initial_bounds_in_parent.right(); 485 int last_x = details().initial_bounds_in_parent.right();
497 for (size_t i = 0; i < attached_windows_.size(); ++i) { 486 for (size_t i = 0; i < attached_windows_.size(); ++i) {
498 gfx::Rect bounds(attached_windows_[i]->bounds()); 487 gfx::Rect bounds(attached_windows_[i]->GetBounds());
499 bounds.set_x(last_x); 488 bounds.set_x(last_x);
500 bounds.set_width(initial_size_[i]); 489 bounds.set_width(initial_size_[i]);
501 attached_windows_[i]->SetBounds(bounds); 490 attached_windows_[i]->SetBounds(bounds);
502 last_x = attached_windows_[i]->bounds().right(); 491 last_x = attached_windows_[i]->GetBounds().right();
503 } 492 }
504 } else { 493 } else {
505 int last_y = details().initial_bounds_in_parent.bottom(); 494 int last_y = details().initial_bounds_in_parent.bottom();
506 for (size_t i = 0; i < attached_windows_.size(); ++i) { 495 for (size_t i = 0; i < attached_windows_.size(); ++i) {
507 gfx::Rect bounds(attached_windows_[i]->bounds()); 496 gfx::Rect bounds(attached_windows_[i]->GetBounds());
508 bounds.set_y(last_y); 497 bounds.set_y(last_y);
509 bounds.set_height(initial_size_[i]); 498 bounds.set_height(initial_size_[i]);
510 attached_windows_[i]->SetBounds(bounds); 499 attached_windows_[i]->SetBounds(bounds);
511 last_y = attached_windows_[i]->bounds().bottom(); 500 last_y = attached_windows_[i]->GetBounds().bottom();
512 } 501 }
513 } 502 }
514 } 503 }
515 504
516 WorkspaceWindowResizer::WorkspaceWindowResizer( 505 WorkspaceWindowResizer::WorkspaceWindowResizer(
517 wm::WindowState* window_state, 506 wm::WindowState* window_state,
518 const std::vector<aura::Window*>& attached_windows) 507 const std::vector<wm::WmWindow*>& attached_windows)
519 : WindowResizer(window_state), 508 : WindowResizer(window_state),
520 attached_windows_(attached_windows), 509 attached_windows_(attached_windows),
510 globals_(window_state->window()->GetGlobals()),
521 did_lock_cursor_(false), 511 did_lock_cursor_(false),
522 did_move_or_resize_(false), 512 did_move_or_resize_(false),
523 initial_bounds_changed_by_user_(window_state_->bounds_changed_by_user()), 513 initial_bounds_changed_by_user_(window_state_->bounds_changed_by_user()),
524 total_min_(0), 514 total_min_(0),
525 total_initial_size_(0), 515 total_initial_size_(0),
526 snap_type_(SNAP_NONE), 516 snap_type_(SNAP_NONE),
527 num_mouse_moves_since_bounds_change_(0), 517 num_mouse_moves_since_bounds_change_(0),
528 magnetism_window_(NULL), 518 magnetism_window_(NULL),
529 weak_ptr_factory_(this) { 519 weak_ptr_factory_(this) {
530 DCHECK(details().is_resizable); 520 DCHECK(details().is_resizable);
531 521
532 // A mousemove should still show the cursor even if the window is 522 // A mousemove should still show the cursor even if the window is
533 // being moved or resized with touch, so do not lock the cursor. 523 // being moved or resized with touch, so do not lock the cursor.
534 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 524 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
535 Shell* shell = Shell::GetInstance(); 525 globals_->LockCursor();
536 shell->cursor_manager()->LockCursor();
537 did_lock_cursor_ = true; 526 did_lock_cursor_ = true;
538 } 527 }
539 528
540 dock_layout_ = DockedWindowLayoutManager::Get(GetTarget()); 529 dock_layout_ = DockedWindowLayoutManager::Get(GetTarget());
541 530
542 // Only support attaching to the right/bottom. 531 // Only support attaching to the right/bottom.
543 DCHECK(attached_windows_.empty() || 532 DCHECK(attached_windows_.empty() ||
544 (details().window_component == HTRIGHT || 533 (details().window_component == HTRIGHT ||
545 details().window_component == HTBOTTOM)); 534 details().window_component == HTBOTTOM));
546 535
547 // TODO: figure out how to deal with window going off the edge. 536 // TODO: figure out how to deal with window going off the edge.
548 537
549 // Calculate sizes so that we can maintain the ratios if we need to resize. 538 // Calculate sizes so that we can maintain the ratios if we need to resize.
550 int total_available = 0; 539 int total_available = 0;
551 for (size_t i = 0; i < attached_windows_.size(); ++i) { 540 for (size_t i = 0; i < attached_windows_.size(); ++i) {
552 gfx::Size min(attached_windows_[i]->delegate()->GetMinimumSize()); 541 gfx::Size min(attached_windows_[i]->GetMinimumSize());
553 int initial_size = PrimaryAxisSize(attached_windows_[i]->bounds().size()); 542 int initial_size =
543 PrimaryAxisSize(attached_windows_[i]->GetBounds().size());
554 initial_size_.push_back(initial_size); 544 initial_size_.push_back(initial_size);
555 // If current size is smaller than the min, use the current size as the min. 545 // If current size is smaller than the min, use the current size as the min.
556 // This way we don't snap on resize. 546 // This way we don't snap on resize.
557 int min_size = std::min(initial_size, 547 int min_size = std::min(initial_size,
558 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); 548 std::max(PrimaryAxisSize(min), kMinOnscreenSize));
559 total_min_ += min_size; 549 total_min_ += min_size;
560 total_initial_size_ += initial_size; 550 total_initial_size_ += initial_size;
561 total_available += std::max(min_size, initial_size) - min_size; 551 total_available += std::max(min_size, initial_size) - min_size;
562 } 552 }
563 instance = this; 553 instance = this;
564 } 554 }
565 555
566 void WorkspaceWindowResizer::LayoutAttachedWindows( 556 void WorkspaceWindowResizer::LayoutAttachedWindows(
567 gfx::Rect* bounds) { 557 gfx::Rect* bounds) {
568 gfx::Rect work_area( 558 gfx::Rect work_area(wm::GetDisplayWorkAreaBoundsInParent(GetTarget()));
569 ScreenUtil::GetDisplayWorkAreaBoundsInParent(GetAuraTarget()));
570 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size()); 559 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size());
571 int current_size = PrimaryAxisSize(bounds->size()); 560 int current_size = PrimaryAxisSize(bounds->size());
572 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); 561 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom());
573 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom()); 562 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom());
574 563
575 int delta = current_size - initial_size; 564 int delta = current_size - initial_size;
576 int available_size = end - start; 565 int available_size = end - start;
577 std::vector<int> sizes; 566 std::vector<int> sizes;
578 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes); 567 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes);
579 568
580 // leftovers > 0 means that the attached windows can't grow to compensate for 569 // leftovers > 0 means that the attached windows can't grow to compensate for
581 // the shrinkage of the main window. This line causes the attached windows to 570 // the shrinkage of the main window. This line causes the attached windows to
582 // be moved so they are still flush against the main window, rather than the 571 // be moved so they are still flush against the main window, rather than the
583 // main window being prevented from shrinking. 572 // main window being prevented from shrinking.
584 leftovers = std::min(0, leftovers); 573 leftovers = std::min(0, leftovers);
585 // Reallocate any leftover pixels back into the main window. This is 574 // Reallocate any leftover pixels back into the main window. This is
586 // necessary when, for example, the main window shrinks, but none of the 575 // necessary when, for example, the main window shrinks, but none of the
587 // attached windows can grow without exceeding their max size constraints. 576 // attached windows can grow without exceeding their max size constraints.
588 // Adding the pixels back to the main window effectively prevents the main 577 // Adding the pixels back to the main window effectively prevents the main
589 // window from resizing too far. 578 // window from resizing too far.
590 if (details().window_component == HTRIGHT) 579 if (details().window_component == HTRIGHT)
591 bounds->set_width(bounds->width() + leftovers); 580 bounds->set_width(bounds->width() + leftovers);
592 else 581 else
593 bounds->set_height(bounds->height() + leftovers); 582 bounds->set_height(bounds->height() + leftovers);
594 583
595 DCHECK_EQ(attached_windows_.size(), sizes.size()); 584 DCHECK_EQ(attached_windows_.size(), sizes.size());
596 int last = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); 585 int last = PrimaryAxisCoordinate(bounds->right(), bounds->bottom());
597 for (size_t i = 0; i < attached_windows_.size(); ++i) { 586 for (size_t i = 0; i < attached_windows_.size(); ++i) {
598 gfx::Rect attached_bounds(attached_windows_[i]->bounds()); 587 gfx::Rect attached_bounds(attached_windows_[i]->GetBounds());
599 if (details().window_component == HTRIGHT) { 588 if (details().window_component == HTRIGHT) {
600 attached_bounds.set_x(last); 589 attached_bounds.set_x(last);
601 attached_bounds.set_width(sizes[i]); 590 attached_bounds.set_width(sizes[i]);
602 } else { 591 } else {
603 attached_bounds.set_y(last); 592 attached_bounds.set_y(last);
604 attached_bounds.set_height(sizes[i]); 593 attached_bounds.set_height(sizes[i]);
605 } 594 }
606 attached_windows_[i]->SetBounds(attached_bounds); 595 attached_windows_[i]->SetBounds(attached_bounds);
607 last += sizes[i]; 596 last += sizes[i];
608 } 597 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 677
689 for (size_t i = 0; i < sizes.size(); ++i) 678 for (size_t i = 0; i < sizes.size(); ++i)
690 out_ratios->push_back( 679 out_ratios->push_back(
691 (static_cast<float>(sizes[i]->size())) / total_value); 680 (static_cast<float>(sizes[i]->size())) / total_value);
692 } 681 }
693 682
694 void WorkspaceWindowResizer::CreateBucketsForAttached( 683 void WorkspaceWindowResizer::CreateBucketsForAttached(
695 std::vector<WindowSize>* sizes) const { 684 std::vector<WindowSize>* sizes) const {
696 for (size_t i = 0; i < attached_windows_.size(); i++) { 685 for (size_t i = 0; i < attached_windows_.size(); i++) {
697 int initial_size = initial_size_[i]; 686 int initial_size = initial_size_[i];
698 aura::WindowDelegate* delegate = attached_windows_[i]->delegate(); 687 int min = PrimaryAxisSize(attached_windows_[i]->GetMinimumSize());
699 int min = PrimaryAxisSize(delegate->GetMinimumSize()); 688 int max = PrimaryAxisSize(attached_windows_[i]->GetMaximumSize());
700 int max = PrimaryAxisSize(delegate->GetMaximumSize());
701 689
702 sizes->push_back(WindowSize(initial_size, min, max)); 690 sizes->push_back(WindowSize(initial_size, min, max));
703 } 691 }
704 } 692 }
705 693
706 void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) { 694 void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) {
707 if (UpdateMagnetismWindow(*bounds, kAllMagnetismEdges)) { 695 if (UpdateMagnetismWindow(*bounds, kAllMagnetismEdges)) {
708 gfx::Point point = OriginForMagneticAttach( 696 gfx::Point point = OriginForMagneticAttach(
709 ScreenUtil::ConvertRectToScreen(GetAuraTarget()->parent(), *bounds), 697 GetTarget()->GetParent()->ConvertRectToScreen(*bounds),
710 magnetism_window_->GetBoundsInScreen(), magnetism_edge_); 698 magnetism_window_->GetBoundsInScreen(), magnetism_edge_);
711 aura::client::GetScreenPositionClient(GetAuraTarget()->GetRootWindow()) 699 point = GetTarget()->GetParent()->ConvertPointFromScreen(point);
712 ->ConvertPointFromScreen(GetAuraTarget()->parent(), &point);
713 bounds->set_origin(point); 700 bounds->set_origin(point);
714 } 701 }
715 } 702 }
716 703
717 void WorkspaceWindowResizer::MagneticallySnapResizeToOtherWindows( 704 void WorkspaceWindowResizer::MagneticallySnapResizeToOtherWindows(
718 gfx::Rect* bounds) { 705 gfx::Rect* bounds) {
719 const uint32_t edges = 706 const uint32_t edges =
720 WindowComponentToMagneticEdge(details().window_component); 707 WindowComponentToMagneticEdge(details().window_component);
721 if (UpdateMagnetismWindow(*bounds, edges)) { 708 if (UpdateMagnetismWindow(*bounds, edges)) {
722 *bounds = ScreenUtil::ConvertRectFromScreen( 709 *bounds = GetTarget()->GetParent()->ConvertRectFromScreen(
723 GetAuraTarget()->parent(),
724 BoundsForMagneticResizeAttach( 710 BoundsForMagneticResizeAttach(
725 ScreenUtil::ConvertRectToScreen(GetAuraTarget()->parent(), *bounds), 711 GetTarget()->GetParent()->ConvertRectToScreen(*bounds),
726 magnetism_window_->GetBoundsInScreen(), magnetism_edge_)); 712 magnetism_window_->GetBoundsInScreen(), magnetism_edge_));
727 } 713 }
728 } 714 }
729 715
730 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds, 716 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds,
731 uint32_t edges) { 717 uint32_t edges) {
732 // |bounds| are in coordinates of original window's parent. 718 // |bounds| are in coordinates of original window's parent.
733 gfx::Rect bounds_in_screen = 719 gfx::Rect bounds_in_screen =
734 ScreenUtil::ConvertRectToScreen(GetAuraTarget()->parent(), bounds); 720 GetTarget()->GetParent()->ConvertRectToScreen(bounds);
735 MagnetismMatcher matcher(bounds_in_screen, edges); 721 MagnetismMatcher matcher(bounds_in_screen, edges);
736 722
737 // If we snapped to a window then check it first. That way we don't bounce 723 // If we snapped to a window then check it first. That way we don't bounce
738 // around when close to multiple edges. 724 // around when close to multiple edges.
739 if (magnetism_window_) { 725 if (magnetism_window_) {
740 if (window_tracker_.Contains(magnetism_window_) && 726 if (window_tracker_.Contains(magnetism_window_) &&
741 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), 727 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(),
742 &magnetism_edge_)) { 728 &magnetism_edge_)) {
743 return true; 729 return true;
744 } 730 }
745 window_tracker_.Remove(magnetism_window_); 731 window_tracker_.Remove(magnetism_window_);
746 magnetism_window_ = NULL; 732 magnetism_window_ = NULL;
747 } 733 }
748 734
749 // Avoid magnetically snapping windows that are not resizable. 735 // Avoid magnetically snapping windows that are not resizable.
750 // TODO(oshima): change this to window.type() == TYPE_NORMAL. 736 // TODO(oshima): change this to window.type() == TYPE_NORMAL.
751 if (!window_state()->CanResize()) 737 if (!window_state()->CanResize())
752 return false; 738 return false;
753 739
754 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 740 for (wm::WmWindow* root_window : globals_->GetAllRootWindows()) {
755 for (aura::Window::Windows::iterator iter = root_windows.begin();
756 iter != root_windows.end(); ++iter) {
757 const aura::Window* root_window = *iter;
758 // Test all children from the desktop in each root window. 741 // Test all children from the desktop in each root window.
759 const aura::Window::Windows& children = Shell::GetContainer( 742 const std::vector<wm::WmWindow*> children =
760 root_window, kShellWindowId_DefaultContainer)->children(); 743 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer)
761 for (aura::Window::Windows::const_reverse_iterator i = children.rbegin(); 744 ->GetChildren();
745 for (auto i = children.rbegin();
762 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { 746 i != children.rend() && !matcher.AreEdgesObscured(); ++i) {
763 wm::WindowState* other_state = wm::GetWindowState(*i); 747 wm::WindowState* other_state = (*i)->GetWindowState();
764 if (other_state->aura_window() == GetAuraTarget() || 748 if (other_state->window() == GetTarget() ||
765 !other_state->window()->IsVisible() || 749 !other_state->window()->IsVisible() ||
766 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { 750 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) {
767 continue; 751 continue;
768 } 752 }
769 if (matcher.ShouldAttach( 753 if (matcher.ShouldAttach(
770 other_state->window()->GetBoundsInScreen(), &magnetism_edge_)) { 754 other_state->window()->GetBoundsInScreen(), &magnetism_edge_)) {
771 magnetism_window_ = other_state->aura_window(); 755 magnetism_window_ = other_state->window();
772 window_tracker_.Add(magnetism_window_); 756 window_tracker_.Add(magnetism_window_);
773 return true; 757 return true;
774 } 758 }
775 } 759 }
776 } 760 }
777 return false; 761 return false;
778 } 762 }
779 763
780 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( 764 void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
781 int sticky_size, 765 int sticky_size,
782 gfx::Rect* bounds) { 766 gfx::Rect* bounds) {
783 gfx::Point last_mouse_location_in_screen = last_mouse_location_; 767 gfx::Point last_mouse_location_in_screen =
784 ::wm::ConvertPointToScreen(GetAuraTarget()->parent(), 768 GetTarget()->GetParent()->ConvertPointToScreen(last_mouse_location_);
785 &last_mouse_location_in_screen);
786 gfx::Display display = gfx::Screen::GetScreen()->GetDisplayNearestPoint( 769 gfx::Display display = gfx::Screen::GetScreen()->GetDisplayNearestPoint(
787 last_mouse_location_in_screen); 770 last_mouse_location_in_screen);
788 gfx::Rect work_area = ScreenUtil::ConvertRectFromScreen( 771 gfx::Rect work_area =
789 GetAuraTarget()->parent(), display.work_area()); 772 GetTarget()->GetParent()->ConvertRectFromScreen(display.work_area());
790 if (details().window_component == HTCAPTION) { 773 if (details().window_component == HTCAPTION) {
791 // Adjust the bounds to the work area where the mouse cursor is located. 774 // Adjust the bounds to the work area where the mouse cursor is located.
792 // Always keep kMinOnscreenHeight or the window height (whichever is less) 775 // Always keep kMinOnscreenHeight or the window height (whichever is less)
793 // on the bottom. 776 // on the bottom.
794 int max_y = work_area.bottom() - std::min(kMinOnscreenHeight, 777 int max_y = work_area.bottom() - std::min(kMinOnscreenHeight,
795 bounds->height()); 778 bounds->height());
796 if (bounds->y() > max_y) { 779 if (bounds->y() > max_y) {
797 bounds->set_y(max_y); 780 bounds->set_y(max_y);
798 } else if (bounds->y() <= work_area.y()) { 781 } else if (bounds->y() <= work_area.y()) {
799 // Don't allow dragging above the top of the display until the mouse 782 // Don't allow dragging above the top of the display until the mouse
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 } else { 929 } else {
947 edge_cycler_->OnMove(location); 930 edge_cycler_->OnMove(location);
948 } 931 }
949 932
950 // Update phantom window with snapped or docked guide bounds. 933 // Update phantom window with snapped or docked guide bounds.
951 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get 934 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get
952 // docked without going through a snapping sequence. 935 // docked without going through a snapping sequence.
953 gfx::Rect phantom_bounds; 936 gfx::Rect phantom_bounds;
954 const bool should_dock = 937 const bool should_dock =
955 can_dock && (!can_snap || 938 can_dock && (!can_snap ||
956 GetAuraTarget()->bounds().width() <= 939 GetTarget()->GetBounds().width() <=
957 DockedWindowLayoutManager::kMaxDockWidth || 940 DockedWindowLayoutManager::kMaxDockWidth ||
958 edge_cycler_->use_second_mode() || 941 edge_cycler_->use_second_mode() ||
959 dock_layout_->is_dragged_window_docked()); 942 dock_layout_->is_dragged_window_docked());
960 if (should_dock) { 943 if (should_dock) {
961 SetDraggedWindowDocked(true); 944 SetDraggedWindowDocked(true);
962 phantom_bounds = ScreenUtil::ConvertRectFromScreen( 945 phantom_bounds = GetTarget()->GetParent()->ConvertRectFromScreen(
963 GetAuraTarget()->parent(), dock_layout_->dragged_bounds()); 946 dock_layout_->dragged_bounds());
964 } else { 947 } else {
965 phantom_bounds = (snap_type_ == SNAP_LEFT) 948 phantom_bounds =
966 ? wm::GetDefaultLeftSnappedWindowBoundsInParent( 949 (snap_type_ == SNAP_LEFT)
967 wm::WmWindowAura::Get(GetAuraTarget())) 950 ? wm::GetDefaultLeftSnappedWindowBoundsInParent(GetTarget())
968 : wm::GetDefaultRightSnappedWindowBoundsInParent( 951 : wm::GetDefaultRightSnappedWindowBoundsInParent(GetTarget());
969 wm::WmWindowAura::Get(GetAuraTarget()));
970 } 952 }
971 953
972 if (!snap_phantom_window_controller_) { 954 if (!snap_phantom_window_controller_) {
973 snap_phantom_window_controller_.reset( 955 snap_phantom_window_controller_.reset(new PhantomWindowController(
974 new PhantomWindowController(GetAuraTarget())); 956 wm::WmWindowAura::GetAuraWindow(GetTarget())));
975 } 957 }
976 snap_phantom_window_controller_->Show(ScreenUtil::ConvertRectToScreen( 958 snap_phantom_window_controller_->Show(
977 GetAuraTarget()->parent(), phantom_bounds)); 959 GetTarget()->GetParent()->ConvertRectToScreen(phantom_bounds));
978 } 960 }
979 961
980 void WorkspaceWindowResizer::RestackWindows() { 962 void WorkspaceWindowResizer::RestackWindows() {
981 if (attached_windows_.empty()) 963 if (attached_windows_.empty())
982 return; 964 return;
983 // Build a map from index in children to window, returning if there is a 965 // Build a map from index in children to window, returning if there is a
984 // window with a different parent. 966 // window with a different parent.
985 typedef std::map<size_t, aura::Window*> IndexToWindowMap; 967 using IndexToWindowMap = std::map<size_t, wm::WmWindow*>;
986 IndexToWindowMap map; 968 IndexToWindowMap map;
987 aura::Window* parent = GetAuraTarget()->parent(); 969 wm::WmWindow* parent = GetTarget()->GetParent();
988 const aura::Window::Windows& windows(parent->children()); 970 const std::vector<wm::WmWindow*> windows(parent->GetChildren());
989 map[std::find(windows.begin(), windows.end(), GetAuraTarget()) - 971 map[std::find(windows.begin(), windows.end(), GetTarget()) -
990 windows.begin()] = GetAuraTarget(); 972 windows.begin()] = GetTarget();
991 for (std::vector<aura::Window*>::const_iterator i = 973 for (auto i = attached_windows_.begin(); i != attached_windows_.end(); ++i) {
992 attached_windows_.begin(); i != attached_windows_.end(); ++i) { 974 if ((*i)->GetParent() != parent)
993 if ((*i)->parent() != parent)
994 return; 975 return;
995 size_t index = 976 size_t index =
996 std::find(windows.begin(), windows.end(), *i) - windows.begin(); 977 std::find(windows.begin(), windows.end(), *i) - windows.begin();
997 map[index] = *i; 978 map[index] = *i;
998 } 979 }
999 980
1000 // Reorder the windows starting at the topmost. 981 // Reorder the windows starting at the topmost.
1001 parent->StackChildAtTop(map.rbegin()->second); 982 parent->StackChildAtTop(map.rbegin()->second);
1002 for (IndexToWindowMap::const_reverse_iterator i = map.rbegin(); 983 for (auto i = map.rbegin(); i != map.rend();) {
1003 i != map.rend(); ) { 984 wm::WmWindow* window = i->second;
1004 aura::Window* window = i->second;
1005 ++i; 985 ++i;
1006 if (i != map.rend()) 986 if (i != map.rend())
1007 parent->StackChildBelow(i->second, window); 987 parent->StackChildBelow(i->second, window);
1008 } 988 }
1009 } 989 }
1010 990
1011 WorkspaceWindowResizer::SnapType WorkspaceWindowResizer::GetSnapType( 991 WorkspaceWindowResizer::SnapType WorkspaceWindowResizer::GetSnapType(
1012 const gfx::Point& location) const { 992 const gfx::Point& location) const {
1013 // TODO: this likely only wants total display area, not the area of a single 993 // TODO: this likely only wants total display area, not the area of a single
1014 // display. 994 // display.
1015 gfx::Rect area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(GetAuraTarget())); 995 gfx::Rect area(wm::GetDisplayWorkAreaBoundsInParent(GetTarget()));
1016 if (details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 996 if (details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
1017 // Increase tolerance for touch-snapping near the screen edges. This is only 997 // Increase tolerance for touch-snapping near the screen edges. This is only
1018 // necessary when the work area left or right edge is same as screen edge. 998 // necessary when the work area left or right edge is same as screen edge.
1019 gfx::Rect display_bounds( 999 gfx::Rect display_bounds(wm::GetDisplayBoundsInParent(GetTarget()));
1020 ScreenUtil::GetDisplayBoundsInParent(GetAuraTarget()));
1021 int inset_left = 0; 1000 int inset_left = 0;
1022 if (area.x() == display_bounds.x()) 1001 if (area.x() == display_bounds.x())
1023 inset_left = kScreenEdgeInsetForTouchDrag; 1002 inset_left = kScreenEdgeInsetForTouchDrag;
1024 int inset_right = 0; 1003 int inset_right = 0;
1025 if (area.right() == display_bounds.right()) 1004 if (area.right() == display_bounds.right())
1026 inset_right = kScreenEdgeInsetForTouchDrag; 1005 inset_right = kScreenEdgeInsetForTouchDrag;
1027 area.Inset(inset_left, 0, inset_right, 0); 1006 area.Inset(inset_left, 0, inset_right, 0);
1028 } 1007 }
1029 if (location.x() <= area.x()) 1008 if (location.x() <= area.x())
1030 return SNAP_LEFT; 1009 return SNAP_LEFT;
(...skipping 14 matching lines...) Expand all
1045 window_state()->set_bounds_changed_by_user(true); 1024 window_state()->set_bounds_changed_by_user(true);
1046 } 1025 }
1047 } 1026 }
1048 } 1027 }
1049 1028
1050 bool WorkspaceWindowResizer::AreBoundsValidSnappedBounds( 1029 bool WorkspaceWindowResizer::AreBoundsValidSnappedBounds(
1051 wm::WindowStateType snapped_type, 1030 wm::WindowStateType snapped_type,
1052 const gfx::Rect& bounds_in_parent) const { 1031 const gfx::Rect& bounds_in_parent) const {
1053 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || 1032 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ||
1054 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); 1033 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED);
1055 gfx::Rect snapped_bounds = 1034 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget());
1056 ScreenUtil::GetDisplayWorkAreaBoundsInParent(GetAuraTarget());
1057 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) 1035 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED)
1058 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); 1036 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width());
1059 snapped_bounds.set_width(bounds_in_parent.width()); 1037 snapped_bounds.set_width(bounds_in_parent.width());
1060 return bounds_in_parent == snapped_bounds; 1038 return bounds_in_parent == snapped_bounds;
1061 } 1039 }
1062 1040
1063 } // namespace ash 1041 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.h ('k') | ash/wm/workspace/workspace_window_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698