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

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

Issue 2901663003: chromeos: converts WindowState to aura::Window (Closed)
Patch Set: moar Created 3 years, 7 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 15 matching lines...) Expand all
26 #include "third_party/skia/include/core/SkColor.h" 26 #include "third_party/skia/include/core/SkColor.h"
27 #include "third_party/skia/include/core/SkPath.h" 27 #include "third_party/skia/include/core/SkPath.h"
28 #include "ui/aura/client/window_parenting_client.h" 28 #include "ui/aura/client/window_parenting_client.h"
29 #include "ui/aura/window_delegate.h" 29 #include "ui/aura/window_delegate.h"
30 #include "ui/compositor/scoped_layer_animation_settings.h" 30 #include "ui/compositor/scoped_layer_animation_settings.h"
31 #include "ui/gfx/canvas.h" 31 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/geometry/rect.h" 32 #include "ui/gfx/geometry/rect.h"
33 #include "ui/gfx/geometry/vector2d.h" 33 #include "ui/gfx/geometry/vector2d.h"
34 #include "ui/views/background.h" 34 #include "ui/views/background.h"
35 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
36 #include "ui/wm/core/window_util.h"
36 #include "ui/wm/public/activation_client.h" 37 #include "ui/wm/public/activation_client.h"
37 38
38 using aura::Window; 39 using aura::Window;
39 40
40 namespace ash { 41 namespace ash {
41 namespace { 42 namespace {
42 43
43 const int kPanelIdealSpacing = 4; 44 const int kPanelIdealSpacing = 4;
44 45
45 const float kMaxHeightFactor = .80f; 46 const float kMaxHeightFactor = .80f;
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 // PanelLayoutManager, WindowStateObserver implementation: 482 // PanelLayoutManager, WindowStateObserver implementation:
482 483
483 void PanelLayoutManager::OnPostWindowStateTypeChange( 484 void PanelLayoutManager::OnPostWindowStateTypeChange(
484 wm::WindowState* window_state, 485 wm::WindowState* window_state,
485 wm::WindowStateType old_type) { 486 wm::WindowStateType old_type) {
486 // If the shelf is currently hidden then windows will not actually be shown 487 // If the shelf is currently hidden then windows will not actually be shown
487 // but the set to restore when the shelf becomes visible is updated. 488 // but the set to restore when the shelf becomes visible is updated.
488 if (restore_windows_on_shelf_visible_) { 489 if (restore_windows_on_shelf_visible_) {
489 if (window_state->IsMinimized()) { 490 if (window_state->IsMinimized()) {
490 MinimizePanel(window_state->window()); 491 MinimizePanel(window_state->window());
491 restore_windows_on_shelf_visible_->Remove( 492 restore_windows_on_shelf_visible_->Remove(window_state->window());
492 window_state->window()->aura_window());
493 } else { 493 } else {
494 restore_windows_on_shelf_visible_->Add( 494 restore_windows_on_shelf_visible_->Add(window_state->window());
495 window_state->window()->aura_window());
496 } 495 }
497 return; 496 return;
498 } 497 }
499 498
500 if (window_state->IsMinimized()) 499 if (window_state->IsMinimized())
501 MinimizePanel(window_state->window()); 500 MinimizePanel(window_state->window());
502 else 501 else
503 RestorePanel(window_state->window()); 502 RestorePanel(window_state->window());
504 } 503 }
505 504
(...skipping 27 matching lines...) Expand all
533 ShelfVisibilityState new_state) { 532 ShelfVisibilityState new_state) {
534 // On entering / leaving full screen mode the shelf visibility state is 533 // On entering / leaving full screen mode the shelf visibility state is
535 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide 534 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide
536 // to allow the full-screen application to use the full screen. 535 // to allow the full-screen application to use the full screen.
537 bool shelf_hidden = new_state == ash::SHELF_HIDDEN; 536 bool shelf_hidden = new_state == ash::SHELF_HIDDEN;
538 if (!shelf_hidden) { 537 if (!shelf_hidden) {
539 if (restore_windows_on_shelf_visible_) { 538 if (restore_windows_on_shelf_visible_) {
540 std::unique_ptr<aura::WindowTracker> restore_windows( 539 std::unique_ptr<aura::WindowTracker> restore_windows(
541 std::move(restore_windows_on_shelf_visible_)); 540 std::move(restore_windows_on_shelf_visible_));
542 for (aura::Window* window : restore_windows->windows()) 541 for (aura::Window* window : restore_windows->windows())
543 RestorePanel(WmWindow::Get(window)); 542 RestorePanel(window);
544 } 543 }
545 return; 544 return;
546 } 545 }
547 546
548 if (restore_windows_on_shelf_visible_) 547 if (restore_windows_on_shelf_visible_)
549 return; 548 return;
550 std::unique_ptr<aura::WindowTracker> minimized_windows( 549 std::unique_ptr<aura::WindowTracker> minimized_windows(
551 new aura::WindowTracker); 550 new aura::WindowTracker);
552 for (PanelList::iterator iter = panel_windows_.begin(); 551 for (PanelList::iterator iter = panel_windows_.begin();
553 iter != panel_windows_.end();) { 552 iter != panel_windows_.end();) {
(...skipping 12 matching lines...) Expand all
566 void PanelLayoutManager::OnShelfIconPositionsChanged() { 565 void PanelLayoutManager::OnShelfIconPositionsChanged() {
567 // TODO: As this is called for every animation step now. Relayout needs to be 566 // TODO: As this is called for every animation step now. Relayout needs to be
568 // updated to use current icon position instead of use the ideal bounds so 567 // updated to use current icon position instead of use the ideal bounds so
569 // that the panels slide with their icons instead of jumping. 568 // that the panels slide with their icons instead of jumping.
570 Relayout(); 569 Relayout();
571 } 570 }
572 571
573 //////////////////////////////////////////////////////////////////////////////// 572 ////////////////////////////////////////////////////////////////////////////////
574 // PanelLayoutManager private implementation: 573 // PanelLayoutManager private implementation:
575 574
576 void PanelLayoutManager::MinimizePanel(WmWindow* panel) { 575 void PanelLayoutManager::MinimizePanel(aura::Window* panel) {
577 // Clusterfuzz can trigger panel accelerators before the shelf is created. 576 // Clusterfuzz can trigger panel accelerators before the shelf is created.
578 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. 577 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed.
579 if (!shelf_) 578 if (!shelf_)
580 return; 579 return;
581 580
582 panel->SetVisibilityAnimationType( 581 ::wm::SetWindowVisibilityAnimationType(
583 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 582 panel, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
584 ui::Layer* layer = panel->GetLayer(); 583 ui::Layer* layer = panel->layer();
585 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator()); 584 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator());
586 panel_slide_settings.SetPreemptionStrategy( 585 panel_slide_settings.SetPreemptionStrategy(
587 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 586 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
588 panel_slide_settings.SetTransitionDuration( 587 panel_slide_settings.SetTransitionDuration(
589 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); 588 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds));
590 gfx::Rect bounds(panel->GetBounds()); 589 gfx::Rect bounds(panel->bounds());
591 bounds.Offset(GetSlideInAnimationOffset(shelf_->GetAlignment())); 590 bounds.Offset(GetSlideInAnimationOffset(shelf_->GetAlignment()));
592 panel->SetBoundsDirect(bounds); 591 SetChildBoundsDirect(panel, bounds);
msw 2017/05/23 05:46:55 q: The impls aren't obviously equivalent, should t
sky 2017/05/23 17:14:38 You are an awesome reviewer! I was worried about t
593 panel->Hide(); 592 panel->Hide();
594 layer->SetOpacity(0); 593 layer->SetOpacity(0);
595 if (panel->IsActive()) 594 if (::wm::IsActiveWindow(panel))
596 panel->Deactivate(); 595 ::wm::DeactivateWindow(panel);
597 Relayout(); 596 Relayout();
598 } 597 }
599 598
600 void PanelLayoutManager::RestorePanel(WmWindow* panel) { 599 void PanelLayoutManager::RestorePanel(aura::Window* panel) {
601 PanelList::iterator found = 600 PanelList::iterator found = std::find(
602 std::find(panel_windows_.begin(), panel_windows_.end(), panel); 601 panel_windows_.begin(), panel_windows_.end(), WmWindow::Get(panel));
603 DCHECK(found != panel_windows_.end()); 602 DCHECK(found != panel_windows_.end());
604 found->slide_in = true; 603 found->slide_in = true;
605 Relayout(); 604 Relayout();
606 } 605 }
607 606
608 void PanelLayoutManager::Relayout() { 607 void PanelLayoutManager::Relayout() {
609 if (!shelf_ || !shelf_->GetWindow()) 608 if (!shelf_ || !shelf_->GetWindow())
610 return; 609 return;
611 610
612 // Suppress layouts during overview mode because changing window bounds 611 // Suppress layouts during overview mode because changing window bounds
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 bounds.set_y(visible_panels[i].major_pos - 728 bounds.set_y(visible_panels[i].major_pos -
730 visible_panels[i].major_length / 2); 729 visible_panels[i].major_length / 2);
731 } 730 }
732 731
733 ui::Layer* layer = visible_panels[i].window->GetLayer(); 732 ui::Layer* layer = visible_panels[i].window->GetLayer();
734 if (slide_in) { 733 if (slide_in) {
735 // New windows shift up from the shelf into position and fade in. 734 // New windows shift up from the shelf into position and fade in.
736 layer->SetOpacity(0); 735 layer->SetOpacity(0);
737 gfx::Rect initial_bounds(bounds); 736 gfx::Rect initial_bounds(bounds);
738 initial_bounds.Offset(GetSlideInAnimationOffset(shelf_->alignment())); 737 initial_bounds.Offset(GetSlideInAnimationOffset(shelf_->alignment()));
739 visible_panels[i].window->SetBoundsDirect(initial_bounds); 738 SetChildBoundsDirect(visible_panels[i].window->aura_window(),
739 initial_bounds);
740 // Set on shelf so that the panel animates into its target position. 740 // Set on shelf so that the panel animates into its target position.
741 on_shelf = true; 741 on_shelf = true;
742 } 742 }
743 743
744 if (on_shelf) { 744 if (on_shelf) {
745 ui::ScopedLayerAnimationSettings panel_slide_settings( 745 ui::ScopedLayerAnimationSettings panel_slide_settings(
746 layer->GetAnimator()); 746 layer->GetAnimator());
747 panel_slide_settings.SetPreemptionStrategy( 747 panel_slide_settings.SetPreemptionStrategy(
748 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 748 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
749 panel_slide_settings.SetTransitionDuration( 749 panel_slide_settings.SetTransitionDuration(
750 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); 750 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds));
751 visible_panels[i].window->SetBoundsDirect(bounds); 751 SetChildBoundsDirect(visible_panels[i].window->aura_window(), bounds);
752 if (slide_in) { 752 if (slide_in) {
753 layer->SetOpacity(1); 753 layer->SetOpacity(1);
754 visible_panels[i].window->Show(); 754 visible_panels[i].window->Show();
755 } 755 }
756 } else { 756 } else {
757 // If the shelf moved don't animate, move immediately to the new 757 // If the shelf moved don't animate, move immediately to the new
758 // target location. 758 // target location.
759 visible_panels[i].window->SetBoundsDirect(bounds); 759 SetChildBoundsDirect(visible_panels[i].window->aura_window(), bounds);
760 } 760 }
761 } 761 }
762 762
763 UpdateStacking(active_panel); 763 UpdateStacking(active_panel);
764 UpdateCallouts(); 764 UpdateCallouts();
765 } 765 }
766 766
767 void PanelLayoutManager::UpdateStacking(WmWindow* active_panel) { 767 void PanelLayoutManager::UpdateStacking(WmWindow* active_panel) {
768 // Clusterfuzz can trigger panel accelerators before the shelf is created. 768 // Clusterfuzz can trigger panel accelerators before the shelf is created.
769 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. 769 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 } 864 }
865 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT) 865 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT)
866 callout_bounds.set_x(bounds.x() - callout_bounds.width()); 866 callout_bounds.set_x(bounds.x() - callout_bounds.width());
867 else if (shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT) 867 else if (shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT)
868 callout_bounds.set_x(bounds.right()); 868 callout_bounds.set_x(bounds.right());
869 else 869 else
870 callout_bounds.set_y(bounds.bottom()); 870 callout_bounds.set_y(bounds.bottom());
871 callout_bounds = callout_widget_window->GetParent()->ConvertRectFromScreen( 871 callout_bounds = callout_widget_window->GetParent()->ConvertRectFromScreen(
872 callout_bounds); 872 callout_bounds);
873 873
874 callout_widget_window->SetBoundsDirect(callout_bounds); 874 SetChildBoundsDirect(callout_widget_window->aura_window(), callout_bounds);
875 DCHECK_EQ(panel_container_, callout_widget_window->GetParent()); 875 DCHECK_EQ(panel_container_, callout_widget_window->GetParent());
876 DCHECK_EQ(panel_container_, panel->GetParent()); 876 DCHECK_EQ(panel_container_, panel->GetParent());
877 panel_container_->StackChildAbove(callout_widget_window, panel); 877 panel_container_->StackChildAbove(callout_widget_window, panel);
878 878
879 ui::Layer* layer = callout_widget_window->GetLayer(); 879 ui::Layer* layer = callout_widget_window->GetLayer();
880 // If the panel is not over the callout position or has just become visible 880 // If the panel is not over the callout position or has just become visible
881 // then fade in the callout. 881 // then fade in the callout.
882 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1)) { 882 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1)) {
883 if (distance_until_over_panel > 0 && 883 if (distance_until_over_panel > 0 &&
884 slide_distance >= distance_until_over_panel) { 884 slide_distance >= distance_until_over_panel) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 // Save existing bounds, so that we can restore them when the keyboard 921 // Save existing bounds, so that we can restore them when the keyboard
922 // hides. 922 // hides.
923 panel_state->SaveCurrentBoundsForRestore(); 923 panel_state->SaveCurrentBoundsForRestore();
924 924
925 gfx::Rect panel_bounds = 925 gfx::Rect panel_bounds =
926 panel->GetParent()->ConvertRectToScreen(panel->GetTargetBounds()); 926 panel->GetParent()->ConvertRectToScreen(panel->GetTargetBounds());
927 int delta = panel_bounds.height() - available_space; 927 int delta = panel_bounds.height() - available_space;
928 // Ensure panels are not pushed above the parent boundaries, shrink any 928 // Ensure panels are not pushed above the parent boundaries, shrink any
929 // panels that violate this constraint. 929 // panels that violate this constraint.
930 if (delta > 0) { 930 if (delta > 0) {
931 panel->SetBoundsDirect( 931 SetChildBoundsDirect(
932 panel->aura_window(),
932 gfx::Rect(panel_bounds.x(), panel_bounds.y() + delta, 933 gfx::Rect(panel_bounds.x(), panel_bounds.y() + delta,
933 panel_bounds.width(), panel_bounds.height() - delta)); 934 panel_bounds.width(), panel_bounds.height() - delta));
934 } 935 }
935 } else if (panel_state->HasRestoreBounds()) { 936 } else if (panel_state->HasRestoreBounds()) {
936 // Keyboard hidden, restore original bounds if they exist. 937 // Keyboard hidden, restore original bounds if they exist.
937 panel->SetBoundsDirect(panel_state->GetRestoreBoundsInScreen()); 938 SetChildBoundsDirect(panel->aura_window(),
939 panel_state->GetRestoreBoundsInScreen());
938 } 940 }
939 } 941 }
940 // This bounds change will have caused a change to the Shelf which does not 942 // This bounds change will have caused a change to the Shelf which does not
941 // propogate automatically to this class, so manually recalculate bounds. 943 // propogate automatically to this class, so manually recalculate bounds.
942 OnWindowResized(); 944 OnWindowResized();
943 } 945 }
944 946
945 void PanelLayoutManager::OnKeyboardClosed() { 947 void PanelLayoutManager::OnKeyboardClosed() {
946 keyboard_observer_.RemoveAll(); 948 keyboard_observer_.RemoveAll();
947 } 949 }
948 950
949 } // namespace ash 951 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698