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. 4 5 #ifndef ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ 6 #define ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ 7 8 #include "ash/ash_export.h" 9 #include "ui/gfx/animation/animation_delegate.h" 10 #include "ui/views/view.h" 11 12 namespace gfx { 13 class SlideAnimation; 14 } 15 16 namespace views { 17 class ImageView; 18 class Label; 19 } 20 21 namespace ash { 22 23 class SystemTrayItem; 24 25 namespace internal { 26 27 // Base-class for items in the tray. It makes sure the widget is updated 28 // correctly when the visibility/size of the tray item changes. It also adds 29 // animation when showing/hiding the item in the tray. 30 class ASH_EXPORT TrayItemView : public views::View, 31 public gfx::AnimationDelegate { 32 public: 33 explicit TrayItemView(SystemTrayItem* owner); 34 virtual ~TrayItemView(); 35 36 static void DisableAnimationsForTest(); 37 38 // Convenience function for creating a child Label or ImageView. 39 void CreateLabel(); 40 void CreateImageView(); 41 owner()42 SystemTrayItem* owner() const { return owner_; } label()43 views::Label* label() const { return label_; } image_view()44 views::ImageView* image_view() const { return image_view_; } 45 46 // Overridden from views::View. 47 virtual void SetVisible(bool visible) OVERRIDE; 48 virtual gfx::Size GetPreferredSize() OVERRIDE; 49 virtual int GetHeightForWidth(int width) OVERRIDE; 50 51 protected: 52 // Makes sure the widget relayouts after the size/visibility of the view 53 // changes. 54 void ApplyChange(); 55 56 // This should return the desired size of the view. For most views, this 57 // returns GetPreferredSize. But since this class overrides GetPreferredSize 58 // for animation purposes, we allow a different way to get this size, and do 59 // not allow GetPreferredSize to be overridden. 60 virtual gfx::Size DesiredSize(); 61 62 // The default animation duration is 200ms. But each view can customize this. 63 virtual int GetAnimationDurationMS(); 64 65 private: 66 // Overridden from views::View. 67 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; 68 69 // Overridden from gfx::AnimationDelegate. 70 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 71 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 72 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; 73 74 SystemTrayItem* owner_; 75 scoped_ptr<gfx::SlideAnimation> animation_; 76 views::Label* label_; 77 views::ImageView* image_view_; 78 79 DISALLOW_COPY_AND_ASSIGN(TrayItemView); 80 }; 81 82 } // namespace internal 83 } // namespace ash 84 85 #endif // ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ 86