| 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_POWER_MENU_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_POWER_MENU_BUTTON_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_STATUS_POWER_MENU_BUTTON_H_ | 6 #define CHROME_BROWSER_CHROMEOS_STATUS_POWER_MENU_BUTTON_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" |
| 9 #include "chrome/browser/chromeos/cros/power_library.h" | 10 #include "chrome/browser/chromeos/cros/power_library.h" |
| 10 #include "chrome/browser/chromeos/status/status_area_button.h" | 11 #include "chrome/browser/chromeos/status/status_area_button.h" |
| 11 #include "ui/base/models/menu_model.h" | 12 #include "views/controls/menu/menu_delegate.h" |
| 12 #include "views/controls/menu/menu_2.h" | |
| 13 #include "views/controls/menu/view_menu_delegate.h" | 13 #include "views/controls/menu/view_menu_delegate.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class TimeDelta; | 16 class TimeDelta; |
| 17 } | 17 } |
| 18 | 18 |
| 19 class SkBitmap; | 19 class SkBitmap; |
| 20 | 20 |
| 21 namespace chromeos { | 21 namespace chromeos { |
| 22 | 22 |
| 23 // The power menu button in the status area. | 23 // The power menu button in the status area. |
| 24 // This class will handle getting the power status and populating the menu. | 24 // This class will handle getting the power status and populating the menu. |
| 25 class PowerMenuButton : public StatusAreaButton, | 25 class PowerMenuButton : public StatusAreaButton, |
| 26 public views::MenuDelegate, |
| 26 public views::ViewMenuDelegate, | 27 public views::ViewMenuDelegate, |
| 27 public ui::MenuModel, | |
| 28 public PowerLibrary::Observer { | 28 public PowerLibrary::Observer { |
| 29 public: | 29 public: |
| 30 PowerMenuButton(); | 30 PowerMenuButton(); |
| 31 virtual ~PowerMenuButton(); | 31 virtual ~PowerMenuButton(); |
| 32 | 32 |
| 33 // ui::MenuModel implementation. | 33 // views::MenuDelegate implementation |
| 34 virtual bool HasIcons() const { return false; } | 34 virtual std::wstring GetLabel(int id) const OVERRIDE; |
| 35 virtual int GetItemCount() const; | 35 virtual bool IsCommandEnabled(int id) const OVERRIDE; |
| 36 virtual ui::MenuModel::ItemType GetTypeAt(int index) const; | |
| 37 virtual int GetCommandIdAt(int index) const { return index; } | |
| 38 virtual string16 GetLabelAt(int index) const; | |
| 39 virtual bool IsItemDynamicAt(int index) const { return true; } | |
| 40 virtual bool GetAcceleratorAt(int index, | |
| 41 ui::Accelerator* accelerator) const { return false; } | |
| 42 virtual bool IsItemCheckedAt(int index) const { return false; } | |
| 43 virtual int GetGroupIdAt(int index) const { return 0; } | |
| 44 virtual bool GetIconAt(int index, SkBitmap* icon) { return false; } | |
| 45 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const { | |
| 46 return NULL; | |
| 47 } | |
| 48 virtual bool IsEnabledAt(int index) const { return false; } | |
| 49 virtual ui::MenuModel* GetSubmenuModelAt(int index) const { return NULL; } | |
| 50 virtual void HighlightChangedTo(int index) {} | |
| 51 virtual void ActivatedAt(int index) {} | |
| 52 virtual void MenuWillShow() {} | |
| 53 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate) {} | |
| 54 | 36 |
| 55 // PowerLibrary::Observer implementation. | 37 // PowerLibrary::Observer implementation. |
| 56 virtual void PowerChanged(PowerLibrary* obj); | 38 virtual void PowerChanged(PowerLibrary* obj); |
| 57 virtual void SystemResumed() {} | 39 virtual void SystemResumed() {} |
| 58 | 40 |
| 59 int icon_id() const { return icon_id_; } | 41 int icon_id() const { return icon_id_; } |
| 60 | 42 |
| 61 protected: | 43 protected: |
| 62 virtual int icon_width() { return 26; } | 44 virtual int icon_width() { return 26; } |
| 63 | 45 |
| 64 private: | 46 private: |
| 65 // views::View | 47 // views::View |
| 66 virtual void OnLocaleChanged() OVERRIDE; | 48 virtual void OnLocaleChanged() OVERRIDE; |
| 67 | 49 |
| 68 // views::ViewMenuDelegate implementation. | 50 // views::ViewMenuDelegate implementation. |
| 69 virtual void RunMenu(views::View* source, const gfx::Point& pt); | 51 virtual void RunMenu(views::View* source, const gfx::Point& pt); |
| 70 | 52 |
| 53 // Format strings with power status |
| 54 string16 GetBatteryPercentageText() const; |
| 55 string16 GetBatteryIsChargedText() const; |
| 56 |
| 71 // Update the power icon and menu label info depending on the power status. | 57 // Update the power icon and menu label info depending on the power status. |
| 72 void UpdateIconAndLabelInfo(); | 58 void UpdateIconAndLabelInfo(); |
| 73 | 59 |
| 74 // The number of power images. | |
| 75 static const int kNumPowerImages; | |
| 76 | |
| 77 // Stored data gathered from CrosLibrary::PowerLibrary. | 60 // Stored data gathered from CrosLibrary::PowerLibrary. |
| 78 bool battery_is_present_; | 61 bool battery_is_present_; |
| 79 bool line_power_on_; | 62 bool line_power_on_; |
| 80 bool battery_fully_charged_; | 63 bool battery_fully_charged_; |
| 81 double battery_percentage_; | 64 double battery_percentage_; |
| 82 base::TimeDelta battery_time_to_full_; | 65 base::TimeDelta battery_time_to_full_; |
| 83 base::TimeDelta battery_time_to_empty_; | 66 base::TimeDelta battery_time_to_empty_; |
| 84 | 67 |
| 85 // The currently showing icon bitmap id. | 68 // The currently showing icon bitmap id. |
| 86 int icon_id_; | 69 int icon_id_; |
| 87 | 70 |
| 88 // The power menu. This needs to be initialized last since it calls into | 71 // The power menu. |
| 89 // GetLabelAt() during construction. | 72 scoped_ptr<views::MenuItemView> menu_; |
| 90 views::Menu2 power_menu_; | |
| 91 | 73 |
| 92 DISALLOW_COPY_AND_ASSIGN(PowerMenuButton); | 74 DISALLOW_COPY_AND_ASSIGN(PowerMenuButton); |
| 93 }; | 75 }; |
| 94 | 76 |
| 95 } // namespace chromeos | 77 } // namespace chromeos |
| 96 | 78 |
| 97 #endif // CHROME_BROWSER_CHROMEOS_STATUS_POWER_MENU_BUTTON_H_ | 79 #endif // CHROME_BROWSER_CHROMEOS_STATUS_POWER_MENU_BUTTON_H_ |
| OLD | NEW |