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