| OLD | NEW |
| 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 Loading... |
| 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().message.empty()) |
| 400 messageLineLimit -= message_center::kContextMessageLineLimit; | 402 messageLineLimit -= message_center::kContextMessageLineLimit; |
| 401 } | 403 } |
| 402 if (messageLineLimit < 0) | 404 if (messageLineLimit < 0) |
| 403 messageLineLimit = 0; | 405 messageLineLimit = 0; |
| 404 | 406 |
| 405 // Set the message and recalculate the frame. | 407 // Set the message and recalculate the frame. |
| 406 [message_ setString:base::SysUTF16ToNSString( | 408 [message_ setString:base::SysUTF16ToNSString( |
| 407 [self wrapText:notification_->message() | 409 [self wrapText:notification_->message() |
| 408 forFont:[message_ font] | 410 forFont:[message_ font] |
| 409 maxNumberOfLines:messageLineLimit])]; | 411 maxNumberOfLines:messageLineLimit])]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 421 messageFrame.origin.y = titleFrame.origin.y; | 423 messageFrame.origin.y = titleFrame.origin.y; |
| 422 messageFrame.size.height = 0; | 424 messageFrame.size.height = 0; |
| 423 } else { | 425 } else { |
| 424 [message_ setHidden:NO]; | 426 [message_ setHidden:NO]; |
| 425 messageFrame.origin.y = | 427 messageFrame.origin.y = |
| 426 NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame); | 428 NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame); |
| 427 messageFrame.size.height = NSHeight([message_ frame]); | 429 messageFrame.size.height = NSHeight([message_ frame]); |
| 428 } | 430 } |
| 429 | 431 |
| 430 // Set the context message and recalculate the frame. | 432 // Set the context message and recalculate the frame. |
| 431 [contextMessage_ setString:base::SysUTF16ToNSString( | 433 base::string16 message; |
| 432 [self wrapText:notification_->context_message() | 434 if (notification->context_message().is_origin) { |
| 433 forFont:[contextMessage_ font] | 435 GURL url(notification_->context_message().message); |
| 434 maxNumberOfLines:message_center::kContextMessageLineLimit])]; | 436 gfx::FontList font_list((gfx::Font([message_ font]))); |
| 437 message = url_formatter::ElideHost( |
| 438 url, font_list, message_center::kContextMessageViewWidth); |
| 439 } else { |
| 440 message = base::UTF8ToUTF16(notification_->context_message().message); |
| 441 } |
| 442 |
| 443 [contextMessage_ |
| 444 setString: |
| 445 base::SysUTF16ToNSString([self |
| 446 wrapText:message |
| 447 forFont:[contextMessage_ font] |
| 448 maxNumberOfLines:message_center::kContextMessageLineLimit])]; |
| 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().message.empty()) { |
| 439 [contextMessage_ setHidden:YES]; | 453 [contextMessage_ setHidden:YES]; |
| 440 contextMessageFrame.origin.y = messageFrame.origin.y; | 454 contextMessageFrame.origin.y = messageFrame.origin.y; |
| 441 contextMessageFrame.size.height = 0; | 455 contextMessageFrame.size.height = 0; |
| 442 } else { | 456 } else { |
| 443 [contextMessage_ setHidden:NO]; | 457 [contextMessage_ setHidden:NO]; |
| 444 contextMessageFrame.origin.y = | 458 contextMessageFrame.origin.y = |
| 445 NSMinY(messageFrame) - | 459 NSMinY(messageFrame) - |
| 446 contextMessagePadding - | 460 contextMessagePadding - |
| 447 NSHeight(contextMessageFrame); | 461 NSHeight(contextMessageFrame); |
| 448 contextMessageFrame.size.height = NSHeight([contextMessage_ frame]); | 462 contextMessageFrame.size.height = NSHeight([contextMessage_ frame]); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 forFont:(NSFont*)nsfont | 905 forFont:(NSFont*)nsfont |
| 892 maxNumberOfLines:(size_t)lines { | 906 maxNumberOfLines:(size_t)lines { |
| 893 size_t unused; | 907 size_t unused; |
| 894 return [self wrapText:text | 908 return [self wrapText:text |
| 895 forFont:nsfont | 909 forFont:nsfont |
| 896 maxNumberOfLines:lines | 910 maxNumberOfLines:lines |
| 897 actualLines:&unused]; | 911 actualLines:&unused]; |
| 898 } | 912 } |
| 899 | 913 |
| 900 @end | 914 @end |
| OLD | NEW |