OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ |
6 #define CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ | 6 #define CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "chrome/browser/chromeos/status/status_area_host.h" | |
11 #include "views/controls/button/menu_button.h" | 10 #include "views/controls/button/menu_button.h" |
12 #include "views/controls/menu/view_menu_delegate.h" | 11 #include "views/controls/menu/view_menu_delegate.h" |
13 | 12 |
14 namespace chromeos { | 13 namespace gfx { |
14 class Font; | |
15 } | |
15 | 16 |
16 // Button to be used to represent status and allow menus to be popped up. | 17 // Button to be used to represent status and allow menus to be popped up. |
17 // Shows current button state by drawing a border around the current icon. | 18 // Shows current button state by drawing a border around the current icon. |
18 class StatusAreaButton : public views::MenuButton { | 19 class StatusAreaButton : public views::MenuButton { |
19 public: | 20 public: |
20 StatusAreaButton(StatusAreaHost* host, | 21 // Different text styles for different types of backgrounds. |
22 enum TextStyle { | |
23 WHITE_PLAIN, | |
24 GRAY_PLAIN, | |
25 WHITE_HALOED, | |
26 GRAY_EMBOSSED | |
27 }; | |
28 | |
29 class Delegate { | |
30 public: | |
31 // |command_id| can be any int, passed from the button to the delegate. | |
32 virtual bool ShouldExecuteCommand( | |
33 const views::View* button_view, int command_id) const = 0; | |
tfarina
2011/11/03 19:45:05
could you add a blank line between each function?
stevenjb
2011/11/04 00:46:42
Done.
| |
34 virtual void ExecuteCommand( | |
35 const views::View* button_view, int command_id) = 0; | |
36 // Contextually adjust the button appearance. | |
37 virtual int GetFontStyle(const gfx::Font& font) const = 0; | |
38 virtual TextStyle GetTextStyle() const = 0; | |
39 // Handle visibility changes (e.g. resize the status area). | |
40 virtual void ButtonVisibilityChanged(views::View* button_view) = 0; | |
41 }; | |
tfarina
2011/11/03 19:45:05
please, add a protected virtual dtor.
stevenjb
2011/11/04 00:46:42
Done.
| |
42 | |
43 StatusAreaButton(Delegate* button_delegate, | |
21 views::ViewMenuDelegate* menu_delegate); | 44 views::ViewMenuDelegate* menu_delegate); |
22 virtual ~StatusAreaButton() {} | 45 virtual ~StatusAreaButton() {} |
23 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); | 46 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); |
24 | 47 |
25 // Overrides TextButton's SetText to clear max text size before seting new | 48 // Overrides TextButton's SetText to clear max text size before seting new |
26 // text content so that the button size would fit the new text size. | 49 // text content so that the button size would fit the new text size. |
27 virtual void SetText(const string16& text); | 50 virtual void SetText(const string16& text); |
28 | 51 |
29 void set_use_menu_button_paint(bool use_menu_button_paint) { | |
30 use_menu_button_paint_ = use_menu_button_paint; | |
31 } | |
32 | |
33 // views::MenuButton overrides. | 52 // views::MenuButton overrides. |
34 virtual bool Activate() OVERRIDE; | 53 virtual bool Activate() OVERRIDE; |
35 | 54 |
36 // View overrides. | 55 // View overrides. |
37 virtual gfx::Size GetPreferredSize() OVERRIDE; | 56 virtual gfx::Size GetPreferredSize() OVERRIDE; |
38 virtual gfx::Insets GetInsets() const OVERRIDE; | 57 virtual gfx::Insets GetInsets() const OVERRIDE; |
39 virtual void OnThemeChanged() OVERRIDE; | 58 virtual void OnThemeChanged() OVERRIDE; |
40 virtual void SetVisible(bool visible) OVERRIDE; | 59 virtual void SetVisible(bool visible) OVERRIDE; |
41 virtual bool HitTest(const gfx::Point& l) const OVERRIDE; | 60 virtual bool HitTest(const gfx::Point& l) const OVERRIDE; |
42 | 61 |
43 // Controls whether or not this status area button is able to be pressed. | 62 void set_menu_active(bool active) { menu_active_ = active; } |
44 void set_active(bool active) { active_ = active; } | 63 bool menu_active() const { return menu_active_; } |
45 bool active() const { return active_; } | |
46 | 64 |
47 protected: | 65 protected: |
66 Delegate* delegate() { return delegate_; } | |
67 const Delegate* delegate() const { return delegate_; } | |
68 | |
48 // Subclasses should override these methods to return the correct dimensions. | 69 // Subclasses should override these methods to return the correct dimensions. |
49 virtual int icon_height(); | 70 virtual int icon_height(); |
50 virtual int icon_width(); | 71 virtual int icon_width(); |
51 | 72 |
52 // Subclasses can override this method to return more or less padding. | 73 // Subclasses can override this method to return more or less padding. |
53 // The padding is added to both the left and right side. | 74 // The padding is added to both the left and right side. |
54 virtual int horizontal_padding(); | 75 virtual int horizontal_padding(); |
55 | 76 |
56 // True if the button wants to use views::MenuButton drawings. | |
57 bool use_menu_button_paint_; | |
58 | |
59 // Insets to use for this button. | 77 // Insets to use for this button. |
60 gfx::Insets insets_; | 78 gfx::Insets insets_; |
61 | 79 |
62 // Indicates when this button can be pressed. Independent of | 80 // Controls whether or not the menu can be activated. This is independent of |
63 // IsEnabled state, so that when IsEnabled is true, this can still | 81 // IsEnabled state, so that we can prevent the menu from appearing without |
64 // be false, and vice versa. | 82 // affecting the appearance of the button. |
65 bool active_; | 83 bool menu_active_; |
66 | |
67 // The status area host, | |
68 StatusAreaHost* host_; | |
69 | 84 |
70 private: | 85 private: |
71 void UpdateTextStyle(); | 86 void UpdateTextStyle(); |
72 | 87 |
88 Delegate* delegate_; | |
89 | |
73 DISALLOW_COPY_AND_ASSIGN(StatusAreaButton); | 90 DISALLOW_COPY_AND_ASSIGN(StatusAreaButton); |
74 }; | 91 }; |
75 | 92 |
76 } // namespace chromeos | |
77 | |
78 #endif // CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ | 93 #endif // CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ |
OLD | NEW |