| 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/common/system/tray/tray_item_view.h" | 5 #include "ash/common/system/tray/tray_item_view.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_types.h" | 7 #include "ash/common/shelf/shelf_types.h" |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 8 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/system/tray/system_tray_item.h" | 9 #include "ash/common/system/tray/system_tray_item.h" |
| 10 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
| 11 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
| 12 #include "ui/gfx/animation/slide_animation.h" | 12 #include "ui/gfx/animation/slide_animation.h" |
| 13 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
| 15 #include "ui/views/layout/box_layout.h" | 15 #include "ui/views/layout/box_layout.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 const int kTrayIconHeight = 29; | 19 const int kTrayIconHeight = 29; |
| 20 const int kTrayIconWidth = 29; | 20 const int kTrayIconWidth = 29; |
| 21 const int kTrayItemAnimationDurationMS = 200; | 21 const int kTrayItemAnimationDurationMS = 200; |
| 22 | 22 |
| 23 // Animations can be disabled for testing. | 23 // Animations can be disabled for testing. |
| 24 bool animations_enabled = true; | 24 bool animations_enabled = true; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace ash { | 27 namespace ash { |
| 28 | 28 |
| 29 TrayItemView::TrayItemView(SystemTrayItem* owner) | 29 TrayItemView::TrayItemView(SystemTrayItem* owner) |
| 30 : owner_(owner), | 30 : owner_(owner), label_(NULL), image_view_(NULL) { |
| 31 label_(NULL), | |
| 32 image_view_(NULL) { | |
| 33 SetPaintToLayer(true); | 31 SetPaintToLayer(true); |
| 34 layer()->SetFillsBoundsOpaquely(false); | 32 layer()->SetFillsBoundsOpaquely(false); |
| 35 SetLayoutManager( | 33 SetLayoutManager( |
| 36 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 34 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 37 } | 35 } |
| 38 | 36 |
| 39 TrayItemView::~TrayItemView() {} | 37 TrayItemView::~TrayItemView() {} |
| 40 | 38 |
| 41 // static | 39 // static |
| 42 void TrayItemView::DisableAnimationsForTest() { | 40 void TrayItemView::DisableAnimationsForTest() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 84 |
| 87 gfx::Size TrayItemView::GetPreferredSize() const { | 85 gfx::Size TrayItemView::GetPreferredSize() const { |
| 88 gfx::Size size = DesiredSize(); | 86 gfx::Size size = DesiredSize(); |
| 89 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) | 87 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) |
| 90 size.set_height(kTrayIconHeight); | 88 size.set_height(kTrayIconHeight); |
| 91 else | 89 else |
| 92 size.set_width(kTrayIconWidth); | 90 size.set_width(kTrayIconWidth); |
| 93 if (!animation_.get() || !animation_->is_animating()) | 91 if (!animation_.get() || !animation_->is_animating()) |
| 94 return size; | 92 return size; |
| 95 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { | 93 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { |
| 96 size.set_width(std::max(1, | 94 size.set_width(std::max( |
| 97 static_cast<int>(size.width() * animation_->GetCurrentValue()))); | 95 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); |
| 98 } else { | 96 } else { |
| 99 size.set_height(std::max(1, | 97 size.set_height(std::max( |
| 100 static_cast<int>(size.height() * animation_->GetCurrentValue()))); | 98 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); |
| 101 } | 99 } |
| 102 return size; | 100 return size; |
| 103 } | 101 } |
| 104 | 102 |
| 105 int TrayItemView::GetHeightForWidth(int width) const { | 103 int TrayItemView::GetHeightForWidth(int width) const { |
| 106 return GetPreferredSize().height(); | 104 return GetPreferredSize().height(); |
| 107 } | 105 } |
| 108 | 106 |
| 109 void TrayItemView::ChildPreferredSizeChanged(views::View* child) { | 107 void TrayItemView::ChildPreferredSizeChanged(views::View* child) { |
| 110 PreferredSizeChanged(); | 108 PreferredSizeChanged(); |
| 111 } | 109 } |
| 112 | 110 |
| 113 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { | 111 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { |
| 114 gfx::Transform transform; | 112 gfx::Transform transform; |
| 115 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { | 113 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { |
| 116 transform.Translate(0, animation->CurrentValueBetween( | 114 transform.Translate(0, animation->CurrentValueBetween( |
| 117 static_cast<double>(height()) / 2, 0.)); | 115 static_cast<double>(height()) / 2, 0.)); |
| 118 } else { | 116 } else { |
| 119 transform.Translate(animation->CurrentValueBetween( | 117 transform.Translate( |
| 120 static_cast<double>(width() / 2), 0.), 0); | 118 animation->CurrentValueBetween(static_cast<double>(width() / 2), 0.), |
| 119 0); |
| 121 } | 120 } |
| 122 transform.Scale(animation->GetCurrentValue(), | 121 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); |
| 123 animation->GetCurrentValue()); | |
| 124 layer()->SetTransform(transform); | 122 layer()->SetTransform(transform); |
| 125 PreferredSizeChanged(); | 123 PreferredSizeChanged(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { | 126 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { |
| 129 if (animation->GetCurrentValue() < 0.1) | 127 if (animation->GetCurrentValue() < 0.1) |
| 130 views::View::SetVisible(false); | 128 views::View::SetVisible(false); |
| 131 } | 129 } |
| 132 | 130 |
| 133 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { | 131 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { |
| 134 AnimationEnded(animation); | 132 AnimationEnded(animation); |
| 135 } | 133 } |
| 136 | 134 |
| 137 } // namespace ash | 135 } // namespace ash |
| OLD | NEW |