| 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 ShouldExecuteStatusAreaCommand( |
| 33 const views::View* button_view, int command_id) const = 0; |
| 34 |
| 35 virtual void ExecuteStatusAreaCommand( |
| 36 const views::View* button_view, int command_id) = 0; |
| 37 |
| 38 // Return the button font. |font| is set to the default button font. |
| 39 virtual gfx::Font GetStatusAreaFont(const gfx::Font& font) const = 0; |
| 40 |
| 41 virtual TextStyle GetStatusAreaTextStyle() const = 0; |
| 42 |
| 43 // Handle visibility changes (e.g. resize the status area). |
| 44 virtual void ButtonVisibilityChanged(views::View* button_view) = 0; |
| 45 |
| 46 protected: |
| 47 virtual ~Delegate() {} |
| 48 }; |
| 49 |
| 50 StatusAreaButton(Delegate* button_delegate, |
| 21 views::ViewMenuDelegate* menu_delegate); | 51 views::ViewMenuDelegate* menu_delegate); |
| 22 virtual ~StatusAreaButton() {} | 52 virtual ~StatusAreaButton() {} |
| 23 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); | 53 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); |
| 24 | 54 |
| 25 // Overrides TextButton's SetText to clear max text size before seting new | 55 // 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. | 56 // text content so that the button size would fit the new text size. |
| 27 virtual void SetText(const string16& text); | 57 virtual void SetText(const string16& text); |
| 28 | 58 |
| 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. | 59 // views::MenuButton overrides. |
| 34 virtual bool Activate() OVERRIDE; | 60 virtual bool Activate() OVERRIDE; |
| 35 | 61 |
| 36 // View overrides. | 62 // View overrides. |
| 37 virtual gfx::Size GetPreferredSize() OVERRIDE; | 63 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 38 virtual gfx::Insets GetInsets() const OVERRIDE; | 64 virtual gfx::Insets GetInsets() const OVERRIDE; |
| 39 virtual void OnThemeChanged() OVERRIDE; | 65 virtual void OnThemeChanged() OVERRIDE; |
| 40 virtual void SetVisible(bool visible) OVERRIDE; | 66 virtual void SetVisible(bool visible) OVERRIDE; |
| 41 virtual bool HitTest(const gfx::Point& l) const OVERRIDE; | 67 virtual bool HitTest(const gfx::Point& l) const OVERRIDE; |
| 42 | 68 |
| 43 // Controls whether or not this status area button is able to be pressed. | 69 void set_menu_active(bool active) { menu_active_ = active; } |
| 44 void set_active(bool active) { active_ = active; } | 70 bool menu_active() const { return menu_active_; } |
| 45 bool active() const { return active_; } | |
| 46 | 71 |
| 47 protected: | 72 protected: |
| 73 Delegate* delegate() { return delegate_; } |
| 74 const Delegate* delegate() const { return delegate_; } |
| 75 |
| 48 // Subclasses should override these methods to return the correct dimensions. | 76 // Subclasses should override these methods to return the correct dimensions. |
| 49 virtual int icon_height(); | 77 virtual int icon_height(); |
| 50 virtual int icon_width(); | 78 virtual int icon_width(); |
| 51 | 79 |
| 52 // Subclasses can override this method to return more or less padding. | 80 // Subclasses can override this method to return more or less padding. |
| 53 // The padding is added to both the left and right side. | 81 // The padding is added to both the left and right side. |
| 54 virtual int horizontal_padding(); | 82 virtual int horizontal_padding(); |
| 55 | 83 |
| 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. | 84 // Insets to use for this button. |
| 60 gfx::Insets insets_; | 85 gfx::Insets insets_; |
| 61 | 86 |
| 62 // Indicates when this button can be pressed. Independent of | 87 // 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 | 88 // IsEnabled state, so that we can prevent the menu from appearing without |
| 64 // be false, and vice versa. | 89 // affecting the appearance of the button. |
| 65 bool active_; | 90 bool menu_active_; |
| 66 | |
| 67 // The status area host, | |
| 68 StatusAreaHost* host_; | |
| 69 | 91 |
| 70 private: | 92 private: |
| 71 void UpdateTextStyle(); | 93 void UpdateTextStyle(); |
| 72 | 94 |
| 95 Delegate* delegate_; |
| 96 |
| 73 DISALLOW_COPY_AND_ASSIGN(StatusAreaButton); | 97 DISALLOW_COPY_AND_ASSIGN(StatusAreaButton); |
| 74 }; | 98 }; |
| 75 | 99 |
| 76 } // namespace chromeos | |
| 77 | |
| 78 #endif // CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ | 100 #endif // CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ |
| OLD | NEW |