| 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_util.h" | 8 #include "ash/screen_util.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 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 for (size_t i = 0; i < dock_container_->children().size(); ++i) { | 583 for (size_t i = 0; i < dock_container_->children().size(); ++i) { |
| 584 aura::Window* window(dock_container_->children()[i]); | 584 aura::Window* window(dock_container_->children()[i]); |
| 585 if (window != dragged_window_ && !IsPopupOrTransient(window)) | 585 if (window != dragged_window_ && !IsPopupOrTransient(window)) |
| 586 return alignment_; | 586 return alignment_; |
| 587 } | 587 } |
| 588 // No docked windows remain other than possibly the window being dragged. | 588 // No docked windows remain other than possibly the window being dragged. |
| 589 // Return |NONE| to indicate that windows may get docked on either side. | 589 // Return |NONE| to indicate that windows may get docked on either side. |
| 590 return DOCKED_ALIGNMENT_NONE; | 590 return DOCKED_ALIGNMENT_NONE; |
| 591 } | 591 } |
| 592 | 592 |
| 593 bool DockedWindowLayoutManager::CanDockWindow(aura::Window* window, | 593 bool DockedWindowLayoutManager::CanDockWindow( |
| 594 SnapType edge) { | 594 aura::Window* window, |
| 595 DockedAlignment desired_alignment) { |
| 595 if (!switches::UseDockedWindows()) | 596 if (!switches::UseDockedWindows()) |
| 596 return false; | 597 return false; |
| 597 // Don't allow interactive docking of windows with transient parents such as | 598 // Don't allow interactive docking of windows with transient parents such as |
| 598 // modal browser dialogs. Prevent docking of panels attached to shelf during | 599 // modal browser dialogs. Prevent docking of panels attached to shelf during |
| 599 // the drag. | 600 // the drag. |
| 600 wm::WindowState* window_state = wm::GetWindowState(window); | 601 wm::WindowState* window_state = wm::GetWindowState(window); |
| 601 bool should_attach_to_shelf = window_state->drag_details() && | 602 bool should_attach_to_shelf = window_state->drag_details() && |
| 602 window_state->drag_details()->should_attach_to_shelf; | 603 window_state->drag_details()->should_attach_to_shelf; |
| 603 if (IsPopupOrTransient(window) || should_attach_to_shelf) | 604 if (IsPopupOrTransient(window) || should_attach_to_shelf) |
| 604 return false; | 605 return false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 615 return false; | 616 return false; |
| 616 } | 617 } |
| 617 // If a window is tall and cannot be resized down to maximum height allowed | 618 // If a window is tall and cannot be resized down to maximum height allowed |
| 618 // then it cannot be docked. | 619 // then it cannot be docked. |
| 619 const gfx::Rect work_area = | 620 const gfx::Rect work_area = |
| 620 Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).work_area(); | 621 Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).work_area(); |
| 621 if (GetWindowHeightCloseTo(window, work_area.height()) > work_area.height()) | 622 if (GetWindowHeightCloseTo(window, work_area.height()) > work_area.height()) |
| 622 return false; | 623 return false; |
| 623 // Cannot dock on the other size from an existing dock. | 624 // Cannot dock on the other size from an existing dock. |
| 624 const DockedAlignment alignment = CalculateAlignment(); | 625 const DockedAlignment alignment = CalculateAlignment(); |
| 625 if ((edge == SNAP_LEFT && alignment == DOCKED_ALIGNMENT_RIGHT) || | 626 if (desired_alignment != DOCKED_ALIGNMENT_NONE && |
| 626 (edge == SNAP_RIGHT && alignment == DOCKED_ALIGNMENT_LEFT)) { | 627 alignment != DOCKED_ALIGNMENT_NONE && |
| 628 alignment != desired_alignment) { |
| 627 return false; | 629 return false; |
| 628 } | 630 } |
| 629 // Do not allow docking on the same side as shelf. | 631 // Do not allow docking on the same side as shelf. |
| 630 ShelfAlignment shelf_alignment = SHELF_ALIGNMENT_BOTTOM; | 632 ShelfAlignment shelf_alignment = SHELF_ALIGNMENT_BOTTOM; |
| 631 if (shelf_) | 633 if (shelf_) |
| 632 shelf_alignment = shelf_->alignment(); | 634 shelf_alignment = shelf_->alignment(); |
| 633 if ((edge == SNAP_LEFT && shelf_alignment == SHELF_ALIGNMENT_LEFT) || | 635 if ((desired_alignment == DOCKED_ALIGNMENT_LEFT && |
| 634 (edge == SNAP_RIGHT && shelf_alignment == SHELF_ALIGNMENT_RIGHT)) { | 636 shelf_alignment == SHELF_ALIGNMENT_LEFT) || |
| 637 (desired_alignment == DOCKED_ALIGNMENT_RIGHT && |
| 638 shelf_alignment == SHELF_ALIGNMENT_RIGHT)) { |
| 635 return false; | 639 return false; |
| 636 } | 640 } |
| 637 return true; | 641 return true; |
| 638 } | 642 } |
| 639 | 643 |
| 640 void DockedWindowLayoutManager::OnShelfBoundsChanged() { | 644 void DockedWindowLayoutManager::OnShelfBoundsChanged() { |
| 641 Relayout(); | 645 Relayout(); |
| 642 UpdateDockBounds(DockedWindowLayoutManagerObserver::DISPLAY_INSETS_CHANGED); | 646 UpdateDockBounds(DockedWindowLayoutManagerObserver::DISPLAY_INSETS_CHANGED); |
| 643 } | 647 } |
| 644 | 648 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 aura::Window* window = window_state->window(); | 940 aura::Window* window = window_state->window(); |
| 937 DCHECK(!IsPopupOrTransient(window)); | 941 DCHECK(!IsPopupOrTransient(window)); |
| 938 // Always place restored window at the bottom shuffling the other windows up. | 942 // Always place restored window at the bottom shuffling the other windows up. |
| 939 // TODO(varkha): add a separate container for docked windows to keep track | 943 // TODO(varkha): add a separate container for docked windows to keep track |
| 940 // of ordering. | 944 // of ordering. |
| 941 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 945 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
| 942 dock_container_); | 946 dock_container_); |
| 943 const gfx::Rect work_area = display.work_area(); | 947 const gfx::Rect work_area = display.work_area(); |
| 944 | 948 |
| 945 // Evict the window if it can no longer be docked because of its height. | 949 // Evict the window if it can no longer be docked because of its height. |
| 946 if (!CanDockWindow(window, SNAP_NONE)) { | 950 if (!CanDockWindow(window, DOCKED_ALIGNMENT_NONE)) { |
| 947 UndockWindow(window); | 951 UndockWindow(window); |
| 948 RecordUmaAction(DOCKED_ACTION_EVICT, DOCKED_ACTION_SOURCE_UNKNOWN); | 952 RecordUmaAction(DOCKED_ACTION_EVICT, DOCKED_ACTION_SOURCE_UNKNOWN); |
| 949 return; | 953 return; |
| 950 } | 954 } |
| 951 gfx::Rect bounds(window->bounds()); | 955 gfx::Rect bounds(window->bounds()); |
| 952 bounds.set_y(work_area.bottom()); | 956 bounds.set_y(work_area.bottom()); |
| 953 window->SetBounds(bounds); | 957 window->SetBounds(bounds); |
| 954 window->Show(); | 958 window->Show(); |
| 955 MaybeMinimizeChildrenExcept(window); | 959 MaybeMinimizeChildrenExcept(window); |
| 956 RecordUmaAction(DOCKED_ACTION_RESTORE, DOCKED_ACTION_SOURCE_UNKNOWN); | 960 RecordUmaAction(DOCKED_ACTION_RESTORE, DOCKED_ACTION_SOURCE_UNKNOWN); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 | 1322 |
| 1319 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1323 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 1320 const gfx::Rect& keyboard_bounds) { | 1324 const gfx::Rect& keyboard_bounds) { |
| 1321 // This bounds change will have caused a change to the Shelf which does not | 1325 // This bounds change will have caused a change to the Shelf which does not |
| 1322 // propagate automatically to this class, so manually recalculate bounds. | 1326 // propagate automatically to this class, so manually recalculate bounds. |
| 1323 Relayout(); | 1327 Relayout(); |
| 1324 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1328 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1325 } | 1329 } |
| 1326 | 1330 |
| 1327 } // namespace ash | 1331 } // namespace ash |
| OLD | NEW |