| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/focus_cycler.h" | 8 #include "ash/focus_cycler.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/session/session_state_delegate.h" | 10 #include "ash/session/session_state_delegate.h" |
| 11 #include "ash/shelf/shelf_constants.h" | 11 #include "ash/shelf/shelf_constants.h" |
| 12 #include "ash/shelf/shelf_delegate.h" | 12 #include "ash/shelf/shelf_delegate.h" |
| 13 #include "ash/shelf/shelf_layout_manager.h" | 13 #include "ash/shelf/shelf_layout_manager.h" |
| 14 #include "ash/shelf/shelf_model.h" | 14 #include "ash/shelf/shelf_model.h" |
| 15 #include "ash/shelf/shelf_navigator.h" | 15 #include "ash/shelf/shelf_navigator.h" |
| 16 #include "ash/shelf/shelf_util.h" | 16 #include "ash/shelf/shelf_util.h" |
| 17 #include "ash/shelf/shelf_view.h" | 17 #include "ash/shelf/shelf_view.h" |
| 18 #include "ash/shelf/shelf_widget.h" | 18 #include "ash/shelf/shelf_widget.h" |
| 19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 20 #include "ash/shell_window_ids.h" | 20 #include "ash/shell_window_ids.h" |
| 21 #include "ash/system/tray/system_tray_delegate.h" | 21 #include "ash/system/tray/system_tray_delegate.h" |
| 22 #include "ash/wm/common/shelf/wm_shelf_constants.h" |
| 22 #include "ash/wm/status_area_layout_manager.h" | 23 #include "ash/wm/status_area_layout_manager.h" |
| 23 #include "ash/wm/window_properties.h" | 24 #include "ash/wm/window_properties.h" |
| 24 #include "ash/wm/workspace_controller.h" | 25 #include "ash/wm/workspace_controller.h" |
| 25 #include "grit/ash_resources.h" | 26 #include "grit/ash_resources.h" |
| 26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
| 27 #include "ui/aura/window_event_dispatcher.h" | 28 #include "ui/aura/window_event_dispatcher.h" |
| 28 #include "ui/aura/window_observer.h" | 29 #include "ui/aura/window_observer.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/compositor/layer.h" | 31 #include "ui/compositor/layer.h" |
| 31 #include "ui/compositor/scoped_layer_animation_settings.h" | 32 #include "ui/compositor/scoped_layer_animation_settings.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 176 } |
| 176 | 177 |
| 177 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { | 178 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { |
| 178 SkPaint paint; | 179 SkPaint paint; |
| 179 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 180 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 180 gfx::ImageSkia shelf_background = | 181 gfx::ImageSkia shelf_background = |
| 181 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); | 182 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); |
| 182 | 183 |
| 183 if (!IsHorizontalAlignment(shelf_->GetAlignment())) { | 184 if (!IsHorizontalAlignment(shelf_->GetAlignment())) { |
| 184 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 185 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 185 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | 186 shelf_background, shelf_->GetAlignment() == wm::SHELF_ALIGNMENT_LEFT |
| 186 ? SkBitmapOperations::ROTATION_90_CW | 187 ? SkBitmapOperations::ROTATION_90_CW |
| 187 : SkBitmapOperations::ROTATION_270_CW); | 188 : SkBitmapOperations::ROTATION_270_CW); |
| 188 } | 189 } |
| 189 paint.setAlpha(alpha_); | 190 paint.setAlpha(alpha_); |
| 190 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(), | 191 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(), |
| 191 shelf_background.height(), 0, 0, width(), height(), | 192 shelf_background.height(), 0, 0, width(), height(), |
| 192 false, paint); | 193 false, paint); |
| 193 } | 194 } |
| 194 | 195 |
| 195 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) | 196 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 shelf_->AddObserver(this); | 246 shelf_->AddObserver(this); |
| 246 } | 247 } |
| 247 | 248 |
| 248 ~ShelfWindowTargeter() override { | 249 ~ShelfWindowTargeter() override { |
| 249 // |shelf_| may have been destroyed by this time. | 250 // |shelf_| may have been destroyed by this time. |
| 250 if (shelf_) | 251 if (shelf_) |
| 251 shelf_->RemoveObserver(this); | 252 shelf_->RemoveObserver(this); |
| 252 } | 253 } |
| 253 | 254 |
| 254 private: | 255 private: |
| 255 gfx::Insets GetInsetsForAlignment(int distance, ShelfAlignment alignment) { | 256 gfx::Insets GetInsetsForAlignment(int distance, |
| 256 if (alignment == SHELF_ALIGNMENT_LEFT) | 257 wm::ShelfAlignment alignment) { |
| 258 if (alignment == wm::SHELF_ALIGNMENT_LEFT) |
| 257 return gfx::Insets(0, 0, 0, distance); | 259 return gfx::Insets(0, 0, 0, distance); |
| 258 if (alignment == SHELF_ALIGNMENT_RIGHT) | 260 if (alignment == wm::SHELF_ALIGNMENT_RIGHT) |
| 259 return gfx::Insets(0, distance, 0, 0); | 261 return gfx::Insets(0, distance, 0, 0); |
| 260 return gfx::Insets(distance, 0, 0, 0); | 262 return gfx::Insets(distance, 0, 0, 0); |
| 261 } | 263 } |
| 262 | 264 |
| 263 // ShelfLayoutManagerObserver: | 265 // ShelfLayoutManagerObserver: |
| 264 void WillDeleteShelf() override { | 266 void WillDeleteShelf() override { |
| 265 shelf_->RemoveObserver(this); | 267 shelf_->RemoveObserver(this); |
| 266 shelf_ = NULL; | 268 shelf_ = NULL; |
| 267 } | 269 } |
| 268 | 270 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 ReorderLayers(); | 447 ReorderLayers(); |
| 446 } | 448 } |
| 447 | 449 |
| 448 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 450 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
| 449 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 451 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 450 gfx::ImageSkia shelf_background = | 452 gfx::ImageSkia shelf_background = |
| 451 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); | 453 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
| 452 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); | 454 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); |
| 453 if (!horizontal) { | 455 if (!horizontal) { |
| 454 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 456 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 455 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | 457 shelf_background, shelf_->GetAlignment() == wm::SHELF_ALIGNMENT_LEFT |
| 456 ? SkBitmapOperations::ROTATION_90_CW | 458 ? SkBitmapOperations::ROTATION_90_CW |
| 457 : SkBitmapOperations::ROTATION_270_CW); | 459 : SkBitmapOperations::ROTATION_270_CW); |
| 458 } | 460 } |
| 459 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); | 461 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
| 460 SkPaint paint; | 462 SkPaint paint; |
| 461 paint.setAlpha(alpha_); | 463 paint.setAlpha(alpha_); |
| 462 canvas->DrawImageInt( | 464 canvas->DrawImageInt( |
| 463 shelf_background, 0, 0, shelf_background.width(), | 465 shelf_background, 0, 0, shelf_background.width(), |
| 464 shelf_background.height(), | 466 shelf_background.height(), |
| 465 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) | 467 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 552 |
| 551 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { | 553 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { |
| 552 alpha_ = alpha; | 554 alpha_ = alpha; |
| 553 SchedulePaint(); | 555 SchedulePaint(); |
| 554 } | 556 } |
| 555 | 557 |
| 556 ShelfWidget::ShelfWidget(aura::Window* shelf_container, | 558 ShelfWidget::ShelfWidget(aura::Window* shelf_container, |
| 557 aura::Window* status_container, | 559 aura::Window* status_container, |
| 558 WorkspaceController* workspace_controller) | 560 WorkspaceController* workspace_controller) |
| 559 : delegate_view_(new DelegateView(this)), | 561 : delegate_view_(new DelegateView(this)), |
| 560 background_animator_(delegate_view_, 0, kShelfBackgroundAlpha), | 562 background_animator_(delegate_view_, 0, wm::kShelfBackgroundAlpha), |
| 561 activating_as_fallback_(false), | 563 activating_as_fallback_(false), |
| 562 window_container_(shelf_container) { | 564 window_container_(shelf_container) { |
| 563 views::Widget::InitParams params( | 565 views::Widget::InitParams params( |
| 564 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 566 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 565 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 567 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 566 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 568 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 567 params.parent = shelf_container; | 569 params.parent = shelf_container; |
| 568 params.delegate = delegate_view_; | 570 params.delegate = delegate_view_; |
| 569 Init(params); | 571 Init(params); |
| 570 | 572 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 598 views::Widget::AddObserver(this); | 600 views::Widget::AddObserver(this); |
| 599 } | 601 } |
| 600 | 602 |
| 601 ShelfWidget::~ShelfWidget() { | 603 ShelfWidget::~ShelfWidget() { |
| 602 Shell::GetInstance()->focus_cycler()->RemoveWidget(this); | 604 Shell::GetInstance()->focus_cycler()->RemoveWidget(this); |
| 603 SetFocusCycler(nullptr); | 605 SetFocusCycler(nullptr); |
| 604 RemoveObserver(this); | 606 RemoveObserver(this); |
| 605 } | 607 } |
| 606 | 608 |
| 607 void ShelfWidget::SetPaintsBackground( | 609 void ShelfWidget::SetPaintsBackground( |
| 608 ShelfBackgroundType background_type, | 610 wm::ShelfBackgroundType background_type, |
| 609 BackgroundAnimatorChangeType change_type) { | 611 BackgroundAnimatorChangeType change_type) { |
| 610 ui::Layer* opaque_background = delegate_view_->opaque_background(); | 612 ui::Layer* opaque_background = delegate_view_->opaque_background(); |
| 611 float target_opacity = | 613 float target_opacity = |
| 612 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | 614 (background_type == wm::SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
| 613 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; | 615 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; |
| 614 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | 616 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { |
| 615 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | 617 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( |
| 616 opaque_background->GetAnimator())); | 618 opaque_background->GetAnimator())); |
| 617 opaque_background_animation->SetTransitionDuration( | 619 opaque_background_animation->SetTransitionDuration( |
| 618 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); | 620 base::TimeDelta::FromMilliseconds(wm::kTimeToSwitchBackgroundMs)); |
| 619 } | 621 } |
| 620 opaque_background->SetOpacity(target_opacity); | 622 opaque_background->SetOpacity(target_opacity); |
| 621 | 623 |
| 622 // TODO(mukai): use ui::Layer on both opaque_background and normal background | 624 // TODO(mukai): use ui::Layer on both opaque_background and normal background |
| 623 // retire background_animator_ at all. It would be simpler. | 625 // retire background_animator_ at all. It would be simpler. |
| 624 // See also DockedBackgroundWidget::SetPaintsBackground. | 626 // See also DockedBackgroundWidget::SetPaintsBackground. |
| 625 background_animator_.SetPaintsBackground( | 627 background_animator_.SetPaintsBackground( |
| 626 background_type != SHELF_BACKGROUND_DEFAULT, | 628 background_type != wm::SHELF_BACKGROUND_DEFAULT, change_type); |
| 627 change_type); | |
| 628 delegate_view_->SchedulePaint(); | 629 delegate_view_->SchedulePaint(); |
| 629 } | 630 } |
| 630 | 631 |
| 631 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 632 wm::ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
| 632 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) | 633 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) |
| 633 return SHELF_BACKGROUND_MAXIMIZED; | 634 return wm::SHELF_BACKGROUND_MAXIMIZED; |
| 634 if (background_animator_.paints_background()) | 635 if (background_animator_.paints_background()) |
| 635 return SHELF_BACKGROUND_OVERLAP; | 636 return wm::SHELF_BACKGROUND_OVERLAP; |
| 636 | 637 |
| 637 return SHELF_BACKGROUND_DEFAULT; | 638 return wm::SHELF_BACKGROUND_DEFAULT; |
| 638 } | 639 } |
| 639 | 640 |
| 640 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { | 641 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { |
| 641 if (IsShelfHiddenBehindBlackBar() == hide) | 642 if (IsShelfHiddenBehindBlackBar() == hide) |
| 642 return; | 643 return; |
| 643 | 644 |
| 644 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); | 645 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); |
| 645 float target_opacity = hide ? 1.0f : 0.0f; | 646 float target_opacity = hide ? 1.0f : 0.0f; |
| 646 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; | 647 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; |
| 647 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings( | 648 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 678 case user::LOGGED_IN_GUEST: | 679 case user::LOGGED_IN_GUEST: |
| 679 case user::LOGGED_IN_KIOSK_APP: | 680 case user::LOGGED_IN_KIOSK_APP: |
| 680 case user::LOGGED_IN_NONE: | 681 case user::LOGGED_IN_NONE: |
| 681 return false; | 682 return false; |
| 682 } | 683 } |
| 683 | 684 |
| 684 NOTREACHED(); | 685 NOTREACHED(); |
| 685 return false; | 686 return false; |
| 686 } | 687 } |
| 687 | 688 |
| 688 ShelfAlignment ShelfWidget::GetAlignment() const { | 689 wm::ShelfAlignment ShelfWidget::GetAlignment() const { |
| 689 // TODO(msw): This should not be called before |shelf_| is created. | 690 // TODO(msw): This should not be called before |shelf_| is created. |
| 690 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED; | 691 return shelf_ ? shelf_->alignment() : wm::SHELF_ALIGNMENT_BOTTOM_LOCKED; |
| 691 } | 692 } |
| 692 | 693 |
| 693 void ShelfWidget::OnShelfAlignmentChanged() { | 694 void ShelfWidget::OnShelfAlignmentChanged() { |
| 694 status_area_widget_->SetShelfAlignment(GetAlignment()); | 695 status_area_widget_->SetShelfAlignment(GetAlignment()); |
| 695 delegate_view_->SchedulePaint(); | 696 delegate_view_->SchedulePaint(); |
| 696 } | 697 } |
| 697 | 698 |
| 698 void ShelfWidget::SetDimsShelf(bool dimming) { | 699 void ShelfWidget::SetDimsShelf(bool dimming) { |
| 699 delegate_view_->SetDimmed(dimming); | 700 delegate_view_->SetDimmed(dimming); |
| 700 // Repaint all children, allowing updates to reflect dimmed state eg: | 701 // Repaint all children, allowing updates to reflect dimmed state eg: |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 DCHECK(delegate_view_); | 786 DCHECK(delegate_view_); |
| 786 return delegate_view_->disable_dimming_animations_for_test(); | 787 return delegate_view_->disable_dimming_animations_for_test(); |
| 787 } | 788 } |
| 788 | 789 |
| 789 void ShelfWidget::WillDeleteShelf() { | 790 void ShelfWidget::WillDeleteShelf() { |
| 790 shelf_layout_manager_->RemoveObserver(this); | 791 shelf_layout_manager_->RemoveObserver(this); |
| 791 shelf_layout_manager_ = NULL; | 792 shelf_layout_manager_ = NULL; |
| 792 } | 793 } |
| 793 | 794 |
| 794 } // namespace ash | 795 } // namespace ash |
| OLD | NEW |