Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(842)

Side by Side Diff: ash/shelf/shelf_button.h

Issue 1743493002: Cleanup ash shelf accessor functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert ash/shelf/shelf_widget.cc for browser_tests crash... Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/shelf_alignment_menu.cc ('k') | ash/shelf/shelf_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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 ASH_EXPORT 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); 46 Shelf* shelf);
47 47
48 // Sets the image to display for this entry. 48 // Sets the image to display for this entry.
49 void SetImage(const gfx::ImageSkia& image); 49 void SetImage(const gfx::ImageSkia& image);
50 50
51 // Retrieve the image to show proxy operations. 51 // Retrieve the image to show proxy operations.
52 const gfx::ImageSkia& GetImage() const; 52 const gfx::ImageSkia& GetImage() const;
53 53
54 // |state| is or'd into the current state. 54 // |state| is or'd into the current state.
55 void AddState(State state); 55 void AddState(State state);
56 void ClearState(State state); 56 void ClearState(State state);
57 int state() const { return state_; } 57 int state() const { return state_; }
58 const ShelfLayoutManager* shelf_layout_manager() const { 58 const Shelf* shelf() const { return shelf_; }
59 return shelf_layout_manager_;
60 }
61 59
62 // Returns the bounds of the icon. 60 // Returns the bounds of the icon.
63 gfx::Rect GetIconBounds() const; 61 gfx::Rect GetIconBounds() const;
64 62
65 // Overrides to views::CustomButton: 63 // Overrides to views::CustomButton:
66 void ShowContextMenu(const gfx::Point& p, 64 void ShowContextMenu(const gfx::Point& p,
67 ui::MenuSourceType source_type) override; 65 ui::MenuSourceType source_type) override;
68 66
69 // View override - needed by unit test. 67 // View override - needed by unit test.
70 void OnMouseCaptureLost() override; 68 void OnMouseCaptureLost() override;
71 69
72 protected: 70 protected:
73 ShelfButton(views::ButtonListener* listener, 71 ShelfButton(views::ButtonListener* listener,
74 ShelfButtonHost* host, 72 ShelfButtonHost* host,
75 ShelfLayoutManager* shelf_layout_manager); 73 Shelf* shelf);
76 74
77 // Class that draws the icon part of a button, so it can be animated 75 // 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 76 // independently of the rest. This can be subclassed to provide a custom
79 // implementation, by overriding CreateIconView(). 77 // implementation, by overriding CreateIconView().
80 class IconView : public views::ImageView { 78 class IconView : public views::ImageView {
81 public: 79 public:
82 IconView(); 80 IconView();
83 ~IconView() override; 81 ~IconView() override;
84 82
85 void set_icon_size(int icon_size) { icon_size_ = icon_size; } 83 void set_icon_size(int icon_size) { icon_size_ = icon_size; }
(...skipping 30 matching lines...) Expand all
116 // Override for custom initialization. 114 // Override for custom initialization.
117 virtual void Init(); 115 virtual void Init();
118 // Override to subclass IconView. 116 // Override to subclass IconView.
119 virtual IconView* CreateIconView(); 117 virtual IconView* CreateIconView();
120 IconView* icon_view() const { return icon_view_; } 118 IconView* icon_view() const { return icon_view_; }
121 ShelfButtonHost* host() const { return host_; } 119 ShelfButtonHost* host() const { return host_; }
122 120
123 private: 121 private:
124 class BarView; 122 class BarView;
125 123
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 124 // Updates the parts of the button to reflect the current |state_| and
131 // alignment. This may add or remove views, layout and paint. 125 // alignment. This may add or remove views, layout and paint.
132 void UpdateState(); 126 void UpdateState();
133 127
134 // Updates the status bar (bitmap, orientation, visibility). 128 // Updates the status bar (bitmap, orientation, visibility).
135 void UpdateBar(); 129 void UpdateBar();
136 130
137 ShelfButtonHost* host_; 131 ShelfButtonHost* host_;
138 IconView* icon_view_; 132 IconView* icon_view_;
139 // Draws a bar underneath the image to represent the state of the application. 133 // Draws a bar underneath the image to represent the state of the application.
140 BarView* bar_; 134 BarView* bar_;
141 // The current state of the application, multiple values of AppState are or'd 135 // The current state of the application, multiple values of AppState are or'd
142 // together. 136 // together.
143 int state_; 137 int state_;
144 138
145 ShelfLayoutManager* shelf_layout_manager_; 139 Shelf* shelf_;
146 140
147 gfx::ShadowValues icon_shadows_; 141 gfx::ShadowValues icon_shadows_;
148 142
149 // If non-null the destuctor sets this to true. This is set while the menu is 143 // 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. 144 // showing and used to detect if the menu was deleted while running.
151 bool* destroyed_flag_; 145 bool* destroyed_flag_;
152 146
153 DISALLOW_COPY_AND_ASSIGN(ShelfButton); 147 DISALLOW_COPY_AND_ASSIGN(ShelfButton);
154 }; 148 };
155 149
156 } // namespace ash 150 } // namespace ash
157 151
158 #endif // ASH_SHELF_SHELF_BUTTON_H_ 152 #endif // ASH_SHELF_SHELF_BUTTON_H_
OLDNEW
« no previous file with comments | « ash/shelf/shelf_alignment_menu.cc ('k') | ash/shelf/shelf_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698