Chromium Code Reviews| Index: ui/message_center/cocoa/notification_controller.mm |
| diff --git a/ui/message_center/cocoa/notification_controller.mm b/ui/message_center/cocoa/notification_controller.mm |
| index 1b4e96a0ce1ecb1a05f0b1e43271e350a26a667d..100caed6a3b11eed9e1963dcdb72bce316ff3bbf 100644 |
| --- a/ui/message_center/cocoa/notification_controller.mm |
| +++ b/ui/message_center/cocoa/notification_controller.mm |
| @@ -10,6 +10,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "components/url_formatter/elide_url.h" |
| #include "skia/ext/skia_utils_mac.h" |
| #import "ui/base/cocoa/hover_image_button.h" |
| #include "ui/base/l10n/l10n_util_mac.h" |
| @@ -22,7 +23,7 @@ |
| #include "ui/message_center/notification.h" |
| #include "ui/resources/grit/ui_resources.h" |
| #include "ui/strings/grit/ui_strings.h" |
| - |
| +#include "url/gurl.h" |
| @interface MCNotificationProgressBar : NSProgressIndicator |
| @end |
| @@ -380,11 +381,11 @@ |
| // Set the title and recalculate the frame. |
| size_t actualTitleLines = 0; |
| - [title_ setString:base::SysUTF16ToNSString( |
| - [self wrapText:notification_->title() |
| - forFont:[title_ font] |
| - maxNumberOfLines:message_center::kMaxTitleLines |
| - actualLines:&actualTitleLines])]; |
| + [title_ setString:base::SysUTF16ToNSString([self |
| + wrapText:notification_->title() |
| + forFont:[title_ font] |
| + maxNumberOfLines:message_center::kMaxTitleLines |
| + actualLines:&actualTitleLines])]; |
|
Nico
2015/08/19 17:58:12
Huh, is this what clang-format does? The formattin
Miguel Garcia
2015/08/19 19:52:46
Acknowledged.
|
| [title_ sizeToFit]; |
| NSRect titleFrame = [title_ frame]; |
| titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame); |
| @@ -396,7 +397,9 @@ |
| messageLineLimit -= (actualTitleLines - 1) * 2; |
| if (!notification_->image().IsEmpty()) { |
| messageLineLimit /= 2; |
| - if (!notification_->context_message().empty()) |
| + |
| + if (!notification_->context_message().empty() && |
| + ![self useOriginAsContextMessage:notification]) |
| messageLineLimit -= message_center::kContextMessageLineLimit; |
| } |
| if (messageLineLimit < 0) |
| @@ -428,14 +431,27 @@ |
| } |
| // Set the context message and recalculate the frame. |
| - [contextMessage_ setString:base::SysUTF16ToNSString( |
| - [self wrapText:notification_->context_message() |
| - forFont:[contextMessage_ font] |
| - maxNumberOfLines:message_center::kContextMessageLineLimit])]; |
| + base::string16 message; |
| + if ([self useOriginAsContextMessage:notification]) { |
| + gfx::FontList font_list((gfx::Font([message_ font]))); |
| + message = |
| + url_formatter::ElideHost(notification->origin_url(), font_list, |
| + message_center::kContextMessageViewWidth); |
| + } else { |
| + message = notification_->context_message(); |
| + } |
| + |
| + [contextMessage_ |
| + setString: |
| + base::SysUTF16ToNSString([self |
| + wrapText:message |
| + forFont:[contextMessage_ font] |
| + maxNumberOfLines:message_center::kContextMessageLineLimit])]; |
|
Nico
2015/08/19 17:58:11
This might look a bit less awkward with a temp var
Miguel Garcia
2015/08/19 19:52:46
Done.
|
| [contextMessage_ sizeToFit]; |
| NSRect contextMessageFrame = [contextMessage_ frame]; |
| - if (notification_->context_message().empty()) { |
| + if (notification_->context_message().empty() && |
| + ![self useOriginAsContextMessage:notification]) { |
| [contextMessage_ setHidden:YES]; |
| contextMessageFrame.origin.y = messageFrame.origin.y; |
| contextMessageFrame.size.height = 0; |
| @@ -642,6 +658,13 @@ |
| return rootFrame; |
| } |
| +- (bool)useOriginAsContextMessage: |
| + (const message_center::Notification*)notification { |
| + return (notification->context_message().empty() && |
| + notification->origin_url().is_valid() && |
| + notification->origin_url().SchemeIsHTTPOrHTTPS()); |
|
Nico
2015/08/19 17:58:12
This kind of looks like model code; why isn't this
Jun Mukai
2015/08/19 18:06:02
+1 (to be clear, I objected the idea to introduce
Miguel Garcia
2015/08/19 19:52:46
Done
On 2015/08/19 18:06:02, Jun Mukai wrote:
|
| +} |
| + |
| - (void)close:(id)sender { |
| [closeButton_ setTarget:nil]; |
| messageCenter_->RemoveNotification([self notificationID], /*by_user=*/true); |