summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 01:04:27 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 01:04:27 +0000
commit7c0c96f4be6e5830bb07fdea868d7ee7b031a81c (patch)
treeb1a7399eac6dfee1fc5232927fdaedcc57d91606 /ash
parentfa5456fa373ce482c284fd57acce05d9a33bc91e (diff)
downloadchromium_src-7c0c96f4be6e5830bb07fdea868d7ee7b031a81c.zip
chromium_src-7c0c96f4be6e5830bb07fdea868d7ee7b031a81c.tar.gz
chromium_src-7c0c96f4be6e5830bb07fdea868d7ee7b031a81c.tar.bz2
ash uber tray: Add an update indicator in the popup.
BUG=110130, 115357 TEST=none Review URL: https://chromiumcodereview.appspot.com/9694049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp1
-rw-r--r--ash/ash_strings.grd3
-rw-r--r--ash/shell.cc14
-rw-r--r--ash/shell.h5
-rw-r--r--ash/system/tray/system_tray_delegate.h6
-rw-r--r--ash/system/user/tray_user.cc126
-rw-r--r--ash/system/user/tray_user.h13
-rw-r--r--ash/system/user/update_controller.h21
8 files changed, 164 insertions, 25 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index cda2082..fe83dec 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -138,6 +138,7 @@
'system/user/login_status.h',
'system/user/tray_user.cc',
'system/user/tray_user.h',
+ 'system/user/update_controller.h',
'tooltips/tooltip_controller.cc',
'tooltips/tooltip_controller.h',
'volume_control_delegate.h',
diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd
index 55b83dc..c747908 100644
--- a/ash/ash_strings.grd
+++ b/ash/ash_strings.grd
@@ -190,6 +190,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_STATUS_TRAY_LOCK" desc="The label used for the button in the status tray to lock the screen.">
Lock
</message>
+ <message name="IDS_ASH_STATUS_TRAY_UPDATE" desc="The label used in the tray popup to notify that the user should restart to get system updates.">
+ Restart to update
+ </message>
</messages>
</release>
</grit>
diff --git a/ash/shell.cc b/ash/shell.cc
index ad8f835..acdce03 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -55,6 +55,7 @@
#include "ash/wm/workspace/workspace_manager.h"
#include "base/bind.h"
#include "base/command_line.h"
+#include "grit/ui_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/layout_manager.h"
@@ -239,6 +240,14 @@ class DummySystemTrayDelegate : public SystemTrayDelegate {
return user::LOGGED_IN_USER;
}
+ virtual bool SystemShouldUpgrade() const OVERRIDE {
+ return true;
+ }
+
+ virtual int GetSystemUpdateIconResource() const OVERRIDE {
+ return IDR_AURA_UBER_TRAY_UPDATE;
+ }
+
virtual void ShowSettings() OVERRIDE {
}
@@ -314,6 +323,7 @@ Shell::Shell(ShellDelegate* delegate)
brightness_controller_(NULL),
network_controller_(NULL),
power_status_controller_(NULL),
+ update_controller_(NULL),
shelf_(NULL),
desktop_background_mode_(BACKGROUND_IMAGE),
root_window_layout_(NULL),
@@ -466,12 +476,14 @@ void Shell::Init() {
internal::TrayBrightness* tray_brightness = new internal::TrayBrightness();
internal::TrayPowerDate* tray_power_date = new internal::TrayPowerDate();
internal::TrayNetwork* tray_network = new internal::TrayNetwork;
+ internal::TrayUser* tray_user = new internal::TrayUser;
audio_controller_ = tray_volume;
brightness_controller_ = tray_brightness;
network_controller_ = tray_network;
power_status_controller_ = tray_power_date;
+ update_controller_ = tray_user;
- tray_->AddTrayItem(new internal::TrayUser());
+ tray_->AddTrayItem(tray_user);
tray_->AddTrayItem(new internal::TrayEmpty());
tray_->AddTrayItem(tray_power_date);
tray_->AddTrayItem(tray_network);
diff --git a/ash/shell.h b/ash/shell.h
index e6af0db..475df7a 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -52,6 +52,7 @@ class ShellDelegate;
class ShellObserver;
class SystemTrayDelegate;
class SystemTray;
+class UpdateController;
class VideoDetector;
class WindowCycleController;
@@ -202,6 +203,9 @@ class ASH_EXPORT Shell {
PowerStatusController* power_status_controller() const {
return power_status_controller_;
}
+ UpdateController* update_controller() const {
+ return update_controller_;
+ }
ShellDelegate* delegate() { return delegate_.get(); }
SystemTrayDelegate* tray_delegate() { return tray_delegate_.get(); }
@@ -284,6 +288,7 @@ class ASH_EXPORT Shell {
BrightnessController* brightness_controller_;
NetworkController* network_controller_;
PowerStatusController* power_status_controller_;
+ UpdateController* update_controller_;
// An event filter that pre-handles all key events to send them to an IME.
scoped_ptr<internal::InputMethodEventFilter> input_method_filter_;
diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h
index 6ae1039..de2b388 100644
--- a/ash/system/tray/system_tray_delegate.h
+++ b/ash/system/tray/system_tray_delegate.h
@@ -30,6 +30,12 @@ class SystemTrayDelegate {
virtual const SkBitmap& GetUserImage() const = 0;
virtual user::LoginStatus GetUserLoginStatus() const = 0;
+ // Returns whether a system upgrade is available.
+ virtual bool SystemShouldUpgrade() const = 0;
+
+ // Returns the resource id for the icon to show for the update notification.
+ virtual int GetSystemUpdateIconResource() const = 0;
+
// Shows settings.
virtual void ShowSettings() = 0;
diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc
index 008ea4a..b676b08 100644
--- a/ash/system/user/tray_user.cc
+++ b/ash/system/user/tray_user.cc
@@ -9,6 +9,7 @@
#include "base/utf_string_conversions.h"
#include "grit/ash_strings.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image.h"
#include "ui/gfx/size.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/text_button.h"
@@ -19,6 +20,8 @@
namespace {
+const int kUpdateNotificationPadding = 5;
+
// A custom textbutton with some extra vertical padding, and custom border,
// alignment and hover-effects.
class TrayButton : public views::TextButton {
@@ -64,12 +67,20 @@ class TrayButton : public views::TextButton {
DISALLOW_COPY_AND_ASSIGN(TrayButton);
};
+} // namespace
+
+namespace ash {
+namespace internal {
+
+namespace tray {
+
class UserView : public views::View,
public views::ButtonListener {
public:
explicit UserView(ash::user::LoginStatus status)
: username_(NULL),
email_(NULL),
+ update_(NULL),
shutdown_(NULL),
signout_(NULL),
lock_(NULL) {
@@ -77,24 +88,8 @@ class UserView : public views::View,
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
0, 0, 3));
- if (status != ash::user::LOGGED_IN_GUEST) {
- views::View* user = new views::View;
- user->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
- 14, 5, 0));
- ash::SystemTrayDelegate* tray =
- ash::Shell::GetInstance()->tray_delegate();
- username_ = new views::Label(ASCIIToUTF16(tray->GetUserDisplayName()));
- username_->SetFont(username_->font().DeriveFont(2));
- username_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- user->AddChildView(username_);
-
- email_ = new views::Label(ASCIIToUTF16(tray->GetUserEmail()));
- email_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- email_->SetEnabled(false);
- user->AddChildView(email_);
-
- AddChildView(user);
- }
+ if (status != ash::user::LOGGED_IN_GUEST)
+ AddUserInfo();
views::View* button_container = new views::View;
views::BoxLayout *layout = new
@@ -128,7 +123,69 @@ class UserView : public views::View,
virtual ~UserView() {}
+ // Shows update notification if available.
+ void RefreshForUpdate() {
+ ash::SystemTrayDelegate* tray = ash::Shell::GetInstance()->tray_delegate();
+ if (tray->SystemShouldUpgrade()) {
+ if (update_)
+ return;
+ update_ = new views::View;
+ update_->SetLayoutManager(new
+ views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 3));
+
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ views::Label *label = new views::Label(bundle.GetLocalizedString(
+ IDS_ASH_STATUS_TRAY_UPDATE));
+ label->SetFont(label->font().DeriveFont(-1));
+ update_->AddChildView(label);
+
+ views::ImageView* icon = new views::ImageView;
+ icon->SetImage(bundle.GetImageNamed(tray->GetSystemUpdateIconResource()).
+ ToSkBitmap());
+ update_->AddChildView(icon);
+
+ update_->set_border(views::Border::CreateEmptyBorder(
+ kUpdateNotificationPadding,
+ kUpdateNotificationPadding,
+ kUpdateNotificationPadding,
+ kUpdateNotificationPadding));
+
+ user_info_->AddChildView(update_);
+ } else if (update_) {
+ delete update_;
+ update_ = NULL;
+ }
+ user_info_->InvalidateLayout();
+ user_info_->SchedulePaint();
+ }
+
private:
+ void AddUserInfo() {
+ user_info_ = new views::View;
+ user_info_->SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kHorizontal, 0, 0, 3));
+
+ views::View* user = new views::View;
+ user->SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kVertical, 14, 5, 0));
+ ash::SystemTrayDelegate* tray =
+ ash::Shell::GetInstance()->tray_delegate();
+ username_ = new views::Label(ASCIIToUTF16(tray->GetUserDisplayName()));
+ username_->SetFont(username_->font().DeriveFont(2));
+ username_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ user->AddChildView(username_);
+
+ email_ = new views::Label(ASCIIToUTF16(tray->GetUserEmail()));
+ email_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ email_->SetEnabled(false);
+ user->AddChildView(email_);
+
+ user_info_->AddChildView(user);
+ AddChildView(user_info_);
+
+ RefreshForUpdate();
+ }
+
// Overridden from views::ButtonListener.
virtual void ButtonPressed(views::Button* sender,
const views::Event& event) OVERRIDE {
@@ -141,8 +198,24 @@ class UserView : public views::View,
tray->RequestLockScreen();
}
+ // Overridden from views::View.
+ virtual void Layout() OVERRIDE {
+ views::View::Layout();
+ if (!update_)
+ return;
+
+ // Position |update_| appropriately.
+ gfx::Rect bounds;
+ bounds.set_x(user_info_->width() - update_->width());
+ bounds.set_y(0);
+ bounds.set_size(update_->GetPreferredSize());
+ update_->SetBoundsRect(bounds);
+ }
+
+ views::View* user_info_;
views::Label* username_;
views::Label* email_;
+ views::View* update_;
TrayButton* shutdown_;
TrayButton* signout_;
@@ -151,10 +224,7 @@ class UserView : public views::View,
DISALLOW_COPY_AND_ASSIGN(UserView);
};
-} // namespace
-
-namespace ash {
-namespace internal {
+} // namespace tray
TrayUser::TrayUser() {
}
@@ -173,7 +243,11 @@ views::View* TrayUser::CreateTrayView(user::LoginStatus status) {
}
views::View* TrayUser::CreateDefaultView(user::LoginStatus status) {
- return status == user::LOGGED_IN_NONE ? NULL : new UserView(status);
+ if (status == user::LOGGED_IN_NONE)
+ return NULL;
+
+ user_.reset(new tray::UserView(status));
+ return user_.get();
}
views::View* TrayUser::CreateDetailedView(user::LoginStatus status) {
@@ -184,10 +258,16 @@ void TrayUser::DestroyTrayView() {
}
void TrayUser::DestroyDefaultView() {
+ user_.reset();
}
void TrayUser::DestroyDetailedView() {
}
+void TrayUser::OnUpdateRecommended() {
+ if (user_.get())
+ user_->RefreshForUpdate();
+}
+
} // namespace internal
} // namespace ash
diff --git a/ash/system/user/tray_user.h b/ash/system/user/tray_user.h
index 167784d..7284701 100644
--- a/ash/system/user/tray_user.h
+++ b/ash/system/user/tray_user.h
@@ -7,11 +7,17 @@
#pragma once
#include "ash/system/tray/system_tray_item.h"
+#include "ash/system/user/update_controller.h"
namespace ash {
namespace internal {
-class TrayUser : public SystemTrayItem {
+namespace tray {
+class UserView;
+}
+
+class TrayUser : public SystemTrayItem,
+ public UpdateController {
public:
TrayUser();
virtual ~TrayUser();
@@ -25,6 +31,11 @@ class TrayUser : public SystemTrayItem {
virtual void DestroyDefaultView() OVERRIDE;
virtual void DestroyDetailedView() OVERRIDE;
+ // Overridden from UpdateController.
+ virtual void OnUpdateRecommended() OVERRIDE;
+
+ scoped_ptr<tray::UserView> user_;
+
DISALLOW_COPY_AND_ASSIGN(TrayUser);
};
diff --git a/ash/system/user/update_controller.h b/ash/system/user/update_controller.h
new file mode 100644
index 0000000..ee6f86c
--- /dev/null
+++ b/ash/system/user/update_controller.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2012 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 ASH_SYSTEM_USER_UPDATE_CONTROLLER_H_
+#define ASH_SYSTEM_USER_UPDATE_CONTROLLER_H_
+
+#include "ash/ash_export.h"
+
+namespace ash {
+
+class ASH_EXPORT UpdateController {
+ public:
+ virtual ~UpdateController() {}
+
+ virtual void OnUpdateRecommended() = 0;
+};
+
+} // namespace ash
+
+#endif //ASH_SYSTEM_USER_UPDATE_CONTROLLER_H_