| 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/system/tray/tray_item_view.h" | 5 #include "ash/system/tray/tray_item_view.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/shelf_types.h" | 7 #include "ash/public/cpp/shelf_types.h" |
| 8 #include "ash/shelf/wm_shelf_util.h" | 8 #include "ash/shelf/wm_shelf.h" |
| 9 #include "ash/system/tray/system_tray.h" | 9 #include "ash/system/tray/system_tray.h" |
| 10 #include "ash/system/tray/system_tray_item.h" | 10 #include "ash/system/tray/system_tray_item.h" |
| 11 #include "ash/system/tray/tray_constants.h" | 11 #include "ash/system/tray/tray_constants.h" |
| 12 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
| 13 #include "ui/gfx/animation/slide_animation.h" | 13 #include "ui/gfx/animation/slide_animation.h" |
| 14 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/layout/fill_layout.h" | 16 #include "ui/views/layout/fill_layout.h" |
| 17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 18 | 18 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 gfx::Size TrayItemView::GetPreferredSize() const { | 83 gfx::Size TrayItemView::GetPreferredSize() const { |
| 84 DCHECK_EQ(1, child_count()); | 84 DCHECK_EQ(1, child_count()); |
| 85 gfx::Size inner_size = views::View::GetPreferredSize(); | 85 gfx::Size inner_size = views::View::GetPreferredSize(); |
| 86 if (image_view_) | 86 if (image_view_) |
| 87 inner_size = gfx::Size(kTrayIconSize, kTrayIconSize); | 87 inner_size = gfx::Size(kTrayIconSize, kTrayIconSize); |
| 88 gfx::Rect rect(inner_size); | 88 gfx::Rect rect(inner_size); |
| 89 rect.Inset(gfx::Insets(-kTrayImageItemPadding)); | 89 rect.Inset(gfx::Insets(-kTrayImageItemPadding)); |
| 90 gfx::Size size = rect.size(); | 90 gfx::Size size = rect.size(); |
| 91 if (!animation_.get() || !animation_->is_animating()) | 91 if (!animation_.get() || !animation_->is_animating()) |
| 92 return size; | 92 return size; |
| 93 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { | 93 if (owner()->system_tray()->shelf()->IsHorizontalAlignment()) { |
| 94 size.set_width(std::max( | 94 size.set_width(std::max( |
| 95 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); | 95 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); |
| 96 } else { | 96 } else { |
| 97 size.set_height(std::max( | 97 size.set_height(std::max( |
| 98 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); | 98 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); |
| 99 } | 99 } |
| 100 return size; | 100 return size; |
| 101 } | 101 } |
| 102 | 102 |
| 103 int TrayItemView::GetHeightForWidth(int width) const { | 103 int TrayItemView::GetHeightForWidth(int width) const { |
| 104 return GetPreferredSize().height(); | 104 return GetPreferredSize().height(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void TrayItemView::ChildPreferredSizeChanged(views::View* child) { | 107 void TrayItemView::ChildPreferredSizeChanged(views::View* child) { |
| 108 PreferredSizeChanged(); | 108 PreferredSizeChanged(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { | 111 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { |
| 112 gfx::Transform transform; | 112 gfx::Transform transform; |
| 113 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { | 113 if (owner()->system_tray()->shelf()->IsHorizontalAlignment()) { |
| 114 transform.Translate(0, animation->CurrentValueBetween( | 114 transform.Translate(0, animation->CurrentValueBetween( |
| 115 static_cast<double>(height()) / 2, 0.)); | 115 static_cast<double>(height()) / 2, 0.)); |
| 116 } else { | 116 } else { |
| 117 transform.Translate( | 117 transform.Translate( |
| 118 animation->CurrentValueBetween(static_cast<double>(width() / 2), 0.), | 118 animation->CurrentValueBetween(static_cast<double>(width() / 2), 0.), |
| 119 0); | 119 0); |
| 120 } | 120 } |
| 121 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); | 121 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); |
| 122 layer()->SetTransform(transform); | 122 layer()->SetTransform(transform); |
| 123 PreferredSizeChanged(); | 123 PreferredSizeChanged(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { | 126 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { |
| 127 if (animation->GetCurrentValue() < 0.1) | 127 if (animation->GetCurrentValue() < 0.1) |
| 128 views::View::SetVisible(false); | 128 views::View::SetVisible(false); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { | 131 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { |
| 132 AnimationEnded(animation); | 132 AnimationEnded(animation); |
| 133 } | 133 } |
| 134 | 134 |
| 135 } // namespace ash | 135 } // namespace ash |
| OLD | NEW |