Chromium Code Reviews| 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 image_view_->set_background( | |
| 55 views::Background::CreateSolidBackground(SK_ColorGREEN)); | |
|
tdanderson
2016/10/27 19:28:01
Is this for debugging?
Evan Stade
2016/10/27 21:36:34
oops.
| |
| 56 PreferredSizeChanged(); | |
| 52 } | 57 } |
| 53 | 58 |
| 54 void TrayItemView::SetVisible(bool set_visible) { | 59 void TrayItemView::SetVisible(bool set_visible) { |
| 55 if (!GetWidget() || !animations_enabled) { | 60 if (!GetWidget() || !animations_enabled) { |
| 56 views::View::SetVisible(set_visible); | 61 views::View::SetVisible(set_visible); |
| 57 return; | 62 return; |
| 58 } | 63 } |
| 59 | 64 |
| 60 if (!animation_) { | 65 if (!animation_) { |
| 61 animation_.reset(new gfx::SlideAnimation(this)); | 66 animation_.reset(new gfx::SlideAnimation(this)); |
| 62 animation_->SetSlideDuration(GetAnimationDurationMS()); | 67 animation_->SetSlideDuration(GetAnimationDurationMS()); |
| 63 animation_->SetTweenType(gfx::Tween::LINEAR); | 68 animation_->SetTweenType(gfx::Tween::LINEAR); |
| 64 animation_->Reset(visible() ? 1.0 : 0.0); | 69 animation_->Reset(visible() ? 1.0 : 0.0); |
| 65 } | 70 } |
| 66 | 71 |
| 67 if (!set_visible) { | 72 if (!set_visible) { |
| 68 animation_->Hide(); | 73 animation_->Hide(); |
| 69 AnimationProgressed(animation_.get()); | 74 AnimationProgressed(animation_.get()); |
| 70 } else { | 75 } else { |
| 71 animation_->Show(); | 76 animation_->Show(); |
| 72 AnimationProgressed(animation_.get()); | 77 AnimationProgressed(animation_.get()); |
| 73 views::View::SetVisible(true); | 78 views::View::SetVisible(true); |
| 74 } | 79 } |
| 75 } | 80 } |
| 76 | 81 |
| 77 gfx::Size TrayItemView::DesiredSize() const { | |
| 78 return views::View::GetPreferredSize(); | |
| 79 } | |
| 80 | |
| 81 int TrayItemView::GetAnimationDurationMS() { | 82 int TrayItemView::GetAnimationDurationMS() { |
| 82 return kTrayItemAnimationDurationMS; | 83 return kTrayItemAnimationDurationMS; |
| 83 } | 84 } |
| 84 | 85 |
| 85 gfx::Size TrayItemView::GetPreferredSize() const { | 86 gfx::Size TrayItemView::GetPreferredSize() const { |
| 86 gfx::Size size = DesiredSize(); | 87 gfx::Size size; |
| 87 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) | 88 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
| 88 size.set_height(kTrayIconHeight); | 89 gfx::Size inner_size = views::View::GetPreferredSize(); |
| 89 else | 90 if (image_view_ && child_count() == 1) |
| 90 size.set_width(kTrayIconWidth); | 91 inner_size = gfx::Size(kTrayIconSize, kTrayIconSize); |
|
tdanderson
2016/10/27 19:28:01
I don't really see the purpose of |inner_size|. Wh
Evan Stade
2016/10/27 21:36:34
another oops. I'm not sure how it worked like this
| |
| 92 const int kInterTrayItemPadding = 6; | |
| 93 size.Enlarge(kInterTrayItemPadding, kInterTrayItemPadding); | |
| 94 } else { | |
| 95 size = views::View::GetPreferredSize(); | |
| 96 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) | |
| 97 size.set_height(kTrayIconHeight); | |
| 98 else | |
| 99 size.set_width(kTrayIconWidth); | |
| 100 } | |
| 91 if (!animation_.get() || !animation_->is_animating()) | 101 if (!animation_.get() || !animation_->is_animating()) |
| 92 return size; | 102 return size; |
| 93 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { | 103 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { |
| 94 size.set_width(std::max( | 104 size.set_width(std::max( |
| 95 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); | 105 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); |
| 96 } else { | 106 } else { |
| 97 size.set_height(std::max( | 107 size.set_height(std::max( |
| 98 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); | 108 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); |
| 99 } | 109 } |
| 100 return size; | 110 return size; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 126 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { | 136 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { |
| 127 if (animation->GetCurrentValue() < 0.1) | 137 if (animation->GetCurrentValue() < 0.1) |
| 128 views::View::SetVisible(false); | 138 views::View::SetVisible(false); |
| 129 } | 139 } |
| 130 | 140 |
| 131 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { | 141 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { |
| 132 AnimationEnded(animation); | 142 AnimationEnded(animation); |
| 133 } | 143 } |
| 134 | 144 |
| 135 } // namespace ash | 145 } // namespace ash |
| OLD | NEW |