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" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
12 #include "chrome/browser/chromeos/status/status_area_host.h" | 12 #include "chrome/browser/chromeos/status/status_area_host.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "content/common/notification_details.h" | 17 #include "content/common/notification_details.h" |
18 #include "content/common/notification_source.h" | 18 #include "content/common/notification_source.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
| 23 #include "views/controls/menu/menu_runner.h" |
23 #include "views/widget/widget.h" | 24 #include "views/widget/widget.h" |
24 #include "unicode/datefmt.h" | 25 #include "unicode/datefmt.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // views::MenuItemView item ids | 29 // views::MenuItemView item ids |
29 enum { | 30 enum { |
30 CLOCK_DISPLAY_ITEM, | 31 CLOCK_DISPLAY_ITEM, |
31 CLOCK_OPEN_OPTIONS_ITEM | 32 CLOCK_OPEN_OPTIONS_ITEM |
32 }; | 33 }; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 150 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
150 // View passed in must be a views::MenuButton, i.e. the ClockMenuButton. | 151 // View passed in must be a views::MenuButton, i.e. the ClockMenuButton. |
151 DCHECK_EQ(source, this); | 152 DCHECK_EQ(source, this); |
152 | 153 |
153 EnsureMenu(); | 154 EnsureMenu(); |
154 | 155 |
155 gfx::Point screen_location; | 156 gfx::Point screen_location; |
156 views::View::ConvertPointToScreen(source, &screen_location); | 157 views::View::ConvertPointToScreen(source, &screen_location); |
157 gfx::Rect bounds(screen_location, source->size()); | 158 gfx::Rect bounds(screen_location, source->size()); |
158 menu_->RunMenuAt( | 159 if (menu_runner_->RunMenuAt( |
159 source->GetWidget()->GetTopLevelWidget(), | 160 source->GetWidget()->GetTopLevelWidget(), this, bounds, |
160 this, | 161 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
161 bounds, | 162 views::MenuRunner::MENU_DELETED) |
162 views::MenuItemView::TOPRIGHT, | 163 return; |
163 true); | |
164 } | 164 } |
165 | 165 |
166 // ClockMenuButton, views::View implementation: | 166 // ClockMenuButton, views::View implementation: |
167 | 167 |
168 void ClockMenuButton::OnLocaleChanged() { | 168 void ClockMenuButton::OnLocaleChanged() { |
169 UpdateText(); | 169 UpdateText(); |
170 } | 170 } |
171 | 171 |
172 void ClockMenuButton::EnsureMenu() { | 172 void ClockMenuButton::EnsureMenu() { |
173 if (!menu_.get()) { | 173 if (menu_runner_.get()) |
174 menu_.reset(new views::MenuItemView(this)); | 174 return; |
175 | 175 |
176 // Text for this item will be set by GetLabel(). | 176 views::MenuItemView* menu = new views::MenuItemView(this); |
177 menu_->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM); | 177 // menu_runner_ takes ownership of menu. |
| 178 menu_runner_.reset(new views::MenuRunner(menu)); |
178 | 179 |
179 // If options dialog is unavailable, don't show a separator and configure | 180 // Text for this item will be set by GetLabel(). |
180 // menu item. | 181 menu->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM); |
181 if (host_->ShouldOpenButtonOptions(this)) { | |
182 menu_->AppendSeparator(); | |
183 | 182 |
184 const string16 clock_open_options_label = | 183 // If options dialog is unavailable, don't show a separator and configure |
185 l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG); | 184 // menu item. |
186 menu_->AppendMenuItemWithLabel( | 185 if (host_->ShouldOpenButtonOptions(this)) { |
187 CLOCK_OPEN_OPTIONS_ITEM, | 186 menu->AppendSeparator(); |
188 UTF16ToWide(clock_open_options_label)); | 187 |
189 } | 188 const string16 clock_open_options_label = |
| 189 l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG); |
| 190 menu->AppendMenuItemWithLabel( |
| 191 CLOCK_OPEN_OPTIONS_ITEM, |
| 192 UTF16ToWide(clock_open_options_label)); |
190 } | 193 } |
191 } | 194 } |
192 | 195 |
193 } // namespace chromeos | 196 } // namespace chromeos |
OLD | NEW |