summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-24 08:29:57 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-24 08:29:57 +0000
commit3d9926e8244274b9d04007b7f9ce0095d29f6e6a (patch)
tree6db51ccfc3d7e1ddfa3e03b47274445946dec450
parent8a6268d9f7ef89a2a082024f92402f23d1819094 (diff)
downloadchromium_src-3d9926e8244274b9d04007b7f9ce0095d29f6e6a.zip
chromium_src-3d9926e8244274b9d04007b7f9ce0095d29f6e6a.tar.gz
chromium_src-3d9926e8244274b9d04007b7f9ce0095d29f6e6a.tar.bz2
Revert 196080 "Supports MessageCenterObserver interface in Messa..."
> Supports MessageCenterObserver interface in MessageCenterView. > > Now it receives the add/remove/update events by itself. This is a > preparation CL for repositioning on the message center, but this itself > also allows partial-update in the center. > > BUG=224089 > TEST=no break on existing tests > > Review URL: https://chromiumcodereview.appspot.com/14358013 TBR=mukai@chromium.org Review URL: https://codereview.chromium.org/14452003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196088 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/system/web_notification/web_notification_tray.cc5
-rw-r--r--ash/system/web_notification/web_notification_tray.h1
-rw-r--r--chrome/browser/ui/views/message_center/web_notification_tray_win.cc5
-rw-r--r--chrome/browser/ui/views/message_center/web_notification_tray_win.h1
-rw-r--r--ui/message_center/message_center_tray.cc8
-rw-r--r--ui/message_center/message_center_tray_delegate.h4
-rw-r--r--ui/message_center/message_center_tray_unittest.cc1
-rw-r--r--ui/message_center/views/message_center_bubble.cc7
-rw-r--r--ui/message_center/views/message_center_bubble.h5
-rw-r--r--ui/message_center/views/message_center_view.cc112
-rw-r--r--ui/message_center/views/message_center_view.h16
-rw-r--r--ui/message_center/views/message_center_view_unittest.cc2
-rw-r--r--ui/message_center/views/message_view.h2
13 files changed, 61 insertions, 108 deletions
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc
index 562bc21..722ec3c 100644
--- a/ash/system/web_notification/web_notification_tray.cc
+++ b/ash/system/web_notification/web_notification_tray.cc
@@ -226,6 +226,11 @@ bool WebNotificationTray::ShowMessageCenter() {
return true;
}
+void WebNotificationTray::UpdateMessageCenter() {
+ if (message_center_bubble())
+ message_center_bubble()->bubble()->ScheduleUpdate();
+}
+
void WebNotificationTray::HideMessageCenter() {
if (!message_center_bubble())
return;
diff --git a/ash/system/web_notification/web_notification_tray.h b/ash/system/web_notification/web_notification_tray.h
index 6ea8c1b..13be8c6 100644
--- a/ash/system/web_notification/web_notification_tray.h
+++ b/ash/system/web_notification/web_notification_tray.h
@@ -100,6 +100,7 @@ class ASH_EXPORT WebNotificationTray
// Overridden from MessageCenterTrayDelegate.
virtual void OnMessageCenterTrayChanged() OVERRIDE;
virtual bool ShowMessageCenter() OVERRIDE;
+ virtual void UpdateMessageCenter() OVERRIDE;
virtual void HideMessageCenter() OVERRIDE;
virtual bool ShowPopups() OVERRIDE;
virtual void UpdatePopups() OVERRIDE;
diff --git a/chrome/browser/ui/views/message_center/web_notification_tray_win.cc b/chrome/browser/ui/views/message_center/web_notification_tray_win.cc
index 63f7464..683e467 100644
--- a/chrome/browser/ui/views/message_center/web_notification_tray_win.cc
+++ b/chrome/browser/ui/views/message_center/web_notification_tray_win.cc
@@ -195,6 +195,11 @@ void WebNotificationTrayWin::HideMessageCenter() {
message_center_bubble_.reset();
}
+void WebNotificationTrayWin::UpdateMessageCenter() {
+ if (message_center_bubble_.get())
+ message_center_bubble_->bubble()->ScheduleUpdate();
+}
+
void WebNotificationTrayWin::UpdatePopups() {
// |popup_collection_| receives notification add/remove events and updates
// itself, so this method doesn't need to do anything.
diff --git a/chrome/browser/ui/views/message_center/web_notification_tray_win.h b/chrome/browser/ui/views/message_center/web_notification_tray_win.h
index 94ced88..bb5b883 100644
--- a/chrome/browser/ui/views/message_center/web_notification_tray_win.h
+++ b/chrome/browser/ui/views/message_center/web_notification_tray_win.h
@@ -47,6 +47,7 @@ class WebNotificationTrayWin
virtual void HidePopups() OVERRIDE;
virtual bool ShowMessageCenter() OVERRIDE;
virtual void HideMessageCenter() OVERRIDE;
+ virtual void UpdateMessageCenter() OVERRIDE;
virtual void UpdatePopups() OVERRIDE;
virtual void OnMessageCenterTrayChanged() OVERRIDE;
diff --git a/ui/message_center/message_center_tray.cc b/ui/message_center/message_center_tray.cc
index 18bf5d0..4c44771 100644
--- a/ui/message_center/message_center_tray.cc
+++ b/ui/message_center/message_center_tray.cc
@@ -71,8 +71,12 @@ void MessageCenterTray::ToggleMessageCenterBubble() {
}
void MessageCenterTray::ShowPopupBubble() {
- if (message_center_visible_)
+ if (message_center_visible_) {
+ // We don't want to show popups if the user is already looking at the
+ // message center. Instead, update it.
+ delegate_->UpdateMessageCenter();
return;
+ }
if (popups_visible_) {
delegate_->UpdatePopups();
@@ -143,6 +147,8 @@ void MessageCenterTray::OnMessageCenterChanged() {
if (message_center_visible_) {
if (message_center_->NotificationCount() == 0)
HideMessageCenterBubble();
+ else
+ delegate_->UpdateMessageCenter();
}
if (popups_visible_) {
if (message_center_->HasPopupNotifications())
diff --git a/ui/message_center/message_center_tray_delegate.h b/ui/message_center/message_center_tray_delegate.h
index f95fb0a..18b89d3 100644
--- a/ui/message_center/message_center_tray_delegate.h
+++ b/ui/message_center/message_center_tray_delegate.h
@@ -35,6 +35,10 @@ class MESSAGE_CENTER_EXPORT MessageCenterTrayDelegate {
// Remove the message center from the UI.
virtual void HideMessageCenter() = 0;
+
+ // Called when a change to the message center could cause a change to the
+ // message center widget that is currently being displayed.
+ virtual void UpdateMessageCenter() = 0;
};
} // namespace message_center
diff --git a/ui/message_center/message_center_tray_unittest.cc b/ui/message_center/message_center_tray_unittest.cc
index 5bbdfb9..bd9271f 100644
--- a/ui/message_center/message_center_tray_unittest.cc
+++ b/ui/message_center/message_center_tray_unittest.cc
@@ -28,6 +28,7 @@ class MockDelegate : public MessageCenterTrayDelegate {
return show_popups_success_;
}
virtual void HideMessageCenter() OVERRIDE {}
+ virtual void UpdateMessageCenter() OVERRIDE {}
bool show_popups_success_;
bool show_message_center_success_;
diff --git a/ui/message_center/views/message_center_bubble.cc b/ui/message_center/views/message_center_bubble.cc
index ae9b2ab..24a536b 100644
--- a/ui/message_center/views/message_center_bubble.cc
+++ b/ui/message_center/views/message_center_bubble.cc
@@ -28,13 +28,13 @@ class ContentsView : public views::View {
virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
private:
- base::WeakPtr<MessageCenterBubble> bubble_;
+ MessageCenterBubble* bubble_; // Weak reference.
DISALLOW_COPY_AND_ASSIGN(ContentsView);
};
ContentsView::ContentsView(MessageCenterBubble* bubble, views::View* contents)
- : bubble_(bubble->AsWeakPtr()) {
+ : bubble_(bubble) {
SetLayoutManager(new views::FillLayout());
AddChildView(contents);
}
@@ -51,8 +51,7 @@ int ContentsView::GetHeightForWidth(int width) {
void ContentsView::ChildPreferredSizeChanged(View* child) {
// TODO(dharcourt): Reduce the amount of updating this requires.
- if (bubble_.get())
- bubble_->bubble_view()->UpdateBubble();
+ bubble_->bubble_view()->UpdateBubble();
}
// MessageCenterBubble /////////////////////////////////////////////////////////
diff --git a/ui/message_center/views/message_center_bubble.h b/ui/message_center/views/message_center_bubble.h
index f5b3850..97e8e88 100644
--- a/ui/message_center/views/message_center_bubble.h
+++ b/ui/message_center/views/message_center_bubble.h
@@ -5,7 +5,6 @@
#ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_CENTER_BUBBLE_H_
#define UI_MESSAGE_CENTER_VIEWS_MESSAGE_CENTER_BUBBLE_H_
-#include "base/memory/weak_ptr.h"
#include "ui/message_center/message_center_export.h"
#include "ui/message_center/views/message_bubble_base.h"
@@ -14,9 +13,7 @@ namespace message_center {
class MessageCenterView;
// Bubble for message center.
-class MESSAGE_CENTER_EXPORT MessageCenterBubble
- : public MessageBubbleBase,
- public base::SupportsWeakPtr<MessageCenterBubble> {
+class MESSAGE_CENTER_EXPORT MessageCenterBubble : public MessageBubbleBase {
public:
explicit MessageCenterBubble(MessageCenter* message_center);
diff --git a/ui/message_center/views/message_center_view.cc b/ui/message_center/views/message_center_view.cc
index d1c4438..01f97c3 100644
--- a/ui/message_center/views/message_center_view.cc
+++ b/ui/message_center/views/message_center_view.cc
@@ -356,7 +356,6 @@ void MessageCenterButtonBar::SetCloseAllVisible(bool visible) {
MessageCenterView::MessageCenterView(MessageCenter* message_center,
int max_height)
: message_center_(message_center) {
- message_center_->AddObserver(this);
int between_child = IsRichNotificationEnabled() ? 0 : 1;
SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, between_child));
@@ -385,22 +384,34 @@ MessageCenterView::MessageCenterView(MessageCenter* message_center,
}
MessageCenterView::~MessageCenterView() {
- message_center_->RemoveObserver(this);
}
void MessageCenterView::SetNotifications(
const NotificationList::Notifications& notifications) {
- message_views_.clear();
- message_list_view_->RemoveAllChildViews(true);
- int index = 0;
+ RemoveAllNotifications();
for (NotificationList::Notifications::const_iterator iter =
- notifications.begin(); iter != notifications.end();
- ++iter, ++index) {
- AddNotificationAt(*(*iter), index);
+ notifications.begin(); iter != notifications.end(); ++iter) {
+ AddNotification(*(*iter));
if (message_views_.size() >= kMaxVisibleMessageCenterNotifications)
break;
}
- NotificationsChanged();
+ if (message_views_.empty()) {
+ views::Label* label = new views::Label(l10n_util::GetStringUTF16(
+ IDS_MESSAGE_CENTER_NO_MESSAGES));
+ label->SetFont(label->font().DeriveFont(1));
+ label->SetEnabledColor(SK_ColorGRAY);
+ // Set transparent background to ensure that subpixel rendering
+ // is disabled. See crbug.com/169056
+ label->SetBackgroundColor(kTransparentColor);
+ message_list_view_->AddChildView(label);
+ button_bar_->SetCloseAllVisible(false);
+ scroller_->set_focusable(false);
+ } else {
+ button_bar_->SetCloseAllVisible(true);
+ scroller_->set_focusable(true);
+ scroller_->RequestFocus();
+ }
+ Layout();
}
size_t MessageCenterView::NumMessageViewsForTest() const {
@@ -424,90 +435,21 @@ bool MessageCenterView::OnMouseWheel(const ui::MouseWheelEvent& event) {
return views::View::OnMouseWheel(event);
}
-void MessageCenterView::OnNotificationAdded(const std::string& id) {
- if (message_views_.empty())
- message_list_view_->RemoveAllChildViews(true);
-
- int index = 0;
- const NotificationList::Notifications& notifications =
- message_center_->GetNotifications();
- for (NotificationList::Notifications::const_iterator iter =
- notifications.begin(); iter != notifications.end();
- ++iter, ++index) {
- if ((*iter)->id() == id) {
- AddNotificationAt(*(*iter), index);
- break;
- }
- if (message_views_.size() >= kMaxVisibleMessageCenterNotifications)
- break;
- }
- NotificationsChanged();
-}
-
-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) {
- // TODO(mukai): introduce reposition handling here.
- delete message_views_[i];
- message_views_.erase(message_views_.begin() + i);
- NotificationsChanged();
- break;
- }
- }
-}
-
-void MessageCenterView::OnNotificationUpdated(const std::string& id) {
- const NotificationList::Notifications& notifications =
- message_center_->GetNotifications();
- 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());
- if ((*iter)->id() == id) {
- delete *iter;
- message_views_.erase(message_views_.begin() + index);
- AddNotificationAt(*(*iter), index);
- NotificationsChanged();
- break;
- }
- }
+void MessageCenterView::RemoveAllNotifications() {
+ message_views_.clear();
+ message_list_view_->RemoveAllChildViews(true);
+ scroller_->InvalidateLayout();
}
-void MessageCenterView::AddNotificationAt(const Notification& notification,
- int index) {
+void MessageCenterView::AddNotification(const Notification& notification) {
// NotificationViews are expanded by default here until
// http://crbug.com/217902 is fixed. TODO(dharcourt): Fix.
MessageView* view = NotificationView::Create(
notification, message_center_, true);
view->set_scroller(scroller_);
- message_views_.insert(message_views_.begin() + index, view);
- message_list_view_->AddChildViewAt(view, index);
+ message_views_[notification.id()] = view;
+ message_list_view_->AddChildView(view);
message_center_->DisplayedNotification(notification.id());
}
-void MessageCenterView::NotificationsChanged() {
- if (message_views_.empty()) {
- views::Label* label = new views::Label(l10n_util::GetStringUTF16(
- IDS_MESSAGE_CENTER_NO_MESSAGES));
- label->SetFont(label->font().DeriveFont(1));
- label->SetEnabledColor(SK_ColorGRAY);
- // Set transparent background to ensure that subpixel rendering
- // is disabled. See crbug.com/169056
- label->SetBackgroundColor(kTransparentColor);
- message_list_view_->AddChildView(label);
- button_bar_->SetCloseAllVisible(false);
- scroller_->set_focusable(false);
- } else {
- button_bar_->SetCloseAllVisible(true);
- scroller_->set_focusable(true);
- scroller_->RequestFocus();
- }
- scroller_->InvalidateLayout();
- PreferredSizeChanged();
- Layout();
-}
-
} // namespace message_center
diff --git a/ui/message_center/views/message_center_view.h b/ui/message_center/views/message_center_view.h
index e2c7da7..a512c63 100644
--- a/ui/message_center/views/message_center_view.h
+++ b/ui/message_center/views/message_center_view.h
@@ -8,7 +8,6 @@
#include "ui/views/view.h"
#include "ui/message_center/message_center_export.h"
-#include "ui/message_center/message_center_observer.h"
#include "ui/message_center/notification_list.h"
namespace views {
@@ -48,8 +47,7 @@ class MessageCenterButtonBar : public views::View {
// MessageCenterView ///////////////////////////////////////////////////////////
-class MESSAGE_CENTER_EXPORT MessageCenterView : public views::View,
- public MessageCenterObserver {
+class MESSAGE_CENTER_EXPORT MessageCenterView : public views::View {
public:
MessageCenterView(MessageCenter* message_center, int max_height);
virtual ~MessageCenterView();
@@ -63,20 +61,14 @@ class MESSAGE_CENTER_EXPORT MessageCenterView : public views::View,
virtual void Layout() OVERRIDE;
virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
- // Overridden from MessageCenterObserver:
- virtual void OnNotificationAdded(const std::string& id) OVERRIDE;
- virtual void OnNotificationRemoved(const std::string& id,
- bool by_user) OVERRIDE;
- virtual void OnNotificationUpdated(const std::string& id) OVERRIDE;
-
private:
friend class MessageCenterViewTest;
- void AddNotificationAt(const Notification& notification, int index);
- void NotificationsChanged();
+ void RemoveAllNotifications();
+ void AddNotification(const Notification& notification);
MessageCenter* message_center_; // Weak reference.
- std::vector<MessageView*> message_views_;
+ std::map<std::string,MessageView*> message_views_;
views::ScrollView* scroller_;
views::View* message_list_view_;
MessageCenterButtonBar* button_bar_;
diff --git a/ui/message_center/views/message_center_view_unittest.cc b/ui/message_center/views/message_center_view_unittest.cc
index a4e9184..ba8ce45 100644
--- a/ui/message_center/views/message_center_view_unittest.cc
+++ b/ui/message_center/views/message_center_view_unittest.cc
@@ -148,7 +148,7 @@ void MessageCenterViewTest::SetUp() {
// 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);
+ message_center_view_->message_views_[notification.id()] = mock;
message_center_view_->message_list_view_->RemoveAllChildViews(true);
message_center_view_->message_list_view_->AddChildView(mock);
}
diff --git a/ui/message_center/views/message_view.h b/ui/message_center/views/message_view.h
index f66885f..82150ae 100644
--- a/ui/message_center/views/message_view.h
+++ b/ui/message_center/views/message_view.h
@@ -48,7 +48,6 @@ 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:
@@ -61,6 +60,7 @@ class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView,
virtual void OnSlideOut() OVERRIDE;
MessageCenter* message_center() { return message_center_; }
+ const std::string& notification_id() { return notification_id_; }
const string16& display_source() const { return display_source_; }
const std::string& extension_id() const { return extension_id_; }
views::ImageButton* close_button() { return close_button_.get(); }