summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 15:45:00 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 15:45:00 +0000
commit530cd6292136de5798bfd05c4ae960cba8e8b84b (patch)
treeba9330952154efdab9a35e0dc24932f4868c6006 /chrome/browser
parent035205ce7b22e0298d3c18980b17d5b4b2a8ca5d (diff)
downloadchromium_src-530cd6292136de5798bfd05c4ae960cba8e8b84b.zip
chromium_src-530cd6292136de5798bfd05c4ae960cba8e8b84b.tar.gz
chromium_src-530cd6292136de5798bfd05c4ae960cba8e8b84b.tar.bz2
Add support for 12/24 hour clock switching on Chrome OS.
Introduce "[ ] Use 24-hour clock" setting in the Chrome OS system settings. The English (United States) locale (en-US) uses 12 hour clock like "15:07 PM" by default, and there was no way to customize the format. With this change, users will be able to change it to 24 hour clock. Likewise, The English (United Kingdom) locale (en-GB) uses 24 hour clock by default. Users will also be able to change it to 12 hour clock. BUG=chromium-os:10534 TEST=confirmed that the 12/24 hour clock switching worked. Review URL: http://codereview.chromium.org/6834019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81593 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/preferences.cc5
-rw-r--r--chrome/browser/chromeos/preferences.h1
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.cc37
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.h12
-rw-r--r--chrome/browser/resources/options/chromeos/system_options.html12
-rw-r--r--chrome/browser/sync/glue/synchronized_preferences.h4
-rw-r--r--chrome/browser/ui/webui/options/chromeos/system_options_handler.cc3
7 files changed, 73 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc
index 46285ae..6ae904f 100644
--- a/chrome/browser/chromeos/preferences.cc
+++ b/chrome/browser/chromeos/preferences.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/chromeos/preferences.h"
+#include "base/i18n/time_formatting.h"
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -42,6 +43,9 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kAccessibilityEnabled, false);
}
prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity, 3);
+ // Set the default based on the hour clock type of the current locale.
+ prefs->RegisterBooleanPref(prefs::kUse24HourClock,
+ base::GetHourClockType() == base::k24HourClock);
prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod, "");
prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod, "");
prefs->RegisterStringPref(prefs::kLanguageHotkeyNextEngineInMenu,
@@ -129,6 +133,7 @@ void Preferences::Init(PrefService* prefs) {
tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this);
accessibility_enabled_.Init(prefs::kAccessibilityEnabled, prefs, this);
sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this);
+ use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this);
language_hotkey_next_engine_in_menu_.Init(
prefs::kLanguageHotkeyNextEngineInMenu, prefs, this);
language_hotkey_previous_engine_.Init(
diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h
index f6c6b55..bf97ac9 100644
--- a/chrome/browser/chromeos/preferences.h
+++ b/chrome/browser/chromeos/preferences.h
@@ -87,6 +87,7 @@ class Preferences : public NotificationObserver {
BooleanPrefMember accessibility_enabled_;
IntegerPrefMember speed_factor_;
IntegerPrefMember sensitivity_;
+ BooleanPrefMember use_24hour_clock_;
// Input method preferences.
StringPrefMember language_hotkey_next_engine_in_menu_;
diff --git a/chrome/browser/chromeos/status/clock_menu_button.cc b/chrome/browser/chromeos/status/clock_menu_button.cc
index 45a2662..54ae8d7 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button.cc
@@ -10,6 +10,11 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/pref_names.h"
+#include "content/common/notification_details.h"
+#include "content/common/notification_source.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
@@ -34,6 +39,11 @@ ClockMenuButton::ClockMenuButton(StatusAreaHost* host)
// Add as SystemLibrary observer. We update the clock if timezone changes.
CrosLibrary::Get()->GetSystemLibrary()->AddObserver(this);
CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this);
+ // Start monitoring the kUse24HourClock preference.
+ if (host->GetProfile()) { // This can be NULL in the login screen.
+ registrar_.Init(host->GetProfile()->GetPrefs());
+ registrar_.Add(prefs::kUse24HourClock, this);
+ }
set_border(NULL);
set_use_menu_button_paint(true);
@@ -76,12 +86,37 @@ void ClockMenuButton::UpdateTextAndSetNextTimer() {
void ClockMenuButton::UpdateText() {
base::Time time(base::Time::Now());
- SetText(UTF16ToWide(base::TimeFormatTimeOfDay(time)));
+ // If the profie is present, check the use 24-hour clock preference.
+ if (host_->GetProfile()) { // This can be NULL in the login screen.
+ const bool use_24hour_clock =
+ host_->GetProfile()->GetPrefs()->GetBoolean(prefs::kUse24HourClock);
+ base::HourClockType clock_type = (use_24hour_clock ?
+ base::k24HourClock : base::k12HourClock);
+ SetText(UTF16ToWide(base::TimeFormatTimeOfDayWithHourClockType(
+ time, clock_type)));
+ } else {
+ SetText(UTF16ToWide(base::TimeFormatTimeOfDay(time)));
+ }
SetTooltipText(UTF16ToWide(base::TimeFormatShortDate(time)));
SchedulePaint();
}
////////////////////////////////////////////////////////////////////////////////
+// ClockMenuButton, NotificationObserver implementation:
+
+void ClockMenuButton::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::PREF_CHANGED) {
+ std::string* pref_name = Details<std::string>(details).ptr();
+ if (*pref_name == prefs::kUse24HourClock) {
+ UpdateText();
+ }
+ }
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
// ClockMenuButton, ui::MenuModel implementation:
int ClockMenuButton::GetItemCount() const {
diff --git a/chrome/browser/chromeos/status/clock_menu_button.h b/chrome/browser/chromeos/status/clock_menu_button.h
index f8d5a1f..778dcf8 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.h
+++ b/chrome/browser/chromeos/status/clock_menu_button.h
@@ -11,6 +11,10 @@
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/cros/system_library.h"
#include "chrome/browser/chromeos/status/status_area_button.h"
+#include "chrome/browser/prefs/pref_change_registrar.h"
+#include "chrome/browser/prefs/pref_member.h"
+#include "content/common/notification_observer.h"
+#include "content/common/notification_type.h"
#include "unicode/calendar.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/menu_2.h"
@@ -25,6 +29,7 @@ class StatusAreaHost;
class ClockMenuButton : public StatusAreaButton,
public views::ViewMenuDelegate,
public ui::MenuModel,
+ public NotificationObserver,
public PowerLibrary::Observer,
public SystemLibrary::Observer {
public:
@@ -67,6 +72,11 @@ class ClockMenuButton : public StatusAreaButton,
// changes.
void UpdateText();
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
protected:
virtual int horizontal_padding() { return 3; }
@@ -86,6 +96,8 @@ class ClockMenuButton : public StatusAreaButton,
StatusAreaHost* host_;
+ PrefChangeRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(ClockMenuButton);
};
diff --git a/chrome/browser/resources/options/chromeos/system_options.html b/chrome/browser/resources/options/chromeos/system_options.html
index a775a2e..9ab473b 100644
--- a/chrome/browser/resources/options/chromeos/system_options.html
+++ b/chrome/browser/resources/options/chromeos/system_options.html
@@ -11,6 +11,18 @@
dataType="string"
pref="cros.system.timezone"></select>
</td>
+ <tr>
+ <td class="option-name" colspan="2">
+ <div class="checkbox">
+ <label>
+ <input id="use-24hour-clock"
+ pref="settings.clock.use_24hour_clock"
+ type="checkbox">
+ <span i18n-content="use_24hour_clock"></span>
+ </label>
+ </div>
+ </td>
+ </tr>
</tr>
</table>
</section>
diff --git a/chrome/browser/sync/glue/synchronized_preferences.h b/chrome/browser/sync/glue/synchronized_preferences.h
index b9429c3..beb8166 100644
--- a/chrome/browser/sync/glue/synchronized_preferences.h
+++ b/chrome/browser/sync/glue/synchronized_preferences.h
@@ -193,6 +193,10 @@ static const char* kSynchronizedPreferences[] = {
// Whether to enable tap-to-click
// Settings -> System -> Touchpad
prefs::kTapToClickEnabled,
+
+ // Whether to use the 24-hour clock format.
+ // Settings -> System -> Date and Time
+ prefs::kUse24HourClock,
#endif
};
diff --git a/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc
index 921e138..00d6133 100644
--- a/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc
@@ -39,6 +39,9 @@ void SystemOptionsHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME));
localized_strings->SetString("timezone",
l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION));
+ localized_strings->SetString("use_24hour_clock",
+ l10n_util::GetStringUTF16(
+ IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION));
localized_strings->SetString("touchpad",
l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_TOUCHPAD));