| 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/material_design/material_design_controller.h" |
| 7 #include "ash/common/shelf/wm_shelf_util.h" | 8 #include "ash/common/shelf/wm_shelf_util.h" |
| 8 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
| 9 #include "ash/common/system/tray/system_tray_item.h" | 10 #include "ash/common/system/tray/system_tray_item.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/public/cpp/shelf_types.h" | 12 #include "ash/public/cpp/shelf_types.h" |
| 11 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
| 12 #include "ui/gfx/animation/slide_animation.h" | 14 #include "ui/gfx/animation/slide_animation.h" |
| 13 #include "ui/views/controls/image_view.h" | 15 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 15 #include "ui/views/layout/box_layout.h" | 17 #include "ui/views/layout/fill_layout.h" |
| 16 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 const int kTrayIconHeight = 29; | 21 const int kTrayIconHeight = 29; |
| 20 const int kTrayIconWidth = 29; | 22 const int kTrayIconWidth = 29; |
| 21 const int kTrayItemAnimationDurationMS = 200; | 23 const int kTrayItemAnimationDurationMS = 200; |
| 22 | 24 |
| 23 // Animations can be disabled for testing. | 25 // Animations can be disabled for testing. |
| 24 bool animations_enabled = true; | 26 bool animations_enabled = true; |
| 25 } | 27 } |
| 26 | 28 |
| 27 namespace ash { | 29 namespace ash { |
| 28 | 30 |
| 29 TrayItemView::TrayItemView(SystemTrayItem* owner) | 31 TrayItemView::TrayItemView(SystemTrayItem* owner) |
| 30 : owner_(owner), label_(NULL), image_view_(NULL) { | 32 : owner_(owner), label_(NULL), image_view_(NULL) { |
| 31 SetPaintToLayer(true); | 33 SetPaintToLayer(true); |
| 32 layer()->SetFillsBoundsOpaquely(false); | 34 layer()->SetFillsBoundsOpaquely(false); |
| 33 SetLayoutManager( | 35 SetLayoutManager(new views::FillLayout()); |
| 34 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 35 } | 36 } |
| 36 | 37 |
| 37 TrayItemView::~TrayItemView() {} | 38 TrayItemView::~TrayItemView() {} |
| 38 | 39 |
| 39 // static | 40 // static |
| 40 void TrayItemView::DisableAnimationsForTest() { | 41 void TrayItemView::DisableAnimationsForTest() { |
| 41 animations_enabled = false; | 42 animations_enabled = false; |
| 42 } | 43 } |
| 43 | 44 |
| 44 void TrayItemView::CreateLabel() { | 45 void TrayItemView::CreateLabel() { |
| 45 label_ = new views::Label; | 46 label_ = new views::Label; |
| 46 AddChildView(label_); | 47 AddChildView(label_); |
| 48 PreferredSizeChanged(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void TrayItemView::CreateImageView() { | 51 void TrayItemView::CreateImageView() { |
| 50 image_view_ = new views::ImageView; | 52 image_view_ = new views::ImageView; |
| 51 AddChildView(image_view_); | 53 AddChildView(image_view_); |
| 54 PreferredSizeChanged(); |
| 52 } | 55 } |
| 53 | 56 |
| 54 void TrayItemView::SetVisible(bool set_visible) { | 57 void TrayItemView::SetVisible(bool set_visible) { |
| 55 if (!GetWidget() || !animations_enabled) { | 58 if (!GetWidget() || !animations_enabled) { |
| 56 views::View::SetVisible(set_visible); | 59 views::View::SetVisible(set_visible); |
| 57 return; | 60 return; |
| 58 } | 61 } |
| 59 | 62 |
| 60 if (!animation_) { | 63 if (!animation_) { |
| 61 animation_.reset(new gfx::SlideAnimation(this)); | 64 animation_.reset(new gfx::SlideAnimation(this)); |
| 62 animation_->SetSlideDuration(GetAnimationDurationMS()); | 65 animation_->SetSlideDuration(GetAnimationDurationMS()); |
| 63 animation_->SetTweenType(gfx::Tween::LINEAR); | 66 animation_->SetTweenType(gfx::Tween::LINEAR); |
| 64 animation_->Reset(visible() ? 1.0 : 0.0); | 67 animation_->Reset(visible() ? 1.0 : 0.0); |
| 65 } | 68 } |
| 66 | 69 |
| 67 if (!set_visible) { | 70 if (!set_visible) { |
| 68 animation_->Hide(); | 71 animation_->Hide(); |
| 69 AnimationProgressed(animation_.get()); | 72 AnimationProgressed(animation_.get()); |
| 70 } else { | 73 } else { |
| 71 animation_->Show(); | 74 animation_->Show(); |
| 72 AnimationProgressed(animation_.get()); | 75 AnimationProgressed(animation_.get()); |
| 73 views::View::SetVisible(true); | 76 views::View::SetVisible(true); |
| 74 } | 77 } |
| 75 } | 78 } |
| 76 | 79 |
| 77 gfx::Size TrayItemView::DesiredSize() const { | |
| 78 return views::View::GetPreferredSize(); | |
| 79 } | |
| 80 | |
| 81 int TrayItemView::GetAnimationDurationMS() { | 80 int TrayItemView::GetAnimationDurationMS() { |
| 82 return kTrayItemAnimationDurationMS; | 81 return kTrayItemAnimationDurationMS; |
| 83 } | 82 } |
| 84 | 83 |
| 85 gfx::Size TrayItemView::GetPreferredSize() const { | 84 gfx::Size TrayItemView::GetPreferredSize() const { |
| 86 gfx::Size size = DesiredSize(); | 85 gfx::Size size; |
| 87 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) | 86 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
| 88 size.set_height(kTrayIconHeight); | 87 gfx::Size inner_size = views::View::GetPreferredSize(); |
| 89 else | 88 if (image_view_ && child_count() == 1) |
| 90 size.set_width(kTrayIconWidth); | 89 inner_size = gfx::Size(kTrayIconSize, kTrayIconSize); |
| 90 gfx::Rect rect(inner_size); |
| 91 rect.Inset(gfx::Insets(-GetTrayConstant(TRAY_IMAGE_ITEM_PADDING))); |
| 92 size = rect.size(); |
| 93 } else { |
| 94 size = views::View::GetPreferredSize(); |
| 95 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) |
| 96 size.set_height(kTrayIconHeight); |
| 97 else |
| 98 size.set_width(kTrayIconWidth); |
| 99 } |
| 91 if (!animation_.get() || !animation_->is_animating()) | 100 if (!animation_.get() || !animation_->is_animating()) |
| 92 return size; | 101 return size; |
| 93 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { | 102 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { |
| 94 size.set_width(std::max( | 103 size.set_width(std::max( |
| 95 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); | 104 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); |
| 96 } else { | 105 } else { |
| 97 size.set_height(std::max( | 106 size.set_height(std::max( |
| 98 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); | 107 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); |
| 99 } | 108 } |
| 100 return size; | 109 return size; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 126 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { | 135 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { |
| 127 if (animation->GetCurrentValue() < 0.1) | 136 if (animation->GetCurrentValue() < 0.1) |
| 128 views::View::SetVisible(false); | 137 views::View::SetVisible(false); |
| 129 } | 138 } |
| 130 | 139 |
| 131 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { | 140 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { |
| 132 AnimationEnded(animation); | 141 AnimationEnded(animation); |
| 133 } | 142 } |
| 134 | 143 |
| 135 } // namespace ash | 144 } // namespace ash |
| OLD | NEW |