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

Unified Diff: ui/message_center/views/notification_view.cc

Issue 1292003004: Elide origins displayed on web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move origin_url to message_center::Notification Created 5 years, 4 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
Index: ui/message_center/views/notification_view.cc
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index 27c8accae20cdf39092662575eb52221be7b4e5d..53da9f23dcdbc0a175281ea401caace34dd9a4ab 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -8,6 +8,7 @@
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/url_formatter/elide_url.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/base/cursor/cursor.h"
@@ -41,6 +42,7 @@
#include "ui/views/painter.h"
#include "ui/views/view_targeter.h"
#include "ui/views/widget/widget.h"
+#include "url/gurl.h"
namespace {
@@ -285,11 +287,11 @@ views::View* NotificationView::TargetForRect(views::View* root,
void NotificationView::CreateOrUpdateViews(const Notification& notification) {
CreateOrUpdateTitleView(notification);
CreateOrUpdateMessageView(notification);
- CreateOrUpdateContextMessageView(notification);
CreateOrUpdateProgressBarView(notification);
CreateOrUpdateListItemViews(notification);
CreateOrUpdateIconView(notification);
CreateOrUpdateImageView(notification);
+ CreateOrUpdateContextMessageView(notification);
CreateOrUpdateActionButtonViews(notification);
}
@@ -297,7 +299,7 @@ void NotificationView::SetAccessibleName(const Notification& notification) {
std::vector<base::string16> accessible_lines;
accessible_lines.push_back(notification.title());
accessible_lines.push_back(notification.message());
- accessible_lines.push_back(notification.context_message());
+ accessible_lines.push_back(notification.context_message().message);
std::vector<NotificationItem> items = notification.items();
for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") +
@@ -553,9 +555,25 @@ void NotificationView::CreateOrUpdateMessageView(
message_view_->SetVisible(!notification.items().size());
}
+base::string16 NotificationView::FormatContextMessage(
+ const Notification& notification) const {
+ const ContextMessage& context = notification.context_message();
+ const GURL url = notification.origin_url();
+ if (context.use_origin_as_context) {
+ DCHECK(context.message.empty());
+ DCHECK(url.is_valid());
+ return url_formatter::ElideHost(url, views::Label().font_list(),
+ kContextMessageViewWidth);
+ }
+
+ return gfx::TruncateString(context.message, kContextMessageCharacterLimit,
+ gfx::WORD_BREAK);
+}
+
void NotificationView::CreateOrUpdateContextMessageView(
const Notification& notification) {
- if (notification.context_message().empty()) {
+ if (notification.context_message().message.empty() &&
+ !notification.context_message().use_origin_as_context) {
if (context_message_view_) {
// Deletion will also remove |context_message_view_| from its parent.
delete context_message_view_;
@@ -566,12 +584,11 @@ void NotificationView::CreateOrUpdateContextMessageView(
DCHECK(top_view_ != NULL);
- base::string16 text = gfx::TruncateString(notification.context_message(),
- kContextMessageCharacterLimit,
- gfx::WORD_BREAK);
+ base::string16 message = FormatContextMessage(notification);
+
if (!context_message_view_) {
int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
- context_message_view_ = new BoundedLabel(text);
+ context_message_view_ = new BoundedLabel(message);
context_message_view_->SetLineLimit(
message_center::kContextMessageLineLimit);
context_message_view_->SetLineHeight(kMessageLineHeight);
@@ -580,7 +597,7 @@ void NotificationView::CreateOrUpdateContextMessageView(
context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
top_view_->AddChildView(context_message_view_);
} else {
- context_message_view_->SetText(text);
+ context_message_view_->SetText(message);
}
}

Powered by Google App Engine
This is Rietveld 408576698