diff options
author | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 22:16:11 +0000 |
---|---|---|
committer | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 22:16:11 +0000 |
commit | cbcb318e4871ab222acff46817cd89a39d51ceb4 (patch) | |
tree | 2ce42ec63b099aa4ed6c9553d5e0991eb017c07d | |
parent | d71283e6e2ddbcdcb9dc20892956d9c7ab6732a3 (diff) | |
download | chromium_src-cbcb318e4871ab222acff46817cd89a39d51ceb4.zip chromium_src-cbcb318e4871ab222acff46817cd89a39d51ceb4.tar.gz chromium_src-cbcb318e4871ab222acff46817cd89a39d51ceb4.tar.bz2 |
When updating timezone, the clock now updates right away.
BUG=1650
TEST=none
Review URL: http://codereview.chromium.org/1081005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42009 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/frame/browser_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/browser_view.h | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/background_view.h | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/clock_menu_button.cc | 20 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/clock_menu_button.h | 14 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/status_area_host.h | 6 |
6 files changed, 49 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc index ff3836a..f3d5db12 100644 --- a/chrome/browser/chromeos/frame/browser_view.cc +++ b/chrome/browser/chromeos/frame/browser_view.cc @@ -480,6 +480,10 @@ void BrowserView::ShowContextMenu(views::View* source, } // StatusAreaHost overrides. +Profile* BrowserView::GetProfile() const { + return browser()->profile(); +} + gfx::NativeWindow BrowserView::GetNativeWindow() const { return GetWindow()->GetNativeWindow(); } diff --git a/chrome/browser/chromeos/frame/browser_view.h b/chrome/browser/chromeos/frame/browser_view.h index a848172..44a4ccd 100644 --- a/chrome/browser/chromeos/frame/browser_view.h +++ b/chrome/browser/chromeos/frame/browser_view.h @@ -20,6 +20,8 @@ class ImageButton; class Menu2; } // namespace views +class Profile; + namespace chromeos { class BrowserStatusAreaView; @@ -76,6 +78,7 @@ class BrowserView : public ::BrowserView, bool is_mouse_gesture); // StatusAreaHost overrides. + virtual Profile* GetProfile() const; virtual gfx::NativeWindow GetNativeWindow() const; virtual bool ShouldOpenButtonOptions( const views::View* button_view) const; diff --git a/chrome/browser/chromeos/login/background_view.h b/chrome/browser/chromeos/login/background_view.h index 995bb58..54c8d13 100644 --- a/chrome/browser/chromeos/login/background_view.h +++ b/chrome/browser/chromeos/login/background_view.h @@ -12,6 +12,8 @@ namespace views { class Widget; } +class Profile; + namespace chromeos { class StatusAreaView; @@ -37,6 +39,7 @@ class BackgroundView : public views::View, public StatusAreaHost { virtual void Layout(); // Overridden from StatusAreaHost: + virtual Profile* GetProfile() const { return NULL; } virtual gfx::NativeWindow GetNativeWindow() const; virtual bool ShouldOpenButtonOptions( const views::View* button_view) const; diff --git a/chrome/browser/chromeos/status/clock_menu_button.cc b/chrome/browser/chromeos/status/clock_menu_button.cc index 450d379..68c5a6c 100644 --- a/chrome/browser/chromeos/status/clock_menu_button.cc +++ b/chrome/browser/chromeos/status/clock_menu_button.cc @@ -14,6 +14,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/chromeos/status/status_area_host.h" #include "chrome/browser/profile.h" +#include "chrome/common/pref_names.h" #include "grit/generated_resources.h" #include "unicode/calendar.h" @@ -37,6 +38,10 @@ ClockMenuButton::ClockMenuButton(StatusAreaHost* host) SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_PM, zero, zero)); set_alignment(TextButton::ALIGN_RIGHT); UpdateTextAndSetNextTimer(); + // Init member prefs so we can update the clock if prefs change. + // This only works if we are within a browser and have a profile. + if (host->GetProfile()) + timezone_.Init(prefs::kTimeZone, host->GetProfile()->GetPrefs(), this); } void ClockMenuButton::UpdateTextAndSetNextTimer() { @@ -122,6 +127,21 @@ void ClockMenuButton::ActivatedAt(int index) { host_->OpenButtonOptions(this); } +/////////////////////////////////////////////////////////////////////////////// +// ClockMenuButton, NotificationObserver implementation: + +void ClockMenuButton::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::PREF_CHANGED) { + const std::wstring* pref_name = Details<std::wstring>(details).ptr(); + if (!pref_name || *pref_name == prefs::kTimeZone) { + UpdateText(); + } + } +} + + //////////////////////////////////////////////////////////////////////////////// // ClockMenuButton, views::ViewMenuDelegate implementation: diff --git a/chrome/browser/chromeos/status/clock_menu_button.h b/chrome/browser/chromeos/status/clock_menu_button.h index bdbf7e2..d94f182 100644 --- a/chrome/browser/chromeos/status/clock_menu_button.h +++ b/chrome/browser/chromeos/status/clock_menu_button.h @@ -7,6 +7,9 @@ #include "base/scoped_ptr.h" #include "base/timer.h" +#include "chrome/browser/pref_member.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_service.h" #include "views/controls/button/menu_button.h" #include "views/controls/menu/menu_2.h" #include "views/controls/menu/view_menu_delegate.h" @@ -19,7 +22,8 @@ class StatusAreaHost; // This button shows the current time. class ClockMenuButton : public views::MenuButton, public views::ViewMenuDelegate, - public menus::MenuModel { + public menus::MenuModel, + public NotificationObserver { public: explicit ClockMenuButton(StatusAreaHost* host); virtual ~ClockMenuButton() {} @@ -42,6 +46,11 @@ class ClockMenuButton : public views::MenuButton, virtual void ActivatedAt(int index); virtual void MenuWillShow() {} + // Overridden from NotificationObserver: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + // Updates the time on the menu button. Can be called by host if timezone // changes. void UpdateText(); @@ -62,6 +71,9 @@ class ClockMenuButton : public views::MenuButton, StatusAreaHost* host_; + // Preferences for this section: + StringPrefMember timezone_; + DISALLOW_COPY_AND_ASSIGN(ClockMenuButton); }; diff --git a/chrome/browser/chromeos/status/status_area_host.h b/chrome/browser/chromeos/status/status_area_host.h index 1d6ab1a..cc33434 100644 --- a/chrome/browser/chromeos/status/status_area_host.h +++ b/chrome/browser/chromeos/status/status_area_host.h @@ -11,12 +11,18 @@ namespace views { class View; } // namespace views +class Profile; + namespace chromeos { // This class is an abstraction decoupling StatusAreaView from its host // window. class StatusAreaHost { public: + // Returns the Profile if this status area is inside the browser and has a + // profile. Otherwise, returns NULL. + virtual Profile* GetProfile() const = 0; + // Returns native window hosting the status area. virtual gfx::NativeWindow GetNativeWindow() const = 0; |