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 #include "chrome/browser/chromeos/status/clock_menu_button.h" | 5 #include "chrome/browser/chromeos/status/clock_menu_button.h" |
6 | 6 |
7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | |
12 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" | 11 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" |
13 #include "chrome/browser/chromeos/view_ids.h" | |
14 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/ui/view_ids.h" | |
16 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
19 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
20 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
24 #include "unicode/datefmt.h" | 23 #include "unicode/datefmt.h" |
25 #include "views/controls/menu/menu_runner.h" | 24 #include "views/controls/menu/menu_runner.h" |
26 #include "views/widget/widget.h" | 25 #include "views/widget/widget.h" |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 // views::MenuItemView item ids | 29 // views::MenuItemView item ids |
31 enum ClockMenuItem { | 30 enum ClockMenuItem { |
32 CLOCK_DISPLAY_ITEM, | 31 CLOCK_DISPLAY_ITEM, |
33 CLOCK_OPEN_OPTIONS_ITEM | 32 CLOCK_OPEN_OPTIONS_ITEM |
34 }; | 33 }; |
35 | 34 |
36 } // namespace | 35 } // namespace |
37 | 36 |
38 namespace chromeos { | |
39 | |
40 // Amount of slop to add into the timer to make sure we're into the next minute | 37 // Amount of slop to add into the timer to make sure we're into the next minute |
41 // when the timer goes off. | 38 // when the timer goes off. |
42 const int kTimerSlopSeconds = 1; | 39 const int kTimerSlopSeconds = 1; |
43 | 40 |
44 ClockMenuButton::ClockMenuButton(StatusAreaButton::Delegate* delegate) | 41 ClockMenuButton::ClockMenuButton(StatusAreaButton::Delegate* delegate) |
45 : StatusAreaButton(delegate, this), | 42 : StatusAreaButton(delegate, this), |
46 default_use_24hour_clock_(false) { | 43 default_use_24hour_clock_(false) { |
47 set_id(VIEW_ID_STATUS_BUTTON_CLOCK); | 44 set_id(VIEW_ID_STATUS_BUTTON_CLOCK); |
45 #if defined(OS_CHROMEOS) | |
DaveMoore
2011/11/10 02:05:46
Whenever we have a #if defined(OS_CHROMEOS) in a f
stevenjb
2011/11/10 19:57:52
Done.
| |
48 // Start monitoring the kUse24HourClock preference. | 46 // Start monitoring the kUse24HourClock preference. |
49 Profile* profile = ProfileManager::GetDefaultProfile(); | 47 Profile* profile = ProfileManager::GetDefaultProfile(); |
50 if (profile) { // This can be NULL in the login screen. | 48 if (profile) { // This can be NULL in the login screen. |
51 registrar_.Init(profile->GetPrefs()); | 49 registrar_.Init(profile->GetPrefs()); |
52 registrar_.Add(prefs::kUse24HourClock, this); | 50 registrar_.Add(prefs::kUse24HourClock, this); |
53 } | 51 } |
54 | 52 #endif |
55 UpdateTextAndSetNextTimer(); | 53 UpdateTextAndSetNextTimer(); |
56 } | 54 } |
57 | 55 |
58 ClockMenuButton::~ClockMenuButton() { | 56 ClockMenuButton::~ClockMenuButton() { |
59 timer_.Stop(); | 57 timer_.Stop(); |
60 } | 58 } |
61 | 59 |
62 void ClockMenuButton::UpdateTextAndSetNextTimer() { | 60 void ClockMenuButton::UpdateTextAndSetNextTimer() { |
63 UpdateText(); | 61 UpdateText(); |
64 | 62 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 105 |
108 default_use_24hour_clock_ = use_24hour_clock; | 106 default_use_24hour_clock_ = use_24hour_clock; |
109 UpdateText(); | 107 UpdateText(); |
110 } | 108 } |
111 | 109 |
112 // ClockMenuButton, content::NotificationObserver implementation: | 110 // ClockMenuButton, content::NotificationObserver implementation: |
113 | 111 |
114 void ClockMenuButton::Observe(int type, | 112 void ClockMenuButton::Observe(int type, |
115 const content::NotificationSource& source, | 113 const content::NotificationSource& source, |
116 const content::NotificationDetails& details) { | 114 const content::NotificationDetails& details) { |
115 #if defined(OS_CHROMEOS) | |
117 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 116 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
118 std::string* pref_name = content::Details<std::string>(details).ptr(); | 117 std::string* pref_name = content::Details<std::string>(details).ptr(); |
119 if (*pref_name == prefs::kUse24HourClock) { | 118 if (*pref_name == prefs::kUse24HourClock) { |
120 UpdateText(); | 119 UpdateText(); |
121 } | 120 } |
122 } | 121 } |
122 #endif | |
123 } | 123 } |
124 | 124 |
125 // ClockMenuButton, views::MenuDelegate implementation: | 125 // ClockMenuButton, views::MenuDelegate implementation: |
126 string16 ClockMenuButton::GetLabel(int id) const { | 126 string16 ClockMenuButton::GetLabel(int id) const { |
127 DCHECK_EQ(CLOCK_DISPLAY_ITEM, id); | 127 DCHECK_EQ(CLOCK_DISPLAY_ITEM, id); |
128 return base::TimeFormatFriendlyDate(base::Time::Now()); | 128 return base::TimeFormatFriendlyDate(base::Time::Now()); |
129 } | 129 } |
130 | 130 |
131 bool ClockMenuButton::IsCommandEnabled(int id) const { | 131 bool ClockMenuButton::IsCommandEnabled(int id) const { |
132 DCHECK(id == CLOCK_DISPLAY_ITEM || id == CLOCK_OPEN_OPTIONS_ITEM); | 132 DCHECK(id == CLOCK_DISPLAY_ITEM || id == CLOCK_OPEN_OPTIONS_ITEM); |
133 return id == CLOCK_OPEN_OPTIONS_ITEM; | 133 return id == CLOCK_OPEN_OPTIONS_ITEM; |
134 } | 134 } |
135 | 135 |
136 void ClockMenuButton::ExecuteCommand(int id) { | 136 void ClockMenuButton::ExecuteCommand(int id) { |
137 DCHECK_EQ(CLOCK_OPEN_OPTIONS_ITEM, id); | 137 DCHECK_EQ(CLOCK_OPEN_OPTIONS_ITEM, id); |
138 delegate()->ExecuteStatusAreaCommand( | 138 delegate()->ExecuteStatusAreaCommand( |
139 this, StatusAreaViewChromeos::SHOW_SYSTEM_OPTIONS); | 139 this, StatusAreaButton::Delegate::SHOW_SYSTEM_OPTIONS); |
140 } | 140 } |
141 | 141 |
142 int ClockMenuButton::horizontal_padding() { | 142 int ClockMenuButton::horizontal_padding() { |
143 return 3; | 143 return 3; |
144 } | 144 } |
145 | 145 |
146 // ClockMenuButton, views::ViewMenuDelegate implementation: | 146 // ClockMenuButton, views::ViewMenuDelegate implementation: |
147 | 147 |
148 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 148 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
149 // View passed in must be a views::MenuButton, i.e. the ClockMenuButton. | 149 // View passed in must be a views::MenuButton, i.e. the ClockMenuButton. |
(...skipping 23 matching lines...) Expand all Loading... | |
173 | 173 |
174 views::MenuItemView* menu = new views::MenuItemView(this); | 174 views::MenuItemView* menu = new views::MenuItemView(this); |
175 // menu_runner_ takes ownership of menu. | 175 // menu_runner_ takes ownership of menu. |
176 menu_runner_.reset(new views::MenuRunner(menu)); | 176 menu_runner_.reset(new views::MenuRunner(menu)); |
177 | 177 |
178 // Text for this item will be set by GetLabel(). | 178 // Text for this item will be set by GetLabel(). |
179 menu->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM); | 179 menu->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM); |
180 | 180 |
181 // If options UI is available, show a separator and configure menu item. | 181 // If options UI is available, show a separator and configure menu item. |
182 if (delegate()->ShouldExecuteStatusAreaCommand( | 182 if (delegate()->ShouldExecuteStatusAreaCommand( |
183 this, StatusAreaViewChromeos::SHOW_SYSTEM_OPTIONS)) { | 183 this, StatusAreaButton::Delegate::SHOW_SYSTEM_OPTIONS)) { |
184 menu->AppendSeparator(); | 184 menu->AppendSeparator(); |
185 | 185 |
186 const string16 clock_open_options_label = | 186 const string16 clock_open_options_label = |
187 l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG); | 187 l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG); |
188 menu->AppendMenuItemWithLabel(CLOCK_OPEN_OPTIONS_ITEM, | 188 menu->AppendMenuItemWithLabel(CLOCK_OPEN_OPTIONS_ITEM, |
189 clock_open_options_label); | 189 clock_open_options_label); |
190 } | 190 } |
191 } | 191 } |
192 | |
193 } // namespace chromeos | |
OLD | NEW |