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

Side by Side Diff: ash/wm/panels/panel_layout_manager.cc

Issue 1743493002: Cleanup ash shelf accessor functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert ash/shelf/shelf_widget.cc for browser_tests crash... Created 4 years, 9 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
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/panels/panel_layout_manager.h" 5 #include "ash/wm/panels/panel_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void PanelLayoutManager::FinishDragging() { 304 void PanelLayoutManager::FinishDragging() {
305 dragged_panel_ = NULL; 305 dragged_panel_ = NULL;
306 Relayout(); 306 Relayout();
307 } 307 }
308 308
309 void PanelLayoutManager::SetShelf(Shelf* shelf) { 309 void PanelLayoutManager::SetShelf(Shelf* shelf) {
310 DCHECK(!shelf_); 310 DCHECK(!shelf_);
311 DCHECK(!shelf_layout_manager_); 311 DCHECK(!shelf_layout_manager_);
312 shelf_ = shelf; 312 shelf_ = shelf;
313 shelf_->AddIconObserver(this); 313 shelf_->AddIconObserver(this);
314 if (shelf_->shelf_widget()) { 314 if (shelf_->shelf_layout_manager()) {
315 shelf_layout_manager_ = shelf_->shelf_widget()->shelf_layout_manager(); 315 shelf_layout_manager_ = shelf_->shelf_layout_manager();
316 WillChangeVisibilityState(shelf_layout_manager_->visibility_state()); 316 WillChangeVisibilityState(shelf_layout_manager_->visibility_state());
317 shelf_layout_manager_->AddObserver(this); 317 shelf_layout_manager_->AddObserver(this);
318 } 318 }
319 } 319 }
320 320
321 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { 321 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) {
322 DCHECK(panel->parent() == panel_container_); 322 DCHECK(panel->parent() == panel_container_);
323 wm::WindowState* window_state = wm::GetWindowState(panel); 323 wm::WindowState* window_state = wm::GetWindowState(panel);
324 if (window_state->IsMinimized()) 324 if (window_state->IsMinimized())
325 window_state->Restore(); 325 window_state->Restore();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 void PanelLayoutManager::MinimizePanel(aura::Window* panel) { 577 void PanelLayoutManager::MinimizePanel(aura::Window* panel) {
578 ::wm::SetWindowVisibilityAnimationType( 578 ::wm::SetWindowVisibilityAnimationType(
579 panel, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 579 panel, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
580 ui::Layer* layer = panel->layer(); 580 ui::Layer* layer = panel->layer();
581 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator()); 581 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator());
582 panel_slide_settings.SetPreemptionStrategy( 582 panel_slide_settings.SetPreemptionStrategy(
583 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 583 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
584 panel_slide_settings.SetTransitionDuration( 584 panel_slide_settings.SetTransitionDuration(
585 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); 585 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds));
586 gfx::Rect bounds(panel->bounds()); 586 gfx::Rect bounds(panel->bounds());
587 bounds.Offset(GetSlideInAnimationOffset( 587 bounds.Offset(GetSlideInAnimationOffset(shelf_->alignment()));
588 shelf_->shelf_widget()->GetAlignment()));
589 SetChildBoundsDirect(panel, bounds); 588 SetChildBoundsDirect(panel, bounds);
590 panel->Hide(); 589 panel->Hide();
591 layer->SetOpacity(0); 590 layer->SetOpacity(0);
592 if (wm::IsActiveWindow(panel)) 591 if (wm::IsActiveWindow(panel))
593 wm::DeactivateWindow(panel); 592 wm::DeactivateWindow(panel);
594 Relayout(); 593 Relayout();
595 } 594 }
596 595
597 void PanelLayoutManager::RestorePanel(aura::Window* panel) { 596 void PanelLayoutManager::RestorePanel(aura::Window* panel) {
598 PanelList::iterator found = 597 PanelList::iterator found =
(...skipping 12 matching lines...) Expand all
611 // when the WindowSelectorController is restoring minimized windows so that 610 // when the WindowSelectorController is restoring minimized windows so that
612 // they actually become visible. 611 // they actually become visible.
613 WindowSelectorController* window_selector_controller = 612 WindowSelectorController* window_selector_controller =
614 Shell::GetInstance()->window_selector_controller(); 613 Shell::GetInstance()->window_selector_controller();
615 if (in_layout_ || !window_selector_controller || 614 if (in_layout_ || !window_selector_controller ||
616 (window_selector_controller->IsSelecting() && 615 (window_selector_controller->IsSelecting() &&
617 !window_selector_controller->IsRestoringMinimizedWindows())) 616 !window_selector_controller->IsRestoringMinimizedWindows()))
618 return; 617 return;
619 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 618 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
620 619
621 ShelfAlignment alignment = shelf_->shelf_widget()->GetAlignment(); 620 const ShelfAlignment alignment = shelf_->alignment();
622 bool horizontal = alignment == SHELF_ALIGNMENT_TOP || 621 const bool horizontal = shelf_->IsHorizontalAlignment();
623 alignment == SHELF_ALIGNMENT_BOTTOM;
624 gfx::Rect shelf_bounds = ash::ScreenUtil::ConvertRectFromScreen( 622 gfx::Rect shelf_bounds = ash::ScreenUtil::ConvertRectFromScreen(
625 panel_container_, shelf_->shelf_widget()->GetWindowBoundsInScreen()); 623 panel_container_, shelf_->shelf_widget()->GetWindowBoundsInScreen());
626 int panel_start_bounds = kPanelIdealSpacing; 624 int panel_start_bounds = kPanelIdealSpacing;
627 int panel_end_bounds = horizontal ? 625 int panel_end_bounds = horizontal ?
628 panel_container_->bounds().width() - kPanelIdealSpacing : 626 panel_container_->bounds().width() - kPanelIdealSpacing :
629 panel_container_->bounds().height() - kPanelIdealSpacing; 627 panel_container_->bounds().height() - kPanelIdealSpacing;
630 aura::Window* active_panel = NULL; 628 aura::Window* active_panel = NULL;
631 std::vector<VisiblePanelPositionInfo> visible_panels; 629 std::vector<VisiblePanelPositionInfo> visible_panels;
632 for (PanelList::iterator iter = panel_windows_.begin(); 630 for (PanelList::iterator iter = panel_windows_.begin();
633 iter != panel_windows_.end(); ++iter) { 631 iter != panel_windows_.end(); ++iter) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 UpdateCallouts(); 769 UpdateCallouts();
772 } 770 }
773 771
774 void PanelLayoutManager::UpdateStacking(aura::Window* active_panel) { 772 void PanelLayoutManager::UpdateStacking(aura::Window* active_panel) {
775 if (!active_panel) { 773 if (!active_panel) {
776 if (!last_active_panel_) 774 if (!last_active_panel_)
777 return; 775 return;
778 active_panel = last_active_panel_; 776 active_panel = last_active_panel_;
779 } 777 }
780 778
781 ShelfAlignment alignment = shelf_->alignment();
782 bool horizontal = alignment == SHELF_ALIGNMENT_TOP ||
783 alignment == SHELF_ALIGNMENT_BOTTOM;
784
785 // We want to to stack the panels like a deck of cards: 779 // We want to to stack the panels like a deck of cards:
786 // ,--,--,--,-------.--.--. 780 // ,--,--,--,-------.--.--.
787 // | | | | | | | 781 // | | | | | | |
788 // | | | | | | | 782 // | | | | | | |
789 // 783 //
790 // We use the middle of each panel to figure out how to stack the panels. This 784 // We use the middle of each panel to figure out how to stack the panels. This
791 // allows us to update the stacking when a panel is being dragged around by 785 // allows us to update the stacking when a panel is being dragged around by
792 // the titlebar--even though it doesn't update the shelf icon positions, we 786 // the titlebar--even though it doesn't update the shelf icon positions, we
793 // still want the visual effect. 787 // still want the visual effect.
794 std::map<int, aura::Window*> window_ordering; 788 std::map<int, aura::Window*> window_ordering;
789 const bool horizontal = shelf_->IsHorizontalAlignment();
795 for (PanelList::const_iterator it = panel_windows_.begin(); 790 for (PanelList::const_iterator it = panel_windows_.begin();
796 it != panel_windows_.end(); ++it) { 791 it != panel_windows_.end(); ++it) {
797 gfx::Rect bounds = it->window->bounds(); 792 gfx::Rect bounds = it->window->bounds();
798 window_ordering.insert(std::make_pair(horizontal ? 793 window_ordering.insert(std::make_pair(horizontal ?
799 bounds.x() + bounds.width() / 2 : 794 bounds.x() + bounds.width() / 2 :
800 bounds.y() + bounds.height() / 2, 795 bounds.y() + bounds.height() / 2,
801 it->window)); 796 it->window));
802 } 797 }
803 798
804 aura::Window* previous_panel = NULL; 799 aura::Window* previous_panel = NULL;
(...skipping 14 matching lines...) Expand all
819 previous_panel = it->second; 814 previous_panel = it->second;
820 } 815 }
821 816
822 panel_container_->StackChildAtTop(active_panel); 817 panel_container_->StackChildAtTop(active_panel);
823 if (dragged_panel_ && dragged_panel_->parent() == panel_container_) 818 if (dragged_panel_ && dragged_panel_->parent() == panel_container_)
824 panel_container_->StackChildAtTop(dragged_panel_); 819 panel_container_->StackChildAtTop(dragged_panel_);
825 last_active_panel_ = active_panel; 820 last_active_panel_ = active_panel;
826 } 821 }
827 822
828 void PanelLayoutManager::UpdateCallouts() { 823 void PanelLayoutManager::UpdateCallouts() {
829 ShelfAlignment alignment = shelf_->alignment(); 824 const bool horizontal = shelf_->IsHorizontalAlignment();
830 bool horizontal = alignment == SHELF_ALIGNMENT_TOP ||
831 alignment == SHELF_ALIGNMENT_BOTTOM;
832
833 for (PanelList::iterator iter = panel_windows_.begin(); 825 for (PanelList::iterator iter = panel_windows_.begin();
834 iter != panel_windows_.end(); ++iter) { 826 iter != panel_windows_.end(); ++iter) {
835 aura::Window* panel = iter->window; 827 aura::Window* panel = iter->window;
836 views::Widget* callout_widget = iter->callout_widget; 828 views::Widget* callout_widget = iter->callout_widget;
837 829
838 gfx::Rect current_bounds = panel->GetBoundsInScreen(); 830 gfx::Rect current_bounds = panel->GetBoundsInScreen();
839 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen( 831 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen(
840 panel->parent(), 832 panel->parent(),
841 panel->GetTargetBounds()); 833 panel->GetTargetBounds());
842 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel); 834 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel);
(...skipping 15 matching lines...) Expand all
858 current_bounds.x() - callout_bounds.x(), 850 current_bounds.x() - callout_bounds.x(),
859 callout_bounds.right() - current_bounds.right()); 851 callout_bounds.right() - current_bounds.right());
860 } else { 852 } else {
861 callout_bounds.set_y( 853 callout_bounds.set_y(
862 icon_bounds.y() + (icon_bounds.height() - 854 icon_bounds.y() + (icon_bounds.height() -
863 callout_bounds.height()) / 2); 855 callout_bounds.height()) / 2);
864 distance_until_over_panel = std::max( 856 distance_until_over_panel = std::max(
865 current_bounds.y() - callout_bounds.y(), 857 current_bounds.y() - callout_bounds.y(),
866 callout_bounds.bottom() - current_bounds.bottom()); 858 callout_bounds.bottom() - current_bounds.bottom());
867 } 859 }
868 switch (alignment) { 860 switch (shelf_->alignment()) {
869 case SHELF_ALIGNMENT_BOTTOM: 861 case SHELF_ALIGNMENT_BOTTOM:
870 callout_bounds.set_y(bounds.bottom()); 862 callout_bounds.set_y(bounds.bottom());
871 break; 863 break;
872 case SHELF_ALIGNMENT_LEFT: 864 case SHELF_ALIGNMENT_LEFT:
873 callout_bounds.set_x(bounds.x() - callout_bounds.width()); 865 callout_bounds.set_x(bounds.x() - callout_bounds.width());
874 break; 866 break;
875 case SHELF_ALIGNMENT_RIGHT: 867 case SHELF_ALIGNMENT_RIGHT:
876 callout_bounds.set_x(bounds.right()); 868 callout_bounds.set_x(bounds.right());
877 break; 869 break;
878 case SHELF_ALIGNMENT_TOP: 870 case SHELF_ALIGNMENT_TOP:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 // Keyboard hidden, restore original bounds if they exist. 943 // Keyboard hidden, restore original bounds if they exist.
952 SetChildBounds(panel, panel_state->GetRestoreBoundsInScreen()); 944 SetChildBounds(panel, panel_state->GetRestoreBoundsInScreen());
953 } 945 }
954 } 946 }
955 // This bounds change will have caused a change to the Shelf which does not 947 // This bounds change will have caused a change to the Shelf which does not
956 // propogate automatically to this class, so manually recalculate bounds. 948 // propogate automatically to this class, so manually recalculate bounds.
957 OnWindowResized(); 949 OnWindowResized();
958 } 950 }
959 951
960 } // namespace ash 952 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/dock/docked_window_layout_manager.cc ('k') | ash/wm/panels/panel_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698