Commit d43899e8 authored by sky@chromium.org's avatar sky@chromium.org

Relands: Fixes bug where clock button wasn't updating in response to a

timezone change.

BUG=104667
TEST=none
R=ben@chromium.org,stevenjb@chromium.org
TBR=ben@chromium.org,stevenjb@chromium.org


Review URL: http://codereview.chromium.org/8605006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110851 0039d316-1c4b-4281-b951-d872f2087c98
parent 5f9041e4
......@@ -17,6 +17,10 @@
#include "unicode/calendar.h"
#include "unicode/timezone.h"
#if defined(USE_AURA)
#include "chrome/browser/ui/views/aura/chrome_shell_delegate.h"
#endif
namespace chromeos {
class ClockMenuButtonTest : public InProcessBrowserTest {
......@@ -27,15 +31,20 @@ class ClockMenuButtonTest : public InProcessBrowserTest {
// to use stub, so reset it here.
CrosLibrary::Get()->GetTestApi()->ResetUseStubImpl();
}
ClockMenuButton* GetClockMenuButton() {
BrowserView* view = static_cast<BrowserView*>(browser()->window());
return static_cast<ClockMenuButton*>(view->GetViewByID(
const ClockMenuButton* GetClockMenuButton() {
const views::View* parent = NULL;
#if defined(USE_AURA)
parent = ChromeShellDelegate::instance()->GetStatusArea();
#else
parent = static_cast<const BrowserView*>(browser()->window());
#endif
return static_cast<const ClockMenuButton*>(parent->GetViewByID(
VIEW_ID_STATUS_BUTTON_CLOCK));
}
};
IN_PROC_BROWSER_TEST_F(ClockMenuButtonTest, TimezoneTest) {
ClockMenuButton* clock = GetClockMenuButton();
const ClockMenuButton* clock = GetClockMenuButton();
ASSERT_TRUE(clock != NULL);
// Update timezone and make sure clock text changes.
......
......@@ -30,7 +30,7 @@ StatusAreaViewChromeos::~StatusAreaViewChromeos() {
void StatusAreaViewChromeos::Init(StatusAreaButton::Delegate* delegate,
ScreenMode screen_mode) {
AddChromeosButtons(this, delegate, screen_mode);
AddChromeosButtons(this, delegate, screen_mode, NULL);
}
void StatusAreaViewChromeos::SystemResumed() {
......@@ -59,7 +59,8 @@ void StatusAreaViewChromeos::SetDefaultUse24HourClock(bool use_24hour_clock) {
void StatusAreaViewChromeos::AddChromeosButtons(
StatusAreaView* status_area,
StatusAreaButton::Delegate* delegate,
ScreenMode screen_mode) {
ScreenMode screen_mode,
ClockMenuButton** clock_button) {
const bool border = true;
const bool no_border = false;
......@@ -69,7 +70,10 @@ void StatusAreaViewChromeos::AddChromeosButtons(
status_area->AddButton(
new AccessibilityMenuButton(delegate, screen_mode), border);
status_area->AddButton(new CapsLockMenuButton(delegate), border);
status_area->AddButton(new ClockMenuButton(delegate), border);
ClockMenuButton* clock = new ClockMenuButton(delegate);
status_area->AddButton(clock, border);
if (clock_button)
*clock_button = clock;
status_area->AddButton(
new InputMethodMenuButton(delegate, screen_mode), no_border);
......
......@@ -12,6 +12,8 @@
#include "chrome/browser/chromeos/system/timezone_settings.h"
#include "chrome/browser/chromeos/view_ids.h"
class ClockMenuButton;
namespace chromeos {
class StatusAreaViewChromeos : public StatusAreaView,
......@@ -41,9 +43,12 @@ class StatusAreaViewChromeos : public StatusAreaView,
void SetDefaultUse24HourClock(bool use_24hour_clock);
// Convenience function to add buttons to a status area for ChromeOS.
// |clock_button| (if non-NULL) is set to the ClockMenuButton that is created
// by this method.
static void AddChromeosButtons(StatusAreaView* status_area,
StatusAreaButton::Delegate* delegate,
ScreenMode screen_mode);
ScreenMode screen_mode,
ClockMenuButton** clock_button);
private:
void UpdateClockText();
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/status/timezone_clock_updater.h"
#include "chrome/browser/chromeos/status/clock_menu_button.h"
#include "chrome/browser/chromeos/system/timezone_settings.h"
TimezoneClockUpdater::TimezoneClockUpdater(ClockMenuButton* button)
: button_(button) {
chromeos::system::TimezoneSettings::GetInstance()->AddObserver(this);
}
TimezoneClockUpdater::~TimezoneClockUpdater() {
chromeos::system::TimezoneSettings::GetInstance()->RemoveObserver(this);
}
void TimezoneClockUpdater::TimezoneChanged(const icu::TimeZone& timezone) {
button_->UpdateText();
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_STATUS_TIMEZONE_CLOCK_UPDATER_H_
#define CHROME_BROWSER_CHROMEOS_STATUS_TIMEZONE_CLOCK_UPDATER_H_
#pragma once
#include "chrome/browser/chromeos/system/timezone_settings.h"
class ClockMenuButton;
// TimezoneClockUpdater is responsible for updating a ClockMenuButton when the
// timezone changes.
class TimezoneClockUpdater
: public chromeos::system::TimezoneSettings::Observer {
public:
explicit TimezoneClockUpdater(ClockMenuButton* button);
virtual ~TimezoneClockUpdater();
// TimezoneSettings::Observer overrides:
virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
private:
ClockMenuButton* button_;
DISALLOW_COPY_AND_ASSIGN(TimezoneClockUpdater);
};
#endif // CHROME_BROWSER_CHROMEOS_STATUS_TIMEZONE_CLOCK_UPDATER_H_
......@@ -12,10 +12,20 @@
#include "ui/aura/window.h"
#include "ui/aura_shell/launcher/launcher_types.h"
// static
ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
ChromeShellDelegate::ChromeShellDelegate() {
instance_ = this;
}
ChromeShellDelegate::~ChromeShellDelegate() {
if (instance_ == this)
instance_ = NULL;
}
const views::View* ChromeShellDelegate::GetStatusArea() const {
return status_area_host_->GetStatusArea();
}
// static
......
......@@ -12,14 +12,22 @@
#include "ui/aura_shell/launcher/launcher_types.h"
#include "ui/aura_shell/shell_delegate.h"
class StatusAreaHostAura;
class Browser;
class StatusAreaHostAura;
namespace views {
class View;
}
class ChromeShellDelegate : public aura_shell::ShellDelegate {
public:
ChromeShellDelegate();
virtual ~ChromeShellDelegate();
static ChromeShellDelegate* instance() { return instance_; }
const views::View* GetStatusArea() const;
// Returns whether a launcher item should be created for |browser|. If an item
// should be created |type| is set to the launcher type to create.
static bool ShouldCreateLauncherItemForBrowser(
......@@ -35,6 +43,8 @@ class ChromeShellDelegate : public aura_shell::ShellDelegate {
virtual bool ConfigureLauncherItem(aura_shell::LauncherItem* item) OVERRIDE;
private:
static ChromeShellDelegate* instance_;
scoped_ptr<StatusAreaHostAura> status_area_host_;
DISALLOW_COPY_AND_ASSIGN(ChromeShellDelegate);
......
......@@ -20,6 +20,7 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/status/status_area_view_chromeos.h"
#include "chrome/browser/chromeos/status/timezone_clock_updater.h"
#endif
StatusAreaHostAura::StatusAreaHostAura()
......@@ -27,6 +28,13 @@ StatusAreaHostAura::StatusAreaHostAura()
status_area_view_(NULL) {
}
StatusAreaHostAura::~StatusAreaHostAura() {
}
const views::View* StatusAreaHostAura::GetStatusArea() const {
return status_area_view_;
}
views::Widget* StatusAreaHostAura::CreateStatusArea() {
aura_shell::Shell* aura_shell = aura_shell::Shell::GetInstance();
aura::Window* status_window = aura_shell->GetContainer(
......@@ -37,8 +45,12 @@ views::Widget* StatusAreaHostAura::CreateStatusArea() {
// Add child buttons.
#if defined(OS_CHROMEOS)
ClockMenuButton* clock = NULL;
chromeos::StatusAreaViewChromeos::AddChromeosButtons(
status_area_view_, this, chromeos::StatusAreaViewChromeos::BROWSER_MODE);
status_area_view_, this, chromeos::StatusAreaViewChromeos::BROWSER_MODE,
&clock);
DCHECK(clock);
timezone_clock_updater_.reset(new TimezoneClockUpdater(clock));
#else
const bool border = true;
const bool no_border = false;
......
......@@ -10,14 +10,20 @@
#include "chrome/browser/chromeos/status/status_area_button.h"
class StatusAreaView;
class TimezoneClockUpdater;
namespace views {
class Views;
class Widget;
}
class StatusAreaHostAura : public StatusAreaButton::Delegate {
public:
StatusAreaHostAura();
virtual ~StatusAreaHostAura();
// Returns the view housing the status area. Exposed for testing.
const views::View* GetStatusArea() const;
// Instantiates and sets |status_area_view_|, and sets it as the contents of
// a new views::Widget |status_area_widget_| which is returned.
......@@ -39,6 +45,10 @@ class StatusAreaHostAura : public StatusAreaButton::Delegate {
// Owned by status_area_widget_.
StatusAreaView* status_area_view_;
#if defined(OS_CHROMEOS)
scoped_ptr<TimezoneClockUpdater> timezone_clock_updater_;
#endif
DISALLOW_COPY_AND_ASSIGN(StatusAreaHostAura);
};
......
......@@ -766,6 +766,8 @@
'browser/chromeos/status/status_area_view.h',
'browser/chromeos/status/status_area_view_chromeos.cc',
'browser/chromeos/status/status_area_view_chromeos.h',
'browser/chromeos/status/timezone_clock_updater.cc',
'browser/chromeos/status/timezone_clock_updater.h',
'browser/chromeos/system/name_value_pairs_parser.cc',
'browser/chromeos/system/name_value_pairs_parser.h',
'browser/chromeos/system/runtime_environment.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment