Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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 "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
| 18 #include "views/window/window.h" | |
| 19 | |
| 20 using views::MenuItemView; | |
|
oshima
2011/04/08 17:21:17
move this nito chromeos namespace.
rhashimoto
2011/04/14 00:58:54
The using declaration or the anonymous namespace c
| |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // MenuItemView item ids | |
| 25 enum { | |
| 26 CLOCK_DISPLAY_ITEM, | |
| 27 CLOCK_OPEN_OPTIONS_ITEM, | |
| 28 }; | |
| 29 | |
| 30 } // anonymous namespace | |
|
oshima
2011/04/08 17:21:17
two space before //
just "namespace"
rhashimoto
2011/04/14 00:58:54
Done.
| |
| 18 | 31 |
| 19 namespace chromeos { | 32 namespace chromeos { |
| 20 | 33 |
| 21 // Amount of slop to add into the timer to make sure we're into the next minute | 34 // Amount of slop to add into the timer to make sure we're into the next minute |
| 22 // when the timer goes off. | 35 // when the timer goes off. |
| 23 const int kTimerSlopSeconds = 1; | 36 const int kTimerSlopSeconds = 1; |
| 24 | 37 |
| 25 #if defined(CROS_FONTS_USING_BCI) | 38 #if defined(CROS_FONTS_USING_BCI) |
| 26 const int kFontSizeDelta = 0; | 39 const int kFontSizeDelta = 0; |
| 27 #else | 40 #else |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 } | 88 } |
| 76 | 89 |
| 77 void ClockMenuButton::UpdateText() { | 90 void ClockMenuButton::UpdateText() { |
| 78 base::Time time(base::Time::Now()); | 91 base::Time time(base::Time::Now()); |
| 79 SetText(UTF16ToWide(base::TimeFormatTimeOfDay(time))); | 92 SetText(UTF16ToWide(base::TimeFormatTimeOfDay(time))); |
| 80 SetTooltipText(UTF16ToWide(base::TimeFormatShortDate(time))); | 93 SetTooltipText(UTF16ToWide(base::TimeFormatShortDate(time))); |
| 81 SchedulePaint(); | 94 SchedulePaint(); |
| 82 } | 95 } |
| 83 | 96 |
| 84 //////////////////////////////////////////////////////////////////////////////// | 97 //////////////////////////////////////////////////////////////////////////////// |
| 85 // ClockMenuButton, ui::MenuModel implementation: | 98 // ClockMenuButton, views::MenuDelegate implementation: |
| 99 std::wstring ClockMenuButton::GetLabel(int id) const | |
| 100 { | |
| 101 string16 label; | |
| 102 switch (id) { | |
| 103 case CLOCK_DISPLAY_ITEM: | |
| 104 label = base::TimeFormatFriendlyDate(base::Time::Now()); | |
| 105 break; | |
|
oshima
2011/04/08 17:21:17
just use if
I assume else case shouldn't happen? I
rhashimoto
2011/04/14 00:58:54
Done.
| |
| 106 } | |
| 86 | 107 |
| 87 int ClockMenuButton::GetItemCount() const { | 108 return UTF16ToWide(label); |
| 88 // If options dialog is unavailable, don't count a separator and configure | |
| 89 // menu item. | |
| 90 return host_->ShouldOpenButtonOptions(this) ? 3 : 1; | |
| 91 } | 109 } |
| 92 | 110 |
| 93 ui::MenuModel::ItemType ClockMenuButton::GetTypeAt(int index) const { | 111 bool ClockMenuButton::IsCommandEnabled(int id) const |
| 94 // There's a separator between the current date and the menu item to open | 112 { |
| 95 // the options menu. | 113 switch (id) { |
| 96 return index == 1 ? ui::MenuModel::TYPE_SEPARATOR: | 114 case CLOCK_DISPLAY_ITEM: |
| 97 ui::MenuModel::TYPE_COMMAND; | 115 return false; |
|
oshima
2011/04/08 17:21:17
same here.
rhashimoto
2011/04/14 00:58:54
This one is disabled only for CLOCK_DISPLAY_ITEM.
| |
| 116 default: | |
| 117 return true; | |
| 118 } | |
| 98 } | 119 } |
| 99 | 120 |
| 100 string16 ClockMenuButton::GetLabelAt(int index) const { | 121 void ClockMenuButton::ExecuteCommand(int id) |
| 101 if (index == 0) | 122 { |
| 102 return base::TimeFormatFriendlyDate(base::Time::Now()); | 123 switch (id) |
| 103 return l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG); | 124 { |
| 104 } | 125 case CLOCK_OPEN_OPTIONS_ITEM: |
| 105 | 126 host_->OpenButtonOptions(this); |
|
oshima
2011/04/08 17:21:17
same here
rhashimoto
2011/04/14 00:58:54
Done.
| |
| 106 bool ClockMenuButton::IsEnabledAt(int index) const { | 127 break; |
| 107 // The 1st item is the current date, which is disabled. | 128 } |
| 108 return index != 0; | |
| 109 } | |
| 110 | |
| 111 void ClockMenuButton::ActivatedAt(int index) { | |
| 112 host_->OpenButtonOptions(this); | |
| 113 } | 129 } |
| 114 | 130 |
| 115 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 116 // ClockMenuButton, PowerLibrary::Observer implementation: | 132 // ClockMenuButton, PowerLibrary::Observer implementation: |
| 117 | 133 |
| 118 void ClockMenuButton::SystemResumed() { | 134 void ClockMenuButton::SystemResumed() { |
| 119 UpdateText(); | 135 UpdateText(); |
| 120 } | 136 } |
| 121 | 137 |
| 122 /////////////////////////////////////////////////////////////////////////////// | 138 /////////////////////////////////////////////////////////////////////////////// |
| 123 // ClockMenuButton, SystemLibrary::Observer implementation: | 139 // ClockMenuButton, SystemLibrary::Observer implementation: |
| 124 | 140 |
| 125 void ClockMenuButton::TimezoneChanged(const icu::TimeZone& timezone) { | 141 void ClockMenuButton::TimezoneChanged(const icu::TimeZone& timezone) { |
| 126 UpdateText(); | 142 UpdateText(); |
| 127 } | 143 } |
| 128 | 144 |
| 129 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
| 130 // ClockMenuButton, views::ViewMenuDelegate implementation: | 146 // ClockMenuButton, views::ViewMenuDelegate implementation: |
| 131 | 147 |
| 132 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 148 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
| 133 if (!clock_menu_.get()) | 149 if (!menu_.get()) { |
| 134 clock_menu_.reset(new views::Menu2(this)); | 150 menu_.reset(new MenuItemView(this)); |
| 135 else | 151 |
| 136 clock_menu_->Rebuild(); | 152 // Text for this item will be set by GetLabel(). |
| 137 clock_menu_->UpdateStates(); | 153 menu_->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM); |
| 138 clock_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 154 |
| 155 // If options dialog is unavailable, don't count a separator and configure | |
| 156 // menu item. | |
| 157 if (host_->ShouldOpenButtonOptions(this)) { | |
| 158 menu_->AppendSeparator(); | |
| 159 | |
| 160 const string16 clock_open_options_label = | |
| 161 l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG); | |
| 162 menu_->AppendMenuItemWithLabel( | |
| 163 CLOCK_OPEN_OPTIONS_ITEM, | |
| 164 UTF16ToWide(clock_open_options_label)); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 gfx::Point screen_loc; | |
| 169 views::View::ConvertPointToScreen(source, &screen_loc); | |
| 170 gfx::Rect bounds(screen_loc, source->size()); | |
|
oshima
2011/04/08 17:21:17
will RTL work with this?
rhashimoto
2011/04/14 00:58:54
I don't know, but this is how the WrenchMenu is im
| |
| 171 menu_->RunMenuAt( | |
| 172 source->GetWindow()->GetNativeWindow(), | |
| 173 this, | |
| 174 bounds, | |
| 175 base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT, | |
| 176 true); | |
| 139 } | 177 } |
| 140 | 178 |
| 141 } // namespace chromeos | 179 } // namespace chromeos |
| OLD | NEW |