blob: b4ea90f9af8e2191768ad114778c75f747868e55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_
#define CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_
#pragma once
#include "base/memory/scoped_ptr.h"
#include "base/timer.h"
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/status/status_area_button.h"
#include "chrome/browser/chromeos/system/timezone_settings.h"
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/browser/prefs/pref_member.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_types.h"
#include "unicode/calendar.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/menu_delegate.h"
#include "views/controls/menu/view_menu_delegate.h"
namespace views {
class MenuRunner;
}
namespace chromeos {
class StatusAreaHost;
// The clock menu button in the status area.
// This button shows the current time.
class ClockMenuButton : public StatusAreaButton,
public views::MenuDelegate,
public views::ViewMenuDelegate,
public content::NotificationObserver,
public PowerLibrary::Observer,
public system::TimezoneSettings::Observer {
public:
explicit ClockMenuButton(StatusAreaHost* host);
virtual ~ClockMenuButton();
// views::MenuDelegate implementation
virtual string16 GetLabel(int id) const OVERRIDE;
virtual bool IsCommandEnabled(int id) const OVERRIDE;
virtual void ExecuteCommand(int id) OVERRIDE;
// Overridden from ResumeLibrary::Observer:
virtual void PowerChanged(PowerLibrary* obj) {}
virtual void SystemResumed();
// Overridden from TimezoneSettings::Observer:
virtual void TimezoneChanged(const icu::TimeZone& timezone);
// views::View
virtual void OnLocaleChanged() OVERRIDE;
// Updates the time on the menu button. Can be called by host if timezone
// changes.
void UpdateText();
// Sets default use 24hour clock mode.
void SetDefaultUse24HourClock(bool use_24hour_clock);
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details);
protected:
virtual int horizontal_padding();
private:
// views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* source, const gfx::Point& pt);
// Create and initialize menu if not already present.
void EnsureMenu();
// Updates text and schedules the timer to fire at the next minute interval.
void UpdateTextAndSetNextTimer();
base::OneShotTimer<ClockMenuButton> timer_;
// The clock menu.
scoped_ptr<views::MenuRunner> menu_runner_;
PrefChangeRegistrar registrar_;
// Default value for use_24hour_clock. Used when StatusAreaHost does not
// have a profile, i.e. on login screen and lock screen.
bool default_use_24hour_clock_;
DISALLOW_COPY_AND_ASSIGN(ClockMenuButton);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_
|