Chromium Code Reviews| Index: ash/system/tray/tray_item_view.cc |
| diff --git a/ash/system/tray/tray_item_view.cc b/ash/system/tray/tray_item_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2698ad583eb19c08e5967cf8b909035b90b27f6c |
| --- /dev/null |
| +++ b/ash/system/tray/tray_item_view.cc |
| @@ -0,0 +1,114 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/system/tray/tray_item_view.h" |
| + |
| +#include "ui/base/animation/slide_animation.h" |
| +#include "ui/gfx/compositor/layer.h" |
| +#include "ui/views/controls/image_view.h" |
| +#include "ui/views/controls/label.h" |
| +#include "ui/views/layout/fill_layout.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace { |
| +const int kTrayIconHeight = 29; |
| +const int kTrayItemAnimationDurationMS = 200; |
| +} |
| + |
| +namespace ash { |
| +namespace internal { |
| + |
| +TrayItemView::TrayItemView() |
| + : label_(NULL), |
| + image_view_(NULL) { |
| + SetPaintToLayer(true); |
| + SetFillsBoundsOpaquely(false); |
| + SetLayoutManager(new views::FillLayout); |
| +} |
| + |
| +TrayItemView::~TrayItemView() {} |
| + |
| +void TrayItemView::CreateLabel() { |
| + label_ = new views::Label; |
| + AddChildView(label_); |
| +} |
| + |
| +void TrayItemView::CreateImageView() { |
| + image_view_ = new views::ImageView; |
| + AddChildView(image_view_); |
| +} |
| + |
| +void TrayItemView::SetVisible(bool set_visible) { |
| + if (!GetWidget()) { |
|
Ben Goodger (Google)
2012/04/23 15:33:42
Can you implement this by overriding VisibilityCha
sadrul
2012/04/23 16:07:58
This would work when showing the view, however, wh
Ben Goodger (Google)
2012/04/23 17:43:38
Ah. I guess we have better support for this sort o
|
| + views::View::SetVisible(set_visible); |
| + return; |
| + } |
| + |
| + if (!animation_.get()) { |
| + animation_.reset(new ui::SlideAnimation(this)); |
| + animation_->SetSlideDuration(GetAnimationDurationMS()); |
| + animation_->SetTweenType(ui::Tween::LINEAR); |
| + animation_->Reset(visible() ? 1.0 : 0.0); |
| + } |
| + |
| + if (!set_visible) { |
| + animation_->Hide(); |
| + AnimationProgressed(animation_.get()); |
| + } else { |
| + animation_->Show(); |
| + AnimationProgressed(animation_.get()); |
| + views::View::SetVisible(true); |
| + } |
| +} |
| + |
| +void TrayItemView::ApplyChange() { |
| + // Forcing the widget to the new size is sufficient. The positioning is |
| + // taken care of by the layout manager (ShelfLayoutManager). |
| + GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); |
| +} |
| + |
| +gfx::Size TrayItemView::DesiredSize() { |
| + return views::View::GetPreferredSize(); |
| +} |
| + |
| +int TrayItemView::GetAnimationDurationMS() { |
| + return kTrayItemAnimationDurationMS; |
| +} |
| + |
| +gfx::Size TrayItemView::GetPreferredSize() { |
|
Ben Goodger (Google)
2012/04/23 15:33:42
.cc function order must match .h
sadrul
2012/04/23 16:07:58
Fixed.
|
| + gfx::Size size = DesiredSize(); |
| + size.set_height(kTrayIconHeight); |
| + if (!animation_.get() || !animation_->is_animating()) |
| + return size; |
| + size.set_width(std::max(1, |
| + static_cast<int>(size.width() * animation_->GetCurrentValue()))); |
| + return size; |
| +} |
| + |
| +void TrayItemView::PreferredSizeChanged() { |
| + views::View::PreferredSizeChanged(); |
| + ApplyChange(); |
| +} |
| + |
| +void TrayItemView::AnimationProgressed(const ui::Animation* animation) { |
| + ui::Transform transform; |
| + transform.SetScale(animation->GetCurrentValue(), |
| + animation->GetCurrentValue()); |
| + transform.ConcatTranslate(0, animation->CurrentValueBetween( |
| + static_cast<double>(height()) / 2, 0.)); |
| + layer()->SetTransform(transform); |
| + ApplyChange(); |
| +} |
| + |
| +void TrayItemView::AnimationEnded(const ui::Animation* animation) { |
| + if (animation->GetCurrentValue() < 0.1) |
| + views::View::SetVisible(false); |
| +} |
| + |
| +void TrayItemView::AnimationCanceled(const ui::Animation* animation) { |
| + AnimationEnded(animation); |
| +} |
| + |
| +} // namespace internal |
| +} // namespace ash |