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/ash_switches.h" | 12 #include "ash/ash_switches.h" |
13 #include "ash/display/display_controller.h" | 13 #include "ash/display/display_controller.h" |
14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
15 #include "ash/screen_ash.h" | 15 #include "ash/screen_ash.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
17 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
18 #include "ash/wm/coordinate_conversion.h" | 18 #include "ash/wm/coordinate_conversion.h" |
19 #include "ash/wm/default_window_resizer.h" | 19 #include "ash/wm/default_window_resizer.h" |
20 #include "ash/wm/dock/docked_window_layout_manager.h" | 20 #include "ash/wm/dock/docked_window_layout_manager.h" |
21 #include "ash/wm/dock/docked_window_resizer.h" | 21 #include "ash/wm/dock/docked_window_resizer.h" |
22 #include "ash/wm/drag_window_resizer.h" | 22 #include "ash/wm/drag_window_resizer.h" |
23 #include "ash/wm/panels/panel_window_resizer.h" | 23 #include "ash/wm/panels/panel_window_resizer.h" |
24 #include "ash/wm/property_util.h" | 24 #include "ash/wm/window_state.h" |
25 #include "ash/wm/window_settings.h" | |
26 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
27 #include "ash/wm/workspace/phantom_window_controller.h" | 26 #include "ash/wm/workspace/phantom_window_controller.h" |
28 #include "ash/wm/workspace/snap_sizer.h" | 27 #include "ash/wm/workspace/snap_sizer.h" |
29 #include "base/command_line.h" | 28 #include "base/command_line.h" |
30 #include "base/memory/weak_ptr.h" | 29 #include "base/memory/weak_ptr.h" |
31 #include "ui/aura/client/aura_constants.h" | 30 #include "ui/aura/client/aura_constants.h" |
32 #include "ui/aura/client/screen_position_client.h" | 31 #include "ui/aura/client/screen_position_client.h" |
33 #include "ui/aura/client/window_types.h" | 32 #include "ui/aura/client/window_types.h" |
34 #include "ui/aura/root_window.h" | 33 #include "ui/aura/root_window.h" |
35 #include "ui/aura/window.h" | 34 #include "ui/aura/window.h" |
36 #include "ui/aura/window_delegate.h" | 35 #include "ui/aura/window_delegate.h" |
37 #include "ui/base/hit_test.h" | 36 #include "ui/base/hit_test.h" |
38 #include "ui/compositor/layer.h" | 37 #include "ui/compositor/layer.h" |
39 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
40 #include "ui/gfx/transform.h" | 39 #include "ui/gfx/transform.h" |
41 | 40 |
42 namespace ash { | 41 namespace ash { |
43 | 42 |
44 scoped_ptr<WindowResizer> CreateWindowResizer( | 43 scoped_ptr<WindowResizer> CreateWindowResizer( |
45 aura::Window* window, | 44 aura::Window* window, |
46 const gfx::Point& point_in_parent, | 45 const gfx::Point& point_in_parent, |
47 int window_component, | 46 int window_component, |
48 aura::client::WindowMoveSource source) { | 47 aura::client::WindowMoveSource source) { |
49 DCHECK(window); | 48 DCHECK(window); |
| 49 wm::WindowState* window_state = wm::GetWindowState(window); |
50 // No need to return a resizer when the window cannot get resized. | 50 // No need to return a resizer when the window cannot get resized. |
51 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) | 51 if (!window_state->CanResize() && window_component != HTCAPTION) |
52 return scoped_ptr<WindowResizer>(); | 52 return scoped_ptr<WindowResizer>(); |
53 | 53 |
54 // 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 |
55 // 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 |
56 // classes using reparenting during drag operations it becomes challenging to | 56 // classes using reparenting during drag operations it becomes challenging to |
57 // 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 |
58 // end of the drag. This also causes http://crbug.com/247085. | 58 // end of the drag. This also causes http://crbug.com/247085. |
59 // 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 |
60 // 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 |
61 // 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 |
62 // 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 |
63 // drag has started or stopped. | 63 // drag has started or stopped. |
64 // It may be possible to refactor and eliminate chaining. | 64 // It may be possible to refactor and eliminate chaining. |
65 WindowResizer* window_resizer = NULL; | 65 WindowResizer* window_resizer = NULL; |
66 if (window->parent() && | 66 if (window->parent() && |
67 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || | 67 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || |
68 window->parent()->id() == internal::kShellWindowId_DockedContainer || | 68 window->parent()->id() == internal::kShellWindowId_DockedContainer || |
69 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { | 69 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { |
70 // Allow dragging maximized windows if it's not tracked by workspace. This | 70 // Allow dragging maximized windows if it's not tracked by workspace. This |
71 // is set by tab dragging code. | 71 // is set by tab dragging code. |
72 if (!wm::IsWindowNormal(window) && | 72 if (!window_state->IsNormalShowState() && |
73 (window_component != HTCAPTION || | 73 (window_component != HTCAPTION || |
74 wm::GetWindowSettings(window)->tracked_by_workspace())) { | 74 window_state->tracked_by_workspace())) { |
75 return scoped_ptr<WindowResizer>(); | 75 return scoped_ptr<WindowResizer>(); |
76 } | 76 } |
77 window_resizer = internal::WorkspaceWindowResizer::Create( | 77 window_resizer = internal::WorkspaceWindowResizer::Create( |
78 window, | 78 window, |
79 point_in_parent, | 79 point_in_parent, |
80 window_component, | 80 window_component, |
81 source, | 81 source, |
82 std::vector<aura::Window*>()); | 82 std::vector<aura::Window*>()); |
83 } else if (wm::IsWindowNormal(window)) { | 83 } else if (window_state->IsNormalShowState()) { |
84 window_resizer = DefaultWindowResizer::Create( | 84 window_resizer = DefaultWindowResizer::Create( |
85 window, point_in_parent, window_component, source); | 85 window, point_in_parent, window_component, source); |
86 } | 86 } |
87 if (window_resizer) { | 87 if (window_resizer) { |
88 window_resizer = internal::DragWindowResizer::Create( | 88 window_resizer = internal::DragWindowResizer::Create( |
89 window_resizer, window, point_in_parent, window_component, source); | 89 window_resizer, window, point_in_parent, window_component, source); |
90 } | 90 } |
91 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { | 91 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { |
92 window_resizer = PanelWindowResizer::Create( | 92 window_resizer = PanelWindowResizer::Create( |
93 window_resizer, window, point_in_parent, window_component, source); | 93 window_resizer, window, point_in_parent, window_component, source); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 switches::kAshEnableDockedWindows)) { | 367 switches::kAshEnableDockedWindows)) { |
368 sticky_size = kStickyDistancePixels; | 368 sticky_size = kStickyDistancePixels; |
369 } else if ((details_.bounds_change & kBoundsChange_Resizes) && | 369 } else if ((details_.bounds_change & kBoundsChange_Resizes) && |
370 details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | 370 details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { |
371 sticky_size = kScreenEdgeInsetForTouchResize; | 371 sticky_size = kScreenEdgeInsetForTouchResize; |
372 } else { | 372 } else { |
373 sticky_size = kScreenEdgeInset; | 373 sticky_size = kScreenEdgeInset; |
374 } | 374 } |
375 // |bounds| is in |window()->parent()|'s coordinates. | 375 // |bounds| is in |window()->parent()|'s coordinates. |
376 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); | 376 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); |
377 | 377 if (window_state()->IsNormalShowState()) |
378 if (wm::IsWindowNormal(window())) | |
379 AdjustBoundsForMainWindow(sticky_size, &bounds); | 378 AdjustBoundsForMainWindow(sticky_size, &bounds); |
380 | 379 |
381 if (bounds != window()->bounds()) { | 380 if (bounds != window()->bounds()) { |
382 if (!did_move_or_resize_) { | 381 if (!did_move_or_resize_) { |
383 if (!details_.restore_bounds.IsEmpty()) | 382 if (!details_.restore_bounds.IsEmpty()) |
384 ClearRestoreBounds(window()); | 383 window_state()->ClearRestoreBounds(); |
385 RestackWindows(); | 384 RestackWindows(); |
386 } | 385 } |
387 did_move_or_resize_ = true; | 386 did_move_or_resize_ = true; |
388 } | 387 } |
389 | 388 |
390 gfx::Point location_in_screen = location_in_parent; | 389 gfx::Point location_in_screen = location_in_parent; |
391 wm::ConvertPointToScreen(window()->parent(), &location_in_screen); | 390 wm::ConvertPointToScreen(window()->parent(), &location_in_screen); |
392 | 391 |
393 aura::RootWindow* root = NULL; | 392 aura::RootWindow* root = NULL; |
394 gfx::Display display = | 393 gfx::Display display = |
(...skipping 22 matching lines...) Expand all Loading... |
417 UpdateSnapPhantomWindow(location_in_parent, bounds); | 416 UpdateSnapPhantomWindow(location_in_parent, bounds); |
418 } else { | 417 } else { |
419 snap_type_ = SNAP_NONE; | 418 snap_type_ = SNAP_NONE; |
420 snap_phantom_window_controller_.reset(); | 419 snap_phantom_window_controller_.reset(); |
421 snap_sizer_.reset(); | 420 snap_sizer_.reset(); |
422 UpdateDockedState(false); | 421 UpdateDockedState(false); |
423 } | 422 } |
424 } | 423 } |
425 | 424 |
426 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { | 425 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
427 wm::GetWindowSettings(details_.window)->set_bounds_changed_by_user(true); | 426 window_state()->set_bounds_changed_by_user(true); |
428 snap_phantom_window_controller_.reset(); | 427 snap_phantom_window_controller_.reset(); |
429 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 428 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
430 return; | 429 return; |
431 | 430 |
432 // When the window is not in the normal show state, we do not snap the window. | 431 // When the window is not in the normal show state, we do not snap the window. |
433 // This happens when the user minimizes or maximizes the window by keyboard | 432 // This happens when the user minimizes or maximizes the window by keyboard |
434 // shortcut while dragging it. If the window is the result of dragging a tab | 433 // shortcut while dragging it. If the window is the result of dragging a tab |
435 // out of a maximized window, it's already in the normal show state when this | 434 // out of a maximized window, it's already in the normal show state when this |
436 // is called, so it does not matter. | 435 // is called, so it does not matter. |
437 if (wm::IsWindowNormal(window()) && | 436 if (window_state()->IsNormalShowState() && |
438 (window()->type() != aura::client::WINDOW_TYPE_PANEL || | 437 (window()->type() != aura::client::WINDOW_TYPE_PANEL || |
439 !wm::GetWindowSettings(window())->panel_attached()) && | 438 !window_state()->panel_attached()) && |
440 (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { | 439 (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { |
441 if (!GetRestoreBoundsInScreen(window())) { | 440 if (!window_state()->HasRestoreBounds()) { |
442 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( | 441 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( |
443 window()->parent(), details_.initial_bounds_in_parent); | 442 window()->parent(), details_.initial_bounds_in_parent); |
444 SetRestoreBoundsInScreen(window(), details_.restore_bounds.IsEmpty() ? | 443 window_state()->SetRestoreBoundsInScreen( |
445 initial_bounds : | 444 details_.restore_bounds.IsEmpty() ? |
446 details_.restore_bounds); | 445 initial_bounds : |
| 446 details_.restore_bounds); |
447 } | 447 } |
448 DCHECK(snap_sizer_); | 448 DCHECK(snap_sizer_); |
449 if (wm::CanResizeWindow(window()) && | 449 if (window_state()->CanResize() && |
450 !dock_layout_->is_dragged_window_docked()) { | 450 !dock_layout_->is_dragged_window_docked()) { |
451 snap_sizer_->SnapWindowToTargetBounds(); | 451 snap_sizer_->SnapWindowToTargetBounds(); |
452 } | 452 } |
453 } | 453 } |
454 } | 454 } |
455 | 455 |
456 void WorkspaceWindowResizer::RevertDrag() { | 456 void WorkspaceWindowResizer::RevertDrag() { |
457 snap_phantom_window_controller_.reset(); | 457 snap_phantom_window_controller_.reset(); |
458 | 458 |
459 if (!did_move_or_resize_) | 459 if (!did_move_or_resize_) |
460 return; | 460 return; |
461 | 461 |
462 window()->SetBounds(details_.initial_bounds_in_parent); | 462 window()->SetBounds(details_.initial_bounds_in_parent); |
463 if (!details_.restore_bounds.IsEmpty()) | 463 if (!details_.restore_bounds.IsEmpty()) { |
464 SetRestoreBoundsInScreen(details_.window, details_.restore_bounds); | 464 window_state()->SetRestoreBoundsInScreen(details_.restore_bounds); |
| 465 } |
465 | 466 |
466 if (details_.window_component == HTRIGHT) { | 467 if (details_.window_component == HTRIGHT) { |
467 int last_x = details_.initial_bounds_in_parent.right(); | 468 int last_x = details_.initial_bounds_in_parent.right(); |
468 for (size_t i = 0; i < attached_windows_.size(); ++i) { | 469 for (size_t i = 0; i < attached_windows_.size(); ++i) { |
469 gfx::Rect bounds(attached_windows_[i]->bounds()); | 470 gfx::Rect bounds(attached_windows_[i]->bounds()); |
470 bounds.set_x(last_x); | 471 bounds.set_x(last_x); |
471 bounds.set_width(initial_size_[i]); | 472 bounds.set_width(initial_size_[i]); |
472 attached_windows_[i]->SetBounds(bounds); | 473 attached_windows_[i]->SetBounds(bounds); |
473 last_x = attached_windows_[i]->bounds().right(); | 474 last_x = attached_windows_[i]->bounds().right(); |
474 } | 475 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), | 725 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), |
725 &magnetism_edge_)) { | 726 &magnetism_edge_)) { |
726 return true; | 727 return true; |
727 } | 728 } |
728 window_tracker_.Remove(magnetism_window_); | 729 window_tracker_.Remove(magnetism_window_); |
729 magnetism_window_ = NULL; | 730 magnetism_window_ = NULL; |
730 } | 731 } |
731 | 732 |
732 // Avoid magnetically snapping to popups, menus, tooltips, controls and | 733 // Avoid magnetically snapping to popups, menus, tooltips, controls and |
733 // windows that are not tracked by workspace. | 734 // windows that are not tracked by workspace. |
734 if (!wm::CanResizeWindow(window()) || | 735 if (!window_state()->CanResize() || !window_state()->tracked_by_workspace()) |
735 !wm::GetWindowSettings(window())->tracked_by_workspace()) | |
736 return false; | 736 return false; |
737 | 737 |
738 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 738 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
739 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 739 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
740 iter != root_windows.end(); ++iter) { | 740 iter != root_windows.end(); ++iter) { |
741 const aura::RootWindow* root_window = *iter; | 741 const aura::RootWindow* root_window = *iter; |
742 // Test all children from the desktop in each root window. | 742 // Test all children from the desktop in each root window. |
743 const aura::Window::Windows& children = Shell::GetContainer( | 743 const aura::Window::Windows& children = Shell::GetContainer( |
744 root_window, kShellWindowId_DefaultContainer)->children(); | 744 root_window, kShellWindowId_DefaultContainer)->children(); |
745 for (aura::Window::Windows::const_reverse_iterator i = children.rbegin(); | 745 for (aura::Window::Windows::const_reverse_iterator i = children.rbegin(); |
746 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { | 746 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { |
747 aura::Window* other = *i; | 747 wm::WindowState* other_state = wm::GetWindowState(*i); |
748 if (other == window() || | 748 if (other_state->window() == window() || |
749 !other->IsVisible() || | 749 !other_state->window()->IsVisible() || |
750 !wm::IsWindowNormal(other) || | 750 !other_state->IsNormalShowState() || |
751 !wm::CanResizeWindow(other)) { | 751 !other_state->CanResize()) { |
752 continue; | 752 continue; |
753 } | 753 } |
754 if (matcher.ShouldAttach(other->GetBoundsInScreen(), &magnetism_edge_)) { | 754 if (matcher.ShouldAttach( |
755 magnetism_window_ = other; | 755 other_state->window()->GetBoundsInScreen(), &magnetism_edge_)) { |
| 756 magnetism_window_ = other_state->window(); |
756 window_tracker_.Add(magnetism_window_); | 757 window_tracker_.Add(magnetism_window_); |
757 return true; | 758 return true; |
758 } | 759 } |
759 } | 760 } |
760 } | 761 } |
761 return false; | 762 return false; |
762 } | 763 } |
763 | 764 |
764 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( | 765 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( |
765 int sticky_size, | 766 int sticky_size, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 if (!snap_sizer_) { | 904 if (!snap_sizer_) { |
904 snap_sizer_.reset(new SnapSizer(window(), | 905 snap_sizer_.reset(new SnapSizer(window(), |
905 location, | 906 location, |
906 edge, | 907 edge, |
907 internal::SnapSizer::OTHER_INPUT)); | 908 internal::SnapSizer::OTHER_INPUT)); |
908 } else { | 909 } else { |
909 snap_sizer_->Update(location); | 910 snap_sizer_->Update(location); |
910 } | 911 } |
911 | 912 |
912 const bool can_dock = dock_layout_->CanDockWindow(window(), snap_type_); | 913 const bool can_dock = dock_layout_->CanDockWindow(window(), snap_type_); |
913 if (!wm::CanSnapWindow(window()) && !can_dock) | 914 if (!window_state()->CanSnap() && !can_dock) |
914 return; | 915 return; |
915 | 916 |
916 // Update phantom window with snapped or docked guide bounds. | 917 // Update phantom window with snapped or docked guide bounds. |
917 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get | 918 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get |
918 // docked without going through a snapping sequence. | 919 // docked without going through a snapping sequence. |
919 gfx::Rect phantom_bounds; | 920 gfx::Rect phantom_bounds; |
920 if (!can_dock || | 921 if (!can_dock || |
921 window()->bounds().width() > DockedWindowLayoutManager::kMaxDockWidth) | 922 window()->bounds().width() > DockedWindowLayoutManager::kMaxDockWidth) |
922 phantom_bounds = snap_sizer_->target_bounds(); | 923 phantom_bounds = snap_sizer_->target_bounds(); |
923 const bool is_docked = can_dock && | 924 const bool is_docked = can_dock && |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 if (!dock_layout_->is_dragged_window_docked()) | 991 if (!dock_layout_->is_dragged_window_docked()) |
991 dock_layout_->DockDraggedWindow(window()); | 992 dock_layout_->DockDraggedWindow(window()); |
992 } else { | 993 } else { |
993 if (dock_layout_->is_dragged_window_docked()) | 994 if (dock_layout_->is_dragged_window_docked()) |
994 dock_layout_->UndockDraggedWindow(); | 995 dock_layout_->UndockDraggedWindow(); |
995 } | 996 } |
996 } | 997 } |
997 | 998 |
998 } // namespace internal | 999 } // namespace internal |
999 } // namespace ash | 1000 } // namespace ash |
OLD | NEW |