Chromium Code Reviews| 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/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/shelf/shelf_background_animator.h" | |
| 9 #include "ash/common/shelf/shelf_background_animator_observer.h" | |
| 8 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| 9 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
| 10 #include "ash/common/shelf/wm_shelf_observer.h" | 12 #include "ash/common/shelf/wm_shelf_observer.h" |
| 11 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/wm/window_animation_types.h" | 14 #include "ash/common/wm/window_animation_types.h" |
| 13 #include "ash/common/wm/window_parenting_utils.h" | 15 #include "ash/common/wm/window_parenting_utils.h" |
| 14 #include "ash/common/wm/window_resizer.h" | 16 #include "ash/common/wm/window_resizer.h" |
| 15 #include "ash/common/wm/window_state.h" | 17 #include "ash/common/wm/window_state.h" |
| 16 #include "ash/common/wm_lookup.h" | 18 #include "ash/common/wm_lookup.h" |
| 17 #include "ash/common/wm_root_window_controller.h" | 19 #include "ash/common/wm_root_window_controller.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 40 // static | 42 // static |
| 41 const int DockedWindowLayoutManager::kMinDockGap = 2; | 43 const int DockedWindowLayoutManager::kMinDockGap = 2; |
| 42 // static | 44 // static |
| 43 const int DockedWindowLayoutManager::kIdealWidth = 250; | 45 const int DockedWindowLayoutManager::kIdealWidth = 250; |
| 44 const int kMinimumHeight = 250; | 46 const int kMinimumHeight = 250; |
| 45 const int kSlideDurationMs = 120; | 47 const int kSlideDurationMs = 120; |
| 46 const int kFadeDurationMs = 60; | 48 const int kFadeDurationMs = 60; |
| 47 const int kMinimizeDurationMs = 720; | 49 const int kMinimizeDurationMs = 720; |
| 48 | 50 |
| 49 class DockedBackgroundWidget : public views::Widget, | 51 class DockedBackgroundWidget : public views::Widget, |
| 50 public BackgroundAnimatorDelegate, | 52 public WmShelfObserver, |
| 51 public WmShelfObserver { | 53 public ShelfBackgroundAnimatorObserver { |
| 52 public: | 54 public: |
| 53 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) | 55 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) |
| 54 : manager_(manager), | 56 : manager_(manager), |
| 55 alignment_(DOCKED_ALIGNMENT_NONE), | 57 alignment_(DOCKED_ALIGNMENT_NONE), |
| 56 background_animator_(this, 0, GetShelfConstant(SHELF_BACKGROUND_ALPHA)), | 58 asset_background_alpha_(0), |
| 57 alpha_(0), | |
| 58 opaque_background_(ui::LAYER_SOLID_COLOR), | 59 opaque_background_(ui::LAYER_SOLID_COLOR), |
| 59 visible_background_type_(manager_->shelf()->GetBackgroundType()), | 60 visible_background_type_(manager_->shelf()->GetBackgroundType()), |
| 60 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { | 61 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { |
| 61 manager_->shelf()->AddObserver(this); | 62 manager_->shelf()->AddObserver(this); |
| 62 InitWidget(manager_->dock_container()); | 63 InitWidget(manager_->dock_container()); |
| 64 | |
| 65 background_animator_.AddObserver(this); | |
| 66 background_animator_.PaintBackground(SHELF_BACKGROUND_DEFAULT, | |
| 67 BACKGROUND_CHANGE_IMMEDIATE); | |
| 63 } | 68 } |
| 64 | 69 |
| 65 ~DockedBackgroundWidget() override { | 70 ~DockedBackgroundWidget() override { |
| 66 manager_->shelf()->RemoveObserver(this); | 71 manager_->shelf()->RemoveObserver(this); |
|
James Cook
2016/06/14 17:50:02
background_animator_.RemoveObserver?
bruthig
2016/07/26 19:50:03
Done.
| |
| 67 } | 72 } |
| 68 | 73 |
| 69 // Sets widget bounds and sizes opaque background layer to fill the widget. | 74 // Sets widget bounds and sizes opaque background layer to fill the widget. |
| 70 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) { | 75 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) { |
| 71 SetBounds(bounds); | 76 SetBounds(bounds); |
| 72 opaque_background_.SetBounds(gfx::Rect(bounds.size())); | 77 opaque_background_.SetBounds(gfx::Rect(bounds.size())); |
| 73 alignment_ = alignment; | 78 alignment_ = alignment; |
| 74 } | 79 } |
| 75 | 80 |
| 76 private: | 81 private: |
| 77 // views::Widget: | 82 // views::Widget: |
| 78 void OnNativeWidgetVisibilityChanged(bool visible) override { | 83 void OnNativeWidgetVisibilityChanged(bool visible) override { |
| 79 views::Widget::OnNativeWidgetVisibilityChanged(visible); | 84 views::Widget::OnNativeWidgetVisibilityChanged(visible); |
| 80 UpdateBackground(); | 85 UpdateBackground(); |
| 81 } | 86 } |
| 82 | 87 |
| 83 void OnNativeWidgetPaint(const ui::PaintContext& context) override { | 88 void OnNativeWidgetPaint(const ui::PaintContext& context) override { |
| 84 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size()); | 89 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size()); |
| 85 ui::PaintRecorder recorder(context, local_window_bounds.size()); | 90 ui::PaintRecorder recorder(context, local_window_bounds.size()); |
| 86 | 91 |
| 87 if (MaterialDesignController::IsShelfMaterial()) { | 92 if (!MaterialDesignController::IsShelfMaterial()) { |
| 88 recorder.canvas()->FillRect( | |
| 89 local_window_bounds, SkColorSetA(kShelfBaseColor, alpha_)); | |
| 90 } else { | |
| 91 const gfx::ImageSkia& shelf_background(alignment_ == DOCKED_ALIGNMENT_LEFT | 93 const gfx::ImageSkia& shelf_background(alignment_ == DOCKED_ALIGNMENT_LEFT |
| 92 ? shelf_background_left_ | 94 ? shelf_background_left_ |
| 93 : shelf_background_right_); | 95 : shelf_background_right_); |
| 94 SkPaint paint; | 96 SkPaint paint; |
| 95 paint.setAlpha(alpha_); | 97 paint.setAlpha(asset_background_alpha_); |
| 96 recorder.canvas()->DrawImageInt( | 98 recorder.canvas()->DrawImageInt( |
| 97 shelf_background, 0, 0, shelf_background.width(), | 99 shelf_background, 0, 0, shelf_background.width(), |
| 98 shelf_background.height(), | 100 shelf_background.height(), |
| 99 alignment_ == DOCKED_ALIGNMENT_LEFT | 101 alignment_ == DOCKED_ALIGNMENT_LEFT |
| 100 ? local_window_bounds.width() - shelf_background.width() | 102 ? local_window_bounds.width() - shelf_background.width() |
| 101 : 0, | 103 : 0, |
| 102 0, shelf_background.width(), local_window_bounds.height(), false, | 104 0, shelf_background.width(), local_window_bounds.height(), false, |
| 103 paint); | 105 paint); |
| 104 recorder.canvas()->DrawImageInt( | 106 recorder.canvas()->DrawImageInt( |
| 105 shelf_background, | 107 shelf_background, |
| 106 alignment_ == DOCKED_ALIGNMENT_LEFT | 108 alignment_ == DOCKED_ALIGNMENT_LEFT |
| 107 ? 0 | 109 ? 0 |
| 108 : shelf_background.width() - 1, | 110 : shelf_background.width() - 1, |
| 109 0, 1, shelf_background.height(), | 111 0, 1, shelf_background.height(), |
| 110 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width(), 0, | 112 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width(), 0, |
| 111 local_window_bounds.width() - shelf_background.width(), | 113 local_window_bounds.width() - shelf_background.width(), |
| 112 local_window_bounds.height(), false, paint); | 114 local_window_bounds.height(), false, paint); |
| 113 } | 115 } |
| 114 } | 116 } |
| 115 | 117 |
| 116 // BackgroundAnimatorDelegate: | 118 // ShelfBackgroundAnimatorObserver: |
| 117 void UpdateBackground(int alpha) override { | 119 void UpdateShelfOpaqueBackground(int alpha) override { |
| 118 alpha_ = alpha; | 120 const double kMaxAlpha = 255.0; |
|
James Cook
2016/06/14 17:50:02
float?
bruthig
2016/07/26 19:50:03
Done.
| |
| 121 opaque_background_.SetOpacity(alpha / kMaxAlpha); | |
| 122 } | |
| 123 | |
| 124 void UpdateShelfAssetBackground(int alpha) override { | |
| 125 asset_background_alpha_ = alpha; | |
| 119 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | 126 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); |
| 120 } | 127 } |
| 121 | 128 |
| 122 // ShelfLayoutManagerObserver: | 129 // ShelfLayoutManagerObserver: |
| 123 void OnBackgroundUpdated(ShelfBackgroundType background_type, | 130 void OnBackgroundUpdated(ShelfBackgroundType background_type, |
| 124 BackgroundAnimatorChangeType change_type) override { | 131 BackgroundAnimatorChangeType change_type) override { |
| 125 // Sets the background type. Starts an animation to transition to | 132 // Sets the background type. Starts an animation to transition to |
| 126 // |background_type| if the widget is visible. If the widget is not visible, | 133 // |background_type| if the widget is visible. If the widget is not visible, |
| 127 // the animation is postponed till the widget becomes visible. | 134 // the animation is postponed till the widget becomes visible. |
| 128 visible_background_type_ = background_type; | 135 visible_background_type_ = background_type; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 } | 175 } |
| 169 | 176 |
| 170 // Transitions to |visible_background_type_| if the widget is visible and to | 177 // Transitions to |visible_background_type_| if the widget is visible and to |
| 171 // SHELF_BACKGROUND_DEFAULT if it is not. | 178 // SHELF_BACKGROUND_DEFAULT if it is not. |
| 172 void UpdateBackground() { | 179 void UpdateBackground() { |
| 173 ShelfBackgroundType background_type = | 180 ShelfBackgroundType background_type = |
| 174 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; | 181 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; |
| 175 BackgroundAnimatorChangeType change_type = | 182 BackgroundAnimatorChangeType change_type = |
| 176 IsVisible() ? visible_background_change_type_ | 183 IsVisible() ? visible_background_change_type_ |
| 177 : BACKGROUND_CHANGE_IMMEDIATE; | 184 : BACKGROUND_CHANGE_IMMEDIATE; |
| 178 | 185 background_animator_.PaintBackground(background_type, change_type); |
| 179 float target_opacity = | |
| 180 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | |
| 181 std::unique_ptr<ui::ScopedLayerAnimationSettings> | |
| 182 opaque_background_animation; | |
| 183 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | |
| 184 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | |
| 185 opaque_background_.GetAnimator())); | |
| 186 opaque_background_animation->SetTransitionDuration( | |
| 187 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); | |
| 188 } | |
| 189 opaque_background_.SetOpacity(target_opacity); | |
| 190 | |
| 191 // TODO(varkha): use ui::Layer on both opaque_background and normal | |
| 192 // background retire background_animator_ at all. It would be simpler. | |
| 193 // See also ShelfWidget::SetPaintsBackground. | |
| 194 background_animator_.SetPaintsBackground( | |
| 195 background_type != SHELF_BACKGROUND_DEFAULT, change_type); | |
| 196 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | 186 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); |
| 197 } | 187 } |
| 198 | 188 |
| 199 DockedWindowLayoutManager* manager_; | 189 DockedWindowLayoutManager* manager_; |
| 200 | 190 |
| 201 DockedAlignment alignment_; | 191 DockedAlignment alignment_; |
| 202 | 192 |
| 203 // The animator for the background transitions. | 193 // The animator for the background transitions. |
| 204 BackgroundAnimator background_animator_; | 194 ShelfBackgroundAnimator background_animator_; |
| 205 | 195 |
| 206 // The alpha to use for drawing image assets covering the docked background. | 196 // The alpha to use for drawing image assets covering the docked background. |
| 207 int alpha_; | 197 int asset_background_alpha_; |
| 208 | 198 |
| 199 // TODO(bruthig): Remove opaque_background_. | |
| 209 // Solid black background that can be made fully opaque. | 200 // Solid black background that can be made fully opaque. |
| 210 ui::Layer opaque_background_; | 201 ui::Layer opaque_background_; |
| 211 | 202 |
| 212 // Backgrounds created from shelf background by 90 or 270 degree rotation. | 203 // Backgrounds created from shelf background by 90 or 270 degree rotation. |
| 213 // TODO(tdanderson): These members can be removed once the material design | 204 // TODO(tdanderson): These members can be removed once the material design |
| 214 // shelf is enabled by default. See crbug.com/614453. | 205 // shelf is enabled by default. See crbug.com/614453. |
| 215 gfx::ImageSkia shelf_background_left_; | 206 gfx::ImageSkia shelf_background_left_; |
| 216 gfx::ImageSkia shelf_background_right_; | 207 gfx::ImageSkia shelf_background_right_; |
| 217 | 208 |
| 218 // The background type to use when the widget is visible. When not visible, | 209 // The background type to use when the widget is visible. When not visible, |
| (...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1325 | 1316 |
| 1326 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1317 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 1327 const gfx::Rect& keyboard_bounds) { | 1318 const gfx::Rect& keyboard_bounds) { |
| 1328 // This bounds change will have caused a change to the Shelf which does not | 1319 // This bounds change will have caused a change to the Shelf which does not |
| 1329 // propagate automatically to this class, so manually recalculate bounds. | 1320 // propagate automatically to this class, so manually recalculate bounds. |
| 1330 Relayout(); | 1321 Relayout(); |
| 1331 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1322 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1332 } | 1323 } |
| 1333 | 1324 |
| 1334 } // namespace ash | 1325 } // namespace ash |
| OLD | NEW |