| 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 "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 220 |
| 221 // Gets the rectangle in which notification content should be placed. This | 221 // Gets the rectangle in which notification content should be placed. This |
| 222 // rectangle is to the right of the icon and left of the control buttons. | 222 // rectangle is to the right of the icon and left of the control buttons. |
| 223 // This depends on the icon_ and closeButton_ being initialized. | 223 // This depends on the icon_ and closeButton_ being initialized. |
| 224 - (NSRect)currentContentRect; | 224 - (NSRect)currentContentRect; |
| 225 | 225 |
| 226 // Returns the wrapped text that could fit within the content rect with not | 226 // Returns the wrapped text that could fit within the content rect with not |
| 227 // more than the given number of lines. The wrapped text would be painted using | 227 // more than the given number of lines. The wrapped text would be painted using |
| 228 // the given font. The Ellipsis could be added at the end of the last line if | 228 // the given font. The Ellipsis could be added at the end of the last line if |
| 229 // it is too long. | 229 // it is too long. |
| 230 - (string16)wrapText:(const base::string16&)text | 230 - (base::string16)wrapText:(const base::string16&)text |
| 231 forFont:(NSFont*)font | 231 forFont:(NSFont*)font |
| 232 maxNumberOfLines:(size_t)lines; | 232 maxNumberOfLines:(size_t)lines; |
| 233 @end | 233 @end |
| 234 | 234 |
| 235 //////////////////////////////////////////////////////////////////////////////// | 235 //////////////////////////////////////////////////////////////////////////////// |
| 236 | 236 |
| 237 @implementation MCNotificationController | 237 @implementation MCNotificationController |
| 238 | 238 |
| 239 - (id)initWithNotification:(const message_center::Notification*)notification | 239 - (id)initWithNotification:(const message_center::Notification*)notification |
| 240 messageCenter:(message_center::MessageCenter*)messageCenter { | 240 messageCenter:(message_center::MessageCenter*)messageCenter { |
| 241 if ((self = [super initWithNibName:nil bundle:nil])) { | 241 if ((self = [super initWithNibName:nil bundle:nil])) { |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 DCHECK(closeButton_); | 717 DCHECK(closeButton_); |
| 718 | 718 |
| 719 NSRect iconFrame, contentFrame; | 719 NSRect iconFrame, contentFrame; |
| 720 NSDivideRect([[self view] bounds], &iconFrame, &contentFrame, | 720 NSDivideRect([[self view] bounds], &iconFrame, &contentFrame, |
| 721 NSWidth([icon_ frame]) + message_center::kIconToTextPadding, | 721 NSWidth([icon_ frame]) + message_center::kIconToTextPadding, |
| 722 NSMinXEdge); | 722 NSMinXEdge); |
| 723 contentFrame.size.width -= NSWidth([closeButton_ frame]); | 723 contentFrame.size.width -= NSWidth([closeButton_ frame]); |
| 724 return contentFrame; | 724 return contentFrame; |
| 725 } | 725 } |
| 726 | 726 |
| 727 - (string16)wrapText:(const base::string16&)text | 727 - (base::string16)wrapText:(const base::string16&)text |
| 728 forFont:(NSFont*)nsfont | 728 forFont:(NSFont*)nsfont |
| 729 maxNumberOfLines:(size_t)lines { | 729 maxNumberOfLines:(size_t)lines { |
| 730 if (text.empty()) | 730 if (text.empty()) |
| 731 return text; | 731 return text; |
| 732 gfx::FontList font_list((gfx::Font(nsfont))); | 732 gfx::FontList font_list((gfx::Font(nsfont))); |
| 733 int width = NSWidth([self currentContentRect]); | 733 int width = NSWidth([self currentContentRect]); |
| 734 int height = (lines + 1) * font_list.GetHeight(); | 734 int height = (lines + 1) * font_list.GetHeight(); |
| 735 | 735 |
| 736 std::vector<base::string16> wrapped; | 736 std::vector<base::string16> wrapped; |
| 737 gfx::ElideRectangleText(text, font_list, width, height, | 737 gfx::ElideRectangleText(text, font_list, width, height, |
| 738 gfx::WRAP_LONG_WORDS, &wrapped); | 738 gfx::WRAP_LONG_WORDS, &wrapped); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 749 if (gfx::GetStringWidth(last, font_list) > width) | 749 if (gfx::GetStringWidth(last, font_list) > width) |
| 750 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END); | 750 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END); |
| 751 wrapped.resize(lines - 1); | 751 wrapped.resize(lines - 1); |
| 752 wrapped.push_back(last); | 752 wrapped.push_back(last); |
| 753 } | 753 } |
| 754 | 754 |
| 755 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n'); | 755 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n'); |
| 756 } | 756 } |
| 757 | 757 |
| 758 @end | 758 @end |
| OLD | NEW |