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