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_CLOCK_MENU_BUTTON_H_
6#define CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_
7#pragma once
8
9#include "base/memory/scoped_ptr.h"
10#include "base/timer.h"
11#include "chrome/browser/chromeos/cros/power_library.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/common/notification_observer.h"
16#include "content/common/notification_type.h"
17#include "chrome/browser/chromeos/system_access.h"
18#include "unicode/calendar.h"
19#include "views/controls/button/menu_button.h"
20#include "views/controls/menu/menu_2.h"
21#include "views/controls/menu/view_menu_delegate.h"
22
23namespace chromeos {
24
25class StatusAreaHost;
26
27// The clock menu button in the status area.
28// This button shows the current time.
29class ClockMenuButton : public StatusAreaButton,
30                        public views::ViewMenuDelegate,
31                        public ui::MenuModel,
32                        public NotificationObserver,
33                        public PowerLibrary::Observer,
34                        public SystemAccess::Observer {
35 public:
36  explicit ClockMenuButton(StatusAreaHost* host);
37  virtual ~ClockMenuButton();
38
39  // ui::MenuModel implementation.
40  virtual bool HasIcons() const  { return false; }
41  virtual int GetItemCount() const;
42  virtual ui::MenuModel::ItemType GetTypeAt(int index) const;
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
61  // Overridden from ResumeLibrary::Observer:
62  virtual void PowerChanged(PowerLibrary* obj) {}
63  virtual void SystemResumed();
64
65  // Overridden from SystemAccess::Observer:
66  virtual void TimezoneChanged(const icu::TimeZone& timezone);
67
68  // views::View
69  virtual void OnLocaleChanged() OVERRIDE;
70
71  // Updates the time on the menu button. Can be called by host if timezone
72  // changes.
73  void UpdateText();
74
75  // NotificationObserver implementation.
76  virtual void Observe(NotificationType type,
77                       const NotificationSource& source,
78                       const NotificationDetails& details);
79
80 protected:
81  virtual int horizontal_padding() { return 3; }
82
83 private:
84  // views::ViewMenuDelegate implementation.
85  virtual void RunMenu(views::View* source, const gfx::Point& pt);
86
87  // Updates text and schedules the timer to fire at the next minute interval.
88  void UpdateTextAndSetNextTimer();
89
90  base::OneShotTimer<ClockMenuButton> timer_;
91
92  // The clock menu.
93  // NOTE: we use a scoped_ptr here as menu calls into 'this' from the
94  // constructor.
95  scoped_ptr<views::Menu2> clock_menu_;
96
97  PrefChangeRegistrar registrar_;
98
99  DISALLOW_COPY_AND_ASSIGN(ClockMenuButton);
100};
101
102}  // namespace chromeos
103
104#endif  // CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_
105