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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_constants.h" | 10 #include "ash/shelf/shelf_constants.h" |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 void DockedWindowLayoutManager::StartDragging(aura::Window* window) { | 457 void DockedWindowLayoutManager::StartDragging(aura::Window* window) { |
458 DCHECK(!dragged_window_); | 458 DCHECK(!dragged_window_); |
459 dragged_window_ = window; | 459 dragged_window_ = window; |
460 DCHECK(!IsPopupOrTransient(window)); | 460 DCHECK(!IsPopupOrTransient(window)); |
461 // Start observing a window unless it is docked container's child in which | 461 // Start observing a window unless it is docked container's child in which |
462 // case it is already observed. | 462 // case it is already observed. |
463 wm::WindowState* dragged_state = wm::GetWindowState(dragged_window_); | 463 wm::WindowState* dragged_state = wm::GetWindowState(dragged_window_); |
464 if (dragged_window_->parent() != dock_container_) { | 464 if (dragged_window_->parent() != dock_container_) { |
465 dragged_window_->AddObserver(this); | 465 dragged_window_->AddObserver(this); |
466 dragged_state->AddObserver(this); | 466 dragged_state->AddObserver(this); |
| 467 } else if (!IsAnyWindowDocked() && |
| 468 dragged_state->drag_details() && |
| 469 !(dragged_state->drag_details()->bounds_change & |
| 470 WindowResizer::kBoundsChange_Resizes)) { |
| 471 // If there are no other docked windows clear alignment when a docked window |
| 472 // is moved (but not when it is resized or the window could get undocked |
| 473 // when resized away from the edge while docked). |
| 474 alignment_ = DOCKED_ALIGNMENT_NONE; |
467 } | 475 } |
468 is_dragged_from_dock_ = window->parent() == dock_container_; | 476 is_dragged_from_dock_ = window->parent() == dock_container_; |
469 DCHECK(!is_dragged_window_docked_); | 477 DCHECK(!is_dragged_window_docked_); |
470 | 478 |
471 // Resize all windows that are flush with the dock edge together if one of | 479 // Resize all windows that are flush with the dock edge together if one of |
472 // them gets resized. | 480 // them gets resized. |
473 if (dragged_window_->bounds().width() == docked_width_ && | 481 if (dragged_window_->bounds().width() == docked_width_ && |
474 (dragged_state->drag_details()->bounds_change & | 482 (dragged_state->drag_details()->bounds_change & |
475 WindowResizer::kBoundsChange_Resizes) && | 483 WindowResizer::kBoundsChange_Resizes) && |
476 (dragged_state->drag_details()->size_change_direction & | 484 (dragged_state->drag_details()->size_change_direction & |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 // case it needs to keep being observed after the drag completes. | 519 // case it needs to keep being observed after the drag completes. |
512 if (dragged_window_->parent() != dock_container_) { | 520 if (dragged_window_->parent() != dock_container_) { |
513 dragged_window_->RemoveObserver(this); | 521 dragged_window_->RemoveObserver(this); |
514 wm::GetWindowState(dragged_window_)->RemoveObserver(this); | 522 wm::GetWindowState(dragged_window_)->RemoveObserver(this); |
515 if (last_active_window_ == dragged_window_) | 523 if (last_active_window_ == dragged_window_) |
516 last_active_window_ = NULL; | 524 last_active_window_ = NULL; |
517 | 525 |
518 views::corewm::SetWindowShowAnimationDuration(dragged_window_, | 526 views::corewm::SetWindowShowAnimationDuration(dragged_window_, |
519 base::TimeDelta()); | 527 base::TimeDelta()); |
520 } else { | 528 } else { |
| 529 // If this is the first window that got docked by a move update alignment. |
| 530 if (alignment_ == DOCKED_ALIGNMENT_NONE) { |
| 531 alignment_ = GetAlignmentOfWindow(dragged_window_); |
| 532 DCHECK(action == DOCKED_ACTION_NONE || |
| 533 alignment_ != DOCKED_ALIGNMENT_NONE); |
| 534 } |
521 // A window is no longer dragged and is a child. | 535 // A window is no longer dragged and is a child. |
522 // When a window becomes a child at drag start this is | 536 // When a window becomes a child at drag start this is |
523 // the only opportunity we will have to enforce a window | 537 // the only opportunity we will have to enforce a window |
524 // count limit so do it here. | 538 // count limit so do it here. |
525 MaybeMinimizeChildrenExcept(dragged_window_); | 539 MaybeMinimizeChildrenExcept(dragged_window_); |
526 | 540 |
527 views::corewm::SetWindowShowAnimationDuration(dragged_window_, | 541 views::corewm::SetWindowShowAnimationDuration(dragged_window_, |
528 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); | 542 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); |
529 } | 543 } |
530 dragged_window_ = NULL; | 544 dragged_window_ = NULL; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 // Dragged windows are already observed by StartDragging and do not change | 664 // Dragged windows are already observed by StartDragging and do not change |
651 // docked alignment during the drag. | 665 // docked alignment during the drag. |
652 if (child == dragged_window_) | 666 if (child == dragged_window_) |
653 return; | 667 return; |
654 // If this is the first window getting docked - update alignment. | 668 // If this is the first window getting docked - update alignment. |
655 // TODO(oshima|varkha): A window can be added without proper bounds when | 669 // TODO(oshima|varkha): A window can be added without proper bounds when |
656 // window is moved to another display via API or due to display configuration | 670 // window is moved to another display via API or due to display configuration |
657 // change, so the the alignment may not be valid. | 671 // change, so the the alignment may not be valid. |
658 if (alignment_ == DOCKED_ALIGNMENT_NONE) { | 672 if (alignment_ == DOCKED_ALIGNMENT_NONE) { |
659 alignment_ = GetAlignmentOfWindow(child); | 673 alignment_ = GetAlignmentOfWindow(child); |
660 DCHECK(alignment_ != DOCKED_ALIGNMENT_NONE); | 674 DCHECK_NE(DOCKED_ALIGNMENT_NONE, alignment_); |
661 } | 675 } |
662 MaybeMinimizeChildrenExcept(child); | 676 MaybeMinimizeChildrenExcept(child); |
663 child->AddObserver(this); | 677 child->AddObserver(this); |
664 wm::GetWindowState(child)->AddObserver(this); | 678 wm::GetWindowState(child)->AddObserver(this); |
665 Relayout(); | 679 Relayout(); |
666 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 680 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
667 views::corewm::SetWindowShowAnimationDuration(child, | 681 views::corewm::SetWindowShowAnimationDuration(child, |
668 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); | 682 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); |
669 } | 683 } |
670 | 684 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 const gfx::Rect& new_bounds) { | 837 const gfx::Rect& new_bounds) { |
824 // Only relayout if the dragged window would get docked. | 838 // Only relayout if the dragged window would get docked. |
825 if (window == dragged_window_ && is_dragged_window_docked_) | 839 if (window == dragged_window_ && is_dragged_window_docked_) |
826 Relayout(); | 840 Relayout(); |
827 } | 841 } |
828 | 842 |
829 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { | 843 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { |
830 if (dragged_window_ == window) { | 844 if (dragged_window_ == window) { |
831 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); | 845 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); |
832 DCHECK(!dragged_window_); | 846 DCHECK(!dragged_window_); |
833 DCHECK (!is_dragged_window_docked_); | 847 DCHECK(!is_dragged_window_docked_); |
834 } | 848 } |
835 if (window == last_active_window_) | 849 if (window == last_active_window_) |
836 last_active_window_ = NULL; | 850 last_active_window_ = NULL; |
837 RecordUmaAction(DOCKED_ACTION_CLOSE, DOCKED_ACTION_SOURCE_UNKNOWN); | 851 RecordUmaAction(DOCKED_ACTION_CLOSE, DOCKED_ACTION_SOURCE_UNKNOWN); |
838 } | 852 } |
839 | 853 |
840 | 854 |
841 //////////////////////////////////////////////////////////////////////////////// | 855 //////////////////////////////////////////////////////////////////////////////// |
842 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver | 856 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver |
843 // implementation: | 857 // implementation: |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 void DockedWindowLayoutManager::UpdateDockedWidth(int width) { | 992 void DockedWindowLayoutManager::UpdateDockedWidth(int width) { |
979 if (docked_width_ == width) | 993 if (docked_width_ == width) |
980 return; | 994 return; |
981 docked_width_ = width; | 995 docked_width_ = width; |
982 UMA_HISTOGRAM_COUNTS_10000("Ash.Dock.Width", docked_width_); | 996 UMA_HISTOGRAM_COUNTS_10000("Ash.Dock.Width", docked_width_); |
983 } | 997 } |
984 | 998 |
985 void DockedWindowLayoutManager::OnDraggedWindowDocked(aura::Window* window) { | 999 void DockedWindowLayoutManager::OnDraggedWindowDocked(aura::Window* window) { |
986 DCHECK(!is_dragged_window_docked_); | 1000 DCHECK(!is_dragged_window_docked_); |
987 is_dragged_window_docked_ = true; | 1001 is_dragged_window_docked_ = true; |
988 | |
989 // If there are no other docked windows update alignment when the window is | |
990 // moved. | |
991 if (!IsAnyWindowDocked() && | |
992 wm::GetWindowState(dragged_window_)->drag_details() && | |
993 !(wm::GetWindowState(dragged_window_)->drag_details()->bounds_change & | |
994 WindowResizer::kBoundsChange_Resizes)) { | |
995 alignment_ = DOCKED_ALIGNMENT_NONE; | |
996 } | |
997 } | 1002 } |
998 | 1003 |
999 void DockedWindowLayoutManager::OnDraggedWindowUndocked() { | 1004 void DockedWindowLayoutManager::OnDraggedWindowUndocked() { |
1000 // If this is the first window getting docked by moving it - update alignment. | |
1001 if (!IsAnyWindowDocked() && | |
1002 wm::GetWindowState(dragged_window_)->drag_details() && | |
1003 !(wm::GetWindowState(dragged_window_)->drag_details()->bounds_change & | |
1004 WindowResizer::kBoundsChange_Resizes)) { | |
1005 alignment_ = GetAlignmentOfWindow(dragged_window_); | |
1006 } | |
1007 DCHECK (is_dragged_window_docked_); | 1005 DCHECK (is_dragged_window_docked_); |
1008 is_dragged_window_docked_ = false; | 1006 is_dragged_window_docked_ = false; |
1009 } | 1007 } |
1010 | 1008 |
1011 bool DockedWindowLayoutManager::IsAnyWindowDocked() { | 1009 bool DockedWindowLayoutManager::IsAnyWindowDocked() { |
1012 return CalculateAlignment() != DOCKED_ALIGNMENT_NONE; | 1010 return CalculateAlignment() != DOCKED_ALIGNMENT_NONE; |
1013 } | 1011 } |
1014 | 1012 |
1015 void DockedWindowLayoutManager::Relayout() { | 1013 void DockedWindowLayoutManager::Relayout() { |
1016 if (in_layout_) | 1014 if (in_layout_) |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1303 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
1306 const gfx::Rect& keyboard_bounds) { | 1304 const gfx::Rect& keyboard_bounds) { |
1307 // This bounds change will have caused a change to the Shelf which does not | 1305 // This bounds change will have caused a change to the Shelf which does not |
1308 // propagate automatically to this class, so manually recalculate bounds. | 1306 // propagate automatically to this class, so manually recalculate bounds. |
1309 Relayout(); | 1307 Relayout(); |
1310 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1308 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
1311 } | 1309 } |
1312 | 1310 |
1313 } // namespace internal | 1311 } // namespace internal |
1314 } // namespace ash | 1312 } // namespace ash |
OLD | NEW |