diff options
author | dharcourt@chromium.org <dharcourt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 12:02:07 +0000 |
---|---|---|
committer | dharcourt@chromium.org <dharcourt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 12:02:07 +0000 |
commit | 4958f0d2b68a5881f96d81fc722c915d270305e9 (patch) | |
tree | caab7d0fa6445190fdfeeffa9f484494fde7d387 /ui/message_center | |
parent | 9d46a570df657ab2b5a58ac17f9dcd92d7761bdc (diff) | |
download | chromium_src-4958f0d2b68a5881f96d81fc722c915d270305e9.zip chromium_src-4958f0d2b68a5881f96d81fc722c915d270305e9.tar.gz chromium_src-4958f0d2b68a5881f96d81fc722c915d270305e9.tar.bz2 |
Added button support to image and list notifications.
BUG=168730
Review URL: https://chromiumcodereview.appspot.com/12016030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178279 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r-- | ui/message_center/base_format_view.cc | 23 | ||||
-rw-r--r-- | ui/message_center/message_center.cc | 4 | ||||
-rw-r--r-- | ui/message_center/notification_list.cc | 32 | ||||
-rw-r--r-- | ui/message_center/notification_list.h | 3 | ||||
-rw-r--r-- | ui/message_center/notification_view.cc | 65 | ||||
-rw-r--r-- | ui/message_center/notification_view.h | 3 |
6 files changed, 102 insertions, 28 deletions
diff --git a/ui/message_center/base_format_view.cc b/ui/message_center/base_format_view.cc index 6f098a1..55a571d 100644 --- a/ui/message_center/base_format_view.cc +++ b/ui/message_center/base_format_view.cc @@ -73,15 +73,13 @@ void BaseFormatView::SetUpView() { // TODO(miket): unreadCount - if (notification().button_one_title.length() != 0) { - button_one_ = new views::LabelButton( - this, notification().button_one_title); + if (notification().button_titles.size() > 0) { + button_one_ = new views::LabelButton(this, notification().button_titles[0]); button_one_->SetHorizontalAlignment(gfx::ALIGN_CENTER); button_one_->SetNativeTheme(true); } - if (button_one_ && notification().button_two_title.length() != 0) { - button_two_ = new views::LabelButton( - this, notification().button_two_title); + if (notification().button_titles.size() > 1) { + button_two_ = new views::LabelButton(this, notification().button_titles[1]); button_two_->SetHorizontalAlignment(gfx::ALIGN_CENTER); button_two_->SetNativeTheme(true); } @@ -146,26 +144,31 @@ void BaseFormatView::SetUpView() { if (timestamp) layout->AddView(timestamp, 1, 1); else - layout->SkipColumns(2); + layout->SkipColumns(1); layout->AddView(close_button(), 1, 1); // Row 1: Big icon, title. layout->StartRow(0, 0); layout->AddView(icon, 1, 3); - layout->AddView(title, 6, 1); + layout->AddView(title, 3, 1); + layout->SkipColumns(1); // Row 2: Continuation of big icon, message. layout->StartRow(0, 0); layout->SkipColumns(1); - layout->AddView(message, 6, 1); + layout->AddView(message, 3, 1); + layout->SkipColumns(1); layout->AddPaddingRow(0, kBaseFormatPaddingBetweenItems); // Row 3: Continuation of big icon, two buttons, secondary icon. layout->StartRow(0,0); layout->SkipColumns(1); - if (button_one_) { + if (button_two_) { layout->AddView(button_one_, 1, 1); layout->AddView(button_two_, 1, 1); + } else if (button_one_) { + layout->AddView(button_one_, 1, 1); + layout->SkipColumns(1); } else { layout->SkipColumns(3); // two buttons plus padding } diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc index 394dab9..f8a7b0c 100644 --- a/ui/message_center/message_center.cc +++ b/ui/message_center/message_center.cc @@ -159,6 +159,10 @@ void MessageCenter::OnQuietModeChanged(bool quiet_mode) { void MessageCenter::OnButtonClicked(const std::string& id, int button_index) { if (delegate_) delegate_->OnButtonClicked(id, button_index); + if (HasPopupNotifications()) { + notification_list_->MarkSinglePopupAsShown(id, true); + NotifyMessageCenterChanged(false); + } } NotificationList* MessageCenter::GetNotificationList() { diff --git a/ui/message_center/notification_list.cc b/ui/message_center/notification_list.cc index 2975360..fcd18e6 100644 --- a/ui/message_center/notification_list.cc +++ b/ui/message_center/notification_list.cc @@ -84,26 +84,28 @@ void NotificationList::UnpackOptionalFields( if (!optional_fields) return; - if (optional_fields->HasKey(ui::notifications::kPriorityKey)) - optional_fields->GetInteger(ui::notifications::kPriorityKey, - ¬ification->priority); + optional_fields->GetInteger(ui::notifications::kPriorityKey, + ¬ification->priority); if (optional_fields->HasKey(ui::notifications::kTimestampKey)) { std::string time_string; optional_fields->GetString(ui::notifications::kTimestampKey, &time_string); base::Time::FromString(time_string.c_str(), ¬ification->timestamp); } - if (optional_fields->HasKey(ui::notifications::kUnreadCountKey)) - optional_fields->GetInteger(ui::notifications::kUnreadCountKey, - ¬ification->unread_count); - if (optional_fields->HasKey(ui::notifications::kButtonOneTitleKey)) - optional_fields->GetString(ui::notifications::kButtonOneTitleKey, - ¬ification->button_one_title); - if (optional_fields->HasKey(ui::notifications::kButtonTwoTitleKey)) - optional_fields->GetString(ui::notifications::kButtonTwoTitleKey, - ¬ification->button_two_title); - if (optional_fields->HasKey(ui::notifications::kExpandedMessageKey)) - optional_fields->GetString(ui::notifications::kExpandedMessageKey, - ¬ification->expanded_message); + optional_fields->GetInteger(ui::notifications::kUnreadCountKey, + ¬ification->unread_count); + if (optional_fields->HasKey(ui::notifications::kButtonOneTitleKey)) { + string16 title; + if (optional_fields->GetString(ui::notifications::kButtonOneTitleKey, + &title) && !title.empty()) { + notification->button_titles.push_back(title); + if (optional_fields->GetString(ui::notifications::kButtonTwoTitleKey, + &title) && !title.empty()) { + notification->button_titles.push_back(title); + } + } + } + optional_fields->GetString(ui::notifications::kExpandedMessageKey, + ¬ification->expanded_message); if (optional_fields->HasKey(ui::notifications::kItemsKey)) { const ListValue* items; CHECK(optional_fields->GetList(ui::notifications::kItemsKey, &items)); diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h index 83bc975..14bb84e 100644 --- a/ui/message_center/notification_list.h +++ b/ui/message_center/notification_list.h @@ -48,8 +48,7 @@ class MESSAGE_CENTER_EXPORT NotificationList { int priority; base::Time timestamp; int unread_count; - string16 button_one_title; - string16 button_two_title; + std::vector<string16> button_titles; string16 expanded_message; std::vector<NotificationItem> items; // End unpacked values diff --git a/ui/message_center/notification_view.cc b/ui/message_center/notification_view.cc index dea0817..b2d386c 100644 --- a/ui/message_center/notification_view.cc +++ b/ui/message_center/notification_view.cc @@ -28,6 +28,9 @@ const int kTextTopPadding = 6; const int kTextBottomPadding = 6; const int kTextRightPadding = 23; const int kItemTitleToMessagePadding = 3; +const int kActionButtonTitleTopPadding = 0; +const int kActionButtonTitleLeftPadding = 16; +const int kActionButtonTitleRightPadding = 16; // Notification colors. The text background colors below are used only to keep // view::Label from modifying the text color and will not actually be drawn. @@ -37,12 +40,18 @@ const SkColor kTitleColor = SkColorSetRGB(68, 68, 68); const SkColor kTitleBackgroundColor = SK_ColorWHITE; const SkColor kMessageColor = SkColorSetRGB(136, 136, 136); const SkColor kMessageBackgroundColor = SK_ColorBLACK; +const SkColor kButtonSeparatorColor = SkColorSetRGB(234, 234, 234); // Static function to create an empty border to be used as padding. views::Border* MakePadding(int top, int left, int bottom, int right) { return views::Border::CreateEmptyBorder(top, left, bottom, right); } +// Static function to create an empty border to be used as padding. +views::Background* MakeBackground(SkColor color) { + return views::Background::CreateSolidBackground(color); +} + // ItemViews are responsible for drawing each list notification item's title and // message next to each other within a single column. class ItemView : public views::View { @@ -115,6 +124,36 @@ int ProportionalImageView::GetHeightForWidth(int width) { return height; } +// NotificationsButtons are used to render the action buttons of notifications. +class NotificationButton : public views::CustomButton { + public: + NotificationButton(views::ButtonListener* listener); + virtual ~NotificationButton(); + + void SetTitle(string16 title); +}; + +NotificationButton::NotificationButton(views::ButtonListener* listener) + : views::CustomButton(listener) { + SetLayoutManager(new views::FillLayout()); +} + +NotificationButton::~NotificationButton() { +} + +void NotificationButton::SetTitle(string16 title) { + RemoveAllChildViews(true); + views::Label* label = new views::Label(title); + label->SetHorizontalAlignment(gfx::ALIGN_LEFT); + label->SetElideBehavior(views::Label::ELIDE_AT_END); + label->SetEnabledColor(kTitleColor); + label->SetBackgroundColor(kTitleBackgroundColor); + label->set_border(MakePadding( + kActionButtonTitleTopPadding, kActionButtonTitleLeftPadding, + 0, kActionButtonTitleRightPadding)); + AddChildView(label); +} + } // namespace namespace message_center { @@ -155,6 +194,17 @@ void NotificationView::SetUpView() { AddChildView(close_button()); } +void NotificationView::ButtonPressed(views::Button* sender, + const ui::Event& event) { + for (size_t i = 0; i < action_buttons_.size(); ++i) { + if (action_buttons_[i] == sender) { + list_delegate()->OnButtonClicked(notification().id, i); + return; + } + } + MessageView::ButtonPressed(sender, event); +} + views::View* NotificationView::MakeContentView() { content_view_ = new views::View(); @@ -257,7 +307,20 @@ views::View* NotificationView::MakeContentView() { layout->AddView(image, 2, 1); } - // TODO(dharcourt): Add action button rows. + // Add action button rows. + for (size_t i = 0; i < notification().button_titles.size(); ++i) { + views::View* separator = new views::View(); + separator->set_background(MakeBackground(kButtonSeparatorColor)); + layout->StartRow(0, 0); + layout->AddView(separator, 2, 1, + views::GridLayout::FILL, views::GridLayout::FILL, 0, 1); + NotificationButton* button = new NotificationButton(this); + button->SetTitle(notification().button_titles[i]); + action_buttons_.push_back(button); + layout->StartRow(0, 0); + layout->AddView(button, 2, 1, + views::GridLayout::FILL, views::GridLayout::FILL, 0, 40); + } return content_view_; } diff --git a/ui/message_center/notification_view.h b/ui/message_center/notification_view.h index e5cf096..468644c 100644 --- a/ui/message_center/notification_view.h +++ b/ui/message_center/notification_view.h @@ -25,11 +25,14 @@ class NotificationView : public MessageView { // Overridden from MessageView. virtual void SetUpView() OVERRIDE; + virtual void ButtonPressed(views::Button* sender, + const ui::Event& event) OVERRIDE; private: views::View* MakeContentView(); views::View* content_view_; + std::vector<views::Button*> action_buttons_; DISALLOW_COPY_AND_ASSIGN(NotificationView); }; |