| 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/common/wm/dock/docked_window_layout_manager.h" | 5 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_constants.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/shelf/wm_shelf_observer.h" |
| 7 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/common/wm/shelf/wm_shelf.h" | |
| 9 #include "ash/common/wm/shelf/wm_shelf_constants.h" | |
| 10 #include "ash/common/wm/shelf/wm_shelf_observer.h" | |
| 11 #include "ash/common/wm/window_animation_types.h" | 11 #include "ash/common/wm/window_animation_types.h" |
| 12 #include "ash/common/wm/window_parenting_utils.h" | 12 #include "ash/common/wm/window_parenting_utils.h" |
| 13 #include "ash/common/wm/window_resizer.h" | 13 #include "ash/common/wm/window_resizer.h" |
| 14 #include "ash/common/wm/window_state.h" | 14 #include "ash/common/wm/window_state.h" |
| 15 #include "ash/common/wm_lookup.h" | 15 #include "ash/common/wm_lookup.h" |
| 16 #include "ash/common/wm_root_window_controller.h" | 16 #include "ash/common/wm_root_window_controller.h" |
| 17 #include "ash/common/wm_shell.h" | 17 #include "ash/common/wm_shell.h" |
| 18 #include "ash/common/wm_window.h" | 18 #include "ash/common/wm_window.h" |
| 19 #include "base/auto_reset.h" | 19 #include "base/auto_reset.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 40 const int DockedWindowLayoutManager::kMinDockGap = 2; | 40 const int DockedWindowLayoutManager::kMinDockGap = 2; |
| 41 // static | 41 // static |
| 42 const int DockedWindowLayoutManager::kIdealWidth = 250; | 42 const int DockedWindowLayoutManager::kIdealWidth = 250; |
| 43 const int kMinimumHeight = 250; | 43 const int kMinimumHeight = 250; |
| 44 const int kSlideDurationMs = 120; | 44 const int kSlideDurationMs = 120; |
| 45 const int kFadeDurationMs = 60; | 45 const int kFadeDurationMs = 60; |
| 46 const int kMinimizeDurationMs = 720; | 46 const int kMinimizeDurationMs = 720; |
| 47 | 47 |
| 48 class DockedBackgroundWidget : public views::Widget, | 48 class DockedBackgroundWidget : public views::Widget, |
| 49 public BackgroundAnimatorDelegate, | 49 public BackgroundAnimatorDelegate, |
| 50 public wm::WmShelfObserver { | 50 public WmShelfObserver { |
| 51 public: | 51 public: |
| 52 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) | 52 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) |
| 53 : manager_(manager), | 53 : manager_(manager), |
| 54 alignment_(DOCKED_ALIGNMENT_NONE), | 54 alignment_(DOCKED_ALIGNMENT_NONE), |
| 55 background_animator_(this, 0, wm::kShelfBackgroundAlpha), | 55 background_animator_(this, 0, kShelfBackgroundAlpha), |
| 56 alpha_(0), | 56 alpha_(0), |
| 57 opaque_background_(ui::LAYER_SOLID_COLOR), | 57 opaque_background_(ui::LAYER_SOLID_COLOR), |
| 58 visible_background_type_(manager_->shelf()->GetBackgroundType()), | 58 visible_background_type_(manager_->shelf()->GetBackgroundType()), |
| 59 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { | 59 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { |
| 60 manager_->shelf()->AddObserver(this); | 60 manager_->shelf()->AddObserver(this); |
| 61 InitWidget(manager_->dock_container()); | 61 InitWidget(manager_->dock_container()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 ~DockedBackgroundWidget() override { | 64 ~DockedBackgroundWidget() override { |
| 65 manager_->shelf()->RemoveObserver(this); | 65 manager_->shelf()->RemoveObserver(this); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 local_window_bounds.height(), false, paint); | 104 local_window_bounds.height(), false, paint); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // BackgroundAnimatorDelegate: | 107 // BackgroundAnimatorDelegate: |
| 108 void UpdateBackground(int alpha) override { | 108 void UpdateBackground(int alpha) override { |
| 109 alpha_ = alpha; | 109 alpha_ = alpha; |
| 110 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | 110 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // ShelfLayoutManagerObserver: | 113 // ShelfLayoutManagerObserver: |
| 114 void OnBackgroundUpdated(wm::ShelfBackgroundType background_type, | 114 void OnBackgroundUpdated(ShelfBackgroundType background_type, |
| 115 BackgroundAnimatorChangeType change_type) override { | 115 BackgroundAnimatorChangeType change_type) override { |
| 116 // Sets the background type. Starts an animation to transition to | 116 // Sets the background type. Starts an animation to transition to |
| 117 // |background_type| if the widget is visible. If the widget is not visible, | 117 // |background_type| if the widget is visible. If the widget is not visible, |
| 118 // the animation is postponed till the widget becomes visible. | 118 // the animation is postponed till the widget becomes visible. |
| 119 visible_background_type_ = background_type; | 119 visible_background_type_ = background_type; |
| 120 visible_background_change_type_ = change_type; | 120 visible_background_change_type_ = change_type; |
| 121 if (IsVisible()) | 121 if (IsVisible()) |
| 122 UpdateBackground(); | 122 UpdateBackground(); |
| 123 } | 123 } |
| 124 | 124 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 152 // This background should be explicitly stacked below any windows already in | 152 // This background should be explicitly stacked below any windows already in |
| 153 // the dock, otherwise the z-order is set by the order in which windows were | 153 // the dock, otherwise the z-order is set by the order in which windows were |
| 154 // added to the container, and UpdateStacking only manages user windows, not | 154 // added to the container, and UpdateStacking only manages user windows, not |
| 155 // the background widget. | 155 // the background widget. |
| 156 parent->StackChildAtBottom(wm_window); | 156 parent->StackChildAtBottom(wm_window); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Transitions to |visible_background_type_| if the widget is visible and to | 159 // Transitions to |visible_background_type_| if the widget is visible and to |
| 160 // SHELF_BACKGROUND_DEFAULT if it is not. | 160 // SHELF_BACKGROUND_DEFAULT if it is not. |
| 161 void UpdateBackground() { | 161 void UpdateBackground() { |
| 162 wm::ShelfBackgroundType background_type = | 162 ShelfBackgroundType background_type = |
| 163 IsVisible() ? visible_background_type_ : wm::SHELF_BACKGROUND_DEFAULT; | 163 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; |
| 164 BackgroundAnimatorChangeType change_type = | 164 BackgroundAnimatorChangeType change_type = |
| 165 IsVisible() ? visible_background_change_type_ | 165 IsVisible() ? visible_background_change_type_ |
| 166 : BACKGROUND_CHANGE_IMMEDIATE; | 166 : BACKGROUND_CHANGE_IMMEDIATE; |
| 167 | 167 |
| 168 float target_opacity = | 168 float target_opacity = |
| 169 (background_type == wm::SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | 169 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
| 170 std::unique_ptr<ui::ScopedLayerAnimationSettings> | 170 std::unique_ptr<ui::ScopedLayerAnimationSettings> |
| 171 opaque_background_animation; | 171 opaque_background_animation; |
| 172 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | 172 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { |
| 173 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | 173 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( |
| 174 opaque_background_.GetAnimator())); | 174 opaque_background_.GetAnimator())); |
| 175 opaque_background_animation->SetTransitionDuration( | 175 opaque_background_animation->SetTransitionDuration( |
| 176 base::TimeDelta::FromMilliseconds(wm::kTimeToSwitchBackgroundMs)); | 176 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); |
| 177 } | 177 } |
| 178 opaque_background_.SetOpacity(target_opacity); | 178 opaque_background_.SetOpacity(target_opacity); |
| 179 | 179 |
| 180 // TODO(varkha): use ui::Layer on both opaque_background and normal | 180 // TODO(varkha): use ui::Layer on both opaque_background and normal |
| 181 // background retire background_animator_ at all. It would be simpler. | 181 // background retire background_animator_ at all. It would be simpler. |
| 182 // See also ShelfWidget::SetPaintsBackground. | 182 // See also ShelfWidget::SetPaintsBackground. |
| 183 background_animator_.SetPaintsBackground( | 183 background_animator_.SetPaintsBackground( |
| 184 background_type != wm::SHELF_BACKGROUND_DEFAULT, change_type); | 184 background_type != SHELF_BACKGROUND_DEFAULT, change_type); |
| 185 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | 185 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); |
| 186 } | 186 } |
| 187 | 187 |
| 188 DockedWindowLayoutManager* manager_; | 188 DockedWindowLayoutManager* manager_; |
| 189 | 189 |
| 190 DockedAlignment alignment_; | 190 DockedAlignment alignment_; |
| 191 | 191 |
| 192 // The animator for the background transitions. | 192 // The animator for the background transitions. |
| 193 BackgroundAnimator background_animator_; | 193 BackgroundAnimator background_animator_; |
| 194 | 194 |
| 195 // The alpha to use for drawing image assets covering the docked background. | 195 // The alpha to use for drawing image assets covering the docked background. |
| 196 int alpha_; | 196 int alpha_; |
| 197 | 197 |
| 198 // Solid black background that can be made fully opaque. | 198 // Solid black background that can be made fully opaque. |
| 199 ui::Layer opaque_background_; | 199 ui::Layer opaque_background_; |
| 200 | 200 |
| 201 // Backgrounds created from shelf background by 90 or 270 degree rotation. | 201 // Backgrounds created from shelf background by 90 or 270 degree rotation. |
| 202 gfx::ImageSkia shelf_background_left_; | 202 gfx::ImageSkia shelf_background_left_; |
| 203 gfx::ImageSkia shelf_background_right_; | 203 gfx::ImageSkia shelf_background_right_; |
| 204 | 204 |
| 205 // The background type to use when the widget is visible. When not visible, | 205 // The background type to use when the widget is visible. When not visible, |
| 206 // the widget uses SHELF_BACKGROUND_DEFAULT. | 206 // the widget uses SHELF_BACKGROUND_DEFAULT. |
| 207 wm::ShelfBackgroundType visible_background_type_; | 207 ShelfBackgroundType visible_background_type_; |
| 208 | 208 |
| 209 // Whether the widget should animate to |visible_background_type_|. | 209 // Whether the widget should animate to |visible_background_type_|. |
| 210 BackgroundAnimatorChangeType visible_background_change_type_; | 210 BackgroundAnimatorChangeType visible_background_change_type_; |
| 211 | 211 |
| 212 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget); | 212 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget); |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 namespace { | 215 namespace { |
| 216 | 216 |
| 217 // Returns true if a window is a popup or a transient child. | 217 // Returns true if a window is a popup or a transient child. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 // count limit so do it here. | 530 // count limit so do it here. |
| 531 MaybeMinimizeChildrenExcept(dragged_window_); | 531 MaybeMinimizeChildrenExcept(dragged_window_); |
| 532 } | 532 } |
| 533 dragged_window_ = nullptr; | 533 dragged_window_ = nullptr; |
| 534 dragged_bounds_ = gfx::Rect(); | 534 dragged_bounds_ = gfx::Rect(); |
| 535 Relayout(); | 535 Relayout(); |
| 536 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 536 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
| 537 RecordUmaAction(action, source); | 537 RecordUmaAction(action, source); |
| 538 } | 538 } |
| 539 | 539 |
| 540 void DockedWindowLayoutManager::SetShelf(wm::WmShelf* shelf) { | 540 void DockedWindowLayoutManager::SetShelf(WmShelf* shelf) { |
| 541 DCHECK(!shelf_); | 541 DCHECK(!shelf_); |
| 542 shelf_ = shelf; | 542 shelf_ = shelf; |
| 543 shelf_observer_.reset(new ShelfWindowObserver(this)); | 543 shelf_observer_.reset(new ShelfWindowObserver(this)); |
| 544 } | 544 } |
| 545 | 545 |
| 546 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( | 546 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( |
| 547 const WmWindow* window) const { | 547 const WmWindow* window) const { |
| 548 const gfx::Rect& bounds(window->GetBoundsInScreen()); | 548 const gfx::Rect& bounds(window->GetBoundsInScreen()); |
| 549 | 549 |
| 550 // Test overlap with an existing docked area first. | 550 // Test overlap with an existing docked area first. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 if (desired_alignment != DOCKED_ALIGNMENT_NONE && | 618 if (desired_alignment != DOCKED_ALIGNMENT_NONE && |
| 619 alignment != DOCKED_ALIGNMENT_NONE && alignment != desired_alignment) { | 619 alignment != DOCKED_ALIGNMENT_NONE && alignment != desired_alignment) { |
| 620 return false; | 620 return false; |
| 621 } | 621 } |
| 622 // Do not allow docking on the same side as shelf. | 622 // Do not allow docking on the same side as shelf. |
| 623 return IsDockedAlignmentValid(desired_alignment); | 623 return IsDockedAlignmentValid(desired_alignment); |
| 624 } | 624 } |
| 625 | 625 |
| 626 bool DockedWindowLayoutManager::IsDockedAlignmentValid( | 626 bool DockedWindowLayoutManager::IsDockedAlignmentValid( |
| 627 DockedAlignment alignment) const { | 627 DockedAlignment alignment) const { |
| 628 wm::ShelfAlignment shelf_alignment = | 628 ShelfAlignment shelf_alignment = |
| 629 shelf_ ? shelf_->GetAlignment() : wm::SHELF_ALIGNMENT_BOTTOM; | 629 shelf_ ? shelf_->GetAlignment() : SHELF_ALIGNMENT_BOTTOM; |
| 630 if ((alignment == DOCKED_ALIGNMENT_LEFT && | 630 if ((alignment == DOCKED_ALIGNMENT_LEFT && |
| 631 shelf_alignment == wm::SHELF_ALIGNMENT_LEFT) || | 631 shelf_alignment == SHELF_ALIGNMENT_LEFT) || |
| 632 (alignment == DOCKED_ALIGNMENT_RIGHT && | 632 (alignment == DOCKED_ALIGNMENT_RIGHT && |
| 633 shelf_alignment == wm::SHELF_ALIGNMENT_RIGHT)) { | 633 shelf_alignment == SHELF_ALIGNMENT_RIGHT)) { |
| 634 return false; | 634 return false; |
| 635 } | 635 } |
| 636 return true; | 636 return true; |
| 637 } | 637 } |
| 638 | 638 |
| 639 void DockedWindowLayoutManager::MaybeSetDesiredDockedAlignment( | 639 void DockedWindowLayoutManager::MaybeSetDesiredDockedAlignment( |
| 640 DockedAlignment alignment) { | 640 DockedAlignment alignment) { |
| 641 // If the requested alignment is |NONE| or there are no | 641 // If the requested alignment is |NONE| or there are no |
| 642 // docked windows return early as we can't change whether there is a | 642 // docked windows return early as we can't change whether there is a |
| 643 // dock or not. If the requested alignment is the same as the current | 643 // dock or not. If the requested alignment is the same as the current |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 Relayout(); | 785 Relayout(); |
| 786 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 786 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
| 787 } | 787 } |
| 788 | 788 |
| 789 void DockedWindowLayoutManager::OnShelfAlignmentChanged() { | 789 void DockedWindowLayoutManager::OnShelfAlignmentChanged() { |
| 790 if (!shelf_ || alignment_ == DOCKED_ALIGNMENT_NONE) | 790 if (!shelf_ || alignment_ == DOCKED_ALIGNMENT_NONE) |
| 791 return; | 791 return; |
| 792 | 792 |
| 793 // Do not allow shelf and dock on the same side. Switch side that | 793 // Do not allow shelf and dock on the same side. Switch side that |
| 794 // the dock is attached to and move all dock windows to that new side. | 794 // the dock is attached to and move all dock windows to that new side. |
| 795 wm::ShelfAlignment shelf_alignment = shelf_->GetAlignment(); | 795 ShelfAlignment shelf_alignment = shelf_->GetAlignment(); |
| 796 if (alignment_ == DOCKED_ALIGNMENT_LEFT && | 796 if (alignment_ == DOCKED_ALIGNMENT_LEFT && |
| 797 shelf_alignment == wm::SHELF_ALIGNMENT_LEFT) { | 797 shelf_alignment == SHELF_ALIGNMENT_LEFT) { |
| 798 alignment_ = DOCKED_ALIGNMENT_RIGHT; | 798 alignment_ = DOCKED_ALIGNMENT_RIGHT; |
| 799 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && | 799 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && |
| 800 shelf_alignment == wm::SHELF_ALIGNMENT_RIGHT) { | 800 shelf_alignment == SHELF_ALIGNMENT_RIGHT) { |
| 801 alignment_ = DOCKED_ALIGNMENT_LEFT; | 801 alignment_ = DOCKED_ALIGNMENT_LEFT; |
| 802 } | 802 } |
| 803 Relayout(); | 803 Relayout(); |
| 804 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); | 804 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); |
| 805 } | 805 } |
| 806 | 806 |
| 807 ///////////////////////////////////////////////////////////////////////////// | 807 ///////////////////////////////////////////////////////////////////////////// |
| 808 // DockedWindowLayoutManager, WindowStateObserver implementation: | 808 // DockedWindowLayoutManager, WindowStateObserver implementation: |
| 809 | 809 |
| 810 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( | 810 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 | 1313 |
| 1314 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1314 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 1315 const gfx::Rect& keyboard_bounds) { | 1315 const gfx::Rect& keyboard_bounds) { |
| 1316 // This bounds change will have caused a change to the Shelf which does not | 1316 // This bounds change will have caused a change to the Shelf which does not |
| 1317 // propagate automatically to this class, so manually recalculate bounds. | 1317 // propagate automatically to this class, so manually recalculate bounds. |
| 1318 Relayout(); | 1318 Relayout(); |
| 1319 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1319 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 } // namespace ash | 1322 } // namespace ash |
| OLD | NEW |