| 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_background_animator.h" | 7 #include "ash/common/shelf/shelf_background_animator.h" |
| 8 #include "ash/common/shelf/shelf_background_animator_observer.h" | 8 #include "ash/common/shelf/shelf_background_animator_observer.h" |
| 9 #include "ash/common/shelf/shelf_constants.h" | 9 #include "ash/common/shelf/shelf_constants.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| 11 #include "ash/common/shelf/wm_shelf_observer.h" | 11 #include "ash/common/shelf/wm_shelf_observer.h" |
| 12 #include "ash/common/wm/overview/window_selector_controller.h" | 12 #include "ash/common/wm/overview/window_selector_controller.h" |
| 13 #include "ash/common/wm/window_animation_types.h" | 13 #include "ash/common/wm/window_animation_types.h" |
| 14 #include "ash/common/wm/window_parenting_utils.h" | 14 #include "ash/common/wm/window_parenting_utils.h" |
| 15 #include "ash/common/wm/window_resizer.h" | 15 #include "ash/common/wm/window_resizer.h" |
| 16 #include "ash/common/wm/window_state.h" | 16 #include "ash/common/wm/window_state.h" |
| 17 #include "ash/common/wm_lookup.h" | 17 #include "ash/common/wm_lookup.h" |
| 18 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 19 #include "ash/common/wm_window.h" | 19 #include "ash/common/wm_window.h" |
| 20 #include "ash/public/cpp/shell_window_ids.h" | 20 #include "ash/public/cpp/shell_window_ids.h" |
| 21 #include "ash/root_window_controller.h" | 21 #include "ash/root_window_controller.h" |
| 22 #include "base/auto_reset.h" | 22 #include "base/auto_reset.h" |
| 23 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
| 24 #include "grit/ash_resources.h" | 24 #include "grit/ash_resources.h" |
| 25 #include "third_party/skia/include/core/SkColor.h" | 25 #include "third_party/skia/include/core/SkColor.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 28 #include "ui/display/display.h" | 28 #include "ui/display/display.h" |
| 29 #include "ui/display/screen.h" | 29 #include "ui/display/screen.h" |
| 30 #include "ui/gfx/animation/animation_change_type.h" |
| 30 #include "ui/views/background.h" | 31 #include "ui/views/background.h" |
| 31 | 32 |
| 32 namespace ash { | 33 namespace ash { |
| 33 | 34 |
| 34 // Minimum, maximum width of the dock area and a width of the gap | 35 // Minimum, maximum width of the dock area and a width of the gap |
| 35 // static | 36 // static |
| 36 const int DockedWindowLayoutManager::kMaxDockWidth = 360; | 37 const int DockedWindowLayoutManager::kMaxDockWidth = 360; |
| 37 // static | 38 // static |
| 38 const int DockedWindowLayoutManager::kMinDockWidth = 200; | 39 const int DockedWindowLayoutManager::kMinDockWidth = 200; |
| 39 // static | 40 // static |
| 40 const int DockedWindowLayoutManager::kMinDockGap = 2; | 41 const int DockedWindowLayoutManager::kMinDockGap = 2; |
| 41 // static | 42 // static |
| 42 const int DockedWindowLayoutManager::kIdealWidth = 250; | 43 const int DockedWindowLayoutManager::kIdealWidth = 250; |
| 43 const int kMinimumHeight = 250; | 44 const int kMinimumHeight = 250; |
| 44 const int kSlideDurationMs = 120; | 45 const int kSlideDurationMs = 120; |
| 45 const int kFadeDurationMs = 60; | 46 const int kFadeDurationMs = 60; |
| 46 const int kMinimizeDurationMs = 720; | 47 const int kMinimizeDurationMs = 720; |
| 47 | 48 |
| 48 class DockedBackgroundWidget : public views::Widget, | 49 class DockedBackgroundWidget : public views::Widget, |
| 49 public WmShelfObserver, | 50 public WmShelfObserver, |
| 50 public ShelfBackgroundAnimatorObserver { | 51 public ShelfBackgroundAnimatorObserver { |
| 51 public: | 52 public: |
| 52 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) | 53 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) |
| 53 : manager_(manager), | 54 : manager_(manager), |
| 54 alignment_(DOCKED_ALIGNMENT_NONE), | 55 alignment_(DOCKED_ALIGNMENT_NONE), |
| 55 background_animator_(SHELF_BACKGROUND_DEFAULT, nullptr), | 56 background_animator_(SHELF_BACKGROUND_DEFAULT, nullptr), |
| 56 opaque_background_(ui::LAYER_SOLID_COLOR), | 57 opaque_background_(ui::LAYER_SOLID_COLOR), |
| 57 visible_background_type_(manager_->shelf()->GetBackgroundType()), | 58 visible_background_type_(manager_->shelf()->GetBackgroundType()), |
| 58 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { | 59 visible_background_change_type_(gfx::AnimationChangeType::IMMEDIATE) { |
| 59 manager_->shelf()->AddObserver(this); | 60 manager_->shelf()->AddObserver(this); |
| 60 InitWidget(manager_->dock_container()); | 61 InitWidget(manager_->dock_container()); |
| 61 | 62 |
| 62 background_animator_.AddObserver(this); | 63 background_animator_.AddObserver(this); |
| 63 } | 64 } |
| 64 | 65 |
| 65 ~DockedBackgroundWidget() override { | 66 ~DockedBackgroundWidget() override { |
| 66 background_animator_.RemoveObserver(this); | 67 background_animator_.RemoveObserver(this); |
| 67 manager_->shelf()->RemoveObserver(this); | 68 manager_->shelf()->RemoveObserver(this); |
| 68 } | 69 } |
| 69 | 70 |
| 70 // Sets widget bounds and sizes opaque background layer to fill the widget. | 71 // Sets widget bounds and sizes opaque background layer to fill the widget. |
| 71 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) { | 72 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) { |
| 72 SetBounds(bounds); | 73 SetBounds(bounds); |
| 73 opaque_background_.SetBounds(gfx::Rect(bounds.size())); | 74 opaque_background_.SetBounds(gfx::Rect(bounds.size())); |
| 74 alignment_ = alignment; | 75 alignment_ = alignment; |
| 75 } | 76 } |
| 76 | 77 |
| 77 private: | 78 private: |
| 78 // views::Widget: | 79 // views::Widget: |
| 79 void OnNativeWidgetVisibilityChanged(bool visible) override { | 80 void OnNativeWidgetVisibilityChanged(bool visible) override { |
| 80 views::Widget::OnNativeWidgetVisibilityChanged(visible); | 81 views::Widget::OnNativeWidgetVisibilityChanged(visible); |
| 81 UpdateBackground(); | 82 UpdateBackground(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 // ShelfBackgroundAnimatorObserver: | 85 // ShelfBackgroundAnimatorObserver: |
| 85 void UpdateShelfOpaqueBackground(int alpha) override { | 86 void UpdateShelfBackground(int alpha) override { |
| 86 const float kMaxAlpha = 255.0f; | 87 const float kMaxAlpha = 255.0f; |
| 87 opaque_background_.SetOpacity(alpha / kMaxAlpha); | 88 opaque_background_.SetOpacity(alpha / kMaxAlpha); |
| 88 } | 89 } |
| 89 | 90 |
| 90 // WmShelfObserver: | 91 // WmShelfObserver: |
| 91 void OnBackgroundTypeChanged( | 92 void OnBackgroundTypeChanged(ShelfBackgroundType background_type, |
| 92 ShelfBackgroundType background_type, | 93 gfx::AnimationChangeType change_type) override { |
| 93 BackgroundAnimatorChangeType change_type) override { | |
| 94 // Sets the background type. Starts an animation to transition to | 94 // Sets the background type. Starts an animation to transition to |
| 95 // |background_type| if the widget is visible. If the widget is not visible, | 95 // |background_type| if the widget is visible. If the widget is not visible, |
| 96 // the animation is postponed till the widget becomes visible. | 96 // the animation is postponed till the widget becomes visible. |
| 97 visible_background_type_ = background_type; | 97 visible_background_type_ = background_type; |
| 98 visible_background_change_type_ = change_type; | 98 visible_background_change_type_ = change_type; |
| 99 if (IsVisible()) | 99 if (IsVisible()) |
| 100 UpdateBackground(); | 100 UpdateBackground(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void InitWidget(WmWindow* parent) { | 103 void InitWidget(WmWindow* parent) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 124 // added to the container, and UpdateStacking only manages user windows, not | 124 // added to the container, and UpdateStacking only manages user windows, not |
| 125 // the background widget. | 125 // the background widget. |
| 126 parent->StackChildAtBottom(wm_window); | 126 parent->StackChildAtBottom(wm_window); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Transitions to |visible_background_type_| if the widget is visible and to | 129 // Transitions to |visible_background_type_| if the widget is visible and to |
| 130 // SHELF_BACKGROUND_DEFAULT if it is not. | 130 // SHELF_BACKGROUND_DEFAULT if it is not. |
| 131 void UpdateBackground() { | 131 void UpdateBackground() { |
| 132 ShelfBackgroundType background_type = | 132 ShelfBackgroundType background_type = |
| 133 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; | 133 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; |
| 134 BackgroundAnimatorChangeType change_type = | 134 gfx::AnimationChangeType change_type = |
| 135 IsVisible() ? visible_background_change_type_ | 135 IsVisible() ? visible_background_change_type_ |
| 136 : BACKGROUND_CHANGE_IMMEDIATE; | 136 : gfx::AnimationChangeType::IMMEDIATE; |
| 137 background_animator_.PaintBackground(background_type, change_type); | 137 background_animator_.PaintBackground(background_type, change_type); |
| 138 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | 138 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); |
| 139 } | 139 } |
| 140 | 140 |
| 141 DockedWindowLayoutManager* manager_; | 141 DockedWindowLayoutManager* manager_; |
| 142 | 142 |
| 143 DockedAlignment alignment_; | 143 DockedAlignment alignment_; |
| 144 | 144 |
| 145 // The animator for the background transitions. | 145 // The animator for the background transitions. |
| 146 ShelfBackgroundAnimator background_animator_; | 146 ShelfBackgroundAnimator background_animator_; |
| 147 | 147 |
| 148 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). | 148 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). |
| 149 // Solid black background that can be made fully opaque. | 149 // Solid black background that can be made fully opaque. |
| 150 ui::Layer opaque_background_; | 150 ui::Layer opaque_background_; |
| 151 | 151 |
| 152 // The background type to use when the widget is visible. When not visible, | 152 // The background type to use when the widget is visible. When not visible, |
| 153 // the widget uses SHELF_BACKGROUND_DEFAULT. | 153 // the widget uses SHELF_BACKGROUND_DEFAULT. |
| 154 ShelfBackgroundType visible_background_type_; | 154 ShelfBackgroundType visible_background_type_; |
| 155 | 155 |
| 156 // Whether the widget should animate to |visible_background_type_|. | 156 // Whether the widget should animate to |visible_background_type_|. |
| 157 BackgroundAnimatorChangeType visible_background_change_type_; | 157 gfx::AnimationChangeType visible_background_change_type_; |
| 158 | 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget); | 159 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 namespace { | 162 namespace { |
| 163 | 163 |
| 164 // Returns true if a window is a popup or a transient child. | 164 // Returns true if a window is a popup or a transient child. |
| 165 bool IsPopupOrTransient(const WmWindow* window) { | 165 bool IsPopupOrTransient(const WmWindow* window) { |
| 166 return (window->GetType() == ui::wm::WINDOW_TYPE_POPUP || | 166 return (window->GetType() == ui::wm::WINDOW_TYPE_POPUP || |
| 167 window->GetTransientParent()); | 167 window->GetTransientParent()); |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 const gfx::Rect& keyboard_bounds) { | 1319 const gfx::Rect& keyboard_bounds) { |
| 1320 // This bounds change will have caused a change to the Shelf which does not | 1320 // This bounds change will have caused a change to the Shelf which does not |
| 1321 // propagate automatically to this class, so manually recalculate bounds. | 1321 // propagate automatically to this class, so manually recalculate bounds. |
| 1322 Relayout(); | 1322 Relayout(); |
| 1323 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1323 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1324 } | 1324 } |
| 1325 | 1325 |
| 1326 void DockedWindowLayoutManager::OnKeyboardClosed() {} | 1326 void DockedWindowLayoutManager::OnKeyboardClosed() {} |
| 1327 | 1327 |
| 1328 } // namespace ash | 1328 } // namespace ash |
| OLD | NEW |