Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: ash/system/web_notification/web_notification_tray.cc

Issue 10833041: Change web notifications to show at the top of the list, clean up layout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/tray/tray_bubble_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/web_notification/web_notification_tray.cc
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc
index 699eeb7d41b564daa4444bc7459c764e3e639247..6d98d7a4e559fca6996a7e1a45c093d888ed941d 100644
--- a/ash/system/web_notification/web_notification_tray.cc
+++ b/ash/system/web_notification/web_notification_tray.cc
@@ -43,7 +43,7 @@ const int kNotificationImageIconInset = 4;
// Web Notification Bubble constants
const int kWebNotificationBubbleMinHeight = 80;
-const int kWebNotificationBubbleMaxHeight = 400;
+const int kWebNotificationBubbleMaxHeight = 480;
// Delay laying out the Bubble until all notifications have been added and icons
// have had a chance to load.
const int kUpdateDelayMs = 50;
@@ -51,7 +51,7 @@ const int kUpdateDelayMs = 50;
const int kMaxVisibleNotifications = 100;
// Individual notifications constants
-const int kWebNotificationWidth = 400;
+const int kWebNotificationWidth = 320;
const int kWebNotificationButtonWidth = 32;
const int kWebNotificationIconSize = 40;
@@ -124,7 +124,7 @@ class WebNotificationList {
iter->display_source = display_source;
iter->extension_id = extension_id;
} else {
- notifications_.push_back(
+ notifications_.push_front(
WebNotification(id, title, message, display_source, extension_id));
}
}
@@ -342,7 +342,8 @@ class WebNotificationView : public views::View,
views::ColumnSet* columns = layout->AddColumnSet(0);
- columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2);
+ int padding_width = kTrayPopupPaddingHorizontal/2;
+ columns->AddPaddingColumn(0, padding_width);
// Notification Icon.
columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING,
@@ -350,14 +351,16 @@ class WebNotificationView : public views::View,
views::GridLayout::FIXED,
kWebNotificationIconSize, kWebNotificationIconSize);
- columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2);
+ columns->AddPaddingColumn(0, padding_width);
// Notification message text.
+ int message_width = kWebNotificationWidth - kWebNotificationIconSize -
+ kWebNotificationButtonWidth - (padding_width * 3);
columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING,
100, /* resize percent */
- views::GridLayout::USE_PREF, 0, 0);
+ views::GridLayout::FIXED, message_width, message_width);
- columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2);
+ columns->AddPaddingColumn(0, padding_width);
// Close and menu buttons.
columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING,
@@ -499,6 +502,7 @@ class WebNotificationTray::BubbleContentsView : public views::View {
scroll_content_ = new views::View;
scroll_content_->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
+
scroller_ = new internal::FixedSizedScrollView;
scroller_->SetContentsView(scroll_content_);
AddChildView(scroller_);
@@ -509,36 +513,16 @@ class WebNotificationTray::BubbleContentsView : public views::View {
void Update(const WebNotificationList::Notifications& notifications) {
scroll_content_->RemoveAllChildViews(true);
- int num_children = notifications.size();
- WebNotificationList::Notifications::const_iterator iter =
- notifications.begin();
- if (num_children > kMaxVisibleNotifications) {
- std::advance(iter, num_children - kMaxVisibleNotifications);
- num_children = kMaxVisibleNotifications;
- }
- for (; iter != notifications.end(); ++iter) {
+ int num_children = 0;
+ for (WebNotificationList::Notifications::const_iterator iter =
+ notifications.begin(); iter != notifications.end(); ++iter) {
WebNotificationView* view = new WebNotificationView(tray_, *iter);
scroll_content_->AddChildView(view);
+ if (++num_children >= kMaxVisibleNotifications)
+ break;
}
- // Layout this first to set the preferred size of the scroller.
- PreferredSizeChanged();
- Layout();
- // Now layout the widget with this correctly sized.
- PreferredSizeChanged();
- GetWidget()->GetRootView()->Layout();
- GetWidget()->GetRootView()->SchedulePaint();
-
- // Scroll to show the most recent notification.
- if (num_children > 0) {
- scroll_content_->ScrollRectToVisible(
- scroll_content_->child_at(num_children - 1)->bounds());
- }
- }
-
- // Overridden from views::View:
- virtual void Layout() OVERRIDE {
SizeScrollContent();
- views::View::Layout();
+ GetWidget()->GetRootView()->SchedulePaint();
}
private:
@@ -549,13 +533,9 @@ class WebNotificationTray::BubbleContentsView : public views::View {
std::max(scroll_size.height(),
kWebNotificationBubbleMinHeight - button_height),
kWebNotificationBubbleMaxHeight - button_height);
- if (scroll_height < scroll_size.height()) {
- scroll_size.set_height(scroll_height);
- scroller_->SetFixedSize(scroll_size);
- } else {
- scroller_->SetFixedSize(gfx::Size());
- }
- scroller_->InvalidateLayout();
+ scroll_size.set_height(scroll_height);
+ scroller_->SetFixedSize(scroll_size);
+ scroller_->SizeToPreferredSize();
}
WebNotificationTray* tray_;
@@ -659,6 +639,7 @@ class WebNotificationTray::Bubble : public internal::TrayBubbleView::Host,
void UpdateBubbleView() {
contents_view_->Update(tray_->notification_list()->notifications());
bubble_view_->Show();
+ bubble_view_->UpdateBubble();
}
WebNotificationTray* tray_;
@@ -817,6 +798,8 @@ void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
alignment == SHELF_ALIGNMENT_BOTTOM ?
views::BoxLayout::kHorizontal : views::BoxLayout::kVertical,
0, 0, 0));
+ // Destroy any existing bubble so that it will be rebuilt correctly.
+ bubble_.reset();
}
bool WebNotificationTray::PerformAction(const views::Event& event) {
« no previous file with comments | « ash/system/tray/tray_bubble_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698