| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 - (void)drawRect:(NSRect)dirtyRect { | 32 - (void)drawRect:(NSRect)dirtyRect { |
| 33 NSRect sliceRect, remainderRect; | 33 NSRect sliceRect, remainderRect; |
| 34 double progressFraction = ([self doubleValue] - [self minValue]) / | 34 double progressFraction = ([self doubleValue] - [self minValue]) / |
| 35 ([self maxValue] - [self minValue]); | 35 ([self maxValue] - [self minValue]); |
| 36 NSDivideRect(dirtyRect, &sliceRect, &remainderRect, | 36 NSDivideRect(dirtyRect, &sliceRect, &remainderRect, |
| 37 NSWidth(dirtyRect) * progressFraction, NSMinXEdge); | 37 NSWidth(dirtyRect) * progressFraction, NSMinXEdge); |
| 38 | 38 |
| 39 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:dirtyRect | 39 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:dirtyRect |
| 40 xRadius:message_center::kProgressBarCornerRadius | 40 xRadius:message_center::kProgressBarCornerRadius |
| 41 yRadius:message_center::kProgressBarCornerRadius]; | 41 yRadius:message_center::kProgressBarCornerRadius]; |
| 42 [gfx::SkColorToCalibratedNSColor(message_center::kProgressBarBackgroundColor) | 42 [skia::SkColorToCalibratedNSColor(message_center::kProgressBarBackgroundColor) |
| 43 set]; | 43 set]; |
| 44 [path fill]; | 44 [path fill]; |
| 45 | 45 |
| 46 if (progressFraction == 0.0) | 46 if (progressFraction == 0.0) |
| 47 return; | 47 return; |
| 48 | 48 |
| 49 path = [NSBezierPath bezierPathWithRoundedRect:sliceRect | 49 path = [NSBezierPath bezierPathWithRoundedRect:sliceRect |
| 50 xRadius:message_center::kProgressBarCornerRadius | 50 xRadius:message_center::kProgressBarCornerRadius |
| 51 yRadius:message_center::kProgressBarCornerRadius]; | 51 yRadius:message_center::kProgressBarCornerRadius]; |
| 52 [gfx::SkColorToCalibratedNSColor(message_center::kProgressBarSliceColor) set]; | 52 [skia::SkColorToCalibratedNSColor(message_center::kProgressBarSliceColor) |
| 53 set]; |
| 53 [path fill]; | 54 [path fill]; |
| 54 } | 55 } |
| 55 | 56 |
| 56 - (id)accessibilityAttributeValue:(NSString*)attribute { | 57 - (id)accessibilityAttributeValue:(NSString*)attribute { |
| 57 double progressValue = 0.0; | 58 double progressValue = 0.0; |
| 58 if ([attribute isEqualToString:NSAccessibilityDescriptionAttribute]) { | 59 if ([attribute isEqualToString:NSAccessibilityDescriptionAttribute]) { |
| 59 progressValue = [self doubleValue]; | 60 progressValue = [self doubleValue]; |
| 60 } else if ([attribute isEqualToString:NSAccessibilityMinValueAttribute]) { | 61 } else if ([attribute isEqualToString:NSAccessibilityMinValueAttribute]) { |
| 61 progressValue = [self minValue]; | 62 progressValue = [self minValue]; |
| 62 } else if ([attribute isEqualToString:NSAccessibilityMaxValueAttribute]) { | 63 } else if ([attribute isEqualToString:NSAccessibilityMaxValueAttribute]) { |
| 63 progressValue = [self maxValue]; | 64 progressValue = [self maxValue]; |
| 64 } else { | 65 } else { |
| 65 return [super accessibilityAttributeValue:attribute]; | 66 return [super accessibilityAttributeValue:attribute]; |
| 66 } | 67 } |
| 67 | 68 |
| 68 return [NSString stringWithFormat:@"%lf", progressValue]; | 69 return [NSString stringWithFormat:@"%lf", progressValue]; |
| 69 } | 70 } |
| 70 @end | 71 @end |
| 71 | 72 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
| 73 @interface MCNotificationButton : NSButton | 74 @interface MCNotificationButton : NSButton |
| 74 @end | 75 @end |
| 75 | 76 |
| 76 @implementation MCNotificationButton | 77 @implementation MCNotificationButton |
| 77 // drawRect: needs to fill the button with a background, otherwise we don't get | 78 // drawRect: needs to fill the button with a background, otherwise we don't get |
| 78 // subpixel antialiasing. | 79 // subpixel antialiasing. |
| 79 - (void)drawRect:(NSRect)dirtyRect { | 80 - (void)drawRect:(NSRect)dirtyRect { |
| 80 NSColor* color = gfx::SkColorToCalibratedNSColor( | 81 NSColor* color = skia::SkColorToCalibratedNSColor( |
| 81 message_center::kNotificationBackgroundColor); | 82 message_center::kNotificationBackgroundColor); |
| 82 [color set]; | 83 [color set]; |
| 83 NSRectFill(dirtyRect); | 84 NSRectFill(dirtyRect); |
| 84 [super drawRect:dirtyRect]; | 85 [super drawRect:dirtyRect]; |
| 85 } | 86 } |
| 86 @end | 87 @end |
| 87 | 88 |
| 88 @interface MCNotificationButtonCell : NSButtonCell { | 89 @interface MCNotificationButtonCell : NSButtonCell { |
| 89 BOOL hovered_; | 90 BOOL hovered_; |
| 90 } | 91 } |
| 91 @end | 92 @end |
| 92 | 93 |
| 93 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
| 94 @implementation MCNotificationButtonCell | 95 @implementation MCNotificationButtonCell |
| 95 - (BOOL)isOpaque { | 96 - (BOOL)isOpaque { |
| 96 return YES; | 97 return YES; |
| 97 } | 98 } |
| 98 | 99 |
| 99 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { | 100 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { |
| 100 // Else mouseEntered: and mouseExited: won't be called and hovered_ won't be | 101 // Else mouseEntered: and mouseExited: won't be called and hovered_ won't be |
| 101 // valid. | 102 // valid. |
| 102 DCHECK([self showsBorderOnlyWhileMouseInside]); | 103 DCHECK([self showsBorderOnlyWhileMouseInside]); |
| 103 | 104 |
| 104 if (!hovered_) | 105 if (!hovered_) |
| 105 return; | 106 return; |
| 106 [gfx::SkColorToCalibratedNSColor( | 107 [skia::SkColorToCalibratedNSColor( |
| 107 message_center::kHoveredButtonBackgroundColor) set]; | 108 message_center::kHoveredButtonBackgroundColor) set]; |
| 108 NSRectFill(frame); | 109 NSRectFill(frame); |
| 109 } | 110 } |
| 110 | 111 |
| 111 - (void)drawImage:(NSImage*)image | 112 - (void)drawImage:(NSImage*)image |
| 112 withFrame:(NSRect)frame | 113 withFrame:(NSRect)frame |
| 113 inView:(NSView*)controlView { | 114 inView:(NSView*)controlView { |
| 114 if (!image) | 115 if (!image) |
| 115 return; | 116 return; |
| 116 NSRect rect = NSMakeRect(message_center::kButtonHorizontalPadding, | 117 NSRect rect = NSMakeRect(message_center::kButtonHorizontalPadding, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 133 offsetX += message_center::kNotificationButtonIconSize + | 134 offsetX += message_center::kNotificationButtonIconSize + |
| 134 message_center::kButtonIconToTitlePadding; | 135 message_center::kButtonIconToTitlePadding; |
| 135 } | 136 } |
| 136 frame.origin.x = offsetX; | 137 frame.origin.x = offsetX; |
| 137 frame.size.width -= offsetX; | 138 frame.size.width -= offsetX; |
| 138 | 139 |
| 139 NSDictionary* attributes = @{ | 140 NSDictionary* attributes = @{ |
| 140 NSFontAttributeName : | 141 NSFontAttributeName : |
| 141 [title attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL], | 142 [title attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL], |
| 142 NSForegroundColorAttributeName : | 143 NSForegroundColorAttributeName : |
| 143 gfx::SkColorToCalibratedNSColor(message_center::kRegularTextColor), | 144 skia::SkColorToCalibratedNSColor(message_center::kRegularTextColor), |
| 144 }; | 145 }; |
| 145 [[title string] drawWithRect:frame | 146 [[title string] drawWithRect:frame |
| 146 options:(NSStringDrawingUsesLineFragmentOrigin | | 147 options:(NSStringDrawingUsesLineFragmentOrigin | |
| 147 NSStringDrawingTruncatesLastVisibleLine) | 148 NSStringDrawingTruncatesLastVisibleLine) |
| 148 attributes:attributes]; | 149 attributes:attributes]; |
| 149 return frame; | 150 return frame; |
| 150 } | 151 } |
| 151 | 152 |
| 152 - (void)mouseEntered:(NSEvent*)event { | 153 - (void)mouseEntered:(NSEvent*)event { |
| 153 hovered_ = YES; | 154 hovered_ = YES; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 313 } |
| 313 | 314 |
| 314 - (void)loadView { | 315 - (void)loadView { |
| 315 // Create the root view of the notification. | 316 // Create the root view of the notification. |
| 316 NSRect rootFrame = NSMakeRect(0, 0, | 317 NSRect rootFrame = NSMakeRect(0, 0, |
| 317 message_center::kNotificationPreferredImageWidth, | 318 message_center::kNotificationPreferredImageWidth, |
| 318 message_center::kNotificationIconSize); | 319 message_center::kNotificationIconSize); |
| 319 base::scoped_nsobject<MCNotificationView> rootView( | 320 base::scoped_nsobject<MCNotificationView> rootView( |
| 320 [[MCNotificationView alloc] initWithController:self frame:rootFrame]); | 321 [[MCNotificationView alloc] initWithController:self frame:rootFrame]); |
| 321 [self configureCustomBox:rootView]; | 322 [self configureCustomBox:rootView]; |
| 322 [rootView setFillColor:gfx::SkColorToCalibratedNSColor( | 323 [rootView setFillColor:skia::SkColorToCalibratedNSColor( |
| 323 message_center::kNotificationBackgroundColor)]; | 324 message_center::kNotificationBackgroundColor)]; |
| 324 [self setView:rootView]; | 325 [self setView:rootView]; |
| 325 | 326 |
| 326 [rootView addSubview:[self createIconView]]; | 327 [rootView addSubview:[self createIconView]]; |
| 327 | 328 |
| 328 // Create the close button. | 329 // Create the close button. |
| 329 [self configureCloseButtonInFrame:rootFrame]; | 330 [self configureCloseButtonInFrame:rootFrame]; |
| 330 [rootView addSubview:closeButton_]; | 331 [rootView addSubview:closeButton_]; |
| 331 | 332 |
| 332 // Create the small image. | 333 // Create the small image. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 507 |
| 507 // Construct the text from the title and message. | 508 // Construct the text from the title and message. |
| 508 base::string16 text = | 509 base::string16 text = |
| 509 items[i].title + base::UTF8ToUTF16(" ") + items[i].message; | 510 items[i].title + base::UTF8ToUTF16(" ") + items[i].message; |
| 510 base::string16 ellidedText = | 511 base::string16 ellidedText = |
| 511 [self wrapText:text forFont:font maxNumberOfLines:1]; | 512 [self wrapText:text forFont:font maxNumberOfLines:1]; |
| 512 [itemView setString:base::SysUTF16ToNSString(ellidedText)]; | 513 [itemView setString:base::SysUTF16ToNSString(ellidedText)]; |
| 513 | 514 |
| 514 // Use dim color for the title part. | 515 // Use dim color for the title part. |
| 515 NSColor* titleColor = | 516 NSColor* titleColor = |
| 516 gfx::SkColorToCalibratedNSColor(message_center::kRegularTextColor); | 517 skia::SkColorToCalibratedNSColor(message_center::kRegularTextColor); |
| 517 NSRange titleRange = NSMakeRange( | 518 NSRange titleRange = NSMakeRange( |
| 518 0, | 519 0, |
| 519 std::min(ellidedText.size(), items[i].title.size())); | 520 std::min(ellidedText.size(), items[i].title.size())); |
| 520 [itemView setTextColor:titleColor range:titleRange]; | 521 [itemView setTextColor:titleColor range:titleRange]; |
| 521 | 522 |
| 522 // Use dim color for the message part if it has not been truncated. | 523 // Use dim color for the message part if it has not been truncated. |
| 523 if (ellidedText.size() > items[i].title.size() + 1) { | 524 if (ellidedText.size() > items[i].title.size() + 1) { |
| 524 NSColor* messageColor = | 525 NSColor* messageColor = |
| 525 gfx::SkColorToCalibratedNSColor(message_center::kDimTextColor); | 526 skia::SkColorToCalibratedNSColor(message_center::kDimTextColor); |
| 526 NSRange messageRange = NSMakeRange( | 527 NSRange messageRange = NSMakeRange( |
| 527 items[i].title.size() + 1, | 528 items[i].title.size() + 1, |
| 528 ellidedText.size() - items[i].title.size() - 1); | 529 ellidedText.size() - items[i].title.size() - 1); |
| 529 [itemView setTextColor:messageColor range:messageRange]; | 530 [itemView setTextColor:messageColor range:messageRange]; |
| 530 } | 531 } |
| 531 | 532 |
| 532 [listView_ addSubview:itemView]; | 533 [listView_ addSubview:itemView]; |
| 533 y += lineHeight; | 534 y += lineHeight; |
| 534 } | 535 } |
| 535 // TODO(thakis): The spacing is not completely right. | 536 // TODO(thakis): The spacing is not completely right. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 y += NSHeight(buttonFrame); | 608 y += NSHeight(buttonFrame); |
| 608 frame.size.height += NSHeight(buttonFrame); | 609 frame.size.height += NSHeight(buttonFrame); |
| 609 [bottomView_ addSubview:button]; | 610 [bottomView_ addSubview:button]; |
| 610 | 611 |
| 611 NSRect separatorFrame = frame; | 612 NSRect separatorFrame = frame; |
| 612 separatorFrame.origin = NSMakePoint(0, y); | 613 separatorFrame.origin = NSMakePoint(0, y); |
| 613 separatorFrame.size.height = 1; | 614 separatorFrame.size.height = 1; |
| 614 base::scoped_nsobject<NSBox> separator( | 615 base::scoped_nsobject<NSBox> separator( |
| 615 [[AccessibilityIgnoredBox alloc] initWithFrame:separatorFrame]); | 616 [[AccessibilityIgnoredBox alloc] initWithFrame:separatorFrame]); |
| 616 [self configureCustomBox:separator]; | 617 [self configureCustomBox:separator]; |
| 617 [separator setFillColor:gfx::SkColorToCalibratedNSColor( | 618 [separator setFillColor:skia::SkColorToCalibratedNSColor( |
| 618 message_center::kButtonSeparatorColor)]; | 619 message_center::kButtonSeparatorColor)]; |
| 619 y += NSHeight(separatorFrame); | 620 y += NSHeight(separatorFrame); |
| 620 frame.size.height += NSHeight(separatorFrame); | 621 frame.size.height += NSHeight(separatorFrame); |
| 621 [bottomView_ addSubview:separator]; | 622 [bottomView_ addSubview:separator]; |
| 622 } | 623 } |
| 623 | 624 |
| 624 // Create the image view if appropriate. | 625 // Create the image view if appropriate. |
| 625 gfx::Image notificationImage = notification->image(); | 626 gfx::Image notificationImage = notification->image(); |
| 626 if (!notificationImage.IsEmpty()) { | 627 if (!notificationImage.IsEmpty()) { |
| 627 NSBox* imageBox = [self createImageBox:notificationImage]; | 628 NSBox* imageBox = [self createImageBox:notificationImage]; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 | 708 |
| 708 - (NSView*)createIconView { | 709 - (NSView*)createIconView { |
| 709 // Create another box that shows a background color when the icon is not | 710 // Create another box that shows a background color when the icon is not |
| 710 // big enough to fill the space. | 711 // big enough to fill the space. |
| 711 NSRect imageFrame = NSMakeRect(0, 0, | 712 NSRect imageFrame = NSMakeRect(0, 0, |
| 712 message_center::kNotificationIconSize, | 713 message_center::kNotificationIconSize, |
| 713 message_center::kNotificationIconSize); | 714 message_center::kNotificationIconSize); |
| 714 base::scoped_nsobject<NSBox> imageBox( | 715 base::scoped_nsobject<NSBox> imageBox( |
| 715 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); | 716 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); |
| 716 [self configureCustomBox:imageBox]; | 717 [self configureCustomBox:imageBox]; |
| 717 [imageBox setFillColor:gfx::SkColorToCalibratedNSColor( | 718 [imageBox setFillColor:skia::SkColorToCalibratedNSColor( |
| 718 message_center::kIconBackgroundColor)]; | 719 message_center::kIconBackgroundColor)]; |
| 719 [imageBox setAutoresizingMask:NSViewMinYMargin]; | 720 [imageBox setAutoresizingMask:NSViewMinYMargin]; |
| 720 | 721 |
| 721 // Inside the image box put the actual icon view. | 722 // Inside the image box put the actual icon view. |
| 722 icon_.reset([[NSImageView alloc] initWithFrame:imageFrame]); | 723 icon_.reset([[NSImageView alloc] initWithFrame:imageFrame]); |
| 723 [imageBox setContentView:icon_]; | 724 [imageBox setContentView:icon_]; |
| 724 | 725 |
| 725 return imageBox.autorelease(); | 726 return imageBox.autorelease(); |
| 726 } | 727 } |
| 727 | 728 |
| 728 - (NSBox*)createImageBox:(const gfx::Image&)notificationImage { | 729 - (NSBox*)createImageBox:(const gfx::Image&)notificationImage { |
| 729 using message_center::kNotificationImageBorderSize; | 730 using message_center::kNotificationImageBorderSize; |
| 730 using message_center::kNotificationPreferredImageWidth; | 731 using message_center::kNotificationPreferredImageWidth; |
| 731 using message_center::kNotificationPreferredImageHeight; | 732 using message_center::kNotificationPreferredImageHeight; |
| 732 | 733 |
| 733 NSRect imageFrame = NSMakeRect(0, 0, | 734 NSRect imageFrame = NSMakeRect(0, 0, |
| 734 kNotificationPreferredImageWidth, | 735 kNotificationPreferredImageWidth, |
| 735 kNotificationPreferredImageHeight); | 736 kNotificationPreferredImageHeight); |
| 736 base::scoped_nsobject<NSBox> imageBox( | 737 base::scoped_nsobject<NSBox> imageBox( |
| 737 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); | 738 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); |
| 738 [self configureCustomBox:imageBox]; | 739 [self configureCustomBox:imageBox]; |
| 739 [imageBox setFillColor:gfx::SkColorToCalibratedNSColor( | 740 [imageBox setFillColor:skia::SkColorToCalibratedNSColor( |
| 740 message_center::kImageBackgroundColor)]; | 741 message_center::kImageBackgroundColor)]; |
| 741 | 742 |
| 742 // Images with non-preferred aspect ratios get a border on all sides. | 743 // Images with non-preferred aspect ratios get a border on all sides. |
| 743 gfx::Size idealSize = gfx::Size( | 744 gfx::Size idealSize = gfx::Size( |
| 744 kNotificationPreferredImageWidth, kNotificationPreferredImageHeight); | 745 kNotificationPreferredImageWidth, kNotificationPreferredImageHeight); |
| 745 gfx::Size scaledSize = message_center::GetImageSizeForContainerSize( | 746 gfx::Size scaledSize = message_center::GetImageSizeForContainerSize( |
| 746 idealSize, notificationImage.Size()); | 747 idealSize, notificationImage.Size()); |
| 747 if (scaledSize != idealSize) { | 748 if (scaledSize != idealSize) { |
| 748 NSSize borderSize = | 749 NSSize borderSize = |
| 749 NSMakeSize(kNotificationImageBorderSize, kNotificationImageBorderSize); | 750 NSMakeSize(kNotificationImageBorderSize, kNotificationImageBorderSize); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 [smallImage_ setImageScaling:NSImageScaleProportionallyUpOrDown]; | 856 [smallImage_ setImageScaling:NSImageScaleProportionallyUpOrDown]; |
| 856 [imageBox setContentView:smallImage_]; | 857 [imageBox setContentView:smallImage_]; |
| 857 | 858 |
| 858 return imageBox.autorelease(); | 859 return imageBox.autorelease(); |
| 859 } | 860 } |
| 860 | 861 |
| 861 - (void)configureTitleInFrame:(NSRect)contentFrame { | 862 - (void)configureTitleInFrame:(NSRect)contentFrame { |
| 862 contentFrame.size.height = 0; | 863 contentFrame.size.height = 0; |
| 863 title_.reset([self newLabelWithFrame:contentFrame]); | 864 title_.reset([self newLabelWithFrame:contentFrame]); |
| 864 [title_ setAutoresizingMask:NSViewMinYMargin]; | 865 [title_ setAutoresizingMask:NSViewMinYMargin]; |
| 865 [title_ setTextColor:gfx::SkColorToCalibratedNSColor( | 866 [title_ setTextColor:skia::SkColorToCalibratedNSColor( |
| 866 message_center::kRegularTextColor)]; | 867 message_center::kRegularTextColor)]; |
| 867 [title_ setFont:[NSFont messageFontOfSize:message_center::kTitleFontSize]]; | 868 [title_ setFont:[NSFont messageFontOfSize:message_center::kTitleFontSize]]; |
| 868 } | 869 } |
| 869 | 870 |
| 870 - (void)configureBodyInFrame:(NSRect)contentFrame { | 871 - (void)configureBodyInFrame:(NSRect)contentFrame { |
| 871 contentFrame.size.height = 0; | 872 contentFrame.size.height = 0; |
| 872 message_.reset([self newLabelWithFrame:contentFrame]); | 873 message_.reset([self newLabelWithFrame:contentFrame]); |
| 873 [message_ setAutoresizingMask:NSViewMinYMargin]; | 874 [message_ setAutoresizingMask:NSViewMinYMargin]; |
| 874 [message_ setTextColor:gfx::SkColorToCalibratedNSColor( | 875 [message_ setTextColor:skia::SkColorToCalibratedNSColor( |
| 875 message_center::kRegularTextColor)]; | 876 message_center::kRegularTextColor)]; |
| 876 [message_ setFont: | 877 [message_ setFont: |
| 877 [NSFont messageFontOfSize:message_center::kMessageFontSize]]; | 878 [NSFont messageFontOfSize:message_center::kMessageFontSize]]; |
| 878 } | 879 } |
| 879 | 880 |
| 880 - (void)configureContextMessageInFrame:(NSRect)contentFrame { | 881 - (void)configureContextMessageInFrame:(NSRect)contentFrame { |
| 881 contentFrame.size.height = 0; | 882 contentFrame.size.height = 0; |
| 882 contextMessage_.reset([self newLabelWithFrame:contentFrame]); | 883 contextMessage_.reset([self newLabelWithFrame:contentFrame]); |
| 883 [contextMessage_ setAutoresizingMask:NSViewMinYMargin]; | 884 [contextMessage_ setAutoresizingMask:NSViewMinYMargin]; |
| 884 [contextMessage_ setTextColor:gfx::SkColorToCalibratedNSColor( | 885 [contextMessage_ setTextColor:skia::SkColorToCalibratedNSColor( |
| 885 message_center::kDimTextColor)]; | 886 message_center::kDimTextColor)]; |
| 886 [contextMessage_ setFont: | 887 [contextMessage_ setFont: |
| 887 [NSFont messageFontOfSize:message_center::kMessageFontSize]]; | 888 [NSFont messageFontOfSize:message_center::kMessageFontSize]]; |
| 888 } | 889 } |
| 889 | 890 |
| 890 - (NSTextView*)newLabelWithFrame:(NSRect)frame { | 891 - (NSTextView*)newLabelWithFrame:(NSRect)frame { |
| 891 NSTextView* label = [[NSTextView alloc] initWithFrame:frame]; | 892 NSTextView* label = [[NSTextView alloc] initWithFrame:frame]; |
| 892 | 893 |
| 893 // The labels MUST draw their background so that subpixel antialiasing can | 894 // The labels MUST draw their background so that subpixel antialiasing can |
| 894 // happen on the text. | 895 // happen on the text. |
| 895 [label setDrawsBackground:YES]; | 896 [label setDrawsBackground:YES]; |
| 896 [label setBackgroundColor:gfx::SkColorToCalibratedNSColor( | 897 [label setBackgroundColor:skia::SkColorToCalibratedNSColor( |
| 897 message_center::kNotificationBackgroundColor)]; | 898 message_center::kNotificationBackgroundColor)]; |
| 898 | 899 |
| 899 [label setEditable:NO]; | 900 [label setEditable:NO]; |
| 900 [label setSelectable:NO]; | 901 [label setSelectable:NO]; |
| 901 [label setTextContainerInset:NSMakeSize(0.0f, 0.0f)]; | 902 [label setTextContainerInset:NSMakeSize(0.0f, 0.0f)]; |
| 902 [[label textContainer] setLineFragmentPadding:0.0f]; | 903 [[label textContainer] setLineFragmentPadding:0.0f]; |
| 903 return label; | 904 return label; |
| 904 } | 905 } |
| 905 | 906 |
| 906 - (NSRect)currentContentRect { | 907 - (NSRect)currentContentRect { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 forFont:(NSFont*)nsfont | 961 forFont:(NSFont*)nsfont |
| 961 maxNumberOfLines:(size_t)lines { | 962 maxNumberOfLines:(size_t)lines { |
| 962 size_t unused; | 963 size_t unused; |
| 963 return [self wrapText:text | 964 return [self wrapText:text |
| 964 forFont:nsfont | 965 forFont:nsfont |
| 965 maxNumberOfLines:lines | 966 maxNumberOfLines:lines |
| 966 actualLines:&unused]; | 967 actualLines:&unused]; |
| 967 } | 968 } |
| 968 | 969 |
| 969 @end | 970 @end |
| OLD | NEW |