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/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
| 9 #include "ash/common/shelf/shelf_constants.h" |
| 10 #include "ash/common/shelf/wm_shelf_util.h" |
9 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
10 #include "ash/common/wm/shelf/wm_shelf_constants.h" | |
11 #include "ash/common/wm/shelf/wm_shelf_util.h" | |
12 #include "ash/common/wm_root_window_controller.h" | 12 #include "ash/common/wm_root_window_controller.h" |
13 #include "ash/focus_cycler.h" | 13 #include "ash/focus_cycler.h" |
14 #include "ash/session/session_state_delegate.h" | 14 #include "ash/session/session_state_delegate.h" |
15 #include "ash/shelf/shelf_constants.h" | |
16 #include "ash/shelf/shelf_delegate.h" | 15 #include "ash/shelf/shelf_delegate.h" |
17 #include "ash/shelf/shelf_layout_manager.h" | 16 #include "ash/shelf/shelf_layout_manager.h" |
18 #include "ash/shelf/shelf_model.h" | 17 #include "ash/shelf/shelf_model.h" |
19 #include "ash/shelf/shelf_navigator.h" | 18 #include "ash/shelf/shelf_navigator.h" |
20 #include "ash/shelf/shelf_util.h" | 19 #include "ash/shelf/shelf_util.h" |
21 #include "ash/shelf/shelf_view.h" | 20 #include "ash/shelf/shelf_view.h" |
22 #include "ash/shelf/shelf_widget.h" | 21 #include "ash/shelf/shelf_widget.h" |
23 #include "ash/shell.h" | 22 #include "ash/shell.h" |
24 #include "ash/system/tray/system_tray_delegate.h" | 23 #include "ash/system/tray/system_tray_delegate.h" |
25 #include "ash/wm/status_area_layout_manager.h" | 24 #include "ash/wm/status_area_layout_manager.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) | 175 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) |
177 SetHovered(is_hovered_); | 176 SetHovered(is_hovered_); |
178 } | 177 } |
179 | 178 |
180 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { | 179 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { |
181 SkPaint paint; | 180 SkPaint paint; |
182 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 181 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
183 gfx::ImageSkia shelf_background = | 182 gfx::ImageSkia shelf_background = |
184 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); | 183 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); |
185 | 184 |
186 if (!wm::IsHorizontalAlignment(shelf_->GetAlignment())) { | 185 if (!IsHorizontalAlignment(shelf_->GetAlignment())) { |
187 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 186 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
188 shelf_background, shelf_->GetAlignment() == wm::SHELF_ALIGNMENT_LEFT | 187 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT |
189 ? SkBitmapOperations::ROTATION_90_CW | 188 ? SkBitmapOperations::ROTATION_90_CW |
190 : SkBitmapOperations::ROTATION_270_CW); | 189 : SkBitmapOperations::ROTATION_270_CW); |
191 } | 190 } |
192 paint.setAlpha(alpha_); | 191 paint.setAlpha(alpha_); |
193 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(), | 192 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(), |
194 shelf_background.height(), 0, 0, width(), height(), | 193 shelf_background.height(), 0, 0, width(), height(), |
195 false, paint); | 194 false, paint); |
196 } | 195 } |
197 | 196 |
198 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) | 197 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 shelf_->AddObserver(this); | 247 shelf_->AddObserver(this); |
249 } | 248 } |
250 | 249 |
251 ~ShelfWindowTargeter() override { | 250 ~ShelfWindowTargeter() override { |
252 // |shelf_| may have been destroyed by this time. | 251 // |shelf_| may have been destroyed by this time. |
253 if (shelf_) | 252 if (shelf_) |
254 shelf_->RemoveObserver(this); | 253 shelf_->RemoveObserver(this); |
255 } | 254 } |
256 | 255 |
257 private: | 256 private: |
258 gfx::Insets GetInsetsForAlignment(int distance, | 257 gfx::Insets GetInsetsForAlignment(int distance, ShelfAlignment alignment) { |
259 wm::ShelfAlignment alignment) { | 258 if (alignment == SHELF_ALIGNMENT_LEFT) |
260 if (alignment == wm::SHELF_ALIGNMENT_LEFT) | |
261 return gfx::Insets(0, 0, 0, distance); | 259 return gfx::Insets(0, 0, 0, distance); |
262 if (alignment == wm::SHELF_ALIGNMENT_RIGHT) | 260 if (alignment == SHELF_ALIGNMENT_RIGHT) |
263 return gfx::Insets(0, distance, 0, 0); | 261 return gfx::Insets(0, distance, 0, 0); |
264 return gfx::Insets(distance, 0, 0, 0); | 262 return gfx::Insets(distance, 0, 0, 0); |
265 } | 263 } |
266 | 264 |
267 // ShelfLayoutManagerObserver: | 265 // ShelfLayoutManagerObserver: |
268 void WillDeleteShelfLayoutManager() override { | 266 void WillDeleteShelfLayoutManager() override { |
269 shelf_->RemoveObserver(this); | 267 shelf_->RemoveObserver(this); |
270 shelf_ = NULL; | 268 shelf_ = NULL; |
271 } | 269 } |
272 | 270 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { | 444 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
447 layer->Add(&opaque_background_); | 445 layer->Add(&opaque_background_); |
448 layer->Add(&opaque_foreground_); | 446 layer->Add(&opaque_foreground_); |
449 ReorderLayers(); | 447 ReorderLayers(); |
450 } | 448 } |
451 | 449 |
452 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 450 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
453 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 451 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
454 gfx::ImageSkia shelf_background = | 452 gfx::ImageSkia shelf_background = |
455 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); | 453 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
456 const bool horizontal = wm::IsHorizontalAlignment(shelf_->GetAlignment()); | 454 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); |
457 if (!horizontal) { | 455 if (!horizontal) { |
458 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 456 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
459 shelf_background, shelf_->GetAlignment() == wm::SHELF_ALIGNMENT_LEFT | 457 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT |
460 ? SkBitmapOperations::ROTATION_90_CW | 458 ? SkBitmapOperations::ROTATION_90_CW |
461 : SkBitmapOperations::ROTATION_270_CW); | 459 : SkBitmapOperations::ROTATION_270_CW); |
462 } | 460 } |
463 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); | 461 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
464 SkPaint paint; | 462 SkPaint paint; |
465 paint.setAlpha(alpha_); | 463 paint.setAlpha(alpha_); |
466 canvas->DrawImageInt( | 464 canvas->DrawImageInt( |
467 shelf_background, 0, 0, shelf_background.width(), | 465 shelf_background, 0, 0, shelf_background.width(), |
468 shelf_background.height(), | 466 shelf_background.height(), |
469 (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... |
554 | 552 |
555 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { | 553 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { |
556 alpha_ = alpha; | 554 alpha_ = alpha; |
557 SchedulePaint(); | 555 SchedulePaint(); |
558 } | 556 } |
559 | 557 |
560 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, | 558 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
561 WmWindow* wm_status_container, | 559 WmWindow* wm_status_container, |
562 WorkspaceController* workspace_controller) | 560 WorkspaceController* workspace_controller) |
563 : delegate_view_(new DelegateView(this)), | 561 : delegate_view_(new DelegateView(this)), |
564 background_animator_(delegate_view_, 0, wm::kShelfBackgroundAlpha), | 562 background_animator_(delegate_view_, 0, kShelfBackgroundAlpha), |
565 activating_as_fallback_(false) { | 563 activating_as_fallback_(false) { |
566 views::Widget::InitParams params( | 564 views::Widget::InitParams params( |
567 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 565 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
568 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 566 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
569 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 567 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
570 params.delegate = delegate_view_; | 568 params.delegate = delegate_view_; |
571 wm_shelf_container->GetRootWindowController() | 569 wm_shelf_container->GetRootWindowController() |
572 ->ConfigureWidgetInitParamsForContainer( | 570 ->ConfigureWidgetInitParamsForContainer( |
573 this, wm_shelf_container->GetShellWindowId(), ¶ms); | 571 this, wm_shelf_container->GetShellWindowId(), ¶ms); |
574 Init(params); | 572 Init(params); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 607 |
610 ShelfWidget::~ShelfWidget() { | 608 ShelfWidget::~ShelfWidget() { |
611 // Must call Shutdown() before destruction. | 609 // Must call Shutdown() before destruction. |
612 DCHECK(!status_area_widget_); | 610 DCHECK(!status_area_widget_); |
613 Shell::GetInstance()->focus_cycler()->RemoveWidget(this); | 611 Shell::GetInstance()->focus_cycler()->RemoveWidget(this); |
614 SetFocusCycler(nullptr); | 612 SetFocusCycler(nullptr); |
615 RemoveObserver(this); | 613 RemoveObserver(this); |
616 } | 614 } |
617 | 615 |
618 void ShelfWidget::SetPaintsBackground( | 616 void ShelfWidget::SetPaintsBackground( |
619 wm::ShelfBackgroundType background_type, | 617 ShelfBackgroundType background_type, |
620 BackgroundAnimatorChangeType change_type) { | 618 BackgroundAnimatorChangeType change_type) { |
621 ui::Layer* opaque_background = delegate_view_->opaque_background(); | 619 ui::Layer* opaque_background = delegate_view_->opaque_background(); |
622 float target_opacity = | 620 float target_opacity = |
623 (background_type == wm::SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | 621 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
624 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; | 622 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; |
625 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | 623 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { |
626 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | 624 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( |
627 opaque_background->GetAnimator())); | 625 opaque_background->GetAnimator())); |
628 opaque_background_animation->SetTransitionDuration( | 626 opaque_background_animation->SetTransitionDuration( |
629 base::TimeDelta::FromMilliseconds(wm::kTimeToSwitchBackgroundMs)); | 627 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); |
630 } | 628 } |
631 opaque_background->SetOpacity(target_opacity); | 629 opaque_background->SetOpacity(target_opacity); |
632 | 630 |
633 // TODO(mukai): use ui::Layer on both opaque_background and normal background | 631 // TODO(mukai): use ui::Layer on both opaque_background and normal background |
634 // retire background_animator_ at all. It would be simpler. | 632 // retire background_animator_ at all. It would be simpler. |
635 // See also DockedBackgroundWidget::SetPaintsBackground. | 633 // See also DockedBackgroundWidget::SetPaintsBackground. |
636 background_animator_.SetPaintsBackground( | 634 background_animator_.SetPaintsBackground( |
637 background_type != wm::SHELF_BACKGROUND_DEFAULT, change_type); | 635 background_type != SHELF_BACKGROUND_DEFAULT, change_type); |
638 } | 636 } |
639 | 637 |
640 wm::ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 638 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
641 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) | 639 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) |
642 return wm::SHELF_BACKGROUND_MAXIMIZED; | 640 return SHELF_BACKGROUND_MAXIMIZED; |
643 if (background_animator_.paints_background()) | 641 if (background_animator_.paints_background()) |
644 return wm::SHELF_BACKGROUND_OVERLAP; | 642 return SHELF_BACKGROUND_OVERLAP; |
645 | 643 |
646 return wm::SHELF_BACKGROUND_DEFAULT; | 644 return SHELF_BACKGROUND_DEFAULT; |
647 } | 645 } |
648 | 646 |
649 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { | 647 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { |
650 if (IsShelfHiddenBehindBlackBar() == hide) | 648 if (IsShelfHiddenBehindBlackBar() == hide) |
651 return; | 649 return; |
652 | 650 |
653 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); | 651 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); |
654 float target_opacity = hide ? 1.0f : 0.0f; | 652 float target_opacity = hide ? 1.0f : 0.0f; |
655 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; | 653 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; |
656 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings( | 654 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings( |
(...skipping 30 matching lines...) Expand all Loading... |
687 case user::LOGGED_IN_GUEST: | 685 case user::LOGGED_IN_GUEST: |
688 case user::LOGGED_IN_KIOSK_APP: | 686 case user::LOGGED_IN_KIOSK_APP: |
689 case user::LOGGED_IN_NONE: | 687 case user::LOGGED_IN_NONE: |
690 return false; | 688 return false; |
691 } | 689 } |
692 | 690 |
693 NOTREACHED(); | 691 NOTREACHED(); |
694 return false; | 692 return false; |
695 } | 693 } |
696 | 694 |
697 wm::ShelfAlignment ShelfWidget::GetAlignment() const { | 695 ShelfAlignment ShelfWidget::GetAlignment() const { |
698 // TODO(msw): This should not be called before |shelf_| is created. | 696 // TODO(msw): This should not be called before |shelf_| is created. |
699 return shelf_ ? shelf_->alignment() : wm::SHELF_ALIGNMENT_BOTTOM_LOCKED; | 697 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED; |
700 } | 698 } |
701 | 699 |
702 void ShelfWidget::OnShelfAlignmentChanged() { | 700 void ShelfWidget::OnShelfAlignmentChanged() { |
703 status_area_widget_->SetShelfAlignment(GetAlignment()); | 701 status_area_widget_->SetShelfAlignment(GetAlignment()); |
704 delegate_view_->SchedulePaint(); | 702 delegate_view_->SchedulePaint(); |
705 } | 703 } |
706 | 704 |
707 void ShelfWidget::SetDimsShelf(bool dimming) { | 705 void ShelfWidget::SetDimsShelf(bool dimming) { |
708 delegate_view_->SetDimmed(dimming); | 706 delegate_view_->SetDimmed(dimming); |
709 // Repaint all children, allowing updates to reflect dimmed state eg: | 707 // Repaint all children, allowing updates to reflect dimmed state eg: |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); | 810 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); |
813 } | 811 } |
814 | 812 |
815 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { | 813 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { |
816 Widget::OnGestureEvent(event); | 814 Widget::OnGestureEvent(event); |
817 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | 815 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) |
818 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); | 816 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); |
819 } | 817 } |
820 | 818 |
821 } // namespace ash | 819 } // namespace ash |
OLD | NEW |