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 MASH_SHELF_SHELF_BUTTON_H_ |
6 #define ASH_SHELF_SHELF_BUTTON_H_ | 6 #define MASH_SHELF_SHELF_BUTTON_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | |
9 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "mash/shelf/shelf_types.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 mash { |
| 15 namespace shelf { |
15 class ShelfButtonHost; | 16 class ShelfButtonHost; |
16 class ShelfLayoutManager; | |
17 | 17 |
18 // Button used for items on the launcher, except for the AppList. | 18 // Button used for items on the launcher, except for the AppList. |
19 class ASH_EXPORT ShelfButton : public views::CustomButton { | 19 class ShelfButton : public views::CustomButton { |
20 public: | 20 public: |
21 static const char kViewClassName[]; | 21 static const char kViewClassName[]; |
22 | 22 |
23 // Used to indicate the current state of the button. | 23 // Used to indicate the current state of the button. |
24 enum State { | 24 enum State { |
25 // Nothing special. Usually represents an app shortcut item with no running | 25 // Nothing special. Usually represents an app shortcut item with no running |
26 // instance. | 26 // instance. |
27 STATE_NORMAL = 0, | 27 STATE_NORMAL = 0, |
28 // Button has mouse hovering on it. | 28 // Button has mouse hovering on it. |
29 STATE_HOVERED = 1 << 0, | 29 STATE_HOVERED = 1 << 0, |
30 // Underlying ShelfItem has a running instance. | 30 // Underlying ShelfItem has a running instance. |
31 STATE_RUNNING = 1 << 1, | 31 STATE_RUNNING = 1 << 1, |
32 // Underlying ShelfItem is active (i.e. has focus). | 32 // Underlying ShelfItem is active (i.e. has focus). |
33 STATE_ACTIVE = 1 << 2, | 33 STATE_ACTIVE = 1 << 2, |
34 // Underlying ShelfItem needs user's attention. | 34 // Underlying ShelfItem needs user's attention. |
35 STATE_ATTENTION = 1 << 3, | 35 STATE_ATTENTION = 1 << 3, |
36 STATE_FOCUSED = 1 << 4, | 36 STATE_FOCUSED = 1 << 4, |
37 // Hide the status (temporarily for some animations). | 37 // Hide the status (temporarily for some animations). |
38 STATE_HIDDEN = 1 << 5, | 38 STATE_HIDDEN = 1 << 5, |
39 }; | 39 }; |
40 | 40 |
41 ~ShelfButton() override; | 41 ~ShelfButton() override; |
42 | 42 |
43 // Called to create an instance of a ShelfButton. | 43 // Called to create an instance of a ShelfButton. |
44 static ShelfButton* Create(views::ButtonListener* listener, | 44 static ShelfButton* Create(views::ButtonListener* listener, |
45 ShelfButtonHost* host, | 45 ShelfButtonHost* host); |
46 ShelfLayoutManager* shelf_layout_manager); | |
47 | 46 |
48 // Sets the image to display for this entry. | 47 // Sets the image to display for this entry. |
49 void SetImage(const gfx::ImageSkia& image); | 48 void SetImage(const gfx::ImageSkia& image); |
50 | 49 |
51 // Retrieve the image to show proxy operations. | 50 // Retrieve the image to show proxy operations. |
52 const gfx::ImageSkia& GetImage() const; | 51 const gfx::ImageSkia& GetImage() const; |
53 | 52 |
54 // |state| is or'd into the current state. | 53 // |state| is or'd into the current state. |
55 void AddState(State state); | 54 void AddState(State state); |
56 void ClearState(State state); | 55 void ClearState(State state); |
57 int state() const { return state_; } | 56 int state() const { return state_; } |
58 const ShelfLayoutManager* shelf_layout_manager() const { | |
59 return shelf_layout_manager_; | |
60 } | |
61 | 57 |
62 // Returns the bounds of the icon. | 58 // Returns the bounds of the icon. |
63 gfx::Rect GetIconBounds() const; | 59 gfx::Rect GetIconBounds() const; |
64 | 60 |
65 // Overrides to views::CustomButton: | 61 // Overrides to views::CustomButton: |
66 void ShowContextMenu(const gfx::Point& p, | 62 void ShowContextMenu(const gfx::Point& p, |
67 ui::MenuSourceType source_type) override; | 63 ui::MenuSourceType source_type) override; |
68 | 64 |
69 // View override - needed by unit test. | 65 // View override - needed by unit test. |
70 void OnMouseCaptureLost() override; | 66 void OnMouseCaptureLost() override; |
71 | 67 |
72 protected: | 68 protected: |
73 ShelfButton(views::ButtonListener* listener, | 69 ShelfButton(views::ButtonListener* listener, |
74 ShelfButtonHost* host, | 70 ShelfButtonHost* host); |
75 ShelfLayoutManager* shelf_layout_manager); | |
76 | 71 |
77 // Class that draws the icon part of a button, so it can be animated | 72 // Class that draws the icon part of a button, so it can be animated |
78 // independently of the rest. This can be subclassed to provide a custom | 73 // independently of the rest. This can be subclassed to provide a custom |
79 // implementation, by overriding CreateIconView(). | 74 // implementation, by overriding CreateIconView(). |
80 class IconView : public views::ImageView { | 75 class IconView : public views::ImageView { |
81 public: | 76 public: |
82 IconView(); | 77 IconView(); |
83 ~IconView() override; | 78 ~IconView() override; |
84 | 79 |
85 void set_icon_size(int icon_size) { icon_size_ = icon_size; } | 80 void set_icon_size(int icon_size) { icon_size_ = icon_size; } |
(...skipping 30 matching lines...) Expand all Loading... |
116 // Override for custom initialization. | 111 // Override for custom initialization. |
117 virtual void Init(); | 112 virtual void Init(); |
118 // Override to subclass IconView. | 113 // Override to subclass IconView. |
119 virtual IconView* CreateIconView(); | 114 virtual IconView* CreateIconView(); |
120 IconView* icon_view() const { return icon_view_; } | 115 IconView* icon_view() const { return icon_view_; } |
121 ShelfButtonHost* host() const { return host_; } | 116 ShelfButtonHost* host() const { return host_; } |
122 | 117 |
123 private: | 118 private: |
124 class BarView; | 119 class BarView; |
125 | 120 |
126 // Returns true if the shelf is horizontal. If this returns false the shelf is | |
127 // vertical. | |
128 bool IsShelfHorizontal() const; | |
129 | |
130 // Updates the parts of the button to reflect the current |state_| and | 121 // Updates the parts of the button to reflect the current |state_| and |
131 // alignment. This may add or remove views, layout and paint. | 122 // alignment. This may add or remove views, layout and paint. |
132 void UpdateState(); | 123 void UpdateState(); |
133 | 124 |
134 // Updates the status bar (bitmap, orientation, visibility). | 125 // Updates the status bar (bitmap, orientation, visibility). |
135 void UpdateBar(); | 126 void UpdateBar(); |
136 | 127 |
137 ShelfButtonHost* host_; | 128 ShelfButtonHost* host_; |
138 IconView* icon_view_; | 129 IconView* icon_view_; |
139 // Draws a bar underneath the image to represent the state of the application. | 130 // Draws a bar underneath the image to represent the state of the application. |
140 BarView* bar_; | 131 BarView* bar_; |
141 // The current state of the application, multiple values of AppState are or'd | 132 // The current state of the application, multiple values of AppState are or'd |
142 // together. | 133 // together. |
143 int state_; | 134 int state_; |
144 | 135 |
145 ShelfLayoutManager* shelf_layout_manager_; | |
146 | |
147 gfx::ShadowValues icon_shadows_; | 136 gfx::ShadowValues icon_shadows_; |
148 | 137 |
149 // If non-null the destuctor sets this to true. This is set while the menu is | 138 // If non-null the destuctor sets this to true. This is set while the menu is |
150 // showing and used to detect if the menu was deleted while running. | 139 // showing and used to detect if the menu was deleted while running. |
151 bool* destroyed_flag_; | 140 bool* destroyed_flag_; |
152 | 141 |
153 DISALLOW_COPY_AND_ASSIGN(ShelfButton); | 142 DISALLOW_COPY_AND_ASSIGN(ShelfButton); |
154 }; | 143 }; |
155 | 144 |
156 } // namespace ash | 145 } // namespace shelf |
| 146 } // namespace mash |
157 | 147 |
158 #endif // ASH_SHELF_SHELF_BUTTON_H_ | 148 #endif // MASH_SHELF_SHELF_BUTTON_H_ |
OLD | NEW |