OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/launcher/launcher_delegate.h" | 9 #include "ash/launcher/launcher_delegate.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 namespace { | 40 namespace { |
41 // Size of black border at bottom (or side) of launcher. | 41 // Size of black border at bottom (or side) of launcher. |
42 const int kNumBlackPixels = 3; | 42 const int kNumBlackPixels = 3; |
43 // Alpha to paint dimming image with. | 43 // Alpha to paint dimming image with. |
44 const int kDimAlpha = 128; | 44 const int kDimAlpha = 128; |
45 | 45 |
46 // The time to dim and un-dim. | 46 // The time to dim and un-dim. |
47 const int kTimeToDimMs = 3000; // Slow in dimming. | 47 const int kTimeToDimMs = 3000; // Slow in dimming. |
48 const int kTimeToUnDimMs = 200; // Fast in activating. | 48 const int kTimeToUnDimMs = 200; // Fast in activating. |
49 const int kTimeToSwitchBackgroundMs = 1000; | |
50 | 49 |
51 // Class used to slightly dim shelf items when maximized and visible. | 50 // Class used to slightly dim shelf items when maximized and visible. |
52 class DimmerView : public views::View, | 51 class DimmerView : public views::View, |
53 public views::WidgetDelegate, | 52 public views::WidgetDelegate, |
54 ash::internal::BackgroundAnimatorDelegate { | 53 ash::internal::BackgroundAnimatorDelegate { |
55 public: | 54 public: |
56 // If |disable_dimming_animations_for_test| is set, all alpha animations will | 55 // If |disable_dimming_animations_for_test| is set, all alpha animations will |
57 // be performed instantly. | 56 // be performed instantly. |
58 DimmerView(ash::ShelfWidget* shelf_widget, | 57 DimmerView(ash::ShelfWidget* shelf_widget, |
59 bool disable_dimming_animations_for_test); | 58 bool disable_dimming_animations_for_test); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 : shelf_(shelf_widget), | 137 : shelf_(shelf_widget), |
139 alpha_(kDimAlpha), | 138 alpha_(kDimAlpha), |
140 is_hovered_(false), | 139 is_hovered_(false), |
141 force_hovered_(false), | 140 force_hovered_(false), |
142 disable_dimming_animations_for_test_(disable_dimming_animations_for_test), | 141 disable_dimming_animations_for_test_(disable_dimming_animations_for_test), |
143 background_animator_(this, 0, kDimAlpha) { | 142 background_animator_(this, 0, kDimAlpha) { |
144 event_filter_.reset(new DimmerEventFilter(this)); | 143 event_filter_.reset(new DimmerEventFilter(this)); |
145 // Make sure it is undimmed at the beginning and then fire off the dimming | 144 // Make sure it is undimmed at the beginning and then fire off the dimming |
146 // animation. | 145 // animation. |
147 background_animator_.SetPaintsBackground(false, | 146 background_animator_.SetPaintsBackground(false, |
148 ash::internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 147 ash::BACKGROUND_CHANGE_IMMEDIATE); |
149 SetHovered(false); | 148 SetHovered(false); |
150 } | 149 } |
151 | 150 |
152 DimmerView::~DimmerView() { | 151 DimmerView::~DimmerView() { |
153 } | 152 } |
154 | 153 |
155 void DimmerView::SetHovered(bool hovered) { | 154 void DimmerView::SetHovered(bool hovered) { |
156 // Remember the hovered state so that we can correct the state once a | 155 // Remember the hovered state so that we can correct the state once a |
157 // possible force state has disappeared. | 156 // possible force state has disappeared. |
158 is_hovered_ = hovered; | 157 is_hovered_ = hovered; |
159 // Undimm also if we were forced to by e.g. an open menu. | 158 // Undimm also if we were forced to by e.g. an open menu. |
160 hovered |= force_hovered_; | 159 hovered |= force_hovered_; |
161 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); | 160 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); |
162 background_animator_.SetPaintsBackground(!hovered, | 161 background_animator_.SetPaintsBackground(!hovered, |
163 disable_dimming_animations_for_test_ ? | 162 disable_dimming_animations_for_test_ ? |
164 ash::internal::BackgroundAnimator::CHANGE_IMMEDIATE : | 163 ash::BACKGROUND_CHANGE_IMMEDIATE : ash::BACKGROUND_CHANGE_ANIMATE); |
165 ash::internal::BackgroundAnimator::CHANGE_ANIMATE); | |
166 } | 164 } |
167 | 165 |
168 void DimmerView::ForceUndimming(bool force) { | 166 void DimmerView::ForceUndimming(bool force) { |
169 bool previous = force_hovered_; | 167 bool previous = force_hovered_; |
170 force_hovered_ = force; | 168 force_hovered_ = force; |
171 // If the forced change does change the result we apply the change. | 169 // If the forced change does change the result we apply the change. |
172 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) | 170 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) |
173 SetHovered(is_hovered_); | 171 SetHovered(is_hovered_); |
174 } | 172 } |
175 | 173 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 gfx::ImageSkia launcher_background = | 382 gfx::ImageSkia launcher_background = |
385 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); | 383 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); |
386 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) | 384 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) |
387 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 385 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
388 launcher_background, | 386 launcher_background, |
389 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | 387 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( |
390 SkBitmapOperations::ROTATION_90_CW, | 388 SkBitmapOperations::ROTATION_90_CW, |
391 SkBitmapOperations::ROTATION_90_CW, | 389 SkBitmapOperations::ROTATION_90_CW, |
392 SkBitmapOperations::ROTATION_270_CW, | 390 SkBitmapOperations::ROTATION_270_CW, |
393 SkBitmapOperations::ROTATION_180_CW)); | 391 SkBitmapOperations::ROTATION_180_CW)); |
394 | 392 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
| 393 SkPaint paint; |
| 394 paint.setAlpha(alpha_); |
| 395 canvas->DrawImageInt( |
| 396 launcher_background, |
| 397 0, 0, launcher_background.width(), launcher_background.height(), |
| 398 (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() && |
| 399 dock_bounds.x() == 0 && dock_bounds.width() > 0) ? |
| 400 dock_bounds.width() : 0, 0, |
| 401 SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() ? |
| 402 width() - dock_bounds.width() : width(), height(), |
| 403 false, |
| 404 paint); |
| 405 if (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() && |
| 406 dock_bounds.width() > 0) { |
| 407 // The part of the shelf background that is in the corner below the docked |
| 408 // windows close to the work area is an arched gradient that blends |
| 409 // vertically oriented docked background and horizontal shelf. |
| 410 gfx::ImageSkia launcher_corner = |
| 411 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_CORNER); |
| 412 if (dock_bounds.x() == 0) { |
| 413 launcher_corner = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 414 launcher_corner, SkBitmapOperations::ROTATION_90_CW); |
| 415 } |
| 416 canvas->DrawImageInt( |
| 417 launcher_corner, |
| 418 0, 0, launcher_corner.width(), launcher_corner.height(), |
| 419 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(), |
| 420 0, |
| 421 height(), height(), |
| 422 false, |
| 423 paint); |
| 424 // The part of the shelf background that is just below the docked windows |
| 425 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. |
| 426 // This avoids showing the border 3D shadow between the shelf and the dock. |
| 427 canvas->DrawImageInt( |
| 428 launcher_background, |
| 429 0, launcher_background.height() - 1, launcher_background.width(), 1, |
| 430 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, 0, |
| 431 dock_bounds.width() - height(), height(), |
| 432 false, |
| 433 paint); |
| 434 } |
395 gfx::Rect black_rect = | 435 gfx::Rect black_rect = |
396 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | 436 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( |
397 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), | 437 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), |
398 gfx::Rect(0, 0, kNumBlackPixels, height()), | 438 gfx::Rect(0, 0, kNumBlackPixels, height()), |
399 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()), | 439 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()), |
400 gfx::Rect(0, 0, width(), kNumBlackPixels)); | 440 gfx::Rect(0, 0, width(), kNumBlackPixels)); |
401 | |
402 SkPaint paint; | |
403 paint.setAlpha(alpha_); | |
404 canvas->DrawImageInt( | |
405 launcher_background, | |
406 0, 0, launcher_background.width(), launcher_background.height(), | |
407 0, 0, width(), height(), | |
408 false, | |
409 paint); | |
410 canvas->FillRect(black_rect, SK_ColorBLACK); | 441 canvas->FillRect(black_rect, SK_ColorBLACK); |
411 } | 442 } |
412 | 443 |
413 bool ShelfWidget::DelegateView::CanActivate() const { | 444 bool ShelfWidget::DelegateView::CanActivate() const { |
414 // Allow to activate as fallback. | 445 // Allow to activate as fallback. |
415 if (shelf_->activating_as_fallback_) | 446 if (shelf_->activating_as_fallback_) |
416 return true; | 447 return true; |
417 // Allow to activate from the focus cycler. | 448 // Allow to activate from the focus cycler. |
418 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) | 449 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) |
419 return true; | 450 return true; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 545 |
515 views::Widget::AddObserver(this); | 546 views::Widget::AddObserver(this); |
516 } | 547 } |
517 | 548 |
518 ShelfWidget::~ShelfWidget() { | 549 ShelfWidget::~ShelfWidget() { |
519 RemoveObserver(this); | 550 RemoveObserver(this); |
520 } | 551 } |
521 | 552 |
522 void ShelfWidget::SetPaintsBackground( | 553 void ShelfWidget::SetPaintsBackground( |
523 ShelfBackgroundType background_type, | 554 ShelfBackgroundType background_type, |
524 internal::BackgroundAnimator::ChangeType change_type) { | 555 BackgroundAnimatorChangeType change_type) { |
525 ui::Layer* opaque_background = delegate_view_->opaque_background(); | 556 ui::Layer* opaque_background = delegate_view_->opaque_background(); |
526 float target_opacity = | 557 float target_opacity = |
527 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | 558 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
528 scoped_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; | 559 scoped_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; |
529 if (change_type != internal::BackgroundAnimator::CHANGE_IMMEDIATE) { | 560 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { |
530 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | 561 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( |
531 opaque_background->GetAnimator())); | 562 opaque_background->GetAnimator())); |
532 opaque_background_animation->SetTransitionDuration( | 563 opaque_background_animation->SetTransitionDuration( |
533 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); | 564 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); |
534 } | 565 } |
535 opaque_background->SetOpacity(target_opacity); | 566 opaque_background->SetOpacity(target_opacity); |
536 | 567 |
537 // TODO(mukai): use ui::Layer on both opaque_background and normal background | 568 // TODO(mukai): use ui::Layer on both opaque_background and normal background |
538 // retire background_animator_ at all. It would be simpler. | 569 // retire background_animator_ at all. It would be simpler. |
| 570 // See also DockedBackgroundWidget::SetPaintsBackground. |
539 background_animator_.SetPaintsBackground( | 571 background_animator_.SetPaintsBackground( |
540 background_type != SHELF_BACKGROUND_DEFAULT, | 572 background_type != SHELF_BACKGROUND_DEFAULT, |
541 change_type); | 573 change_type); |
| 574 delegate_view_->SchedulePaint(); |
542 } | 575 } |
543 | 576 |
544 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 577 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
545 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) | 578 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) |
546 return SHELF_BACKGROUND_MAXIMIZED; | 579 return SHELF_BACKGROUND_MAXIMIZED; |
547 if (background_animator_.paints_background()) | 580 if (background_animator_.paints_background()) |
548 return SHELF_BACKGROUND_OVERLAP; | 581 return SHELF_BACKGROUND_OVERLAP; |
549 | 582 |
550 return SHELF_BACKGROUND_DEFAULT; | 583 return SHELF_BACKGROUND_DEFAULT; |
551 } | 584 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 return delegate_view_->GetDimmerBoundsForTest(); | 706 return delegate_view_->GetDimmerBoundsForTest(); |
674 return gfx::Rect(); | 707 return gfx::Rect(); |
675 } | 708 } |
676 | 709 |
677 void ShelfWidget::DisableDimmingAnimationsForTest() { | 710 void ShelfWidget::DisableDimmingAnimationsForTest() { |
678 DCHECK(delegate_view_); | 711 DCHECK(delegate_view_); |
679 return delegate_view_->disable_dimming_animations_for_test(); | 712 return delegate_view_->disable_dimming_animations_for_test(); |
680 } | 713 } |
681 | 714 |
682 } // namespace ash | 715 } // namespace ash |
OLD | NEW |