| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/shelf/shelf_widget.h" | 5 #include "ash/shelf/shelf_widget.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_shelf_aura.h" | 7 #include "ash/aura/wm_shelf_aura.h" |
| 8 #include "ash/common/focus_cycler.h" | 8 #include "ash/common/focus_cycler.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| 11 #include "ash/common/shelf/shelf_background_animator_observer.h" | 11 #include "ash/common/shelf/shelf_background_animator_observer.h" |
| 12 #include "ash/common/shelf/shelf_constants.h" | 12 #include "ash/common/shelf/shelf_constants.h" |
| 13 #include "ash/common/shelf/shelf_delegate.h" | 13 #include "ash/common/shelf/shelf_delegate.h" |
| 14 #include "ash/common/shelf/wm_dimmer_view.h" |
| 14 #include "ash/common/shelf/wm_shelf.h" | 15 #include "ash/common/shelf/wm_shelf.h" |
| 15 #include "ash/common/shelf/wm_shelf_util.h" | 16 #include "ash/common/shelf/wm_shelf_util.h" |
| 16 #include "ash/common/system/status_area_widget.h" | 17 #include "ash/common/system/status_area_widget.h" |
| 17 #include "ash/common/system/tray/system_tray_delegate.h" | 18 #include "ash/common/system/tray/system_tray_delegate.h" |
| 18 #include "ash/common/wm_root_window_controller.h" | 19 #include "ash/common/wm_root_window_controller.h" |
| 19 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 20 #include "ash/common/wm_window.h" | 21 #include "ash/common/wm_window.h" |
| 21 #include "ash/shelf/dimmer_view.h" | |
| 22 #include "ash/shelf/shelf.h" | 22 #include "ash/shelf/shelf.h" |
| 23 #include "ash/shelf/shelf_layout_manager.h" | 23 #include "ash/shelf/shelf_layout_manager.h" |
| 24 #include "ash/wm/status_area_layout_manager.h" | 24 #include "ash/wm/status_area_layout_manager.h" |
| 25 #include "ash/wm/workspace_controller.h" | 25 #include "ash/wm/workspace_controller.h" |
| 26 #include "base/memory/ptr_util.h" | 26 #include "base/memory/ptr_util.h" |
| 27 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/compositor/layer.h" | 29 #include "ui/compositor/layer.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" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // the dimmer is inactive. | 96 // the dimmer is inactive. |
| 97 gfx::Rect GetDimmerBoundsForTest(); | 97 gfx::Rect GetDimmerBoundsForTest(); |
| 98 | 98 |
| 99 // Disable dimming animations for running tests. This needs to be called | 99 // Disable dimming animations for running tests. This needs to be called |
| 100 // prior to the creation of of the dimmer. | 100 // prior to the creation of of the dimmer. |
| 101 void disable_dimming_animations_for_test() { | 101 void disable_dimming_animations_for_test() { |
| 102 disable_dimming_animations_for_test_ = true; | 102 disable_dimming_animations_for_test_ = true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 ShelfWidget* shelf_; | 106 ShelfWidget* shelf_widget_; |
| 107 FocusCycler* focus_cycler_; | 107 FocusCycler* focus_cycler_; |
| 108 int asset_background_alpha_; | 108 int asset_background_alpha_; |
| 109 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). | 109 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). |
| 110 // A black background layer which is shown when a maximized window is visible. | 110 // A black background layer which is shown when a maximized window is visible. |
| 111 ui::Layer opaque_background_; | 111 ui::Layer opaque_background_; |
| 112 // A black foreground layer which is shown while transitioning between users. | 112 // A black foreground layer which is shown while transitioning between users. |
| 113 // Note: Since the back- and foreground layers have different functions they | 113 // Note: Since the back- and foreground layers have different functions they |
| 114 // can be used simultaneously - so no repurposing possible. | 114 // can be used simultaneously - so no repurposing possible. |
| 115 ui::Layer opaque_foreground_; | 115 ui::Layer opaque_foreground_; |
| 116 | 116 |
| 117 // The view which does the dimming. | 117 // The interface for the view which does the dimming. Null if the shelf is not |
| 118 DimmerView* dimmer_view_; | 118 // being dimmed, or if dimming is not supported (e.g. for mus). |
| 119 WmDimmerView* dimmer_view_; |
| 119 | 120 |
| 120 // True if dimming animations should be turned off. | 121 // True if dimming animations should be turned off. |
| 121 bool disable_dimming_animations_for_test_; | 122 bool disable_dimming_animations_for_test_; |
| 122 | 123 |
| 123 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 124 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) | 127 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget) |
| 127 : shelf_(shelf), | 128 : shelf_widget_(shelf_widget), |
| 128 focus_cycler_(nullptr), | 129 focus_cycler_(nullptr), |
| 129 asset_background_alpha_(0), | 130 asset_background_alpha_(0), |
| 130 opaque_background_(ui::LAYER_SOLID_COLOR), | 131 opaque_background_(ui::LAYER_SOLID_COLOR), |
| 131 opaque_foreground_(ui::LAYER_SOLID_COLOR), | 132 opaque_foreground_(ui::LAYER_SOLID_COLOR), |
| 132 dimmer_view_(nullptr), | 133 dimmer_view_(nullptr), |
| 133 disable_dimming_animations_for_test_(false) { | 134 disable_dimming_animations_for_test_(false) { |
| 134 SetLayoutManager(new views::FillLayout()); | 135 SetLayoutManager(new views::FillLayout()); |
| 135 set_allow_deactivate_on_esc(true); | 136 set_allow_deactivate_on_esc(true); |
| 136 opaque_background_.SetColor(SK_ColorBLACK); | 137 opaque_background_.SetColor(SK_ColorBLACK); |
| 137 opaque_background_.SetBounds(GetLocalBounds()); | 138 opaque_background_.SetBounds(GetLocalBounds()); |
| 138 opaque_background_.SetOpacity(0.0f); | 139 opaque_background_.SetOpacity(0.0f); |
| 139 opaque_foreground_.SetColor(SK_ColorBLACK); | 140 opaque_foreground_.SetColor(SK_ColorBLACK); |
| 140 opaque_foreground_.SetBounds(GetLocalBounds()); | 141 opaque_foreground_.SetBounds(GetLocalBounds()); |
| 141 opaque_foreground_.SetOpacity(0.0f); | 142 opaque_foreground_.SetOpacity(0.0f); |
| 142 } | 143 } |
| 143 | 144 |
| 144 ShelfWidget::DelegateView::~DelegateView() { | 145 ShelfWidget::DelegateView::~DelegateView() { |
| 145 // Make sure that the dimmer goes away since it might have set an observer. | 146 // Make sure that the dimmer goes away since it might have set an observer. |
| 146 SetDimmed(false); | 147 SetDimmed(false); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void ShelfWidget::DelegateView::SetDimmed(bool dimmed) { | 150 void ShelfWidget::DelegateView::SetDimmed(bool dimmed) { |
| 150 if (dimmed == (dimmer_view_ != nullptr)) | 151 // When starting dimming, attempt to create a dimmer view. |
| 152 if (dimmed) { |
| 153 if (!dimmer_view_) { |
| 154 // The WmShelf interface is private in WmShelfAura. |
| 155 WmShelf* shelf = static_cast<WmShelf*>(shelf_widget_->wm_shelf_aura_); |
| 156 dimmer_view_ = |
| 157 shelf->CreateDimmerView(disable_dimming_animations_for_test_); |
| 158 } |
| 151 return; | 159 return; |
| 160 } |
| 152 | 161 |
| 153 if (dimmed) { | 162 // Close the dimmer widget when stopping dimming. |
| 154 dimmer_view_ = DimmerView::Create(shelf_->wm_shelf_aura_, | 163 if (dimmer_view_) { |
| 155 disable_dimming_animations_for_test_); | 164 dimmer_view_->GetDimmerWidget()->CloseNow(); |
| 156 } else { | |
| 157 dimmer_view_->GetWidget()->CloseNow(); | |
| 158 dimmer_view_ = nullptr; | 165 dimmer_view_ = nullptr; |
| 159 } | 166 } |
| 160 } | 167 } |
| 161 | 168 |
| 162 bool ShelfWidget::DelegateView::GetDimmed() const { | 169 bool ShelfWidget::DelegateView::GetDimmed() const { |
| 163 return dimmer_view_ && dimmer_view_->GetWidget()->IsVisible(); | 170 return dimmer_view_ && dimmer_view_->GetDimmerWidget()->IsVisible(); |
| 164 } | 171 } |
| 165 | 172 |
| 166 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { | 173 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
| 167 layer->Add(&opaque_background_); | 174 layer->Add(&opaque_background_); |
| 168 layer->Add(&opaque_foreground_); | 175 layer->Add(&opaque_foreground_); |
| 169 ReorderLayers(); | 176 ReorderLayers(); |
| 170 } | 177 } |
| 171 | 178 |
| 172 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 179 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
| 173 if (MaterialDesignController::IsShelfMaterial()) | 180 if (MaterialDesignController::IsShelfMaterial()) |
| 174 return; | 181 return; |
| 175 | 182 |
| 176 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 183 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 177 gfx::ImageSkia shelf_background = | 184 gfx::ImageSkia shelf_background = |
| 178 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); | 185 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
| 179 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); | 186 const bool horizontal = IsHorizontalAlignment(shelf_widget_->GetAlignment()); |
| 180 if (!horizontal) { | 187 if (!horizontal) { |
| 181 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 188 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 182 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | 189 shelf_background, shelf_widget_->GetAlignment() == SHELF_ALIGNMENT_LEFT |
| 183 ? SkBitmapOperations::ROTATION_90_CW | 190 ? SkBitmapOperations::ROTATION_90_CW |
| 184 : SkBitmapOperations::ROTATION_270_CW); | 191 : SkBitmapOperations::ROTATION_270_CW); |
| 185 } | 192 } |
| 186 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); | 193 const gfx::Rect dock_bounds( |
| 194 shelf_widget_->shelf_layout_manager()->dock_bounds()); |
| 187 SkPaint paint; | 195 SkPaint paint; |
| 188 paint.setAlpha(asset_background_alpha_); | 196 paint.setAlpha(asset_background_alpha_); |
| 189 canvas->DrawImageInt( | 197 canvas->DrawImageInt( |
| 190 shelf_background, 0, 0, shelf_background.width(), | 198 shelf_background, 0, 0, shelf_background.width(), |
| 191 shelf_background.height(), | 199 shelf_background.height(), |
| 192 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) | 200 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) |
| 193 ? dock_bounds.width() | 201 ? dock_bounds.width() |
| 194 : 0, | 202 : 0, |
| 195 0, horizontal ? width() - dock_bounds.width() : width(), height(), false, | 203 0, horizontal ? width() - dock_bounds.width() : width(), height(), false, |
| 196 paint); | 204 paint); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 211 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. | 219 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. |
| 212 // This avoids showing the border 3D shadow between the shelf and the | 220 // This avoids showing the border 3D shadow between the shelf and the |
| 213 // dock. | 221 // dock. |
| 214 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, | 222 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, |
| 215 shelf_background.width(), 1, | 223 shelf_background.width(), 1, |
| 216 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, | 224 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, |
| 217 0, dock_bounds.width() - height(), height(), false, | 225 0, dock_bounds.width() - height(), height(), false, |
| 218 paint); | 226 paint); |
| 219 } | 227 } |
| 220 gfx::Rect black_rect = | 228 gfx::Rect black_rect = |
| 221 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | 229 shelf_widget_->shelf_layout_manager()->SelectValueForShelfAlignment( |
| 222 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), | 230 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), |
| 223 gfx::Rect(0, 0, kNumBlackPixels, height()), | 231 gfx::Rect(0, 0, kNumBlackPixels, height()), |
| 224 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height())); | 232 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height())); |
| 225 canvas->FillRect(black_rect, SK_ColorBLACK); | 233 canvas->FillRect(black_rect, SK_ColorBLACK); |
| 226 } | 234 } |
| 227 | 235 |
| 228 bool ShelfWidget::DelegateView::CanActivate() const { | 236 bool ShelfWidget::DelegateView::CanActivate() const { |
| 229 // Allow to activate as fallback. | 237 // Allow to activate as fallback. |
| 230 if (shelf_->activating_as_fallback_) | 238 if (shelf_widget_->activating_as_fallback_) |
| 231 return true; | 239 return true; |
| 232 // Allow to activate from the focus cycler. | 240 // Allow to activate from the focus cycler. |
| 233 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) | 241 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) |
| 234 return true; | 242 return true; |
| 235 // Disallow activating in other cases, especially when using mouse. | 243 // Disallow activating in other cases, especially when using mouse. |
| 236 return false; | 244 return false; |
| 237 } | 245 } |
| 238 | 246 |
| 239 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { | 247 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { |
| 240 views::View::ReorderChildLayers(parent_layer); | 248 views::View::ReorderChildLayers(parent_layer); |
| 241 parent_layer->StackAtBottom(&opaque_background_); | 249 parent_layer->StackAtBottom(&opaque_background_); |
| 242 parent_layer->StackAtTop(&opaque_foreground_); | 250 parent_layer->StackAtTop(&opaque_foreground_); |
| 243 } | 251 } |
| 244 | 252 |
| 245 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { | 253 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { |
| 246 opaque_background_.SetBounds(GetLocalBounds()); | 254 opaque_background_.SetBounds(GetLocalBounds()); |
| 247 opaque_foreground_.SetBounds(GetLocalBounds()); | 255 opaque_foreground_.SetBounds(GetLocalBounds()); |
| 248 if (dimmer_view_) | 256 if (dimmer_view_) |
| 249 dimmer_view_->GetWidget()->SetBounds(GetBoundsInScreen()); | 257 dimmer_view_->GetDimmerWidget()->SetBounds(GetBoundsInScreen()); |
| 250 } | 258 } |
| 251 | 259 |
| 252 void ShelfWidget::DelegateView::ForceUndimming(bool force) { | 260 void ShelfWidget::DelegateView::ForceUndimming(bool force) { |
| 253 if (GetDimmed()) | 261 if (GetDimmed()) |
| 254 dimmer_view_->ForceUndimming(force); | 262 dimmer_view_->ForceUndimming(force); |
| 255 } | 263 } |
| 256 | 264 |
| 257 int ShelfWidget::DelegateView::GetDimmingAlphaForTest() { | 265 int ShelfWidget::DelegateView::GetDimmingAlphaForTest() { |
| 258 if (GetDimmed()) | 266 if (GetDimmed()) |
| 259 return dimmer_view_->get_dimming_alpha_for_test(); | 267 return dimmer_view_->GetDimmingAlphaForTest(); |
| 260 return -1; | 268 return -1; |
| 261 } | 269 } |
| 262 | 270 |
| 263 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { | 271 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { |
| 264 if (GetDimmed()) | 272 if (GetDimmed()) |
| 265 return dimmer_view_->GetBoundsInScreen(); | 273 return dimmer_view_->GetDimmerWidget()->GetWindowBoundsInScreen(); |
| 266 return gfx::Rect(); | 274 return gfx::Rect(); |
| 267 } | 275 } |
| 268 | 276 |
| 269 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { | 277 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { |
| 270 const float kMaxAlpha = 255.0f; | 278 const float kMaxAlpha = 255.0f; |
| 271 opaque_background_.SetOpacity(alpha / kMaxAlpha); | 279 opaque_background_.SetOpacity(alpha / kMaxAlpha); |
| 272 } | 280 } |
| 273 | 281 |
| 274 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { | 282 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { |
| 275 asset_background_alpha_ = alpha; | 283 asset_background_alpha_ = alpha; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 } | 506 } |
| 499 | 507 |
| 500 gfx::Rect ShelfWidget::GetDimmerBoundsForTest() { | 508 gfx::Rect ShelfWidget::GetDimmerBoundsForTest() { |
| 501 if (delegate_view_) | 509 if (delegate_view_) |
| 502 return delegate_view_->GetDimmerBoundsForTest(); | 510 return delegate_view_->GetDimmerBoundsForTest(); |
| 503 return gfx::Rect(); | 511 return gfx::Rect(); |
| 504 } | 512 } |
| 505 | 513 |
| 506 void ShelfWidget::DisableDimmingAnimationsForTest() { | 514 void ShelfWidget::DisableDimmingAnimationsForTest() { |
| 507 DCHECK(delegate_view_); | 515 DCHECK(delegate_view_); |
| 508 return delegate_view_->disable_dimming_animations_for_test(); | 516 delegate_view_->disable_dimming_animations_for_test(); |
| 509 } | 517 } |
| 510 | 518 |
| 511 void ShelfWidget::UpdateShelfItemBackground(int alpha) { | 519 void ShelfWidget::UpdateShelfItemBackground(int alpha) { |
| 512 if (shelf_) | 520 if (shelf_) |
| 513 shelf_->UpdateShelfItemBackground(alpha); | 521 shelf_->UpdateShelfItemBackground(alpha); |
| 514 } | 522 } |
| 515 | 523 |
| 516 void ShelfWidget::WillDeleteShelfLayoutManager() { | 524 void ShelfWidget::WillDeleteShelfLayoutManager() { |
| 517 shelf_layout_manager_->RemoveObserver(this); | 525 shelf_layout_manager_->RemoveObserver(this); |
| 518 shelf_layout_manager_ = nullptr; | 526 shelf_layout_manager_ = nullptr; |
| 519 } | 527 } |
| 520 | 528 |
| 521 } // namespace ash | 529 } // namespace ash |
| OLD | NEW |