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

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

Issue 24108003: [Cleanup] Rename WindowSettings to WindowState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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/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->IsNormal() &&
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->IsNormal()) {
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
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()->IsNormal())
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
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()->IsNormal() &&
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_->target_bounds().IsEmpty()) { 451 !snap_sizer_->target_bounds().IsEmpty()) {
452 window()->SetBounds(snap_sizer_->target_bounds()); 452 window()->SetBounds(snap_sizer_->target_bounds());
453 } 453 }
454 return; 454 return;
455 } 455 }
456 } 456 }
457 457
458 void WorkspaceWindowResizer::RevertDrag() { 458 void WorkspaceWindowResizer::RevertDrag() {
459 snap_phantom_window_controller_.reset(); 459 snap_phantom_window_controller_.reset();
460 460
461 if (!did_move_or_resize_) 461 if (!did_move_or_resize_)
462 return; 462 return;
463 463
464 window()->SetBounds(details_.initial_bounds_in_parent); 464 window()->SetBounds(details_.initial_bounds_in_parent);
465 if (!details_.restore_bounds.IsEmpty()) 465 if (!details_.restore_bounds.IsEmpty()) {
466 SetRestoreBoundsInScreen(details_.window, details_.restore_bounds); 466 window_state()->SetRestoreBoundsInScreen(details_.restore_bounds);
467 }
467 468
468 if (details_.window_component == HTRIGHT) { 469 if (details_.window_component == HTRIGHT) {
469 int last_x = details_.initial_bounds_in_parent.right(); 470 int last_x = details_.initial_bounds_in_parent.right();
470 for (size_t i = 0; i < attached_windows_.size(); ++i) { 471 for (size_t i = 0; i < attached_windows_.size(); ++i) {
471 gfx::Rect bounds(attached_windows_[i]->bounds()); 472 gfx::Rect bounds(attached_windows_[i]->bounds());
472 bounds.set_x(last_x); 473 bounds.set_x(last_x);
473 bounds.set_width(initial_size_[i]); 474 bounds.set_width(initial_size_[i]);
474 attached_windows_[i]->SetBounds(bounds); 475 attached_windows_[i]->SetBounds(bounds);
475 last_x = attached_windows_[i]->bounds().right(); 476 last_x = attached_windows_[i]->bounds().right();
476 } 477 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), 727 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(),
727 &magnetism_edge_)) { 728 &magnetism_edge_)) {
728 return true; 729 return true;
729 } 730 }
730 window_tracker_.Remove(magnetism_window_); 731 window_tracker_.Remove(magnetism_window_);
731 magnetism_window_ = NULL; 732 magnetism_window_ = NULL;
732 } 733 }
733 734
734 // Avoid magnetically snapping to popups, menus, tooltips, controls and 735 // Avoid magnetically snapping to popups, menus, tooltips, controls and
735 // windows that are not tracked by workspace. 736 // windows that are not tracked by workspace.
736 if (!wm::CanResizeWindow(window()) || 737 if (!window_state()->CanResize() || !window_state()->tracked_by_workspace())
737 !wm::GetWindowSettings(window())->tracked_by_workspace())
738 return false; 738 return false;
739 739
740 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 740 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
741 for (Shell::RootWindowList::iterator iter = root_windows.begin(); 741 for (Shell::RootWindowList::iterator iter = root_windows.begin();
742 iter != root_windows.end(); ++iter) { 742 iter != root_windows.end(); ++iter) {
743 const aura::RootWindow* root_window = *iter; 743 const aura::RootWindow* root_window = *iter;
744 // Test all children from the desktop in each root window. 744 // Test all children from the desktop in each root window.
745 const aura::Window::Windows& children = Shell::GetContainer( 745 const aura::Window::Windows& children = Shell::GetContainer(
746 root_window, kShellWindowId_DefaultContainer)->children(); 746 root_window, kShellWindowId_DefaultContainer)->children();
747 for (aura::Window::Windows::const_reverse_iterator i = children.rbegin(); 747 for (aura::Window::Windows::const_reverse_iterator i = children.rbegin();
748 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { 748 i != children.rend() && !matcher.AreEdgesObscured(); ++i) {
749 aura::Window* other = *i; 749 wm::WindowState* other_state = wm::GetWindowState(*i);
750 if (other == window() || 750 if (other_state->window() == window() ||
751 !other->IsVisible() || 751 !other_state->window()->IsVisible() ||
752 !wm::IsWindowNormal(other) || 752 !other_state->IsNormal() ||
753 !wm::CanResizeWindow(other)) { 753 !other_state->CanResize()) {
754 continue; 754 continue;
755 } 755 }
756 if (matcher.ShouldAttach(other->GetBoundsInScreen(), &magnetism_edge_)) { 756 if (matcher.ShouldAttach(
757 magnetism_window_ = other; 757 other_state->window()->GetBoundsInScreen(), &magnetism_edge_)) {
758 magnetism_window_ = other_state->window();
758 window_tracker_.Add(magnetism_window_); 759 window_tracker_.Add(magnetism_window_);
759 return true; 760 return true;
760 } 761 }
761 } 762 }
762 } 763 }
763 return false; 764 return false;
764 } 765 }
765 766
766 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( 767 void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
767 int sticky_size, 768 int sticky_size,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 NOTREACHED(); 884 NOTREACHED();
884 } 885 }
885 return 0; 886 return 0;
886 } 887 }
887 888
888 void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location, 889 void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location,
889 const gfx::Rect& bounds) { 890 const gfx::Rect& bounds) {
890 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) 891 if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
891 return; 892 return;
892 893
894 #if 0
James Cook 2013/09/18 20:44:17 Did you mean to include this?
oshima 2013/09/19 01:52:01 Done.
895 if (!wm::CanSnapWindow(window()))
896 return;
897
898 if (window()->type() == aura::client::WINDOW_TYPE_PANEL &&
899 wm::GetWindowState(window())->panel_attached()) {
900 return;
901 }
902 #endif
893 SnapType last_type = snap_type_; 903 SnapType last_type = snap_type_;
894 snap_type_ = GetSnapType(location); 904 snap_type_ = GetSnapType(location);
895 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) { 905 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) {
896 snap_phantom_window_controller_.reset(); 906 snap_phantom_window_controller_.reset();
897 snap_sizer_.reset(); 907 snap_sizer_.reset();
898 UpdateDockedState(false); 908 UpdateDockedState(false);
899 if (snap_type_ == SNAP_NONE) 909 if (snap_type_ == SNAP_NONE)
900 return; 910 return;
901 } 911 }
902 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT) ? 912 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT) ?
903 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; 913 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE;
904 914
905 if (!snap_sizer_) { 915 if (!snap_sizer_) {
906 snap_sizer_.reset(new SnapSizer(window(), 916 snap_sizer_.reset(new SnapSizer(window(),
907 location, 917 location,
908 edge, 918 edge,
909 internal::SnapSizer::OTHER_INPUT)); 919 internal::SnapSizer::OTHER_INPUT));
910 } else { 920 } else {
911 snap_sizer_->Update(location); 921 snap_sizer_->Update(location);
912 } 922 }
913 923
914 const bool can_dock = dock_layout_->CanDockWindow(window(), snap_type_); 924 const bool can_dock = dock_layout_->CanDockWindow(window(), snap_type_);
915 if (!wm::CanSnapWindow(window()) && !can_dock) 925 if (!window_state()->CanSnap() && !can_dock)
916 return; 926 return;
917 927
918 // Update phantom window with snapped or docked guide bounds. 928 // Update phantom window with snapped or docked guide bounds.
919 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get 929 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get
920 // docked without going through a snapping sequence. 930 // docked without going through a snapping sequence.
921 gfx::Rect phantom_bounds; 931 gfx::Rect phantom_bounds;
922 if (!can_dock || 932 if (!can_dock ||
923 window()->bounds().width() > DockedWindowLayoutManager::kMaxDockWidth) 933 window()->bounds().width() > DockedWindowLayoutManager::kMaxDockWidth)
924 phantom_bounds = snap_sizer_->target_bounds(); 934 phantom_bounds = snap_sizer_->target_bounds();
925 const bool is_docked = can_dock && 935 const bool is_docked = can_dock &&
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 if (!dock_layout_->is_dragged_window_docked()) 1002 if (!dock_layout_->is_dragged_window_docked())
993 dock_layout_->DockDraggedWindow(window()); 1003 dock_layout_->DockDraggedWindow(window());
994 } else { 1004 } else {
995 if (dock_layout_->is_dragged_window_docked()) 1005 if (dock_layout_->is_dragged_window_docked())
996 dock_layout_->UndockDraggedWindow(); 1006 dock_layout_->UndockDraggedWindow();
997 } 1007 }
998 } 1008 }
999 1009
1000 } // namespace internal 1010 } // namespace internal
1001 } // namespace ash 1011 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698