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 "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "ash/shell_observer.h" | |
9 #include "ui/base/animation/animation_delegate.h" | 10 #include "ui/base/animation/animation_delegate.h" |
10 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
11 | 12 |
13 namespace aura { | |
14 class RootWindow; | |
15 } | |
16 | |
12 namespace ui { | 17 namespace ui { |
13 class SlideAnimation; | 18 class SlideAnimation; |
14 } | 19 } |
15 | 20 |
16 namespace views { | 21 namespace views { |
17 class ImageView; | 22 class ImageView; |
18 class Label; | 23 class Label; |
19 } | 24 } |
20 | 25 |
21 namespace ash { | 26 namespace ash { |
22 | 27 |
23 class SystemTrayItem; | 28 class SystemTrayItem; |
24 | 29 |
25 namespace internal { | 30 namespace internal { |
26 | 31 |
27 // Base-class for items in the tray. It makes sure the widget is updated | 32 // 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 | 33 // correctly when the visibility/size of the tray item changes. It also adds |
29 // animation when showing/hiding the item in the tray. | 34 // animation when showing/hiding the item in the tray. |
30 class ASH_EXPORT TrayItemView : public views::View, | 35 class ASH_EXPORT TrayItemView : public views::View, |
36 public ash::ShellObserver, | |
31 public ui::AnimationDelegate { | 37 public ui::AnimationDelegate { |
32 public: | 38 public: |
33 explicit TrayItemView(SystemTrayItem* owner); | 39 explicit TrayItemView(SystemTrayItem* owner); |
34 virtual ~TrayItemView(); | 40 virtual ~TrayItemView(); |
35 | 41 |
36 static void DisableAnimationsForTest(); | 42 static void DisableAnimationsForTest(); |
37 | 43 |
38 // Convenience function for creating a child Label or ImageView. | 44 // Convenience function for creating a child Label or ImageView. |
39 void CreateLabel(); | 45 void CreateLabel(); |
40 void CreateImageView(); | 46 void CreateImageView(); |
41 | 47 |
42 SystemTrayItem* owner() const { return owner_; } | 48 SystemTrayItem* owner() const { return owner_; } |
43 views::Label* label() const { return label_; } | 49 views::Label* label() const { return label_; } |
44 views::ImageView* image_view() const { return image_view_; } | 50 views::ImageView* image_view() const { return image_view_; } |
45 | 51 |
52 enum AlignmentOverride { | |
53 AUTO, | |
54 HORIZONTAL, | |
55 VERTICAL | |
56 }; | |
57 | |
58 // Enforce a shelf alignment independent alignment for this item. | |
59 void SetAlignmentOverride(AlignmentOverride alignment_override); | |
60 | |
46 // Overridden from views::View. | 61 // Overridden from views::View. |
47 virtual void SetVisible(bool visible) OVERRIDE; | 62 virtual void SetVisible(bool visible) OVERRIDE; |
48 virtual gfx::Size GetPreferredSize() OVERRIDE; | 63 virtual gfx::Size GetPreferredSize() OVERRIDE; |
49 virtual int GetHeightForWidth(int width) OVERRIDE; | 64 virtual int GetHeightForWidth(int width) OVERRIDE; |
50 | 65 |
66 // Overridden from ash::ShellObserver. | |
67 virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE; | |
jennyz
2013/08/13 20:32:51
We already have UpdateAfterShelfAlignmentChange()
Mr4D (OOO till 08-26)
2013/08/13 21:25:01
Okay - as discussed - changed it now only in the o
| |
68 | |
51 protected: | 69 protected: |
52 // Makes sure the widget relayouts after the size/visibility of the view | 70 // Makes sure the widget relayouts after the size/visibility of the view |
53 // changes. | 71 // changes. |
54 void ApplyChange(); | 72 void ApplyChange(); |
55 | 73 |
56 // This should return the desired size of the view. For most views, this | 74 // This should return the desired size of the view. For most views, this |
57 // returns GetPreferredSize. But since this class overrides GetPreferredSize | 75 // returns GetPreferredSize. But since this class overrides GetPreferredSize |
58 // for animation purposes, we allow a different way to get this size, and do | 76 // for animation purposes, we allow a different way to get this size, and do |
59 // not allow GetPreferredSize to be overridden. | 77 // not allow GetPreferredSize to be overridden. |
60 virtual gfx::Size DesiredSize(); | 78 virtual gfx::Size DesiredSize(); |
61 | 79 |
62 // The default animation duration is 200ms. But each view can customize this. | 80 // The default animation duration is 200ms. But each view can customize this. |
63 virtual int GetAnimationDurationMS(); | 81 virtual int GetAnimationDurationMS(); |
64 | 82 |
65 private: | 83 private: |
66 // Overridden from views::View. | 84 // Overridden from views::View. |
67 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 85 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
68 | 86 |
69 // Overridden from ui::AnimationDelegate. | 87 // Overridden from ui::AnimationDelegate. |
70 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 88 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
71 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 89 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
72 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE; | 90 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE; |
73 | 91 |
92 // Set the layout alignment of the view inside its parent from the shelf. | |
93 void SetLayoutAlignment(); | |
94 | |
74 SystemTrayItem* owner_; | 95 SystemTrayItem* owner_; |
75 scoped_ptr<ui::SlideAnimation> animation_; | 96 scoped_ptr<ui::SlideAnimation> animation_; |
76 views::Label* label_; | 97 views::Label* label_; |
77 views::ImageView* image_view_; | 98 views::ImageView* image_view_; |
78 | 99 |
100 // The alignment override - or |AUTO| if the shelf alignment should be used. | |
101 AlignmentOverride alignment_override_; | |
102 | |
103 | |
79 DISALLOW_COPY_AND_ASSIGN(TrayItemView); | 104 DISALLOW_COPY_AND_ASSIGN(TrayItemView); |
80 }; | 105 }; |
81 | 106 |
82 } // namespace internal | 107 } // namespace internal |
83 } // namespace ash | 108 } // namespace ash |
84 | 109 |
85 #endif // ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ | 110 #endif // ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ |
OLD | NEW |