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/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
10 #include "ash/common/focus_cycler.h" | 10 #include "ash/common/focus_cycler.h" |
11 #include "ash/common/material_design/material_design_controller.h" | 11 #include "ash/common/material_design/material_design_controller.h" |
12 #include "ash/common/session/session_state_delegate.h" | 12 #include "ash/common/session/session_state_delegate.h" |
13 #include "ash/common/shelf/shelf_background_animator_observer.h" | |
14 #include "ash/common/shelf/shelf_constants.h" | 13 #include "ash/common/shelf/shelf_constants.h" |
15 #include "ash/common/shelf/shelf_delegate.h" | 14 #include "ash/common/shelf/shelf_delegate.h" |
16 #include "ash/common/shelf/shelf_model.h" | 15 #include "ash/common/shelf/shelf_model.h" |
17 #include "ash/common/shelf/wm_shelf.h" | |
18 #include "ash/common/shelf/wm_shelf_util.h" | 16 #include "ash/common/shelf/wm_shelf_util.h" |
19 #include "ash/common/shell_window_ids.h" | 17 #include "ash/common/shell_window_ids.h" |
20 #include "ash/common/system/status_area_widget.h" | 18 #include "ash/common/system/status_area_widget.h" |
21 #include "ash/common/system/tray/system_tray_delegate.h" | 19 #include "ash/common/system/tray/system_tray_delegate.h" |
22 #include "ash/common/wm_root_window_controller.h" | 20 #include "ash/common/wm_root_window_controller.h" |
23 #include "ash/common/wm_shell.h" | 21 #include "ash/common/wm_shell.h" |
24 #include "ash/shelf/shelf.h" | 22 #include "ash/shelf/shelf.h" |
25 #include "ash/shelf/shelf_layout_manager.h" | 23 #include "ash/shelf/shelf_layout_manager.h" |
26 #include "ash/shelf/shelf_util.h" | 24 #include "ash/shelf/shelf_util.h" |
27 #include "ash/shelf/shelf_view.h" | 25 #include "ash/shelf/shelf_view.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 void SetHovered(bool hovered); | 74 void SetHovered(bool hovered); |
77 | 75 |
78 // Force the dimmer to be undimmed. | 76 // Force the dimmer to be undimmed. |
79 void ForceUndimming(bool force); | 77 void ForceUndimming(bool force); |
80 | 78 |
81 // views::WidgetDelegate overrides: | 79 // views::WidgetDelegate overrides: |
82 views::Widget* GetWidget() override { return View::GetWidget(); } | 80 views::Widget* GetWidget() override { return View::GetWidget(); } |
83 const views::Widget* GetWidget() const override { return View::GetWidget(); } | 81 const views::Widget* GetWidget() const override { return View::GetWidget(); } |
84 | 82 |
85 // BackgroundAnimatorDelegate overrides: | 83 // BackgroundAnimatorDelegate overrides: |
86 void UpdateBackground(BackgroundAnimator* animator, int alpha) override { | 84 void UpdateBackground(int alpha) override { |
87 alpha_ = alpha; | 85 alpha_ = alpha; |
88 SchedulePaint(); | 86 SchedulePaint(); |
89 } | 87 } |
90 | 88 |
91 void BackgroundAnimationEnded(BackgroundAnimator* animator) override {} | |
92 | |
93 // views::View overrides: | 89 // views::View overrides: |
94 void OnPaintBackground(gfx::Canvas* canvas) override; | 90 void OnPaintBackground(gfx::Canvas* canvas) override; |
95 | 91 |
96 // A function to test the current alpha used. | 92 // A function to test the current alpha used. |
97 int get_dimming_alpha_for_test() { return alpha_; } | 93 int get_dimming_alpha_for_test() { return alpha_; } |
98 | 94 |
99 private: | 95 private: |
100 // This class monitors mouse events to see if it is on top of the shelf. | 96 // This class monitors mouse events to see if it is on top of the shelf. |
101 class DimmerEventFilter : public ui::EventHandler { | 97 class DimmerEventFilter : public ui::EventHandler { |
102 public: | 98 public: |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 291 |
296 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); | 292 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); |
297 }; | 293 }; |
298 | 294 |
299 } // namespace | 295 } // namespace |
300 | 296 |
301 // The contents view of the Shelf. This view contains ShelfView and | 297 // The contents view of the Shelf. This view contains ShelfView and |
302 // sizes it to the width of the shelf minus the size of the status area. | 298 // sizes it to the width of the shelf minus the size of the status area. |
303 class ShelfWidget::DelegateView : public views::WidgetDelegate, | 299 class ShelfWidget::DelegateView : public views::WidgetDelegate, |
304 public views::AccessiblePaneView, | 300 public views::AccessiblePaneView, |
305 public aura::WindowObserver, | 301 public BackgroundAnimatorDelegate, |
306 public ShelfBackgroundAnimatorObserver { | 302 public aura::WindowObserver { |
307 public: | 303 public: |
308 explicit DelegateView(ShelfWidget* shelf); | 304 explicit DelegateView(ShelfWidget* shelf); |
309 ~DelegateView() override; | 305 ~DelegateView() override; |
310 | 306 |
311 void set_focus_cycler(FocusCycler* focus_cycler) { | 307 void set_focus_cycler(FocusCycler* focus_cycler) { |
312 focus_cycler_ = focus_cycler; | 308 focus_cycler_ = focus_cycler; |
313 } | 309 } |
314 FocusCycler* focus_cycler() { return focus_cycler_; } | 310 FocusCycler* focus_cycler() { return focus_cycler_; } |
315 | 311 |
316 ui::Layer* opaque_background() { return &opaque_background_; } | 312 ui::Layer* opaque_background() { return &opaque_background_; } |
(...skipping 19 matching lines...) Expand all Loading... |
336 | 332 |
337 // aura::WindowObserver overrides: | 333 // aura::WindowObserver overrides: |
338 // This will be called when the shelf itself changes its absolute position. | 334 // This will be called when the shelf itself changes its absolute position. |
339 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs | 335 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs |
340 // to be repositioned. The difference to the OnBoundsChanged call above is | 336 // to be repositioned. The difference to the OnBoundsChanged call above is |
341 // that this gets also triggered when the shelf only moves. | 337 // that this gets also triggered when the shelf only moves. |
342 void OnWindowBoundsChanged(aura::Window* window, | 338 void OnWindowBoundsChanged(aura::Window* window, |
343 const gfx::Rect& old_bounds, | 339 const gfx::Rect& old_bounds, |
344 const gfx::Rect& new_bounds) override; | 340 const gfx::Rect& new_bounds) override; |
345 | 341 |
346 // ShelfBackgroundAnimatorObserver: | 342 // BackgroundAnimatorDelegate overrides: |
347 void UpdateShelfOpaqueBackground(int alpha) override; | 343 void UpdateBackground(int alpha) override; |
348 void UpdateShelfAssetBackground(int alpha) override; | |
349 | 344 |
350 // Force the shelf to be presented in an undimmed state. | 345 // Force the shelf to be presented in an undimmed state. |
351 void ForceUndimming(bool force); | 346 void ForceUndimming(bool force); |
352 | 347 |
353 // A function to test the current alpha used by the dimming bar. If there is | 348 // A function to test the current alpha used by the dimming bar. If there is |
354 // no dimmer active, the function will return -1. | 349 // no dimmer active, the function will return -1. |
355 int GetDimmingAlphaForTest(); | 350 int GetDimmingAlphaForTest(); |
356 | 351 |
357 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if | 352 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if |
358 // the dimmer is inactive. | 353 // the dimmer is inactive. |
359 gfx::Rect GetDimmerBoundsForTest(); | 354 gfx::Rect GetDimmerBoundsForTest(); |
360 | 355 |
361 // Disable dimming animations for running tests. This needs to be called | 356 // Disable dimming animations for running tests. This needs to be called |
362 // prior to the creation of of the |dimmer_|. | 357 // prior to the creation of of the |dimmer_|. |
363 void disable_dimming_animations_for_test() { | 358 void disable_dimming_animations_for_test() { |
364 disable_dimming_animations_for_test_ = true; | 359 disable_dimming_animations_for_test_ = true; |
365 } | 360 } |
366 | 361 |
367 private: | 362 private: |
368 ShelfWidget* shelf_; | 363 ShelfWidget* shelf_; |
369 std::unique_ptr<views::Widget> dimmer_; | 364 std::unique_ptr<views::Widget> dimmer_; |
370 FocusCycler* focus_cycler_; | 365 FocusCycler* focus_cycler_; |
371 int asset_background_alpha_; | 366 int alpha_; |
372 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). | |
373 // A black background layer which is shown when a maximized window is visible. | 367 // A black background layer which is shown when a maximized window is visible. |
374 ui::Layer opaque_background_; | 368 ui::Layer opaque_background_; |
375 // A black foreground layer which is shown while transitioning between users. | 369 // A black foreground layer which is shown while transitioning between users. |
376 // Note: Since the back- and foreground layers have different functions they | 370 // Note: Since the back- and foreground layers have different functions they |
377 // can be used simultaneously - so no repurposing possible. | 371 // can be used simultaneously - so no repurposing possible. |
378 ui::Layer opaque_foreground_; | 372 ui::Layer opaque_foreground_; |
379 | 373 |
380 // The view which does the dimming. | 374 // The view which does the dimming. |
381 DimmerView* dimmer_view_; | 375 DimmerView* dimmer_view_; |
382 | 376 |
383 // True if dimming animations should be turned off. | 377 // True if dimming animations should be turned off. |
384 bool disable_dimming_animations_for_test_; | 378 bool disable_dimming_animations_for_test_; |
385 | 379 |
386 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 380 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
387 }; | 381 }; |
388 | 382 |
389 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) | 383 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) |
390 : shelf_(shelf), | 384 : shelf_(shelf), |
391 focus_cycler_(NULL), | 385 focus_cycler_(NULL), |
392 asset_background_alpha_(0), | 386 alpha_(0), |
393 opaque_background_(ui::LAYER_SOLID_COLOR), | 387 opaque_background_(ui::LAYER_SOLID_COLOR), |
394 opaque_foreground_(ui::LAYER_SOLID_COLOR), | 388 opaque_foreground_(ui::LAYER_SOLID_COLOR), |
395 dimmer_view_(NULL), | 389 dimmer_view_(NULL), |
396 disable_dimming_animations_for_test_(false) { | 390 disable_dimming_animations_for_test_(false) { |
397 SetLayoutManager(new views::FillLayout()); | 391 SetLayoutManager(new views::FillLayout()); |
398 set_allow_deactivate_on_esc(true); | 392 set_allow_deactivate_on_esc(true); |
399 opaque_background_.SetColor(SK_ColorBLACK); | 393 opaque_background_.SetColor(SK_ColorBLACK); |
400 opaque_background_.SetBounds(GetLocalBounds()); | 394 opaque_background_.SetBounds(GetLocalBounds()); |
401 opaque_background_.SetOpacity(0.0f); | 395 opaque_background_.SetOpacity(0.0f); |
402 opaque_foreground_.SetColor(SK_ColorBLACK); | 396 opaque_foreground_.SetColor(SK_ColorBLACK); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 return dimmer_.get() && dimmer_->IsVisible(); | 439 return dimmer_.get() && dimmer_->IsVisible(); |
446 } | 440 } |
447 | 441 |
448 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { | 442 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
449 layer->Add(&opaque_background_); | 443 layer->Add(&opaque_background_); |
450 layer->Add(&opaque_foreground_); | 444 layer->Add(&opaque_foreground_); |
451 ReorderLayers(); | 445 ReorderLayers(); |
452 } | 446 } |
453 | 447 |
454 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 448 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
455 if (MaterialDesignController::IsShelfMaterial()) | 449 if (MaterialDesignController::IsShelfMaterial()) { |
456 return; | 450 canvas->FillRect(bounds(), SkColorSetA(kShelfBaseColor, alpha_)); |
457 | 451 } else { |
458 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 452 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
459 gfx::ImageSkia shelf_background = | 453 gfx::ImageSkia shelf_background = |
460 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); | 454 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
461 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); | 455 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); |
462 if (!horizontal) { | 456 if (!horizontal) { |
463 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 457 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
464 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | 458 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT |
465 ? SkBitmapOperations::ROTATION_90_CW | 459 ? SkBitmapOperations::ROTATION_90_CW |
466 : SkBitmapOperations::ROTATION_270_CW); | 460 : SkBitmapOperations::ROTATION_270_CW); |
| 461 } |
| 462 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
| 463 SkPaint paint; |
| 464 paint.setAlpha(alpha_); |
| 465 canvas->DrawImageInt( |
| 466 shelf_background, 0, 0, shelf_background.width(), |
| 467 shelf_background.height(), |
| 468 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) |
| 469 ? dock_bounds.width() |
| 470 : 0, |
| 471 0, horizontal ? width() - dock_bounds.width() : width(), height(), |
| 472 false, paint); |
| 473 if (horizontal && dock_bounds.width() > 0) { |
| 474 // The part of the shelf background that is in the corner below the docked |
| 475 // windows close to the work area is an arched gradient that blends |
| 476 // vertically oriented docked background and horizontal shelf. |
| 477 gfx::ImageSkia shelf_corner = |
| 478 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER); |
| 479 if (dock_bounds.x() == 0) { |
| 480 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 481 shelf_corner, SkBitmapOperations::ROTATION_90_CW); |
| 482 } |
| 483 canvas->DrawImageInt(shelf_corner, 0, 0, shelf_corner.width(), |
| 484 shelf_corner.height(), |
| 485 dock_bounds.x() > 0 ? dock_bounds.x() |
| 486 : dock_bounds.width() - height(), |
| 487 0, height(), height(), false, paint); |
| 488 // The part of the shelf background that is just below the docked windows |
| 489 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. |
| 490 // This avoids showing the border 3D shadow between the shelf and the |
| 491 // dock. |
| 492 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, |
| 493 shelf_background.width(), 1, |
| 494 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, |
| 495 0, dock_bounds.width() - height(), height(), false, |
| 496 paint); |
| 497 } |
| 498 gfx::Rect black_rect = |
| 499 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( |
| 500 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), |
| 501 gfx::Rect(0, 0, kNumBlackPixels, height()), |
| 502 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height())); |
| 503 canvas->FillRect(black_rect, SK_ColorBLACK); |
467 } | 504 } |
468 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); | |
469 SkPaint paint; | |
470 paint.setAlpha(asset_background_alpha_); | |
471 canvas->DrawImageInt( | |
472 shelf_background, 0, 0, shelf_background.width(), | |
473 shelf_background.height(), | |
474 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) | |
475 ? dock_bounds.width() | |
476 : 0, | |
477 0, horizontal ? width() - dock_bounds.width() : width(), height(), false, | |
478 paint); | |
479 if (horizontal && dock_bounds.width() > 0) { | |
480 // The part of the shelf background that is in the corner below the docked | |
481 // windows close to the work area is an arched gradient that blends | |
482 // vertically oriented docked background and horizontal shelf. | |
483 gfx::ImageSkia shelf_corner = *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER); | |
484 if (dock_bounds.x() == 0) { | |
485 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage( | |
486 shelf_corner, SkBitmapOperations::ROTATION_90_CW); | |
487 } | |
488 canvas->DrawImageInt( | |
489 shelf_corner, 0, 0, shelf_corner.width(), shelf_corner.height(), | |
490 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(), | |
491 0, height(), height(), false, paint); | |
492 // The part of the shelf background that is just below the docked windows | |
493 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. | |
494 // This avoids showing the border 3D shadow between the shelf and the | |
495 // dock. | |
496 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, | |
497 shelf_background.width(), 1, | |
498 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, | |
499 0, dock_bounds.width() - height(), height(), false, | |
500 paint); | |
501 } | |
502 gfx::Rect black_rect = | |
503 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | |
504 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), | |
505 gfx::Rect(0, 0, kNumBlackPixels, height()), | |
506 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height())); | |
507 canvas->FillRect(black_rect, SK_ColorBLACK); | |
508 } | 505 } |
509 | 506 |
510 bool ShelfWidget::DelegateView::CanActivate() const { | 507 bool ShelfWidget::DelegateView::CanActivate() const { |
511 // Allow to activate as fallback. | 508 // Allow to activate as fallback. |
512 if (shelf_->activating_as_fallback_) | 509 if (shelf_->activating_as_fallback_) |
513 return true; | 510 return true; |
514 // Allow to activate from the focus cycler. | 511 // Allow to activate from the focus cycler. |
515 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) | 512 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) |
516 return true; | 513 return true; |
517 // Disallow activating in other cases, especially when using mouse. | 514 // Disallow activating in other cases, especially when using mouse. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 return dimmer_view_->get_dimming_alpha_for_test(); | 548 return dimmer_view_->get_dimming_alpha_for_test(); |
552 return -1; | 549 return -1; |
553 } | 550 } |
554 | 551 |
555 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { | 552 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { |
556 if (GetDimmed()) | 553 if (GetDimmed()) |
557 return dimmer_view_->GetBoundsInScreen(); | 554 return dimmer_view_->GetBoundsInScreen(); |
558 return gfx::Rect(); | 555 return gfx::Rect(); |
559 } | 556 } |
560 | 557 |
561 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { | 558 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { |
562 const float kMaxAlpha = 255.0f; | 559 alpha_ = alpha; |
563 opaque_background_.SetOpacity(alpha / kMaxAlpha); | |
564 } | |
565 | |
566 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { | |
567 asset_background_alpha_ = alpha; | |
568 SchedulePaint(); | 560 SchedulePaint(); |
569 } | 561 } |
570 | 562 |
571 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, | 563 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
572 WmWindow* wm_status_container, | 564 WmWindow* wm_status_container, |
573 WmShelfAura* wm_shelf_aura, | 565 WmShelfAura* wm_shelf_aura, |
574 WorkspaceController* workspace_controller) | 566 WorkspaceController* workspace_controller) |
575 : wm_shelf_aura_(wm_shelf_aura), | 567 : delegate_view_(new DelegateView(this)), |
576 delegate_view_(new DelegateView(this)), | 568 background_animator_(delegate_view_, |
577 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_), | 569 0, |
| 570 GetShelfConstant(SHELF_BACKGROUND_ALPHA)), |
578 activating_as_fallback_(false) { | 571 activating_as_fallback_(false) { |
579 background_animator_.AddObserver(delegate_view_); | |
580 | |
581 views::Widget::InitParams params( | 572 views::Widget::InitParams params( |
582 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 573 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
583 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 574 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
584 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 575 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
585 params.delegate = delegate_view_; | 576 params.delegate = delegate_view_; |
586 wm_shelf_container->GetRootWindowController() | 577 wm_shelf_container->GetRootWindowController() |
587 ->ConfigureWidgetInitParamsForContainer( | 578 ->ConfigureWidgetInitParamsForContainer( |
588 this, wm_shelf_container->GetShellWindowId(), ¶ms); | 579 this, wm_shelf_container->GetShellWindowId(), ¶ms); |
589 Init(params); | 580 Init(params); |
590 | 581 |
591 // The shelf should not take focus when initially shown. | 582 // The shelf should not take focus when initially shown. |
592 set_focus_on_creation(false); | 583 set_focus_on_creation(false); |
593 SetContentsView(delegate_view_); | 584 SetContentsView(delegate_view_); |
594 delegate_view_->SetParentLayer(GetLayer()); | 585 delegate_view_->SetParentLayer(GetLayer()); |
595 | 586 |
596 shelf_layout_manager_ = new ShelfLayoutManager(this); | 587 shelf_layout_manager_ = new ShelfLayoutManager(this); |
597 shelf_layout_manager_->AddObserver(this); | 588 shelf_layout_manager_->AddObserver(this); |
598 aura::Window* shelf_container = | 589 aura::Window* shelf_container = |
599 WmWindowAura::GetAuraWindow(wm_shelf_container); | 590 WmWindowAura::GetAuraWindow(wm_shelf_container); |
600 shelf_container->SetLayoutManager(shelf_layout_manager_); | 591 shelf_container->SetLayoutManager(shelf_layout_manager_); |
601 shelf_layout_manager_->set_workspace_controller(workspace_controller); | 592 shelf_layout_manager_->set_workspace_controller(workspace_controller); |
602 workspace_controller->SetShelf(shelf_layout_manager_); | 593 workspace_controller->SetShelf(shelf_layout_manager_); |
603 background_animator_.PaintBackground( | 594 wm_shelf_aura->SetShelfLayoutManager(shelf_layout_manager_); |
604 shelf_layout_manager_->GetShelfBackgroundType(), | |
605 BACKGROUND_CHANGE_IMMEDIATE); | |
606 wm_shelf_aura_->SetShelfLayoutManager(shelf_layout_manager_); | |
607 | 595 |
608 // TODO(jamescook): Move ownership to RootWindowController. | 596 // TODO(jamescook): Move ownership to RootWindowController. |
609 status_area_widget_ = | 597 status_area_widget_ = |
610 new StatusAreaWidget(wm_status_container, wm_shelf_aura_); | 598 new StatusAreaWidget(wm_status_container, wm_shelf_aura); |
611 status_area_widget_->CreateTrayViews(); | 599 status_area_widget_->CreateTrayViews(); |
612 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) | 600 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) |
613 status_area_widget_->Show(); | 601 status_area_widget_->Show(); |
614 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); | 602 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); |
615 background_animator_.AddObserver(status_area_widget_); | |
616 | 603 |
617 aura::Window* status_container = | 604 aura::Window* status_container = |
618 WmWindowAura::GetAuraWindow(wm_status_container); | 605 WmWindowAura::GetAuraWindow(wm_status_container); |
619 status_container->SetLayoutManager( | 606 status_container->SetLayoutManager( |
620 new StatusAreaLayoutManager(status_container, this)); | 607 new StatusAreaLayoutManager(status_container, this)); |
621 | 608 |
622 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 609 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
623 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_))); | 610 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_))); |
624 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 611 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
625 new ShelfWindowTargeter(status_container, shelf_layout_manager_))); | 612 new ShelfWindowTargeter(status_container, shelf_layout_manager_))); |
626 | 613 |
627 views::Widget::AddObserver(this); | 614 views::Widget::AddObserver(this); |
628 } | 615 } |
629 | 616 |
630 ShelfWidget::~ShelfWidget() { | 617 ShelfWidget::~ShelfWidget() { |
631 // Must call Shutdown() before destruction. | 618 // Must call Shutdown() before destruction. |
632 DCHECK(!status_area_widget_); | 619 DCHECK(!status_area_widget_); |
633 WmShell::Get()->focus_cycler()->RemoveWidget(this); | 620 WmShell::Get()->focus_cycler()->RemoveWidget(this); |
634 SetFocusCycler(nullptr); | 621 SetFocusCycler(nullptr); |
635 RemoveObserver(this); | 622 RemoveObserver(this); |
636 background_animator_.RemoveObserver(delegate_view_); | |
637 } | 623 } |
638 | 624 |
639 void ShelfWidget::SetPaintsBackground( | 625 void ShelfWidget::SetPaintsBackground( |
640 ShelfBackgroundType background_type, | 626 ShelfBackgroundType background_type, |
641 BackgroundAnimatorChangeType change_type) { | 627 BackgroundAnimatorChangeType change_type) { |
642 background_animator_.PaintBackground(background_type, change_type); | 628 ui::Layer* opaque_background = delegate_view_->opaque_background(); |
| 629 float target_opacity = |
| 630 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
| 631 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; |
| 632 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { |
| 633 opaque_background_animation.reset( |
| 634 new ui::ScopedLayerAnimationSettings(opaque_background->GetAnimator())); |
| 635 opaque_background_animation->SetTransitionDuration( |
| 636 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); |
| 637 } |
| 638 opaque_background->SetOpacity(target_opacity); |
| 639 |
| 640 // TODO(mukai): use ui::Layer on both opaque_background and normal background |
| 641 // retire background_animator_ at all. It would be simpler. |
| 642 // See also DockedBackgroundWidget::SetPaintsBackground. |
| 643 background_animator_.SetPaintsBackground( |
| 644 background_type != SHELF_BACKGROUND_DEFAULT, change_type); |
643 } | 645 } |
644 | 646 |
645 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 647 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
646 return background_animator_.target_background_type(); | 648 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) |
| 649 return SHELF_BACKGROUND_MAXIMIZED; |
| 650 if (background_animator_.paints_background()) |
| 651 return SHELF_BACKGROUND_OVERLAP; |
| 652 |
| 653 return SHELF_BACKGROUND_DEFAULT; |
647 } | 654 } |
648 | 655 |
649 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { | 656 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { |
650 if (IsShelfHiddenBehindBlackBar() == hide) | 657 if (IsShelfHiddenBehindBlackBar() == hide) |
651 return; | 658 return; |
652 | 659 |
653 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); | 660 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); |
654 float target_opacity = hide ? 1.0f : 0.0f; | 661 float target_opacity = hide ? 1.0f : 0.0f; |
655 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; | 662 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; |
656 opaque_foreground_animation.reset( | 663 opaque_foreground_animation.reset( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 // status area background, app list button and overflow button. | 717 // status area background, app list button and overflow button. |
711 if (shelf_) | 718 if (shelf_) |
712 shelf_->SchedulePaint(); | 719 shelf_->SchedulePaint(); |
713 status_area_widget_->SchedulePaint(); | 720 status_area_widget_->SchedulePaint(); |
714 } | 721 } |
715 | 722 |
716 bool ShelfWidget::GetDimsShelf() const { | 723 bool ShelfWidget::GetDimsShelf() const { |
717 return delegate_view_->GetDimmed(); | 724 return delegate_view_->GetDimmed(); |
718 } | 725 } |
719 | 726 |
720 void ShelfWidget::CreateShelf() { | 727 void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) { |
721 DCHECK(!shelf_); | 728 DCHECK(!shelf_); |
722 | 729 |
723 shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura_, this, | 730 shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura, this)); |
724 &background_animator_)); | |
725 // Must be initialized before the delegate is notified because the delegate | 731 // Must be initialized before the delegate is notified because the delegate |
726 // may try to access the WmShelf. | 732 // may try to access the WmShelf. |
727 wm_shelf_aura_->SetShelf(shelf_.get()); | 733 wm_shelf_aura->SetShelf(shelf_.get()); |
728 WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get()); | 734 WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get()); |
729 | 735 |
730 SetFocusCycler(WmShell::Get()->focus_cycler()); | 736 SetFocusCycler(WmShell::Get()->focus_cycler()); |
731 } | 737 } |
732 | 738 |
733 void ShelfWidget::PostCreateShelf() { | 739 void ShelfWidget::PostCreateShelf() { |
734 shelf_->SetVisible( | 740 shelf_->SetVisible( |
735 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); | 741 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); |
736 shelf_layout_manager_->LayoutShelf(); | 742 shelf_layout_manager_->LayoutShelf(); |
737 shelf_layout_manager_->UpdateAutoHideState(); | 743 shelf_layout_manager_->UpdateAutoHideState(); |
(...skipping 21 matching lines...) Expand all Loading... |
759 | 765 |
760 void ShelfWidget::Shutdown() { | 766 void ShelfWidget::Shutdown() { |
761 // Shutting down the status area widget may cause some widgets (e.g. bubbles) | 767 // Shutting down the status area widget may cause some widgets (e.g. bubbles) |
762 // to close, so uninstall the ShelfLayoutManager event filters first. Don't | 768 // to close, so uninstall the ShelfLayoutManager event filters first. Don't |
763 // reset the pointer until later because other widgets (e.g. app list) may | 769 // reset the pointer until later because other widgets (e.g. app list) may |
764 // access it later in shutdown. | 770 // access it later in shutdown. |
765 if (shelf_layout_manager_) | 771 if (shelf_layout_manager_) |
766 shelf_layout_manager_->PrepareForShutdown(); | 772 shelf_layout_manager_->PrepareForShutdown(); |
767 | 773 |
768 if (status_area_widget_) { | 774 if (status_area_widget_) { |
769 background_animator_.RemoveObserver(status_area_widget_); | |
770 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); | 775 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); |
771 status_area_widget_->Shutdown(); | 776 status_area_widget_->Shutdown(); |
772 status_area_widget_ = nullptr; | 777 status_area_widget_ = nullptr; |
773 } | 778 } |
774 } | 779 } |
775 | 780 |
776 void ShelfWidget::ForceUndimming(bool force) { | 781 void ShelfWidget::ForceUndimming(bool force) { |
777 delegate_view_->ForceUndimming(force); | 782 delegate_view_->ForceUndimming(force); |
778 } | 783 } |
779 | 784 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); | 819 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); |
815 } | 820 } |
816 | 821 |
817 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { | 822 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { |
818 Widget::OnGestureEvent(event); | 823 Widget::OnGestureEvent(event); |
819 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | 824 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) |
820 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); | 825 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); |
821 } | 826 } |
822 | 827 |
823 } // namespace ash | 828 } // namespace ash |
OLD | NEW |