OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/timer.h" | 11 #include "base/timer.h" |
12 #include "chrome/browser/chromeos/status/status_area_button.h" | 12 #include "chrome/browser/chromeos/status/status_area_button.h" |
13 #include "chrome/browser/prefs/pref_change_registrar.h" | 13 #include "chrome/browser/prefs/pref_change_registrar.h" |
14 #include "chrome/browser/prefs/pref_member.h" | 14 #include "chrome/browser/prefs/pref_member.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 #include "ui/views/controls/button/menu_button.h" | 17 #include "ui/views/controls/button/menu_button.h" |
18 #include "ui/views/controls/button/menu_button_delegate.h" | 18 #include "ui/views/controls/button/menu_button_listener.h" |
19 #include "ui/views/controls/menu/menu_delegate.h" | 19 #include "ui/views/controls/menu/menu_delegate.h" |
20 #include "unicode/calendar.h" | 20 #include "unicode/calendar.h" |
21 | 21 |
22 namespace views { | 22 namespace views { |
23 class MenuRunner; | 23 class MenuRunner; |
24 } | 24 } |
25 | 25 |
26 // The clock menu button in the status area. | 26 // The clock menu button in the status area. |
27 // This button shows the current time. | 27 // This button shows the current time. |
28 class ClockMenuButton : public StatusAreaButton, | 28 class ClockMenuButton : public StatusAreaButton, |
29 public views::MenuDelegate, | 29 public views::MenuDelegate, |
30 public views::MenuButtonDelegate, | 30 public views::MenuButtonListener, |
31 public content::NotificationObserver { | 31 public content::NotificationObserver { |
32 public: | 32 public: |
33 explicit ClockMenuButton(StatusAreaButton::Delegate* delegate); | 33 explicit ClockMenuButton(StatusAreaButton::Delegate* delegate); |
34 virtual ~ClockMenuButton(); | 34 virtual ~ClockMenuButton(); |
35 | 35 |
36 // content::NotificationObserver implementation. | 36 // content::NotificationObserver implementation. |
37 virtual void Observe(int type, | 37 virtual void Observe(int type, |
38 const content::NotificationSource& source, | 38 const content::NotificationSource& source, |
39 const content::NotificationDetails& details) OVERRIDE; | 39 const content::NotificationDetails& details) OVERRIDE; |
40 | 40 |
41 // views::MenuDelegate implementation | 41 // views::MenuDelegate implementation |
42 virtual string16 GetLabel(int id) const OVERRIDE; | 42 virtual string16 GetLabel(int id) const OVERRIDE; |
43 virtual bool IsCommandEnabled(int id) const OVERRIDE; | 43 virtual bool IsCommandEnabled(int id) const OVERRIDE; |
44 virtual void ExecuteCommand(int id) OVERRIDE; | 44 virtual void ExecuteCommand(int id) OVERRIDE; |
45 | 45 |
46 // Initialize PrefChangeRegistrar with the current default profile. | 46 // Initialize PrefChangeRegistrar with the current default profile. |
47 void UpdateProfile(); | 47 void UpdateProfile(); |
48 | 48 |
49 // Updates the time on the menu button. | 49 // Updates the time on the menu button. |
50 void UpdateText(); | 50 void UpdateText(); |
51 | 51 |
52 protected: | 52 protected: |
53 // StatusAreaButton implementation | 53 // StatusAreaButton implementation |
54 virtual void SetMenuActive(bool active) OVERRIDE; | 54 virtual void SetMenuActive(bool active) OVERRIDE; |
55 virtual int horizontal_padding() OVERRIDE; | 55 virtual int horizontal_padding() OVERRIDE; |
56 | 56 |
57 // views::View implementation | 57 // views::View implementation |
58 virtual void OnLocaleChanged() OVERRIDE; | 58 virtual void OnLocaleChanged() OVERRIDE; |
59 | 59 |
60 // views::MenuButtonDelegate implementation. | 60 // views::MenuButtonListener implementation. |
61 virtual void RunMenu(views::View* source, const gfx::Point& pt) OVERRIDE; | 61 virtual void OnMenuButtonClicked(views::View* source, |
| 62 const gfx::Point& point) OVERRIDE; |
62 | 63 |
63 private: | 64 private: |
64 // Sets default use 24hour clock mode. | 65 // Sets default use 24hour clock mode. |
65 void SetUse24HourClock(bool use_24hour_clock); | 66 void SetUse24HourClock(bool use_24hour_clock); |
66 | 67 |
67 // Create menu and return menu runner. | 68 // Create menu and return menu runner. |
68 views::MenuRunner* CreateMenu(); | 69 views::MenuRunner* CreateMenu(); |
69 | 70 |
70 // Updates text and schedules the timer to fire at the next minute interval. | 71 // Updates text and schedules the timer to fire at the next minute interval. |
71 void UpdateTextAndSetNextTimer(); | 72 void UpdateTextAndSetNextTimer(); |
72 | 73 |
73 base::OneShotTimer<ClockMenuButton> timer_; | 74 base::OneShotTimer<ClockMenuButton> timer_; |
74 PrefService* pref_service_; | 75 PrefService* pref_service_; |
75 scoped_ptr<PrefChangeRegistrar> registrar_; | 76 scoped_ptr<PrefChangeRegistrar> registrar_; |
76 | 77 |
77 // Cached value for use_24hour_clock. | 78 // Cached value for use_24hour_clock. |
78 bool use_24hour_clock_; | 79 bool use_24hour_clock_; |
79 | 80 |
80 DISALLOW_COPY_AND_ASSIGN(ClockMenuButton); | 81 DISALLOW_COPY_AND_ASSIGN(ClockMenuButton); |
81 }; | 82 }; |
82 | 83 |
83 #endif // CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ | 84 #endif // CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ |
OLD | NEW |