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