Home | History | Annotate | Download | only in status
      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.
     34   virtual bool HasIcons() const  { return false; }
     35   virtual int GetItemCount() const;
     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 
     55   // PowerLibrary::Observer implementation.
     56   virtual void PowerChanged(PowerLibrary* obj);
     57   virtual void SystemResumed() {}
     58 
     59   int icon_id() const { return icon_id_; }
     60 
     61  protected:
     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