summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-28 23:59:19 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-28 23:59:19 +0000
commit1366f20c25eb94d26e13d9c69498aaa693443d32 (patch)
treea30d8977338a7cae7aeff6f6f8eb71300afafd6f /ash
parentb0c2cf00ad1cc95d8fcbb6ba890419ade0e3305e (diff)
downloadchromium_src-1366f20c25eb94d26e13d9c69498aaa693443d32.zip
chromium_src-1366f20c25eb94d26e13d9c69498aaa693443d32.tar.gz
chromium_src-1366f20c25eb94d26e13d9c69498aaa693443d32.tar.bz2
Land stevenjb's cl: Replace Ash web notification tray view with a button.
This cl is almost identical to stevenjb's cl: http://codereview.chromium.org/10878068/ The only difference are some minor white space and typo correction. BUG=144723 TBR=stevenjb,sky Review URL: https://chromiumcodereview.appspot.com/10897012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/system/tray/system_tray.cc1
-rw-r--r--ash/system/tray/tray_background_view.cc8
-rw-r--r--ash/system/tray/tray_background_view.h5
-rw-r--r--ash/system/web_notification/web_notification_tray.cc74
-rw-r--r--ash/system/web_notification/web_notification_tray.h14
5 files changed, 65 insertions, 37 deletions
diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc
index da98726..c1fe09a 100644
--- a/ash/system/tray/system_tray.cc
+++ b/ash/system/tray/system_tray.cc
@@ -71,6 +71,7 @@ SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget)
user_observer_(NULL),
default_bubble_height_(0),
hide_notifications_(false) {
+ SetContentsBackground();
}
SystemTray::~SystemTray() {
diff --git a/ash/system/tray/tray_background_view.cc b/ash/system/tray/tray_background_view.cc
index 2a87185..98cd651 100644
--- a/ash/system/tray/tray_background_view.cc
+++ b/ash/system/tray/tray_background_view.cc
@@ -236,13 +236,15 @@ void TrayBackgroundView::UpdateBackground(int alpha) {
}
void TrayBackgroundView::SetContents(views::View* contents) {
- background_ = new internal::TrayBackground;
- contents->set_background(background_);
-
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
AddChildView(contents);
}
+void TrayBackgroundView::SetContentsBackground() {
+ background_ = new internal::TrayBackground;
+ tray_container_->set_background(background_);
+}
+
void TrayBackgroundView::SetPaintsBackground(
bool value,
internal::BackgroundAnimator::ChangeType change_type) {
diff --git a/ash/system/tray/tray_background_view.h b/ash/system/tray/tray_background_view.h
index 20a7031..615a455 100644
--- a/ash/system/tray/tray_background_view.h
+++ b/ash/system/tray/tray_background_view.h
@@ -84,9 +84,12 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
virtual string16 GetAccessibleName() = 0;
- // Sets |contents| as a child and sets its background to |background_|.
+ // Sets |contents| as a child.
void SetContents(views::View* contents);
+ // Creates and sets contents background to |background_|.
+ void SetContentsBackground();
+
// Sets whether the tray paints a background. Default is true, but is set to
// false if a window overlaps the shelf.
void SetPaintsBackground(
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc
index d1477fd..1e0ecf0 100644
--- a/ash/system/web_notification/web_notification_tray.cc
+++ b/ash/system/web_notification/web_notification_tray.cc
@@ -24,13 +24,13 @@
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/button/button.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/menu_button_listener.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/layout/box_layout.h"
-#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/painter.h"
#include "ui/views/widget/widget_observer.h"
@@ -44,10 +44,6 @@ const int kTrayContainerVerticalPaddingVerticalAlignment = 1;
const int kTrayContainerHorizontalPaddingVerticalAlignment = 0;
const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8;
const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10;
-const int kTrayWidth = 40;
-const int kTrayHeight = 31;
-const int kTraySideWidth = 32;
-const int kTraySideHeight = 24;
// Web Notification Bubble constants
const int kWebNotificationBubbleMinHeight = 80;
@@ -120,11 +116,10 @@ class WebNotificationList {
if (message_center_visible_ == visible)
return;
message_center_visible_ = visible;
- if (visible) {
- // Clear the unread count when the list is shown.
+ if (!visible) {
+ // When the list is hidden, clear the unread count, and mark all
+ // notifications as read and shown.
unread_count_ = 0;
- } else {
- // Mark all notifications as read and shown when the list is hidden.
for (Notifications::iterator iter = notifications_.begin();
iter != notifications_.end(); ++iter) {
iter->is_read = true;
@@ -1088,18 +1083,12 @@ WebNotificationTray::WebNotificationTray(
internal::StatusAreaWidget* status_area_widget)
: internal::TrayBackgroundView(status_area_widget),
notification_list_(new WebNotificationList()),
- count_label_(NULL),
+ button_(NULL),
delegate_(NULL),
show_message_center_on_unlock_(false) {
- count_label_ = new views::Label(UTF8ToUTF16("0"));
- internal::SetupLabelForTray(count_label_);
- gfx::Font font = count_label_->font();
- count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD));
- count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
- count_label_->SetEnabledColor(kMessageCountColor);
+ button_ = new views::ImageButton(this);
- tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight));
- tray_container()->AddChildView(count_label_);
+ tray_container()->AddChildView(button_);
UpdateTray();
}
@@ -1177,6 +1166,7 @@ void WebNotificationTray::HideMessageCenterBubble() {
message_center_bubble_.reset();
show_message_center_on_unlock_ = false;
notification_list_->SetMessageCenterVisible(false);
+ UpdateTray();
status_area_widget()->SetHideSystemNotifications(false);
UpdateShouldShowLauncher();
}
@@ -1238,10 +1228,6 @@ void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
if (alignment == shelf_alignment())
return;
internal::TrayBackgroundView::SetShelfAlignment(alignment);
- if (alignment == SHELF_ALIGNMENT_BOTTOM)
- tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight));
- else
- tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight));
// Destroy any existing bubble so that it will be rebuilt correctly.
HideMessageCenterBubble();
HidePopupBubble();
@@ -1307,13 +1293,16 @@ void WebNotificationTray::DisableByUrl(const std::string& id) {
}
bool WebNotificationTray::PerformAction(const ui::Event& event) {
- if (message_center_bubble())
- HideMessageCenterBubble();
- else
- ShowMessageCenterBubble();
+ ToggleMessageCenterBubble();
return true;
}
+void WebNotificationTray::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
+ DCHECK(sender == button_);
+ ToggleMessageCenterBubble();
+}
+
void WebNotificationTray::ShowSettings(const std::string& id) {
if (delegate_)
delegate_->ShowSettings(id);
@@ -1326,9 +1315,35 @@ void WebNotificationTray::OnClicked(const std::string& id) {
// Other private methods
+void WebNotificationTray::ToggleMessageCenterBubble() {
+ if (message_center_bubble())
+ HideMessageCenterBubble();
+ else
+ ShowMessageCenterBubble();
+ UpdateTray();
+}
+
void WebNotificationTray::UpdateTray() {
- count_label_->SetText(UTF8ToUTF16(
- GetNotificationText(notification_list()->unread_count())));
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ if (notification_list()->unread_count() > 0) {
+ button_->SetImage(views::CustomButton::BS_NORMAL, rb.GetImageSkiaNamed(
+ IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL));
+ button_->SetImage(views::CustomButton::BS_HOT, rb.GetImageSkiaNamed(
+ IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER));
+ button_->SetImage(views::CustomButton::BS_PUSHED, rb.GetImageSkiaNamed(
+ IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED));
+ } else {
+ button_->SetImage(views::CustomButton::BS_NORMAL, rb.GetImageSkiaNamed(
+ IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL));
+ button_->SetImage(views::CustomButton::BS_HOT, rb.GetImageSkiaNamed(
+ IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER));
+ button_->SetImage(views::CustomButton::BS_PUSHED, rb.GetImageSkiaNamed(
+ IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED));
+ }
+ if (message_center_bubble())
+ button_->SetState(views::CustomButton::BS_PUSHED);
+ else
+ button_->SetState(views::CustomButton::BS_NORMAL);
bool is_visible =
(status_area_widget()->login_status() != user::LOGGED_IN_NONE) &&
(status_area_widget()->login_status() != user::LOGGED_IN_LOCKED) &&
@@ -1339,8 +1354,6 @@ void WebNotificationTray::UpdateTray() {
}
void WebNotificationTray::UpdateTrayAndBubble() {
- UpdateTray();
-
if (message_center_bubble()) {
if (notification_list_->notifications().size() == 0)
HideMessageCenterBubble();
@@ -1353,6 +1366,7 @@ void WebNotificationTray::UpdateTrayAndBubble() {
else
popup_bubble()->ScheduleUpdate();
}
+ UpdateTray();
}
void WebNotificationTray::HideBubble(Bubble* bubble) {
diff --git a/ash/system/web_notification/web_notification_tray.h b/ash/system/web_notification/web_notification_tray.h
index 1cfdab1..b76a714 100644
--- a/ash/system/web_notification/web_notification_tray.h
+++ b/ash/system/web_notification/web_notification_tray.h
@@ -20,7 +20,7 @@ class ImageSkia;
}
namespace views {
-class Label;
+class ImageButton;
}
namespace ash {
@@ -43,7 +43,8 @@ class WebNotificationView;
// generated by SystemTrayItem). Visibility of one notification type or other
// is controlled by StatusAreaWidget.
-class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView {
+class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView,
+ public views::ButtonListener {
public:
class Delegate {
public:
@@ -121,6 +122,10 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView {
// Overridden from internal::ActionableView.
virtual bool PerformAction(const ui::Event& event) OVERRIDE;
+ // Overridden from ButtonListener.
+ virtual void ButtonPressed(views::Button* sender,
+ const ui::Event& event) OVERRIDE;
+
// Constants exposed for unit tests:
static const size_t kMaxVisibleTrayNotifications;
static const size_t kMaxVisiblePopupNotifications;
@@ -155,6 +160,9 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView {
// Called when a notification is clicked on. Event is passed to the Delegate.
void OnClicked(const std::string& id);
+ // Shows or hides the message center bubble.
+ void ToggleMessageCenterBubble();
+
// Shows or updates the message center bubble and hides the popup bubble.
void ShowMessageCenterBubble();
@@ -194,7 +202,7 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView {
scoped_ptr<internal::WebNotificationList> notification_list_;
scoped_ptr<MessageCenterBubble> message_center_bubble_;
scoped_ptr<PopupBubble> popup_bubble_;
- views::Label* count_label_;
+ views::ImageButton* button_;
Delegate* delegate_;
bool show_message_center_on_unlock_;