| 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_CLOCK_MENU_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ | 6 #define CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/timer.h" | 11 #include "base/timer.h" |
| 11 #include "chrome/browser/chromeos/cros/power_library.h" | 12 #include "chrome/browser/chromeos/cros/power_library.h" |
| 12 #include "chrome/browser/chromeos/status/status_area_button.h" | 13 #include "chrome/browser/chromeos/status/status_area_button.h" |
| 13 #include "chrome/browser/prefs/pref_change_registrar.h" | 14 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 14 #include "chrome/browser/prefs/pref_member.h" | 15 #include "chrome/browser/prefs/pref_member.h" |
| 15 #include "content/common/notification_observer.h" | 16 #include "content/common/notification_observer.h" |
| 16 #include "content/common/notification_type.h" | 17 #include "content/common/notification_type.h" |
| 17 #include "chrome/browser/chromeos/system_access.h" | 18 #include "chrome/browser/chromeos/system_access.h" |
| 18 #include "unicode/calendar.h" | 19 #include "unicode/calendar.h" |
| 19 #include "views/controls/button/menu_button.h" | 20 #include "views/controls/button/menu_button.h" |
| 20 #include "views/controls/menu/menu_2.h" | 21 #include "views/controls/menu/menu_delegate.h" |
| 21 #include "views/controls/menu/view_menu_delegate.h" | 22 #include "views/controls/menu/view_menu_delegate.h" |
| 22 | 23 |
| 23 namespace chromeos { | 24 namespace chromeos { |
| 24 | 25 |
| 25 class StatusAreaHost; | 26 class StatusAreaHost; |
| 26 | 27 |
| 27 // The clock menu button in the status area. | 28 // The clock menu button in the status area. |
| 28 // This button shows the current time. | 29 // This button shows the current time. |
| 29 class ClockMenuButton : public StatusAreaButton, | 30 class ClockMenuButton : public StatusAreaButton, |
| 31 public views::MenuDelegate, |
| 30 public views::ViewMenuDelegate, | 32 public views::ViewMenuDelegate, |
| 31 public ui::MenuModel, | |
| 32 public NotificationObserver, | 33 public NotificationObserver, |
| 33 public PowerLibrary::Observer, | 34 public PowerLibrary::Observer, |
| 34 public SystemAccess::Observer { | 35 public SystemAccess::Observer { |
| 35 public: | 36 public: |
| 36 explicit ClockMenuButton(StatusAreaHost* host); | 37 explicit ClockMenuButton(StatusAreaHost* host); |
| 37 virtual ~ClockMenuButton(); | 38 virtual ~ClockMenuButton(); |
| 38 | 39 |
| 39 // ui::MenuModel implementation. | 40 // views::MenuDelegate implementation |
| 40 virtual bool HasIcons() const { return false; } | 41 virtual std::wstring GetLabel(int id) const OVERRIDE; |
| 41 virtual int GetItemCount() const; | 42 virtual bool IsCommandEnabled(int id) const OVERRIDE; |
| 42 virtual ui::MenuModel::ItemType GetTypeAt(int index) const; | 43 virtual void ExecuteCommand(int id) OVERRIDE; |
| 43 virtual int GetCommandIdAt(int index) const { return index; } | |
| 44 virtual string16 GetLabelAt(int index) const; | |
| 45 virtual bool IsItemDynamicAt(int index) const { return true; } | |
| 46 virtual bool GetAcceleratorAt(int index, | |
| 47 ui::Accelerator* accelerator) const { return false; } | |
| 48 virtual bool IsItemCheckedAt(int index) const { return false; } | |
| 49 virtual int GetGroupIdAt(int index) const { return 0; } | |
| 50 virtual bool GetIconAt(int index, SkBitmap* icon) { return false; } | |
| 51 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const { | |
| 52 return NULL; | |
| 53 } | |
| 54 virtual bool IsEnabledAt(int index) const; | |
| 55 virtual ui::MenuModel* GetSubmenuModelAt(int index) const { return NULL; } | |
| 56 virtual void HighlightChangedTo(int index) {} | |
| 57 virtual void ActivatedAt(int index); | |
| 58 virtual void MenuWillShow() {} | |
| 59 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate) {} | |
| 60 | 44 |
| 61 // Overridden from ResumeLibrary::Observer: | 45 // Overridden from ResumeLibrary::Observer: |
| 62 virtual void PowerChanged(PowerLibrary* obj) {} | 46 virtual void PowerChanged(PowerLibrary* obj) {} |
| 63 virtual void SystemResumed(); | 47 virtual void SystemResumed(); |
| 64 | 48 |
| 65 // Overridden from SystemAccess::Observer: | 49 // Overridden from SystemAccess::Observer: |
| 66 virtual void TimezoneChanged(const icu::TimeZone& timezone); | 50 virtual void TimezoneChanged(const icu::TimeZone& timezone); |
| 67 | 51 |
| 68 // views::View | 52 // views::View |
| 69 virtual void OnLocaleChanged() OVERRIDE; | 53 virtual void OnLocaleChanged() OVERRIDE; |
| 70 | 54 |
| 71 // Updates the time on the menu button. Can be called by host if timezone | 55 // Updates the time on the menu button. Can be called by host if timezone |
| 72 // changes. | 56 // changes. |
| 73 void UpdateText(); | 57 void UpdateText(); |
| 74 | 58 |
| 75 // NotificationObserver implementation. | 59 // NotificationObserver implementation. |
| 76 virtual void Observe(NotificationType type, | 60 virtual void Observe(NotificationType type, |
| 77 const NotificationSource& source, | 61 const NotificationSource& source, |
| 78 const NotificationDetails& details); | 62 const NotificationDetails& details); |
| 79 | 63 |
| 80 protected: | 64 protected: |
| 81 virtual int horizontal_padding() { return 3; } | 65 virtual int horizontal_padding() { return 3; } |
| 82 | 66 |
| 83 private: | 67 private: |
| 84 // views::ViewMenuDelegate implementation. | 68 // views::ViewMenuDelegate implementation. |
| 85 virtual void RunMenu(views::View* source, const gfx::Point& pt); | 69 virtual void RunMenu(views::View* source, const gfx::Point& pt); |
| 86 | 70 |
| 71 // Create and initialize menu if not already present. |
| 72 void EnsureMenu(); |
| 73 |
| 87 // Updates text and schedules the timer to fire at the next minute interval. | 74 // Updates text and schedules the timer to fire at the next minute interval. |
| 88 void UpdateTextAndSetNextTimer(); | 75 void UpdateTextAndSetNextTimer(); |
| 89 | 76 |
| 90 base::OneShotTimer<ClockMenuButton> timer_; | 77 base::OneShotTimer<ClockMenuButton> timer_; |
| 91 | 78 |
| 92 // The clock menu. | 79 // The clock menu. |
| 93 // NOTE: we use a scoped_ptr here as menu calls into 'this' from the | 80 // NOTE: we use a scoped_ptr here as menu calls into 'this' from the |
| 94 // constructor. | 81 // constructor. |
| 95 scoped_ptr<views::Menu2> clock_menu_; | 82 scoped_ptr<views::MenuItemView> menu_; |
| 96 | 83 |
| 97 StatusAreaHost* host_; | 84 StatusAreaHost* host_; |
| 98 | 85 |
| 99 PrefChangeRegistrar registrar_; | 86 PrefChangeRegistrar registrar_; |
| 100 | 87 |
| 101 DISALLOW_COPY_AND_ASSIGN(ClockMenuButton); | 88 DISALLOW_COPY_AND_ASSIGN(ClockMenuButton); |
| 102 }; | 89 }; |
| 103 | 90 |
| 104 } // namespace chromeos | 91 } // namespace chromeos |
| 105 | 92 |
| 106 #endif // CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ | 93 #endif // CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ |
| OLD | NEW |