OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SHELF_SHELF_BUTTON_H_ | 5 #ifndef ASH_SHELF_SHELF_BUTTON_H_ |
6 #define ASH_SHELF_SHELF_BUTTON_H_ | 6 #define ASH_SHELF_SHELF_BUTTON_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "ui/gfx/shadow_value.h" | 10 #include "ui/gfx/shadow_value.h" |
11 #include "ui/views/controls/button/custom_button.h" | 11 #include "ui/views/controls/button/custom_button.h" |
12 #include "ui/views/controls/image_view.h" | 12 #include "ui/views/controls/image_view.h" |
13 | 13 |
14 namespace ash { | 14 namespace ash { |
15 class Shelf; | 15 class ShelfView; |
16 class ShelfButtonHost; | |
17 | 16 |
18 // Button used for items on the launcher, except for the AppList. | 17 // Button used for items on the launcher, except for the AppList. |
19 class ASH_EXPORT ShelfButton : public views::CustomButton { | 18 class ASH_EXPORT ShelfButton : public views::CustomButton { |
20 public: | 19 public: |
21 static const char kViewClassName[]; | 20 static const char kViewClassName[]; |
22 | 21 |
23 // Used to indicate the current state of the button. | 22 // Used to indicate the current state of the button. |
24 enum State { | 23 enum State { |
25 // Nothing special. Usually represents an app shortcut item with no running | 24 // Nothing special. Usually represents an app shortcut item with no running |
26 // instance. | 25 // instance. |
27 STATE_NORMAL = 0, | 26 STATE_NORMAL = 0, |
28 // Button has mouse hovering on it. | 27 // Button has mouse hovering on it. |
29 STATE_HOVERED = 1 << 0, | 28 STATE_HOVERED = 1 << 0, |
30 // Underlying ShelfItem has a running instance. | 29 // Underlying ShelfItem has a running instance. |
31 STATE_RUNNING = 1 << 1, | 30 STATE_RUNNING = 1 << 1, |
32 // Underlying ShelfItem is active (i.e. has focus). | 31 // Underlying ShelfItem is active (i.e. has focus). |
33 STATE_ACTIVE = 1 << 2, | 32 STATE_ACTIVE = 1 << 2, |
34 // Underlying ShelfItem needs user's attention. | 33 // Underlying ShelfItem needs user's attention. |
35 STATE_ATTENTION = 1 << 3, | 34 STATE_ATTENTION = 1 << 3, |
36 STATE_FOCUSED = 1 << 4, | 35 STATE_FOCUSED = 1 << 4, |
37 // Hide the status (temporarily for some animations). | 36 // Hide the status (temporarily for some animations). |
38 STATE_HIDDEN = 1 << 5, | 37 STATE_HIDDEN = 1 << 5, |
39 }; | 38 }; |
40 | 39 |
| 40 explicit ShelfButton(ShelfView* shelf_view); |
41 ~ShelfButton() override; | 41 ~ShelfButton() override; |
42 | 42 |
43 // Called to create an instance of a ShelfButton. | |
44 static ShelfButton* Create(views::ButtonListener* listener, | |
45 ShelfButtonHost* host, | |
46 Shelf* shelf); | |
47 | |
48 // Sets the image to display for this entry. | 43 // Sets the image to display for this entry. |
49 void SetImage(const gfx::ImageSkia& image); | 44 void SetImage(const gfx::ImageSkia& image); |
50 | 45 |
51 // Retrieve the image to show proxy operations. | 46 // Retrieve the image to show proxy operations. |
52 const gfx::ImageSkia& GetImage() const; | 47 const gfx::ImageSkia& GetImage() const; |
53 | 48 |
54 // |state| is or'd into the current state. | 49 // |state| is or'd into the current state. |
55 void AddState(State state); | 50 void AddState(State state); |
56 void ClearState(State state); | 51 void ClearState(State state); |
57 int state() const { return state_; } | 52 int state() const { return state_; } |
58 const Shelf* shelf() const { return shelf_; } | |
59 | 53 |
60 // Returns the bounds of the icon. | 54 // Returns the bounds of the icon. |
61 gfx::Rect GetIconBounds() const; | 55 gfx::Rect GetIconBounds() const; |
62 | 56 |
63 // Overrides to views::CustomButton: | 57 // Overrides to views::CustomButton: |
64 void ShowContextMenu(const gfx::Point& p, | 58 void ShowContextMenu(const gfx::Point& p, |
65 ui::MenuSourceType source_type) override; | 59 ui::MenuSourceType source_type) override; |
66 | 60 |
67 // View override - needed by unit test. | 61 // View override - needed by unit test. |
68 void OnMouseCaptureLost() override; | 62 void OnMouseCaptureLost() override; |
69 | 63 |
70 protected: | 64 protected: |
71 ShelfButton(views::ButtonListener* listener, | |
72 ShelfButtonHost* host, | |
73 Shelf* shelf); | |
74 | |
75 // Class that draws the icon part of a button, so it can be animated | |
76 // independently of the rest. This can be subclassed to provide a custom | |
77 // implementation, by overriding CreateIconView(). | |
78 class IconView : public views::ImageView { | |
79 public: | |
80 IconView(); | |
81 ~IconView() override; | |
82 | |
83 void set_icon_size(int icon_size) { icon_size_ = icon_size; } | |
84 int icon_size() const { return icon_size_; } | |
85 | |
86 private: | |
87 // Set to non-zero to force icons to be resized to fit within a square, | |
88 // while maintaining original proportions. | |
89 int icon_size_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(IconView); | |
92 }; | |
93 | |
94 // View overrides: | 65 // View overrides: |
95 const char* GetClassName() const override; | 66 const char* GetClassName() const override; |
96 bool OnMousePressed(const ui::MouseEvent& event) override; | 67 bool OnMousePressed(const ui::MouseEvent& event) override; |
97 void OnMouseReleased(const ui::MouseEvent& event) override; | 68 void OnMouseReleased(const ui::MouseEvent& event) override; |
98 bool OnMouseDragged(const ui::MouseEvent& event) override; | 69 bool OnMouseDragged(const ui::MouseEvent& event) override; |
99 void OnMouseMoved(const ui::MouseEvent& event) override; | |
100 void OnMouseEntered(const ui::MouseEvent& event) override; | |
101 void OnMouseExited(const ui::MouseEvent& event) override; | |
102 void GetAccessibleState(ui::AXViewState* state) override; | 70 void GetAccessibleState(ui::AXViewState* state) override; |
103 void Layout() override; | 71 void Layout() override; |
104 void ChildPreferredSizeChanged(views::View* child) override; | 72 void ChildPreferredSizeChanged(views::View* child) override; |
105 void OnFocus() override; | 73 void OnFocus() override; |
106 void OnBlur() override; | 74 void OnBlur() override; |
107 void OnPaint(gfx::Canvas* canvas) override; | 75 void OnPaint(gfx::Canvas* canvas) override; |
108 | 76 |
109 // ui::EventHandler overrides: | 77 // ui::EventHandler overrides: |
110 void OnGestureEvent(ui::GestureEvent* event) override; | 78 void OnGestureEvent(ui::GestureEvent* event) override; |
111 | 79 |
112 // Sets the icon image with a shadow. | 80 // Sets the icon image with a shadow. |
113 void SetShadowedImage(const gfx::ImageSkia& bitmap); | 81 void SetShadowedImage(const gfx::ImageSkia& bitmap); |
114 // Override for custom initialization. | |
115 virtual void Init(); | |
116 // Override to subclass IconView. | |
117 virtual IconView* CreateIconView(); | |
118 IconView* icon_view() const { return icon_view_; } | |
119 ShelfButtonHost* host() const { return host_; } | |
120 | 82 |
121 private: | 83 private: |
122 class BarView; | 84 class BarView; |
123 | 85 |
124 // Updates the parts of the button to reflect the current |state_| and | 86 // Updates the parts of the button to reflect the current |state_| and |
125 // alignment. This may add or remove views, layout and paint. | 87 // alignment. This may add or remove views, layout and paint. |
126 void UpdateState(); | 88 void UpdateState(); |
127 | 89 |
128 // Updates the status bar (bitmap, orientation, visibility). | 90 // Updates the status bar (bitmap, orientation, visibility). |
129 void UpdateBar(); | 91 void UpdateBar(); |
130 | 92 |
131 ShelfButtonHost* host_; | 93 // The shelf view hosting this button. |
132 IconView* icon_view_; | 94 ShelfView* shelf_view_; |
| 95 |
| 96 // The icon part of a button can be animated independently of the rest. |
| 97 views::ImageView* icon_view_; |
| 98 |
133 // Draws a bar underneath the image to represent the state of the application. | 99 // Draws a bar underneath the image to represent the state of the application. |
134 BarView* bar_; | 100 BarView* bar_; |
135 // The current state of the application, multiple values of AppState are or'd | 101 |
136 // together. | 102 // The current application state, a bitfield of State enum values. |
137 int state_; | 103 int state_; |
138 | 104 |
139 Shelf* shelf_; | |
140 | |
141 gfx::ShadowValues icon_shadows_; | 105 gfx::ShadowValues icon_shadows_; |
142 | 106 |
143 // If non-null the destuctor sets this to true. This is set while the menu is | 107 // If non-null the destuctor sets this to true. This is set while the menu is |
144 // showing and used to detect if the menu was deleted while running. | 108 // showing and used to detect if the menu was deleted while running. |
145 bool* destroyed_flag_; | 109 bool* destroyed_flag_; |
146 | 110 |
147 DISALLOW_COPY_AND_ASSIGN(ShelfButton); | 111 DISALLOW_COPY_AND_ASSIGN(ShelfButton); |
148 }; | 112 }; |
149 | 113 |
150 } // namespace ash | 114 } // namespace ash |
151 | 115 |
152 #endif // ASH_SHELF_SHELF_BUTTON_H_ | 116 #endif // ASH_SHELF_SHELF_BUTTON_H_ |
OLD | NEW |