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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 bool disable_dimming_animations_for_test) | 136 bool disable_dimming_animations_for_test) |
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, ash::CHANGE_IMMEDIATE); |
148 ash::internal::BackgroundAnimator::CHANGE_IMMEDIATE); | |
149 SetHovered(false); | 147 SetHovered(false); |
150 } | 148 } |
151 | 149 |
152 DimmerView::~DimmerView() { | 150 DimmerView::~DimmerView() { |
153 } | 151 } |
154 | 152 |
155 void DimmerView::SetHovered(bool hovered) { | 153 void DimmerView::SetHovered(bool hovered) { |
156 // Remember the hovered state so that we can correct the state once a | 154 // Remember the hovered state so that we can correct the state once a |
157 // possible force state has disappeared. | 155 // possible force state has disappeared. |
158 is_hovered_ = hovered; | 156 is_hovered_ = hovered; |
159 // Undimm also if we were forced to by e.g. an open menu. | 157 // Undimm also if we were forced to by e.g. an open menu. |
160 hovered |= force_hovered_; | 158 hovered |= force_hovered_; |
161 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); | 159 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); |
162 background_animator_.SetPaintsBackground(!hovered, | 160 background_animator_.SetPaintsBackground(!hovered, |
163 disable_dimming_animations_for_test_ ? | 161 disable_dimming_animations_for_test_ ? |
164 ash::internal::BackgroundAnimator::CHANGE_IMMEDIATE : | 162 ash::CHANGE_IMMEDIATE : ash::CHANGE_ANIMATE); |
165 ash::internal::BackgroundAnimator::CHANGE_ANIMATE); | |
166 } | 163 } |
167 | 164 |
168 void DimmerView::ForceUndimming(bool force) { | 165 void DimmerView::ForceUndimming(bool force) { |
169 bool previous = force_hovered_; | 166 bool previous = force_hovered_; |
170 force_hovered_ = force; | 167 force_hovered_ = force; |
171 // If the forced change does change the result we apply the change. | 168 // If the forced change does change the result we apply the change. |
172 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) | 169 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) |
173 SetHovered(is_hovered_); | 170 SetHovered(is_hovered_); |
174 } | 171 } |
175 | 172 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 gfx::ImageSkia launcher_background = | 381 gfx::ImageSkia launcher_background = |
385 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); | 382 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); |
386 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) | 383 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) |
387 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 384 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
388 launcher_background, | 385 launcher_background, |
389 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | 386 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( |
390 SkBitmapOperations::ROTATION_90_CW, | 387 SkBitmapOperations::ROTATION_90_CW, |
391 SkBitmapOperations::ROTATION_90_CW, | 388 SkBitmapOperations::ROTATION_90_CW, |
392 SkBitmapOperations::ROTATION_270_CW, | 389 SkBitmapOperations::ROTATION_270_CW, |
393 SkBitmapOperations::ROTATION_180_CW)); | 390 SkBitmapOperations::ROTATION_180_CW)); |
394 | 391 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
| 392 SkPaint paint; |
| 393 paint.setAlpha(alpha_); |
| 394 canvas->DrawImageInt( |
| 395 launcher_background, |
| 396 0, 0, launcher_background.width(), launcher_background.height(), |
| 397 (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() && |
| 398 dock_bounds.x() == 0 && dock_bounds.width() > 0) ? |
| 399 dock_bounds.width() : 0, 0, |
| 400 SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() ? |
| 401 width() - dock_bounds.width() : width(), height(), |
| 402 false, |
| 403 paint); |
| 404 if (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() && |
| 405 dock_bounds.width() > 0) { |
| 406 // The part of the shelf background that is in the corner below the docked |
| 407 // windows close to the work area is an arched gradient that blends |
| 408 // vertically oriented docked background and horizontal shelf. |
| 409 gfx::ImageSkia launcher_corner = |
| 410 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_CORNER); |
| 411 if (dock_bounds.x() == 0) { |
| 412 launcher_corner = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 413 launcher_corner, SkBitmapOperations::ROTATION_90_CW); |
| 414 } |
| 415 canvas->DrawImageInt( |
| 416 launcher_corner, |
| 417 0, 0, launcher_corner.width(), launcher_corner.height(), |
| 418 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(), |
| 419 0, |
| 420 height(), height(), |
| 421 false, |
| 422 paint); |
| 423 // The part of the shelf background that is just below the docked windows |
| 424 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. |
| 425 // This avoids showing the border 3D shadow between the shelf and the dock. |
| 426 canvas->DrawImageInt( |
| 427 launcher_background, |
| 428 0, launcher_background.height() - 1, launcher_background.width(), 1, |
| 429 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, 0, |
| 430 dock_bounds.width() - height(), height(), |
| 431 false, |
| 432 paint); |
| 433 } |
395 gfx::Rect black_rect = | 434 gfx::Rect black_rect = |
396 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | 435 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( |
397 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), | 436 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), |
398 gfx::Rect(0, 0, kNumBlackPixels, height()), | 437 gfx::Rect(0, 0, kNumBlackPixels, height()), |
399 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()), | 438 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()), |
400 gfx::Rect(0, 0, width(), kNumBlackPixels)); | 439 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); | 440 canvas->FillRect(black_rect, SK_ColorBLACK); |
411 } | 441 } |
412 | 442 |
413 bool ShelfWidget::DelegateView::CanActivate() const { | 443 bool ShelfWidget::DelegateView::CanActivate() const { |
414 // Allow to activate as fallback. | 444 // Allow to activate as fallback. |
415 if (shelf_->activating_as_fallback_) | 445 if (shelf_->activating_as_fallback_) |
416 return true; | 446 return true; |
417 // Allow to activate from the focus cycler. | 447 // Allow to activate from the focus cycler. |
418 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) | 448 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) |
419 return true; | 449 return true; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 544 |
515 views::Widget::AddObserver(this); | 545 views::Widget::AddObserver(this); |
516 } | 546 } |
517 | 547 |
518 ShelfWidget::~ShelfWidget() { | 548 ShelfWidget::~ShelfWidget() { |
519 RemoveObserver(this); | 549 RemoveObserver(this); |
520 } | 550 } |
521 | 551 |
522 void ShelfWidget::SetPaintsBackground( | 552 void ShelfWidget::SetPaintsBackground( |
523 ShelfBackgroundType background_type, | 553 ShelfBackgroundType background_type, |
524 internal::BackgroundAnimator::ChangeType change_type) { | 554 BackgroundAnimatorChangeType change_type) { |
525 ui::Layer* opaque_background = delegate_view_->opaque_background(); | 555 ui::Layer* opaque_background = delegate_view_->opaque_background(); |
526 float target_opacity = | 556 float target_opacity = |
527 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | 557 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
528 scoped_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; | 558 scoped_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; |
529 if (change_type != internal::BackgroundAnimator::CHANGE_IMMEDIATE) { | 559 if (change_type != CHANGE_IMMEDIATE) { |
530 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | 560 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( |
531 opaque_background->GetAnimator())); | 561 opaque_background->GetAnimator())); |
532 opaque_background_animation->SetTransitionDuration( | 562 opaque_background_animation->SetTransitionDuration( |
533 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); | 563 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); |
534 } | 564 } |
535 opaque_background->SetOpacity(target_opacity); | 565 opaque_background->SetOpacity(target_opacity); |
536 | 566 |
537 // TODO(mukai): use ui::Layer on both opaque_background and normal background | 567 // TODO(mukai): use ui::Layer on both opaque_background and normal background |
538 // retire background_animator_ at all. It would be simpler. | 568 // retire background_animator_ at all. It would be simpler. |
| 569 // See also DockedBackgroundWidget::SetPaintsBackground. |
539 background_animator_.SetPaintsBackground( | 570 background_animator_.SetPaintsBackground( |
540 background_type != SHELF_BACKGROUND_DEFAULT, | 571 background_type != SHELF_BACKGROUND_DEFAULT, |
541 change_type); | 572 change_type); |
| 573 delegate_view_->SchedulePaint(); |
542 } | 574 } |
543 | 575 |
544 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 576 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
545 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) | 577 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) |
546 return SHELF_BACKGROUND_MAXIMIZED; | 578 return SHELF_BACKGROUND_MAXIMIZED; |
547 if (background_animator_.paints_background()) | 579 if (background_animator_.paints_background()) |
548 return SHELF_BACKGROUND_OVERLAP; | 580 return SHELF_BACKGROUND_OVERLAP; |
549 | 581 |
550 return SHELF_BACKGROUND_DEFAULT; | 582 return SHELF_BACKGROUND_DEFAULT; |
551 } | 583 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 return delegate_view_->GetDimmerBoundsForTest(); | 705 return delegate_view_->GetDimmerBoundsForTest(); |
674 return gfx::Rect(); | 706 return gfx::Rect(); |
675 } | 707 } |
676 | 708 |
677 void ShelfWidget::DisableDimmingAnimationsForTest() { | 709 void ShelfWidget::DisableDimmingAnimationsForTest() { |
678 DCHECK(delegate_view_); | 710 DCHECK(delegate_view_); |
679 return delegate_view_->disable_dimming_animations_for_test(); | 711 return delegate_view_->disable_dimming_animations_for_test(); |
680 } | 712 } |
681 | 713 |
682 } // namespace ash | 714 } // namespace ash |
OLD | NEW |