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
3 // found in the LICENSE file.
5 #ifndef ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_
6 #define ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_
8 #include "ui/base/animation/animation_delegate.h"
9 #include "ui/views/view.h"
26 // Base-class for items in the tray. It makes sure the widget is updated
27 // correctly when the visibility/size of the tray item changes. It also adds
28 // animation when showing/hiding the item in the tray.
29 class TrayItemView
: public views::View
,
30 public ui::AnimationDelegate
{
32 explicit TrayItemView(SystemTrayItem
* owner
);
33 virtual ~TrayItemView();
35 // Convenience function for creating a child Label or ImageView.
37 void CreateImageView();
39 SystemTrayItem
* owner() const { return owner_
; }
40 views::Label
* label() const { return label_
; }
41 views::ImageView
* image_view() const { return image_view_
; }
43 // Overridden from views::View.
44 virtual void SetVisible(bool visible
) OVERRIDE
;
45 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
48 // Makes sure the widget relayouts after the size/visibility of the view
52 // This should return the desired size of the view. For most views, this
53 // returns GetPreferredSize. But since this class overrides GetPreferredSize
54 // for animation purposes, we allow a different way to get this size, and do
55 // not allow GetPreferredSize to be overridden.
56 virtual gfx::Size
DesiredSize();
58 // The default animation duration is 200ms. But each view can customize this.
59 virtual int GetAnimationDurationMS();
62 // Overridden from views::View.
63 virtual void ChildPreferredSizeChanged(View
* child
) OVERRIDE
;
65 // Overridden from ui::AnimationDelegate.
66 virtual void AnimationProgressed(const ui::Animation
* animation
) OVERRIDE
;
67 virtual void AnimationEnded(const ui::Animation
* animation
) OVERRIDE
;
68 virtual void AnimationCanceled(const ui::Animation
* animation
) OVERRIDE
;
70 SystemTrayItem
* owner_
;
71 scoped_ptr
<ui::SlideAnimation
> animation_
;
73 views::ImageView
* image_view_
;
75 DISALLOW_COPY_AND_ASSIGN(TrayItemView
);
78 } // namespace internal
81 #endif // ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_