summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 09:34:46 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 09:34:46 +0000
commit73c982dc7f89551cd4f6f17cf14715f827312148 (patch)
treec15d17fb27ff0347bf15fcb0b9b200d1c6bfb0ab /ui
parent2c39b29c3bceb34ad240702e2d3174330a6feb51 (diff)
downloadchromium_src-73c982dc7f89551cd4f6f17cf14715f827312148.zip
chromium_src-73c982dc7f89551cd4f6f17cf14715f827312148.tar.gz
chromium_src-73c982dc7f89551cd4f6f17cf14715f827312148.tar.bz2
Adds the limit to the text lengths in the notifications.
The very long text causes performance issue when rendering because the calculation of the text wrapping is expensive. We decide to truncate very very long text for M27, we will revisit this issue and add better strategy here. This won't affect most of normal notifications. BUG=222151 TEST=check the raspberry one of Notification Galore, with crrev.com/12575005 Review URL: https://chromiumcodereview.appspot.com/12941004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189232 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/message_center/views/notification_view.cc19
-rw-r--r--ui/message_center/views/notification_view.h4
2 files changed, 21 insertions, 2 deletions
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index 8be9e75..6f8f2ff 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -44,6 +44,9 @@ const int kButtonIconTopPadding = 11;
const int kButtonIconToTitlePadding = 16;
const int kButtonTitleTopPadding = 0;
+const size_t kTitleCharacterLimit = 100;
+const size_t kMessageCharacterLimit = 200;
+
// 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.
// See view::Label's SetEnabledColor() and SetBackgroundColor() for details.
@@ -359,7 +362,8 @@ NotificationView::NotificationView(const Notification& notification,
// Create the title view if appropriate.
title_view_ = NULL;
if (!notification.title().empty()) {
- title_view_ = new views::Label(notification.title());
+ title_view_ = new views::Label(
+ MaybeTruncateText( notification.title(), kTitleCharacterLimit));
title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
if (is_expanded())
title_view_->SetMultiLine(true);
@@ -375,7 +379,8 @@ NotificationView::NotificationView(const Notification& notification,
// Create the message view if appropriate.
message_view_ = NULL;
if (!notification.message().empty()) {
- message_view_ = new views::Label(notification.message());
+ message_view_ = new views::Label(
+ MaybeTruncateText(notification.message(), kMessageCharacterLimit));
message_view_->SetVisible(!is_expanded() || !notification.items().size());
message_view_->set_collapse_when_hidden(true);
message_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
@@ -528,4 +533,14 @@ void NotificationView::ButtonPressed(views::Button* sender,
}
}
+string16 NotificationView::MaybeTruncateText(const string16& text,
+ size_t limit) {
+ // Currently just truncate the text by the total number of characters.
+ // TODO(mukai): add better assumption like number of lines.
+ if (!is_expanded())
+ return text;
+
+ return ui::TruncateString(text, limit);
+}
+
} // namespace message_center
diff --git a/ui/message_center/views/notification_view.h b/ui/message_center/views/notification_view.h
index fb9adb7..10fd870 100644
--- a/ui/message_center/views/notification_view.h
+++ b/ui/message_center/views/notification_view.h
@@ -47,6 +47,10 @@ class NotificationView : public MessageView {
NotificationChangeObserver* observer,
bool expanded);
+ // Truncate the very long text if we should. See crbug.com/222151 for the
+ // details.
+ string16 MaybeTruncateText(const string16& text, size_t limit);
+
// Weak references to NotificationView descendants owned by their parents.
views::View* background_view_;
views::View* top_view_;