Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/wm/shadow.h" | 5 #include "ash/wm/shadow.h" |
| 6 | 6 |
| 7 #include "ash/wm/image_grid.h" | 7 #include "ash/wm/image_grid.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 // Shadow opacity for active window. | |
| 15 const float kActiveShadowOpacity = 1.0f; | |
| 16 | |
| 17 // Shadow opacity for inactive window. | |
| 18 const float kInactiveShadowOpacity = 0.2f; | |
| 19 | |
| 20 // Duration for opacity animation in milliseconds. | |
| 21 const int64 kAnimationDurationMs = 200; | |
| 22 | |
| 23 } // namespace | |
| 10 | 24 |
| 11 namespace ash { | 25 namespace ash { |
| 12 namespace internal { | 26 namespace internal { |
| 13 | 27 |
| 14 Shadow::Shadow() { | 28 Shadow::Shadow() : style_(STYLE_ACTIVE) { |
| 15 } | 29 } |
| 16 | 30 |
| 17 Shadow::~Shadow() { | 31 Shadow::~Shadow() { |
| 18 } | 32 } |
| 19 | 33 |
| 20 ui::Layer* Shadow::layer() const { return image_grid_->layer(); } | |
| 21 | |
| 22 void Shadow::Init() { | 34 void Shadow::Init() { |
| 23 image_grid_.reset(new ImageGrid); | 35 image_grid_.reset(new ImageGrid); |
| 24 | 36 UpdateImagesForStyle(); |
| 25 ResourceBundle& res = ResourceBundle::GetSharedInstance(); | 37 image_grid_->layer()->set_name("Shadow"); |
| 26 image_grid_->Init(&res.GetImageNamed(IDR_AURA_SHADOW_RECT_TOP_LEFT), | 38 image_grid_->layer()->SetOpacity( |
| 27 &res.GetImageNamed(IDR_AURA_SHADOW_RECT_TOP), | 39 style_ == STYLE_ACTIVE ? kActiveShadowOpacity : kInactiveShadowOpacity); |
|
Daniel Erat
2012/02/17 00:18:32
mind changing this to a switch statement with a NO
James Cook
2012/02/17 03:41:27
Done.
| |
| 28 &res.GetImageNamed(IDR_AURA_SHADOW_RECT_TOP_RIGHT), | |
| 29 &res.GetImageNamed(IDR_AURA_SHADOW_RECT_LEFT), | |
| 30 NULL, | |
| 31 &res.GetImageNamed(IDR_AURA_SHADOW_RECT_RIGHT), | |
| 32 &res.GetImageNamed(IDR_AURA_SHADOW_RECT_BOTTOM_LEFT), | |
| 33 &res.GetImageNamed(IDR_AURA_SHADOW_RECT_BOTTOM), | |
| 34 &res.GetImageNamed(IDR_AURA_SHADOW_RECT_BOTTOM_RIGHT)); | |
| 35 } | 40 } |
| 36 | 41 |
| 37 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) { | 42 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) { |
| 38 content_bounds_ = content_bounds; | 43 content_bounds_ = content_bounds; |
| 44 UpdateImageGridBounds(); | |
| 45 } | |
| 46 | |
| 47 ui::Layer* Shadow::layer() const { | |
| 48 return image_grid_->layer(); | |
| 49 } | |
| 50 | |
| 51 void Shadow::SetStyle(Style style) { | |
| 52 if (style_ == style) | |
| 53 return; | |
| 54 style_ = style; | |
| 55 | |
| 56 // Stop waiting for any as yet unfinished implicit animations. | |
| 57 StopObservingImplicitAnimations(); | |
| 58 | |
| 59 // If we're becoming active, switch images now. Because the inactive image | |
| 60 // has a very low opacity the switch isn't noticeable and this approach | |
| 61 // allows us to use only a single set of shadow images at a time. | |
| 62 if (style == STYLE_ACTIVE) | |
| 63 UpdateImagesForStyle(); | |
| 64 | |
| 65 { | |
| 66 // Property sets within this scope will be implicitly animated. | |
| 67 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); | |
| 68 settings.AddObserver(this); | |
| 69 settings.SetTransitionDuration( | |
| 70 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | |
| 71 image_grid_->layer()->SetOpacity( | |
| 72 style_ == STYLE_ACTIVE ? kActiveShadowOpacity : kInactiveShadowOpacity); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void Shadow::OnImplicitAnimationsCompleted() { | |
| 77 // If we just finished going inactive, switch images. This doesn't cause | |
| 78 // a visual pop because the inactive image opacity is so low. | |
| 79 if (style_ == STYLE_INACTIVE) | |
| 80 UpdateImagesForStyle(); | |
| 81 } | |
| 82 | |
| 83 void Shadow::UpdateImagesForStyle() { | |
| 84 ResourceBundle& res = ResourceBundle::GetSharedInstance(); | |
| 85 if (style_ == STYLE_ACTIVE) | |
|
Daniel Erat
2012/02/17 00:18:32
nit: change to a switch statement
James Cook
2012/02/17 03:41:27
Done.
| |
| 86 image_grid_->SetImages( | |
| 87 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_TOP_LEFT), | |
| 88 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_TOP), | |
| 89 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_TOP_RIGHT), | |
| 90 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_LEFT), | |
| 91 NULL, | |
| 92 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_RIGHT), | |
| 93 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_BOTTOM_LEFT), | |
| 94 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_BOTTOM), | |
| 95 &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_BOTTOM_RIGHT)); | |
| 96 else | |
| 97 image_grid_->SetImages( | |
| 98 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_TOP_LEFT), | |
| 99 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_TOP), | |
| 100 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_TOP_RIGHT), | |
| 101 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_LEFT), | |
| 102 NULL, | |
| 103 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_RIGHT), | |
| 104 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM_LEFT), | |
| 105 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM), | |
| 106 &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM_RIGHT)); | |
| 107 | |
| 108 // Image sizes may have changed. | |
| 109 UpdateImageGridBounds(); | |
| 110 } | |
| 111 | |
| 112 void Shadow::UpdateImageGridBounds() { | |
| 39 image_grid_->SetSize( | 113 image_grid_->SetSize( |
| 40 gfx::Size(content_bounds.width() + | 114 gfx::Size(content_bounds_.width() + |
| 41 image_grid_->left_image_width() + | 115 image_grid_->left_image_width() + |
| 42 image_grid_->right_image_width(), | 116 image_grid_->right_image_width(), |
| 43 content_bounds.height() + | 117 content_bounds_.height() + |
| 44 image_grid_->top_image_height() + | 118 image_grid_->top_image_height() + |
| 45 image_grid_->bottom_image_height())); | 119 image_grid_->bottom_image_height())); |
| 46 image_grid_->layer()->SetBounds( | 120 image_grid_->layer()->SetBounds( |
| 47 gfx::Rect(content_bounds.x() - image_grid_->left_image_width(), | 121 gfx::Rect(content_bounds_.x() - image_grid_->left_image_width(), |
| 48 content_bounds.y() - image_grid_->top_image_height(), | 122 content_bounds_.y() - image_grid_->top_image_height(), |
| 49 image_grid_->layer()->bounds().width(), | 123 image_grid_->layer()->bounds().width(), |
| 50 image_grid_->layer()->bounds().height())); | 124 image_grid_->layer()->bounds().height())); |
| 51 } | 125 } |
| 52 | 126 |
| 53 } // namespace internal | 127 } // namespace internal |
| 54 } // namespace ash | 128 } // namespace ash |
| OLD | NEW |