| 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" | |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 7 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 10 #include "ash/common/system/tray/system_tray_item.h" | 9 #include "ash/common/system/tray/system_tray_item.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/public/cpp/shelf_types.h" | 11 #include "ash/public/cpp/shelf_types.h" |
| 13 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
| 14 #include "ui/gfx/animation/slide_animation.h" | 13 #include "ui/gfx/animation/slide_animation.h" |
| 15 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 16 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/layout/fill_layout.h" | 16 #include "ui/views/layout/fill_layout.h" |
| 18 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 19 | 18 |
| 19 namespace ash { |
| 20 |
| 20 namespace { | 21 namespace { |
| 21 const int kTrayIconHeight = 29; | 22 |
| 22 const int kTrayIconWidth = 29; | |
| 23 const int kTrayItemAnimationDurationMS = 200; | 23 const int kTrayItemAnimationDurationMS = 200; |
| 24 | 24 |
| 25 // Animations can be disabled for testing. | 25 // Animations can be disabled for testing. |
| 26 bool animations_enabled = true; | 26 bool animations_enabled = true; |
| 27 } | |
| 28 | 27 |
| 29 namespace ash { | 28 } // namespace |
| 30 | 29 |
| 31 TrayItemView::TrayItemView(SystemTrayItem* owner) | 30 TrayItemView::TrayItemView(SystemTrayItem* owner) |
| 32 : owner_(owner), label_(NULL), image_view_(NULL) { | 31 : owner_(owner), label_(NULL), image_view_(NULL) { |
| 33 SetPaintToLayer(); | 32 SetPaintToLayer(); |
| 34 layer()->SetFillsBoundsOpaquely(false); | 33 layer()->SetFillsBoundsOpaquely(false); |
| 35 SetLayoutManager(new views::FillLayout()); | 34 SetLayoutManager(new views::FillLayout()); |
| 36 } | 35 } |
| 37 | 36 |
| 38 TrayItemView::~TrayItemView() {} | 37 TrayItemView::~TrayItemView() {} |
| 39 | 38 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 70 if (!set_visible) { | 69 if (!set_visible) { |
| 71 animation_->Hide(); | 70 animation_->Hide(); |
| 72 AnimationProgressed(animation_.get()); | 71 AnimationProgressed(animation_.get()); |
| 73 } else { | 72 } else { |
| 74 animation_->Show(); | 73 animation_->Show(); |
| 75 AnimationProgressed(animation_.get()); | 74 AnimationProgressed(animation_.get()); |
| 76 views::View::SetVisible(true); | 75 views::View::SetVisible(true); |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 | 78 |
| 80 // static | |
| 81 bool TrayItemView::UseMd() { | |
| 82 return MaterialDesignController::UseMaterialDesignSystemIcons(); | |
| 83 } | |
| 84 | |
| 85 int TrayItemView::GetAnimationDurationMS() { | 79 int TrayItemView::GetAnimationDurationMS() { |
| 86 return kTrayItemAnimationDurationMS; | 80 return kTrayItemAnimationDurationMS; |
| 87 } | 81 } |
| 88 | 82 |
| 89 gfx::Size TrayItemView::GetPreferredSize() const { | 83 gfx::Size TrayItemView::GetPreferredSize() const { |
| 90 DCHECK_EQ(1, child_count()); | 84 DCHECK_EQ(1, child_count()); |
| 91 gfx::Size size; | 85 gfx::Size inner_size = views::View::GetPreferredSize(); |
| 92 if (UseMd()) { | 86 if (image_view_) |
| 93 gfx::Size inner_size = views::View::GetPreferredSize(); | 87 inner_size = gfx::Size(kTrayIconSize, kTrayIconSize); |
| 94 if (image_view_) | 88 gfx::Rect rect(inner_size); |
| 95 inner_size = gfx::Size(kTrayIconSize, kTrayIconSize); | 89 rect.Inset(gfx::Insets(-kTrayImageItemPadding)); |
| 96 gfx::Rect rect(inner_size); | 90 gfx::Size size = rect.size(); |
| 97 rect.Inset(gfx::Insets(-kTrayImageItemPadding)); | |
| 98 size = rect.size(); | |
| 99 } else { | |
| 100 size = views::View::GetPreferredSize(); | |
| 101 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) | |
| 102 size.set_height(kTrayIconHeight); | |
| 103 else | |
| 104 size.set_width(kTrayIconWidth); | |
| 105 } | |
| 106 if (!animation_.get() || !animation_->is_animating()) | 91 if (!animation_.get() || !animation_->is_animating()) |
| 107 return size; | 92 return size; |
| 108 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { | 93 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) { |
| 109 size.set_width(std::max( | 94 size.set_width(std::max( |
| 110 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); | 95 1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); |
| 111 } else { | 96 } else { |
| 112 size.set_height(std::max( | 97 size.set_height(std::max( |
| 113 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); | 98 1, static_cast<int>(size.height() * animation_->GetCurrentValue()))); |
| 114 } | 99 } |
| 115 return size; | 100 return size; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 141 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { | 126 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { |
| 142 if (animation->GetCurrentValue() < 0.1) | 127 if (animation->GetCurrentValue() < 0.1) |
| 143 views::View::SetVisible(false); | 128 views::View::SetVisible(false); |
| 144 } | 129 } |
| 145 | 130 |
| 146 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { | 131 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { |
| 147 AnimationEnded(animation); | 132 AnimationEnded(animation); |
| 148 } | 133 } |
| 149 | 134 |
| 150 } // namespace ash | 135 } // namespace ash |
| OLD | NEW |