Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/chromeos/status/power_menu_button.h

Issue 6811025: Change status button menu implementation from Menu2 to MenuItemView. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Changed refcount guard to use OS_CHROMEOS. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 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 "chrome/browser/chromeos/cros/power_library.h" 9 #include "chrome/browser/chromeos/cros/power_library.h"
10 #include "chrome/browser/chromeos/status/status_area_button.h" 10 #include "chrome/browser/chromeos/status/status_area_button.h"
11 #include "ui/base/models/menu_model.h" 11 #include "views/controls/menu/menu_delegate.h"
12 #include "views/controls/menu/menu_2.h"
13 #include "views/controls/menu/view_menu_delegate.h" 12 #include "views/controls/menu/view_menu_delegate.h"
14 13
15 namespace base { 14 namespace base {
16 class TimeDelta; 15 class TimeDelta;
17 } 16 }
18 17
19 class SkBitmap; 18 class SkBitmap;
20 19
21 namespace chromeos { 20 namespace chromeos {
22 21
23 // The power menu button in the status area. 22 // The power menu button in the status area.
24 // This class will handle getting the power status and populating the menu. 23 // This class will handle getting the power status and populating the menu.
25 class PowerMenuButton : public StatusAreaButton, 24 class PowerMenuButton : public StatusAreaButton,
25 public views::MenuDelegate,
26 public views::ViewMenuDelegate, 26 public views::ViewMenuDelegate,
27 public ui::MenuModel,
28 public PowerLibrary::Observer { 27 public PowerLibrary::Observer {
29 public: 28 public:
30 PowerMenuButton(); 29 PowerMenuButton();
31 virtual ~PowerMenuButton(); 30 virtual ~PowerMenuButton();
32 31
33 // ui::MenuModel implementation. 32 // views::MenuDelegate implementation
34 virtual bool HasIcons() const { return false; } 33 virtual std::wstring GetLabel(int id) const;
oshima 2011/04/14 17:27:31 OVERRIDE
rhashimoto 2011/04/14 18:27:04 Done.
35 virtual int GetItemCount() const; 34 virtual bool IsCommandEnabled(int id) 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 35
55 // PowerLibrary::Observer implementation. 36 // PowerLibrary::Observer implementation.
56 virtual void PowerChanged(PowerLibrary* obj); 37 virtual void PowerChanged(PowerLibrary* obj);
57 virtual void SystemResumed() {} 38 virtual void SystemResumed() {}
58 39
59 int icon_id() const { return icon_id_; } 40 int icon_id() const { return icon_id_; }
60 41
61 protected: 42 protected:
62 virtual int icon_width() { return 26; } 43 virtual int icon_width() { return 26; }
63 44
64 private: 45 private:
65 // views::ViewMenuDelegate implementation. 46 // views::ViewMenuDelegate implementation.
66 virtual void RunMenu(views::View* source, const gfx::Point& pt); 47 virtual void RunMenu(views::View* source, const gfx::Point& pt);
67 48
49 // Format strings with power status
50 string16 GetBatteryPercentageText() const;
51 string16 GetBatteryIsChargedText() const;
52
68 // Update the power icon and menu label info depending on the power status. 53 // Update the power icon and menu label info depending on the power status.
69 void UpdateIconAndLabelInfo(); 54 void UpdateIconAndLabelInfo();
70 55
71 // The number of power images. 56 // The number of power images.
72 static const int kNumPowerImages; 57 static const int kNumPowerImages;
73 58
74 // Stored data gathered from CrosLibrary::PowerLibrary. 59 // Stored data gathered from CrosLibrary::PowerLibrary.
75 bool battery_is_present_; 60 bool battery_is_present_;
76 bool line_power_on_; 61 bool line_power_on_;
77 bool battery_fully_charged_; 62 bool battery_fully_charged_;
78 double battery_percentage_; 63 double battery_percentage_;
79 base::TimeDelta battery_time_to_full_; 64 base::TimeDelta battery_time_to_full_;
80 base::TimeDelta battery_time_to_empty_; 65 base::TimeDelta battery_time_to_empty_;
81 66
82 // The currently showing icon bitmap id. 67 // The currently showing icon bitmap id.
83 int icon_id_; 68 int icon_id_;
84 69
85 // The power menu. This needs to be initialized last since it calls into 70 // The power menu.
86 // GetLabelAt() during construction. 71 scoped_ptr<views::MenuItemView> menu_;
87 views::Menu2 power_menu_;
88 72
89 DISALLOW_COPY_AND_ASSIGN(PowerMenuButton); 73 DISALLOW_COPY_AND_ASSIGN(PowerMenuButton);
90 }; 74 };
91 75
92 } // namespace chromeos 76 } // namespace chromeos
93 77
94 #endif // CHROME_BROWSER_CHROMEOS_STATUS_POWER_MENU_BUTTON_H_ 78 #endif // CHROME_BROWSER_CHROMEOS_STATUS_POWER_MENU_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698