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

Side by Side Diff: ui/message_center/cocoa/notification_controller.mm

Issue 1292003004: Elide origins displayed on web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style nit 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 unified diff | Download patch
« no previous file with comments | « ui/message_center/DEPS ('k') | ui/message_center/cocoa/notification_controller_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/message_center/cocoa/notification_controller.h" 5 #import "ui/message_center/cocoa/notification_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/url_formatter/elide_url.h"
13 #include "skia/ext/skia_utils_mac.h" 14 #include "skia/ext/skia_utils_mac.h"
14 #import "ui/base/cocoa/hover_image_button.h" 15 #import "ui/base/cocoa/hover_image_button.h"
15 #include "ui/base/l10n/l10n_util_mac.h" 16 #include "ui/base/l10n/l10n_util_mac.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/font_list.h" 18 #include "ui/gfx/font_list.h"
18 #include "ui/gfx/text_elider.h" 19 #include "ui/gfx/text_elider.h"
19 #include "ui/gfx/text_utils.h" 20 #include "ui/gfx/text_utils.h"
20 #include "ui/message_center/message_center.h" 21 #include "ui/message_center/message_center.h"
21 #include "ui/message_center/message_center_style.h" 22 #include "ui/message_center/message_center_style.h"
22 #include "ui/message_center/notification.h" 23 #include "ui/message_center/notification.h"
23 #include "ui/resources/grit/ui_resources.h" 24 #include "ui/resources/grit/ui_resources.h"
24 #include "ui/strings/grit/ui_strings.h" 25 #include "ui/strings/grit/ui_strings.h"
25 26 #include "url/gurl.h"
26 27
27 @interface MCNotificationProgressBar : NSProgressIndicator 28 @interface MCNotificationProgressBar : NSProgressIndicator
28 @end 29 @end
29 30
30 @implementation MCNotificationProgressBar 31 @implementation MCNotificationProgressBar
31 - (void)drawRect:(NSRect)dirtyRect { 32 - (void)drawRect:(NSRect)dirtyRect {
32 NSRect sliceRect, remainderRect; 33 NSRect sliceRect, remainderRect;
33 double progressFraction = ([self doubleValue] - [self minValue]) / 34 double progressFraction = ([self doubleValue] - [self minValue]) /
34 ([self maxValue] - [self minValue]); 35 ([self maxValue] - [self minValue]);
35 NSDivideRect(dirtyRect, &sliceRect, &remainderRect, 36 NSDivideRect(dirtyRect, &sliceRect, &remainderRect,
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 CGFloat messagePadding = 374 CGFloat messagePadding =
374 message_center::kTextTopPadding - titleBottomGap - messageTopGap; 375 message_center::kTextTopPadding - titleBottomGap - messageTopGap;
375 376
376 CGFloat contextMessageTopGap = roundf( 377 CGFloat contextMessageTopGap = roundf(
377 [[contextMessage_ font] ascender] - [[contextMessage_ font] capHeight]); 378 [[contextMessage_ font] ascender] - [[contextMessage_ font] capHeight]);
378 CGFloat contextMessagePadding = 379 CGFloat contextMessagePadding =
379 message_center::kTextTopPadding - messageBottomGap - contextMessageTopGap; 380 message_center::kTextTopPadding - messageBottomGap - contextMessageTopGap;
380 381
381 // Set the title and recalculate the frame. 382 // Set the title and recalculate the frame.
382 size_t actualTitleLines = 0; 383 size_t actualTitleLines = 0;
383 [title_ setString:base::SysUTF16ToNSString( 384 [title_ setString:base::SysUTF16ToNSString([self
384 [self wrapText:notification_->title() 385 wrapText:notification_->title()
385 forFont:[title_ font] 386 forFont:[title_ font]
386 maxNumberOfLines:message_center::kMaxTitleLines 387 maxNumberOfLines:message_center::kMaxTitleLines
387 actualLines:&actualTitleLines])]; 388 actualLines:&actualTitleLines])];
388 [title_ sizeToFit]; 389 [title_ sizeToFit];
389 NSRect titleFrame = [title_ frame]; 390 NSRect titleFrame = [title_ frame];
390 titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame); 391 titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame);
391 392
392 // The number of message lines depends on the number of context message lines 393 // The number of message lines depends on the number of context message lines
393 // and the lines within the title, and whether an image exists. 394 // and the lines within the title, and whether an image exists.
394 int messageLineLimit = message_center::kMessageExpandedLineLimit; 395 int messageLineLimit = message_center::kMessageExpandedLineLimit;
395 if (actualTitleLines > 1) 396 if (actualTitleLines > 1)
396 messageLineLimit -= (actualTitleLines - 1) * 2; 397 messageLineLimit -= (actualTitleLines - 1) * 2;
397 if (!notification_->image().IsEmpty()) { 398 if (!notification_->image().IsEmpty()) {
398 messageLineLimit /= 2; 399 messageLineLimit /= 2;
399 if (!notification_->context_message().empty()) 400
401 if (!notification_->context_message().empty() &&
402 !notification_->UseOriginAsContextMessage())
400 messageLineLimit -= message_center::kContextMessageLineLimit; 403 messageLineLimit -= message_center::kContextMessageLineLimit;
401 } 404 }
402 if (messageLineLimit < 0) 405 if (messageLineLimit < 0)
403 messageLineLimit = 0; 406 messageLineLimit = 0;
404 407
405 // Set the message and recalculate the frame. 408 // Set the message and recalculate the frame.
406 [message_ setString:base::SysUTF16ToNSString( 409 [message_ setString:base::SysUTF16ToNSString(
407 [self wrapText:notification_->message() 410 [self wrapText:notification_->message()
408 forFont:[message_ font] 411 forFont:[message_ font]
409 maxNumberOfLines:messageLineLimit])]; 412 maxNumberOfLines:messageLineLimit])];
(...skipping 11 matching lines...) Expand all
421 messageFrame.origin.y = titleFrame.origin.y; 424 messageFrame.origin.y = titleFrame.origin.y;
422 messageFrame.size.height = 0; 425 messageFrame.size.height = 0;
423 } else { 426 } else {
424 [message_ setHidden:NO]; 427 [message_ setHidden:NO];
425 messageFrame.origin.y = 428 messageFrame.origin.y =
426 NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame); 429 NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame);
427 messageFrame.size.height = NSHeight([message_ frame]); 430 messageFrame.size.height = NSHeight([message_ frame]);
428 } 431 }
429 432
430 // Set the context message and recalculate the frame. 433 // Set the context message and recalculate the frame.
431 [contextMessage_ setString:base::SysUTF16ToNSString( 434 base::string16 message;
432 [self wrapText:notification_->context_message() 435 if (notification->UseOriginAsContextMessage()) {
436 gfx::FontList font_list((gfx::Font([message_ font])));
437 message =
438 url_formatter::ElideHost(notification->origin_url(), font_list,
439 message_center::kContextMessageViewWidth);
440 } else {
441 message = notification->context_message();
442 }
443
444 base::string16 elided =
445 [self wrapText:message
433 forFont:[contextMessage_ font] 446 forFont:[contextMessage_ font]
434 maxNumberOfLines:message_center::kContextMessageLineLimit])]; 447 maxNumberOfLines:message_center::kContextMessageLineLimit];
448 [contextMessage_ setString:base::SysUTF16ToNSString(elided)];
435 [contextMessage_ sizeToFit]; 449 [contextMessage_ sizeToFit];
436 NSRect contextMessageFrame = [contextMessage_ frame]; 450 NSRect contextMessageFrame = [contextMessage_ frame];
437 451
438 if (notification_->context_message().empty()) { 452 if (notification->context_message().empty() &&
453 !notification->UseOriginAsContextMessage()) {
439 [contextMessage_ setHidden:YES]; 454 [contextMessage_ setHidden:YES];
440 contextMessageFrame.origin.y = messageFrame.origin.y; 455 contextMessageFrame.origin.y = messageFrame.origin.y;
441 contextMessageFrame.size.height = 0; 456 contextMessageFrame.size.height = 0;
442 } else { 457 } else {
443 [contextMessage_ setHidden:NO]; 458 [contextMessage_ setHidden:NO];
444 contextMessageFrame.origin.y = 459 contextMessageFrame.origin.y =
445 NSMinY(messageFrame) - 460 NSMinY(messageFrame) -
446 contextMessagePadding - 461 contextMessagePadding -
447 NSHeight(contextMessageFrame); 462 NSHeight(contextMessageFrame);
448 contextMessageFrame.size.height = NSHeight([contextMessage_ frame]); 463 contextMessageFrame.size.height = NSHeight([contextMessage_ frame]);
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 forFont:(NSFont*)nsfont 906 forFont:(NSFont*)nsfont
892 maxNumberOfLines:(size_t)lines { 907 maxNumberOfLines:(size_t)lines {
893 size_t unused; 908 size_t unused;
894 return [self wrapText:text 909 return [self wrapText:text
895 forFont:nsfont 910 forFont:nsfont
896 maxNumberOfLines:lines 911 maxNumberOfLines:lines
897 actualLines:&unused]; 912 actualLines:&unused];
898 } 913 }
899 914
900 @end 915 @end
OLDNEW
« no previous file with comments | « ui/message_center/DEPS ('k') | ui/message_center/cocoa/notification_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698