summaryrefslogtreecommitdiffstats
path: root/ui/message_center
diff options
context:
space:
mode:
authordimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-23 00:59:40 +0000
committerdimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-23 00:59:40 +0000
commitb2311a318bd37fbf401780f8101bdc58fc2a1d77 (patch)
treef91ab53ee7c8e27f82a5bf34a517563b21891584 /ui/message_center
parentc5006d524e1c6fb4b9962c3e7fc0f6ccd53a9ea4 (diff)
downloadchromium_src-b2311a318bd37fbf401780f8101bdc58fc2a1d77.zip
chromium_src-b2311a318bd37fbf401780f8101bdc58fc2a1d77.tar.gz
chromium_src-b2311a318bd37fbf401780f8101bdc58fc2a1d77.tar.bz2
Move knowledge about MessageCenter out of MessageView.
This is because I need to create a new subclass of MessageView - a synthetic placeholder for multiple notifications from the same source. Hence the new enum, MesageViewTypes, which is not used in this patch but will in second... the derived classes override abstract methods of the MesageView to provide functionality. NotificationView currently knows about MessageCenter but in the future refactorings it can yield this to MessageCenterView. BUG=320827 Review URL: https://codereview.chromium.org/75133006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236888 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r--ui/message_center/views/message_center_view.cc94
-rw-r--r--ui/message_center/views/message_center_view.h8
-rw-r--r--ui/message_center/views/message_center_view_unittest.cc46
-rw-r--r--ui/message_center/views/message_view.cc93
-rw-r--r--ui/message_center/views/message_view.h17
-rw-r--r--ui/message_center/views/notification_view.cc41
-rw-r--r--ui/message_center/views/notification_view.h24
7 files changed, 161 insertions, 162 deletions
diff --git a/ui/message_center/views/message_center_view.cc b/ui/message_center/views/message_center_view.cc
index 7d2e9d6..d50814a 100644
--- a/ui/message_center/views/message_center_view.cc
+++ b/ui/message_center/views/message_center_view.cc
@@ -159,7 +159,8 @@ void NoNotificationMessageView::Layout() {
label_->SetBounds(0, margin, width(), text_height);
}
-// Displays a list of messages for rich notifications. It also supports
+// Displays a list of messages for rich notifications. Functions as an array of
+// MessageViews and animates them on transitions. It also supports
// repositioning.
class MessageListView : public views::View,
public views::BoundsAnimatorObserver {
@@ -168,9 +169,9 @@ class MessageListView : public views::View,
bool top_down);
virtual ~MessageListView();
- void AddNotificationAt(views::View* view, int i);
+ void AddNotificationAt(MessageView* view, int i);
void RemoveNotificationAt(int i);
- void UpdateNotificationAt(views::View* view, int i);
+ void UpdateNotificationAt(MessageView* view, int i);
void SetRepositionTarget(const gfx::Rect& target_rect);
void ResetRepositionSession();
void ClearAllNotifications(const gfx::Rect& visible_scroll_rect);
@@ -285,7 +286,7 @@ void MessageListView::Layout() {
}
}
-void MessageListView::AddNotificationAt(views::View* view, int i) {
+void MessageListView::AddNotificationAt(MessageView* view, int i) {
AddChildViewAt(view, GetActualIndex(i));
if (GetContentsBounds().IsEmpty())
return;
@@ -310,7 +311,7 @@ void MessageListView::RemoveNotificationAt(int i) {
}
}
-void MessageListView::UpdateNotificationAt(views::View* view, int i) {
+void MessageListView::UpdateNotificationAt(MessageView* view, int i) {
int actual_index = GetActualIndex(i);
views::View* child = child_at(actual_index);
if (animator_.get())
@@ -663,13 +664,13 @@ void MessageCenterView::SetNotifications(
if (is_closing_)
return;
- message_views_.clear();
+ notification_views_.clear();
int index = 0;
for (NotificationList::Notifications::const_iterator iter =
notifications.begin(); iter != notifications.end();
++iter, ++index) {
AddNotificationAt(*(*iter), index);
- if (message_views_.size() >= kMaxVisibleMessageCenterNotifications)
+ if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications)
break;
}
NotificationsChanged();
@@ -879,7 +880,7 @@ void MessageCenterView::OnNotificationAdded(const std::string& id) {
AddNotificationAt(*(*iter), index);
break;
}
- if (message_views_.size() >= kMaxVisibleMessageCenterNotifications)
+ if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications)
break;
}
NotificationsChanged();
@@ -887,49 +888,56 @@ void MessageCenterView::OnNotificationAdded(const std::string& id) {
void MessageCenterView::OnNotificationRemoved(const std::string& id,
bool by_user) {
- for (size_t i = 0; i < message_views_.size(); ++i) {
- if (message_views_[i]->notification_id() == id) {
- if (by_user) {
- message_list_view_->SetRepositionTarget(message_views_[i]->bounds());
- // Moves the keyboard focus to the next notification if the removed
- // notification is focused so that the user can dismiss notifications
- // without re-focusing by tab key.
- if (message_views_.size() > 1) {
- views::View* focused_view = GetFocusManager()->GetFocusedView();
- if (message_views_[i]->IsCloseButtonFocused() ||
- focused_view == message_views_[i]) {
- size_t next_index = i + 1;
- if (next_index >= message_views_.size())
- next_index = message_views_.size() - 2;
- if (focused_view == message_views_[i])
- message_views_[next_index]->RequestFocus();
- else
- message_views_[next_index]->RequestFocusOnCloseButton();
- }
- }
+ NotificationViewsMap::iterator view_iter = notification_views_.find(id);
+ if (view_iter == notification_views_.end())
+ return;
+ NotificationView* view = view_iter->second;
+ int index = message_list_view_->GetIndexOf(view);
+ if (by_user) {
+ message_list_view_->SetRepositionTarget(view->bounds());
+ // Moves the keyboard focus to the next notification if the removed
+ // notification is focused so that the user can dismiss notifications
+ // without re-focusing by tab key.
+ if (view->IsCloseButtonFocused() ||
+ view == GetFocusManager()->GetFocusedView()) {
+ views::View* next_focused_view = NULL;
+ if (message_list_view_->child_count() > index + 1)
+ next_focused_view = message_list_view_->child_at(index + 1);
+ else if (index > 0)
+ next_focused_view = message_list_view_->child_at(index - 1);
+
+ if (next_focused_view) {
+ if (view->IsCloseButtonFocused())
+ // Safe cast since all views in MessageListView are MessageViews.
+ static_cast<MessageView*>(
+ next_focused_view)->RequestFocusOnCloseButton();
+ else
+ next_focused_view->RequestFocus();
}
- message_list_view_->RemoveNotificationAt(i);
- message_views_.erase(message_views_.begin() + i);
- NotificationsChanged();
- break;
}
}
+ message_list_view_->RemoveNotificationAt(index);
+ notification_views_.erase(view_iter);
+ NotificationsChanged();
}
void MessageCenterView::OnNotificationUpdated(const std::string& id) {
+ NotificationViewsMap::const_iterator view_iter = notification_views_.find(id);
+ if (view_iter == notification_views_.end())
+ return;
+ NotificationView* view = view_iter->second;
+ size_t index = message_list_view_->GetIndexOf(view);
+ DCHECK(index >= 0);
+ // TODO(dimich): add MessageCenter::GetVisibleNotificationById(id)
const NotificationList::Notifications& notifications =
message_center_->GetVisibleNotifications();
- size_t index = 0;
for (NotificationList::Notifications::const_iterator iter =
- notifications.begin();
- iter != notifications.end() && index < message_views_.size();
- ++iter, ++index) {
- DCHECK((*iter)->id() == message_views_[index]->notification_id());
+ notifications.begin(); iter != notifications.end(); ++iter) {
if ((*iter)->id() == id) {
bool expanded = true;
if (IsExperimentalNotificationUIEnabled())
expanded = (*iter)->is_expanded();
- MessageView* view =
+ NotificationView* view =
NotificationView::Create(*(*iter),
message_center_,
tray_,
@@ -938,7 +946,7 @@ void MessageCenterView::OnNotificationUpdated(const std::string& id) {
// notification.
view->set_scroller(scroller_);
message_list_view_->UpdateNotificationAt(view, index);
- message_views_[index] = view;
+ notification_views_[id] = view;
NotificationsChanged();
break;
}
@@ -992,7 +1000,7 @@ void MessageCenterView::AddNotificationAt(const Notification& notification,
bool expanded = true;
if (IsExperimentalNotificationUIEnabled())
expanded = notification.is_expanded();
- MessageView* view =
+ NotificationView* view =
NotificationView::Create(notification,
message_center_,
tray_,
@@ -1000,13 +1008,13 @@ void MessageCenterView::AddNotificationAt(const Notification& notification,
false); // Not creating a top-level
// notification.
view->set_scroller(scroller_);
- message_views_.insert(message_views_.begin() + index, view);
+ notification_views_[notification.id()] = view;
message_list_view_->AddNotificationAt(view, index);
message_center_->DisplayedNotification(notification.id());
}
void MessageCenterView::NotificationsChanged() {
- bool no_message_views = message_views_.empty();
+ bool no_message_views = notification_views_.empty();
// All the children of this view are owned by |this|.
scroller_->contents()->RemoveAllChildViews(/*delete_children=*/false);
scroller_->contents()->AddChildView(
@@ -1020,7 +1028,7 @@ void MessageCenterView::NotificationsChanged() {
Layout();
}
-void MessageCenterView::SetNotificationViewForTest(views::View* view) {
+void MessageCenterView::SetNotificationViewForTest(MessageView* view) {
message_list_view_->AddNotificationAt(view, 0);
}
diff --git a/ui/message_center/views/message_center_view.h b/ui/message_center/views/message_center_view.h
index e230c38..10381b3 100644
--- a/ui/message_center/views/message_center_view.h
+++ b/ui/message_center/views/message_center_view.h
@@ -31,6 +31,7 @@ class MessageCenterTray;
class MessageCenterView;
class MessageView;
class MessageListView;
+class NotificationView;
class NotifierSettingsView;
// MessageCenterView ///////////////////////////////////////////////////////////
@@ -83,11 +84,14 @@ class MESSAGE_CENTER_EXPORT MessageCenterView : public views::View,
void AddNotificationAt(const Notification& notification, int index);
void NotificationsChanged();
- void SetNotificationViewForTest(views::View* view);
+ void SetNotificationViewForTest(MessageView* view);
MessageCenter* message_center_; // Weak reference.
MessageCenterTray* tray_; // Weak reference.
- std::vector<MessageView*> message_views_; // Weak references.
+ // Map notification_id->NotificationView*. It contains all NotificaitonViews
+ // currently displayed in MessageCenter.
+ typedef std::map<std::string, NotificationView*> NotificationViewsMap;
+ NotificationViewsMap notification_views_; // Weak.
// Child views.
views::ScrollView* scroller_;
diff --git a/ui/message_center/views/message_center_view_unittest.cc b/ui/message_center/views/message_center_view_unittest.cc
index b9e34a1..ddc5e65 100644
--- a/ui/message_center/views/message_center_view_unittest.cc
+++ b/ui/message_center/views/message_center_view_unittest.cc
@@ -31,62 +31,50 @@ class MockNotificationView : public NotificationView {
public:
class Test {
public:
- virtual void RegisterCall(int receiver_id, CallType type) = 0;
+ virtual void RegisterCall(CallType type) = 0;
};
explicit MockNotificationView(const Notification& notification,
MessageCenter* message_center,
- Test* test,
- int view_id);
+ Test* test);
virtual ~MockNotificationView();
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual int GetHeightForWidth(int w) OVERRIDE;
virtual void Layout() OVERRIDE;
- int get_id() { return id_; };
-
private:
- void RegisterCall(CallType type);
-
Test* test_;
- int id_;
DISALLOW_COPY_AND_ASSIGN(MockNotificationView);
};
MockNotificationView::MockNotificationView(const Notification& notification,
MessageCenter* message_center,
- Test* test,
- int view_id)
+ Test* test)
: NotificationView(notification, message_center, NULL, true),
- test_(test),
- id_(view_id) {
+ test_(test) {
}
MockNotificationView::~MockNotificationView() {
}
gfx::Size MockNotificationView::GetPreferredSize() {
- RegisterCall(GET_PREFERRED_SIZE);
- return child_count() ? NotificationView::GetPreferredSize() :
- gfx::Size(id_, id_);
+ test_->RegisterCall(GET_PREFERRED_SIZE);
+ DCHECK(child_count() > 0);
+ return NotificationView::GetPreferredSize();
}
int MockNotificationView::GetHeightForWidth(int width) {
- RegisterCall(GET_HEIGHT_FOR_WIDTH);
- return child_count() ? NotificationView::GetHeightForWidth(width) : (id_);
+ test_->RegisterCall(GET_HEIGHT_FOR_WIDTH);
+ DCHECK(child_count() > 0);
+ return NotificationView::GetHeightForWidth(width);
}
void MockNotificationView::Layout() {
- RegisterCall(LAYOUT);
- if (child_count())
- NotificationView::Layout();
-}
-
-void MockNotificationView::RegisterCall(CallType type) {
- if (test_)
- test_->RegisterCall(id_, type);
+ test_->RegisterCall(LAYOUT);
+ DCHECK(child_count() > 0);
+ NotificationView::Layout();
}
/* Test fixture ***************************************************************/
@@ -104,7 +92,7 @@ class MessageCenterViewTest : public testing::Test,
int GetNotificationCount();
int GetCallCount(CallType type);
- virtual void RegisterCall(int receiver_id, CallType type) OVERRIDE;
+ virtual void RegisterCall(CallType type) OVERRIDE;
void LogBounds(int depth, views::View* view);
@@ -150,8 +138,8 @@ void MessageCenterViewTest::SetUp() {
// MessageListView and replace it with an instrumented MockNotificationView
// that will become owned by the MessageListView.
MockNotificationView* mock;
- mock = new MockNotificationView(notification, &message_center_, this, 42);
- message_center_view_->message_views_.push_back(mock);
+ mock = new MockNotificationView(notification, &message_center_, this);
+ message_center_view_->notification_views_[notification.id()] = mock;
message_center_view_->SetNotificationViewForTest(mock);
}
@@ -171,7 +159,7 @@ int MessageCenterViewTest::GetCallCount(CallType type) {
return callCounts_[type];
}
-void MessageCenterViewTest::RegisterCall(int receiver_id, CallType type) {
+void MessageCenterViewTest::RegisterCall(CallType type) {
callCounts_[type] += 1;
}
diff --git a/ui/message_center/views/message_view.cc b/ui/message_center/views/message_view.cc
index da65a0a..56e2202 100644
--- a/ui/message_center/views/message_view.cc
+++ b/ui/message_center/views/message_view.cc
@@ -14,7 +14,6 @@
#include "ui/gfx/canvas.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_style.h"
-#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/message_center_util.h"
#include "ui/message_center/views/padded_button.h"
#include "ui/views/context_menu_controller.h"
@@ -40,11 +39,8 @@ const int kShowSettingsCommand = 1;
class MenuModel : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
- MenuModel(message_center::MessageCenter* message_center,
- message_center::MessageCenterTray* tray,
- const std::string& notification_id,
- const string16& display_source,
- const message_center::NotifierId& notifier_id);
+ MenuModel(message_center::MessageView* message_view,
+ const string16& display_source);
virtual ~MenuModel();
// Overridden from ui::SimpleMenuModel::Delegate:
@@ -57,24 +53,14 @@ class MenuModel : public ui::SimpleMenuModel,
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
private:
- message_center::MessageCenter* message_center_; // Weak reference.
- message_center::MessageCenterTray* tray_; // Weak reference.
- std::string notification_id_;
- message_center::NotifierId notifier_id_;
-
+ message_center::MessageView* message_view_; // Weak, owns us.
DISALLOW_COPY_AND_ASSIGN(MenuModel);
};
-MenuModel::MenuModel(message_center::MessageCenter* message_center,
- message_center::MessageCenterTray* tray,
- const std::string& notification_id,
- const string16& display_source,
- const message_center::NotifierId& notifier_id)
+MenuModel::MenuModel(message_center::MessageView* message_view,
+ const string16& display_source)
: ui::SimpleMenuModel(this),
- message_center_(message_center),
- tray_(tray),
- notification_id_(notification_id),
- notifier_id_(notifier_id) {
+ message_view_(message_view) {
// Add 'disable notifications' menu item.
if (!display_source.empty()) {
AddItem(kTogglePermissionCommand,
@@ -109,12 +95,10 @@ bool MenuModel::GetAcceleratorForCommandId(int command_id,
void MenuModel::ExecuteCommand(int command_id, int event_flags) {
switch (command_id) {
case kTogglePermissionCommand:
- message_center_->DisableNotificationsByNotifier(notifier_id_);
+ message_view_->DisableNotificationsFromThisSource();
break;
case kShowSettingsCommand:
- // |tray_| may be NULL in tests.
- if (tray_)
- tray_->ShowNotifierSettingsBubble();
+ message_view_->ShowNotifierSettingsBubble();
break;
default:
NOTREACHED();
@@ -127,10 +111,8 @@ namespace message_center {
class MessageViewContextMenuController : public views::ContextMenuController {
public:
- MessageViewContextMenuController(
- MessageCenter* message_center,
- MessageCenterTray* tray,
- const Notification& notification);
+ MessageViewContextMenuController(MessageView* message_view,
+ const string16& display_source);
virtual ~MessageViewContextMenuController();
protected:
@@ -139,22 +121,15 @@ class MessageViewContextMenuController : public views::ContextMenuController {
const gfx::Point& point,
ui::MenuSourceType source_type) OVERRIDE;
- MessageCenter* message_center_; // Weak reference.
- MessageCenterTray* tray_; // Weak reference.
- std::string notification_id_;
+ MessageView* message_view_; // Weak, owns us.
string16 display_source_;
- NotifierId notifier_id_;
};
MessageViewContextMenuController::MessageViewContextMenuController(
- MessageCenter* message_center,
- MessageCenterTray* tray,
- const Notification& notification)
- : message_center_(message_center),
- tray_(tray),
- notification_id_(notification.id()),
- display_source_(notification.display_source()),
- notifier_id_(notification.notifier_id()) {
+ MessageView* message_view,
+ const string16& display_source)
+ : message_view_(message_view),
+ display_source_(display_source) {
}
MessageViewContextMenuController::~MessageViewContextMenuController() {
@@ -164,8 +139,7 @@ void MessageViewContextMenuController::ShowContextMenuForView(
views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
- MenuModel menu_model(message_center_, tray_, notification_id_,
- display_source_, notifier_id_);
+ MenuModel menu_model(message_view_, display_source_);
if (menu_model.GetItemCount() == 0)
return;
@@ -180,13 +154,9 @@ void MessageViewContextMenuController::ShowContextMenuForView(
views::MenuRunner::HAS_MNEMONICS));
}
-MessageView::MessageView(const Notification& notification,
- MessageCenter* message_center,
- MessageCenterTray* tray)
- : message_center_(message_center),
- notification_id_(notification.id()),
- context_menu_controller_(new MessageViewContextMenuController(
- message_center, tray, notification)),
+MessageView::MessageView(const string16& display_source)
+ : context_menu_controller_(
+ new MessageViewContextMenuController(this, display_source)),
scroller_(NULL) {
set_focusable(true);
set_context_menu_controller(context_menu_controller_.get());
@@ -203,9 +173,6 @@ MessageView::MessageView(const Notification& notification,
close_button_.reset(close);
}
-MessageView::MessageView() {
-}
-
MessageView::~MessageView() {
}
@@ -239,11 +206,11 @@ void MessageView::GetAccessibleState(ui::AccessibleViewState* state) {
}
bool MessageView::OnMousePressed(const ui::MouseEvent& event) {
- if (event.IsOnlyLeftMouseButton()) {
- message_center_->ClickOnNotification(notification_id_);
- return true;
- }
- return false;
+ if (!event.IsOnlyLeftMouseButton())
+ return false;
+
+ ClickOnNotification();
+ return true;
}
bool MessageView::OnKeyPressed(const ui::KeyEvent& event) {
@@ -251,11 +218,11 @@ bool MessageView::OnKeyPressed(const ui::KeyEvent& event) {
return false;
if (event.key_code() == ui::VKEY_RETURN) {
- message_center_->ClickOnNotification(notification_id_);
+ ClickOnNotification();
return true;
} else if ((event.key_code() == ui::VKEY_DELETE ||
event.key_code() == ui::VKEY_BACK)) {
- message_center_->RemoveNotification(notification_id_, true); // By user.
+ RemoveNotification(true); // By user.
return true;
}
@@ -268,13 +235,13 @@ bool MessageView::OnKeyReleased(const ui::KeyEvent& event) {
if (event.flags() != ui::EF_NONE || event.flags() != ui::VKEY_SPACE)
return false;
- message_center_->ClickOnNotification(notification_id_);
+ ClickOnNotification();
return true;
}
void MessageView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP) {
- message_center_->ClickOnNotification(notification_id_);
+ ClickOnNotification();
event->SetHandled();
return;
}
@@ -302,12 +269,12 @@ void MessageView::OnPaintFocusBorder(gfx::Canvas* canvas) {
void MessageView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == close_button()) {
- message_center_->RemoveNotification(notification_id_, true); // By user.
+ RemoveNotification(true); // By user.
}
}
void MessageView::OnSlideOut() {
- message_center_->RemoveNotification(notification_id_, true); // By user.
+ RemoveNotification(true); // By user.
}
} // namespace message_center
diff --git a/ui/message_center/views/message_view.h b/ui/message_center/views/message_view.h
index 8e39555..961c050 100644
--- a/ui/message_center/views/message_view.h
+++ b/ui/message_center/views/message_view.h
@@ -33,11 +33,15 @@ const int kWebNotificationIconSize = 40;
class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView,
public views::ButtonListener {
public:
- MessageView(const Notification& notification,
- MessageCenter* message_center,
- MessageCenterTray* tray);
+ MessageView(const string16& display_source);
virtual ~MessageView();
+ // Overrided by derived classes.
+ virtual void ClickOnNotification() = 0;
+ virtual void RemoveNotification(bool by_user) = 0;
+ virtual void DisableNotificationsFromThisSource() = 0;
+ virtual void ShowNotifierSettingsBubble() = 0;
+
// Returns the insets for the shadow it will have for rich notification.
static gfx::Insets GetShadowInsets();
@@ -63,23 +67,16 @@ class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView,
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
- const std::string& notification_id() { return notification_id_; }
void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; }
protected:
- MessageView();
-
// Overridden from views::SlideOutView:
virtual void OnSlideOut() OVERRIDE;
- MessageCenter* message_center() { return message_center_; }
views::ImageButton* close_button() { return close_button_.get(); }
views::ScrollView* scroller() { return scroller_; }
private:
- MessageCenter* message_center_; // Weak reference.
- std::string notification_id_;
-
scoped_ptr<MessageViewContextMenuController> context_menu_controller_;
scoped_ptr<views::ImageButton> close_button_;
views::ScrollView* scroller_;
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index 73d168c..bcd1ea9 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -19,6 +19,7 @@
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_style.h"
#include "ui/message_center/message_center_switches.h"
+#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/message_center_util.h"
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_types.h"
@@ -419,11 +420,11 @@ namespace message_center {
// NotificationView ////////////////////////////////////////////////////////////
// static
-MessageView* NotificationView::Create(const Notification& notification,
- MessageCenter* message_center,
- MessageCenterTray* tray,
- bool expanded,
- bool top_level) {
+NotificationView* NotificationView::Create(const Notification& notification,
+ MessageCenter* message_center,
+ MessageCenterTray* tray,
+ bool expanded,
+ bool top_level) {
switch (notification.type()) {
case NOTIFICATION_TYPE_BASE_FORMAT:
case NOTIFICATION_TYPE_IMAGE:
@@ -443,7 +444,7 @@ MessageView* NotificationView::Create(const Notification& notification,
}
// Currently all roads lead to the generic NotificationView.
- MessageView* notification_view =
+ NotificationView* notification_view =
new NotificationView(notification, message_center, tray, expanded);
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
@@ -460,7 +461,11 @@ NotificationView::NotificationView(const Notification& notification,
MessageCenter* message_center,
MessageCenterTray* tray,
bool expanded)
- : MessageView(notification, message_center, tray),
+ : MessageView(notification.display_source()),
+ message_center_(message_center),
+ tray_(tray),
+ notification_id_(notification.id()),
+ notifier_id_(notification.notifier_id()),
clickable_(notification.clickable()),
is_expanded_(expanded) {
std::vector<string16> accessible_lines;
@@ -738,7 +743,7 @@ views::View* NotificationView::GetEventHandlerForRect(const gfx::Rect& rect) {
}
gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) {
- if (!clickable_ || !message_center()->HasClickedListener(notification_id()))
+ if (!clickable_ || !message_center_->HasClickedListener(notification_id_))
return views::View::GetCursor(event);
#if defined(USE_AURA)
@@ -754,7 +759,7 @@ void NotificationView::ButtonPressed(views::Button* sender,
// See if the button pressed was an action button.
for (size_t i = 0; i < action_buttons_.size(); ++i) {
if (sender == action_buttons_[i]) {
- message_center()->ClickOnNotificationButton(notification_id(), i);
+ message_center_->ClickOnNotificationButton(notification_id_, i);
return;
}
}
@@ -769,7 +774,7 @@ void NotificationView::ButtonPressed(views::Button* sender,
image_view_->SetVisible(true);
is_expanded_ = true;
- message_center()->ExpandNotification(notification_id());
+ message_center_->ExpandNotification(notification_id_);
return;
}
@@ -779,6 +784,22 @@ void NotificationView::ButtonPressed(views::Button* sender,
MessageView::ButtonPressed(sender, event);
}
+void NotificationView::ClickOnNotification() {
+ message_center_->ClickOnNotification(notification_id_);
+}
+
+void NotificationView::RemoveNotification(bool by_user) {
+ message_center_->RemoveNotification(notification_id_, by_user);
+}
+
+void NotificationView::DisableNotificationsFromThisSource() {
+ message_center_->DisableNotificationsByNotifier(notifier_id_);
+}
+
+void NotificationView::ShowNotifierSettingsBubble() {
+ tray_->ShowNotifierSettingsBubble();
+}
+
bool NotificationView::IsExpansionNeeded(int width) {
return (!is_expanded_ &&
(image_view_ ||
diff --git a/ui/message_center/views/notification_view.h b/ui/message_center/views/notification_view.h
index c27037b..6621ecd 100644
--- a/ui/message_center/views/notification_view.h
+++ b/ui/message_center/views/notification_view.h
@@ -18,6 +18,7 @@ namespace message_center {
class BoundedLabel;
class MessageCenter;
+class NotificationView;
class PaddedButton;
// View that displays all current types of notification (web, basic, image, and
@@ -32,11 +33,11 @@ class MESSAGE_CENTER_EXPORT NotificationView : public MessageView {
// notification type. A notification is top level if it needs to be rendered
// outside the browser window. No custom shadows are created for top level
// notifications on Linux with Aura.
- static MessageView* Create(const Notification& notification,
- MessageCenter* message_center,
- MessageCenterTray* tray,
- bool expanded,
- bool top_level);
+ static NotificationView* Create(const Notification& notification,
+ MessageCenter* message_center,
+ MessageCenterTray* tray,
+ bool expanded,
+ bool top_level);
virtual ~NotificationView();
@@ -53,12 +54,20 @@ class MESSAGE_CENTER_EXPORT NotificationView : public MessageView {
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
+ std::string notification_id() { return notification_id_; }
+
protected:
NotificationView(const Notification& notification,
MessageCenter* message_center,
MessageCenterTray* tray,
bool expanded);
+ // Overrides from base class MessageView:
+ virtual void ClickOnNotification() OVERRIDE;
+ virtual void RemoveNotification(bool by_user) OVERRIDE;
+ virtual void DisableNotificationsFromThisSource() OVERRIDE;
+ virtual void ShowNotifierSettingsBubble() OVERRIDE;
+
private:
bool IsExpansionNeeded(int width);
bool IsMessageExpansionNeeded(int width);
@@ -66,6 +75,11 @@ class MESSAGE_CENTER_EXPORT NotificationView : public MessageView {
int GetMessageLines(int width, int limit);
int GetMessageHeight(int width, int limit);
+ MessageCenter* message_center_; // Weak.
+ MessageCenterTray* tray_; // Weak.
+ std::string notification_id_;
+ message_center::NotifierId notifier_id_;
+
// Describes whether the view should display a hand pointer or not.
bool clickable_;
bool is_expanded_;