Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/dock/docked_window_layout_manager.h" | 5 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_constants.h" | 9 #include "ash/shelf/shelf_constants.h" |
| 10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 in_layout_(false), | 409 in_layout_(false), |
| 410 dragged_window_(NULL), | 410 dragged_window_(NULL), |
| 411 is_dragged_window_docked_(false), | 411 is_dragged_window_docked_(false), |
| 412 is_dragged_from_dock_(false), | 412 is_dragged_from_dock_(false), |
| 413 shelf_(NULL), | 413 shelf_(NULL), |
| 414 workspace_controller_(workspace_controller), | 414 workspace_controller_(workspace_controller), |
| 415 in_fullscreen_(workspace_controller_->GetWindowState() == | 415 in_fullscreen_(workspace_controller_->GetWindowState() == |
| 416 WORKSPACE_WINDOW_STATE_FULL_SCREEN), | 416 WORKSPACE_WINDOW_STATE_FULL_SCREEN), |
| 417 docked_width_(0), | 417 docked_width_(0), |
| 418 alignment_(DOCKED_ALIGNMENT_NONE), | 418 alignment_(DOCKED_ALIGNMENT_NONE), |
| 419 preferred_alignment_(DOCKED_ALIGNMENT_NONE), | |
| 420 event_source_(DOCKED_ACTION_SOURCE_UNKNOWN), | |
| 419 last_active_window_(NULL), | 421 last_active_window_(NULL), |
| 420 last_action_time_(base::Time::Now()), | 422 last_action_time_(base::Time::Now()), |
| 421 background_widget_(new DockedBackgroundWidget(dock_container_)) { | 423 background_widget_(new DockedBackgroundWidget(dock_container_)) { |
| 422 DCHECK(dock_container); | 424 DCHECK(dock_container); |
| 423 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 425 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> |
| 424 AddObserver(this); | 426 AddObserver(this); |
| 425 Shell::GetInstance()->AddShellObserver(this); | 427 Shell::GetInstance()->AddShellObserver(this); |
| 426 } | 428 } |
| 427 | 429 |
| 428 DockedWindowLayoutManager::~DockedWindowLayoutManager() { | 430 DockedWindowLayoutManager::~DockedWindowLayoutManager() { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 alignment != DOCKED_ALIGNMENT_NONE && | 632 alignment != DOCKED_ALIGNMENT_NONE && |
| 631 alignment != desired_alignment) { | 633 alignment != desired_alignment) { |
| 632 return false; | 634 return false; |
| 633 } | 635 } |
| 634 // Do not allow docking on the same side as shelf. | 636 // Do not allow docking on the same side as shelf. |
| 635 return IsDockedAlignmentValid(desired_alignment); | 637 return IsDockedAlignmentValid(desired_alignment); |
| 636 } | 638 } |
| 637 | 639 |
| 638 bool DockedWindowLayoutManager::IsDockedAlignmentValid( | 640 bool DockedWindowLayoutManager::IsDockedAlignmentValid( |
| 639 DockedAlignment alignment) const { | 641 DockedAlignment alignment) const { |
| 640 ShelfAlignment shelf_alignment = shelf_ ? shelf->alignment() : | 642 ShelfAlignment shelf_alignment = shelf_ ? shelf_->alignment() : |
| 641 SHELF_ALIGNMENT_BOTTOM; | 643 SHELF_ALIGNMENT_BOTTOM; |
| 642 if ((alignment == DOCKED_ALIGNMENT_LEFT && | 644 if ((alignment == DOCKED_ALIGNMENT_LEFT && |
| 643 shelf_alignment == SHELF_ALIGNMENT_LEFT) || | 645 shelf_alignment == SHELF_ALIGNMENT_LEFT) || |
| 644 (alignment == DOCKED_ALIGNMENT_RIGHT && | 646 (alignment == DOCKED_ALIGNMENT_RIGHT && |
| 645 shelf_alignment == SHELF_ALIGNMENT_RIGHT)) { | 647 shelf_alignment == SHELF_ALIGNMENT_RIGHT)) { |
| 646 return false; | 648 return false; |
| 647 } | 649 } |
| 648 return true; | 650 return true; |
| 649 } | 651 } |
| 650 | 652 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 if (IsPopupOrTransient(child)) | 687 if (IsPopupOrTransient(child)) |
| 686 return; | 688 return; |
| 687 // Dragged windows are already observed by StartDragging and do not change | 689 // Dragged windows are already observed by StartDragging and do not change |
| 688 // docked alignment during the drag. | 690 // docked alignment during the drag. |
| 689 if (child == dragged_window_) | 691 if (child == dragged_window_) |
| 690 return; | 692 return; |
| 691 // If this is the first window getting docked - update alignment. | 693 // If this is the first window getting docked - update alignment. |
| 692 // A window can be added without proper bounds when window is moved to another | 694 // A window can be added without proper bounds when window is moved to another |
| 693 // display via API or due to display configuration change, so the alignment | 695 // display via API or due to display configuration change, so the alignment |
| 694 // is set based on which edge is closer in the new display. | 696 // is set based on which edge is closer in the new display. |
| 695 if (alignment_ == DOCKED_ALIGNMENT_NONE) | 697 if (alignment_ == DOCKED_ALIGNMENT_NONE) { |
| 696 alignment_ = GetEdgeNearestWindow(child); | 698 alignment_ = preferred_alignment_ != DOCKED_ALIGNMENT_NONE ? |
| 699 preferred_alignment_ : GetEdgeNearestWindow(child); | |
| 700 } | |
| 697 MaybeMinimizeChildrenExcept(child); | 701 MaybeMinimizeChildrenExcept(child); |
| 698 child->AddObserver(this); | 702 child->AddObserver(this); |
| 699 wm::GetWindowState(child)->AddObserver(this); | 703 wm::GetWindowState(child)->AddObserver(this); |
| 700 Relayout(); | 704 Relayout(); |
| 701 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 705 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
| 706 | |
| 707 // Only keyboard-initiated actions are recorded here. Dragging cases | |
| 708 // are handled in FinishDragging | |
|
varkha
2014/10/03 17:42:12
nit: period at the end of a sentence.
dtapuska
2014/10/03 19:05:59
Done.
| |
| 709 if (event_source_ != DOCKED_ACTION_SOURCE_UNKNOWN) | |
| 710 RecordUmaAction(DOCKED_ACTION_DOCK, event_source_); | |
| 702 } | 711 } |
| 703 | 712 |
| 704 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 713 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
| 705 if (IsPopupOrTransient(child)) | 714 if (IsPopupOrTransient(child)) |
| 706 return; | 715 return; |
| 707 // Dragged windows are stopped being observed by FinishDragging and do not | 716 // Dragged windows are stopped being observed by FinishDragging and do not |
| 708 // change alignment during the drag. They also cannot be set to be the | 717 // change alignment during the drag. They also cannot be set to be the |
| 709 // |last_active_window_|. | 718 // |last_active_window_|. |
| 710 if (child == dragged_window_) | 719 if (child == dragged_window_) |
| 711 return; | 720 return; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 if (IsPopupOrTransient(window)) | 850 if (IsPopupOrTransient(window)) |
| 842 return; | 851 return; |
| 843 // The window property will still be set, but no actual change will occur | 852 // The window property will still be set, but no actual change will occur |
| 844 // until OnFullscreenStateChange is called when exiting fullscreen. | 853 // until OnFullscreenStateChange is called when exiting fullscreen. |
| 845 if (in_fullscreen_) | 854 if (in_fullscreen_) |
| 846 return; | 855 return; |
| 847 if (!window_state->IsDocked()) { | 856 if (!window_state->IsDocked()) { |
| 848 if (window != dragged_window_) { | 857 if (window != dragged_window_) { |
| 849 UndockWindow(window); | 858 UndockWindow(window); |
| 850 if (window_state->IsMaximizedOrFullscreen()) | 859 if (window_state->IsMaximizedOrFullscreen()) |
| 851 RecordUmaAction(DOCKED_ACTION_MAXIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); | 860 RecordUmaAction(DOCKED_ACTION_MAXIMIZE, event_source_); |
| 861 else | |
| 862 RecordUmaAction(DOCKED_ACTION_UNDOCK, event_source_); | |
| 852 } | 863 } |
| 853 } else if (window_state->IsMinimized()) { | 864 } else if (window_state->IsMinimized()) { |
| 854 MinimizeDockedWindow(window_state); | 865 MinimizeDockedWindow(window_state); |
| 855 } else if (old_type == wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED) { | 866 } else if (old_type == wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED) { |
| 856 RestoreDockedWindow(window_state); | 867 RestoreDockedWindow(window_state); |
| 868 } else if (old_type == wm::WINDOW_STATE_TYPE_MINIMIZED) { | |
| 869 NOTREACHED() << "Minimized window in docked layout manager"; | |
| 857 } | 870 } |
| 858 } | 871 } |
| 859 | 872 |
| 860 ///////////////////////////////////////////////////////////////////////////// | 873 ///////////////////////////////////////////////////////////////////////////// |
| 861 // DockedWindowLayoutManager, WindowObserver implementation: | 874 // DockedWindowLayoutManager, WindowObserver implementation: |
| 862 | 875 |
| 863 void DockedWindowLayoutManager::OnWindowBoundsChanged( | 876 void DockedWindowLayoutManager::OnWindowBoundsChanged( |
| 864 aura::Window* window, | 877 aura::Window* window, |
| 865 const gfx::Rect& old_bounds, | 878 const gfx::Rect& old_bounds, |
| 866 const gfx::Rect& new_bounds) { | 879 const gfx::Rect& new_bounds) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 885 } | 898 } |
| 886 | 899 |
| 887 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { | 900 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 888 if (dragged_window_ == window) { | 901 if (dragged_window_ == window) { |
| 889 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); | 902 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); |
| 890 DCHECK(!dragged_window_); | 903 DCHECK(!dragged_window_); |
| 891 DCHECK(!is_dragged_window_docked_); | 904 DCHECK(!is_dragged_window_docked_); |
| 892 } | 905 } |
| 893 if (window == last_active_window_) | 906 if (window == last_active_window_) |
| 894 last_active_window_ = NULL; | 907 last_active_window_ = NULL; |
| 895 RecordUmaAction(DOCKED_ACTION_CLOSE, DOCKED_ACTION_SOURCE_UNKNOWN); | 908 RecordUmaAction(DOCKED_ACTION_CLOSE, event_source_); |
| 896 } | 909 } |
| 897 | 910 |
| 898 | 911 |
| 899 //////////////////////////////////////////////////////////////////////////////// | 912 //////////////////////////////////////////////////////////////////////////////// |
| 900 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver | 913 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver |
| 901 // implementation: | 914 // implementation: |
| 902 | 915 |
| 903 void DockedWindowLayoutManager::OnWindowActivated(aura::Window* gained_active, | 916 void DockedWindowLayoutManager::OnWindowActivated(aura::Window* gained_active, |
| 904 aura::Window* lost_active) { | 917 aura::Window* lost_active) { |
| 905 if (gained_active && IsPopupOrTransient(gained_active)) | 918 if (gained_active && IsPopupOrTransient(gained_active)) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 } | 965 } |
| 953 } | 966 } |
| 954 } | 967 } |
| 955 | 968 |
| 956 void DockedWindowLayoutManager::MinimizeDockedWindow( | 969 void DockedWindowLayoutManager::MinimizeDockedWindow( |
| 957 wm::WindowState* window_state) { | 970 wm::WindowState* window_state) { |
| 958 DCHECK(!IsPopupOrTransient(window_state->window())); | 971 DCHECK(!IsPopupOrTransient(window_state->window())); |
| 959 window_state->window()->Hide(); | 972 window_state->window()->Hide(); |
| 960 if (window_state->IsActive()) | 973 if (window_state->IsActive()) |
| 961 window_state->Deactivate(); | 974 window_state->Deactivate(); |
| 962 RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); | 975 RecordUmaAction(DOCKED_ACTION_MINIMIZE, event_source_); |
| 963 } | 976 } |
| 964 | 977 |
| 965 void DockedWindowLayoutManager::RestoreDockedWindow( | 978 void DockedWindowLayoutManager::RestoreDockedWindow( |
| 966 wm::WindowState* window_state) { | 979 wm::WindowState* window_state) { |
| 967 aura::Window* window = window_state->window(); | 980 aura::Window* window = window_state->window(); |
| 968 DCHECK(!IsPopupOrTransient(window)); | 981 DCHECK(!IsPopupOrTransient(window)); |
| 969 // Always place restored window at the bottom shuffling the other windows up. | 982 // Always place restored window at the bottom shuffling the other windows up. |
| 970 // TODO(varkha): add a separate container for docked windows to keep track | 983 // TODO(varkha): add a separate container for docked windows to keep track |
| 971 // of ordering. | 984 // of ordering. |
| 972 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 985 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
| 973 dock_container_); | 986 dock_container_); |
| 974 const gfx::Rect work_area = display.work_area(); | 987 const gfx::Rect work_area = display.work_area(); |
| 975 | 988 |
| 976 // Evict the window if it can no longer be docked because of its height. | 989 // Evict the window if it can no longer be docked because of its height. |
| 977 if (!CanDockWindow(window, DOCKED_ALIGNMENT_NONE)) { | 990 if (!CanDockWindow(window, DOCKED_ALIGNMENT_NONE)) { |
| 978 window_state->Restore(); | 991 window_state->Restore(); |
| 979 RecordUmaAction(DOCKED_ACTION_EVICT, DOCKED_ACTION_SOURCE_UNKNOWN); | 992 RecordUmaAction(DOCKED_ACTION_EVICT, event_source_); |
| 980 return; | 993 return; |
| 981 } | 994 } |
| 982 gfx::Rect bounds(window->bounds()); | 995 gfx::Rect bounds(window->bounds()); |
| 983 bounds.set_y(work_area.bottom()); | 996 bounds.set_y(work_area.bottom()); |
| 984 window->SetBounds(bounds); | 997 window->SetBounds(bounds); |
| 985 window->Show(); | 998 window->Show(); |
| 986 MaybeMinimizeChildrenExcept(window); | 999 MaybeMinimizeChildrenExcept(window); |
| 987 RecordUmaAction(DOCKED_ACTION_RESTORE, DOCKED_ACTION_SOURCE_UNKNOWN); | 1000 RecordUmaAction(DOCKED_ACTION_RESTORE, event_source_); |
| 988 } | 1001 } |
| 989 | 1002 |
| 990 void DockedWindowLayoutManager::RecordUmaAction(DockedAction action, | 1003 void DockedWindowLayoutManager::RecordUmaAction(DockedAction action, |
| 991 DockedActionSource source) { | 1004 DockedActionSource source) { |
| 992 if (action == DOCKED_ACTION_NONE) | 1005 if (action == DOCKED_ACTION_NONE) |
| 993 return; | 1006 return; |
| 994 UMA_HISTOGRAM_ENUMERATION("Ash.Dock.Action", action, DOCKED_ACTION_COUNT); | 1007 UMA_HISTOGRAM_ENUMERATION("Ash.Dock.Action", action, DOCKED_ACTION_COUNT); |
| 995 UMA_HISTOGRAM_ENUMERATION("Ash.Dock.ActionSource", source, | 1008 UMA_HISTOGRAM_ENUMERATION("Ash.Dock.ActionSource", source, |
| 996 DOCKED_ACTION_SOURCE_COUNT); | 1009 DOCKED_ACTION_SOURCE_COUNT); |
| 997 base::Time time_now = base::Time::Now(); | 1010 base::Time time_now = base::Time::Now(); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1349 | 1362 |
| 1350 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1363 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 1351 const gfx::Rect& keyboard_bounds) { | 1364 const gfx::Rect& keyboard_bounds) { |
| 1352 // This bounds change will have caused a change to the Shelf which does not | 1365 // This bounds change will have caused a change to the Shelf which does not |
| 1353 // propagate automatically to this class, so manually recalculate bounds. | 1366 // propagate automatically to this class, so manually recalculate bounds. |
| 1354 Relayout(); | 1367 Relayout(); |
| 1355 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1368 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1356 } | 1369 } |
| 1357 | 1370 |
| 1358 } // namespace ash | 1371 } // namespace ash |
| OLD | NEW |