OLD | NEW |
| (Empty) |
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_COMMON_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ | |
6 #define ASH_COMMON_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "base/macros.h" | |
12 #include "ui/gfx/animation/animation_delegate.h" | |
13 #include "ui/views/view.h" | |
14 | |
15 namespace gfx { | |
16 class SlideAnimation; | |
17 } | |
18 | |
19 namespace views { | |
20 class ImageView; | |
21 class Label; | |
22 } | |
23 | |
24 namespace ash { | |
25 class SystemTrayItem; | |
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 ~TrayItemView() override; | |
35 | |
36 static void DisableAnimationsForTest(); | |
37 | |
38 // Convenience function for creating a child Label or ImageView. | |
39 // Only one of the two should be called. | |
40 void CreateLabel(); | |
41 void CreateImageView(); | |
42 | |
43 SystemTrayItem* owner() const { return owner_; } | |
44 views::Label* label() const { return label_; } | |
45 views::ImageView* image_view() const { return image_view_; } | |
46 | |
47 // Overridden from views::View. | |
48 void SetVisible(bool visible) override; | |
49 gfx::Size GetPreferredSize() const override; | |
50 int GetHeightForWidth(int width) const override; | |
51 | |
52 protected: | |
53 static bool UseMd(); | |
54 | |
55 // The default animation duration is 200ms. But each view can customize this. | |
56 virtual int GetAnimationDurationMS(); | |
57 | |
58 private: | |
59 // Overridden from views::View. | |
60 void ChildPreferredSizeChanged(View* child) override; | |
61 | |
62 // Overridden from gfx::AnimationDelegate. | |
63 void AnimationProgressed(const gfx::Animation* animation) override; | |
64 void AnimationEnded(const gfx::Animation* animation) override; | |
65 void AnimationCanceled(const gfx::Animation* animation) override; | |
66 | |
67 SystemTrayItem* owner_; | |
68 std::unique_ptr<gfx::SlideAnimation> animation_; | |
69 // Only one of |label_| and |image_view_| should be non-null. | |
70 views::Label* label_; | |
71 views::ImageView* image_view_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(TrayItemView); | |
74 }; | |
75 | |
76 } // namespace ash | |
77 | |
78 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ | |
OLD | NEW |