Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/chromeos/status/clock_menu_button.cc

Issue 1589021: Status area improvements:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/i18n/time_formatting.h" 9 #include "base/i18n/time_formatting.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 10 matching lines...) Expand all
21 21
22 // Amount of slop to add into the timer to make sure we're into the next minute 22 // Amount of slop to add into the timer to make sure we're into the next minute
23 // when the timer goes off. 23 // when the timer goes off.
24 const int kTimerSlopSeconds = 1; 24 const int kTimerSlopSeconds = 1;
25 25
26 ClockMenuButton::ClockMenuButton(StatusAreaHost* host) 26 ClockMenuButton::ClockMenuButton(StatusAreaHost* host)
27 : MenuButton(NULL, std::wstring(), this, false), 27 : MenuButton(NULL, std::wstring(), this, false),
28 host_(host) { 28 host_(host) {
29 set_border(NULL); 29 set_border(NULL);
30 SetFont(ResourceBundle::GetSharedInstance().GetFont( 30 SetFont(ResourceBundle::GetSharedInstance().GetFont(
31 ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD)); 31 ResourceBundle::BaseFont).DeriveFont(1, gfx::Font::BOLD));
32 SetEnabledColor(SK_ColorWHITE); 32 SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha
33 SetShowHighlighted(false); 33 SetShowHighlighted(false);
34 // Set initial text to make sure that the text button wide enough. 34 // Fill text with 0s to figure out max width of text size.
35 std::wstring zero = ASCIIToWide("00"); 35 ClearMaxTextSize();
36 SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_AM, zero, zero)); 36 std::wstring zero = ASCIIToWide("0");
37 SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_PM, zero, zero)); 37 std::wstring zerozero = ASCIIToWide("00");
38 SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_AM,
39 zero, zerozero));
40 SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_PM,
41 zero, zerozero));
42 max_width_one_digit = GetPreferredSize().width();
43 ClearMaxTextSize();
44 SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_AM,
45 zerozero, zerozero));
46 SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_PM,
47 zerozero, zerozero));
48 max_width_two_digit = GetPreferredSize().width();
38 set_alignment(TextButton::ALIGN_RIGHT); 49 set_alignment(TextButton::ALIGN_RIGHT);
39 UpdateTextAndSetNextTimer(); 50 UpdateTextAndSetNextTimer();
40 // Init member prefs so we can update the clock if prefs change. 51 // Init member prefs so we can update the clock if prefs change.
41 // This only works if we are within a browser and have a profile. 52 // This only works if we are within a browser and have a profile.
42 if (host->GetProfile()) 53 if (host->GetProfile())
43 timezone_.Init(prefs::kTimeZone, host->GetProfile()->GetPrefs(), this); 54 timezone_.Init(prefs::kTimeZone, host->GetProfile()->GetPrefs(), this);
44 } 55 }
45 56
46 void ClockMenuButton::UpdateTextAndSetNextTimer() { 57 void ClockMenuButton::UpdateTextAndSetNextTimer() {
47 UpdateText(); 58 UpdateText();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 std::wstring hour_str = IntToWString(hour); 95 std::wstring hour_str = IntToWString(hour);
85 std::wstring min_str = IntToWString(minute); 96 std::wstring min_str = IntToWString(minute);
86 // Append a "0" before the minute if it's only a single digit. 97 // Append a "0" before the minute if it's only a single digit.
87 if (minute < 10) 98 if (minute < 10)
88 min_str = IntToWString(0) + min_str; 99 min_str = IntToWString(0) + min_str;
89 int msg = (ampm == UCAL_AM) ? IDS_STATUSBAR_CLOCK_SHORT_TIME_AM : 100 int msg = (ampm == UCAL_AM) ? IDS_STATUSBAR_CLOCK_SHORT_TIME_AM :
90 IDS_STATUSBAR_CLOCK_SHORT_TIME_PM; 101 IDS_STATUSBAR_CLOCK_SHORT_TIME_PM;
91 102
92 std::wstring time_string = l10n_util::GetStringF(msg, hour_str, min_str); 103 std::wstring time_string = l10n_util::GetStringF(msg, hour_str, min_str);
93 104
105 // See if the preferred size changed. If so, relayout the StatusAreaView.
106 int cur_width = GetPreferredSize().width();
107 int new_width = hour < 10 ? max_width_one_digit : max_width_two_digit;
94 SetText(time_string); 108 SetText(time_string);
109 set_max_width(new_width);
110
111 // If width has changed, we want to relayout the StatusAreaView.
112 if (new_width != cur_width)
113 PreferredSizeChanged();
114
95 SchedulePaint(); 115 SchedulePaint();
96 } 116 }
97 117
98 //////////////////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////////////////
99 // ClockMenuButton, menus::MenuModel implementation: 119 // ClockMenuButton, menus::MenuModel implementation:
100 120
101 int ClockMenuButton::GetItemCount() const { 121 int ClockMenuButton::GetItemCount() const {
102 // If options dialog is unavailable, don't count a separator and configure 122 // If options dialog is unavailable, don't count a separator and configure
103 // menu item. 123 // menu item.
104 return host_->ShouldOpenButtonOptions(this) ? 3 : 1; 124 return host_->ShouldOpenButtonOptions(this) ? 3 : 1;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { 167 void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
148 if (!clock_menu_.get()) 168 if (!clock_menu_.get())
149 clock_menu_.reset(new views::Menu2(this)); 169 clock_menu_.reset(new views::Menu2(this));
150 else 170 else
151 clock_menu_->Rebuild(); 171 clock_menu_->Rebuild();
152 clock_menu_->UpdateStates(); 172 clock_menu_->UpdateStates();
153 clock_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); 173 clock_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
154 } 174 }
155 175
156 } // namespace chromeos 176 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698