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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 path = [NSBezierPath bezierPathWithRoundedRect:sliceRect | 46 path = [NSBezierPath bezierPathWithRoundedRect:sliceRect |
47 xRadius:message_center::kProgressBarCornerRadius | 47 xRadius:message_center::kProgressBarCornerRadius |
48 yRadius:message_center::kProgressBarCornerRadius]; | 48 yRadius:message_center::kProgressBarCornerRadius]; |
49 [gfx::SkColorToCalibratedNSColor(message_center::kProgressBarSliceColor) set]; | 49 [gfx::SkColorToCalibratedNSColor(message_center::kProgressBarSliceColor) set]; |
50 [path fill]; | 50 [path fill]; |
51 } | 51 } |
52 @end | 52 @end |
53 | 53 |
54 //////////////////////////////////////////////////////////////////////////////// | 54 //////////////////////////////////////////////////////////////////////////////// |
| 55 @interface MCNotificationButton : NSButton |
| 56 @end |
| 57 |
| 58 @implementation MCNotificationButton |
| 59 // drawRect: needs to fill the button with a background, otherwise we don't get |
| 60 // subpixel antialiasing. |
| 61 - (void)drawRect:(NSRect)dirtyRect { |
| 62 NSColor* color = gfx::SkColorToCalibratedNSColor( |
| 63 message_center::kNotificationBackgroundColor); |
| 64 [color set]; |
| 65 NSRectFill(dirtyRect); |
| 66 [super drawRect:dirtyRect]; |
| 67 } |
| 68 @end |
55 | 69 |
56 @interface MCNotificationButtonCell : NSButtonCell { | 70 @interface MCNotificationButtonCell : NSButtonCell { |
57 BOOL hovered_; | 71 BOOL hovered_; |
58 } | 72 } |
59 @end | 73 @end |
60 | 74 |
| 75 //////////////////////////////////////////////////////////////////////////////// |
61 @implementation MCNotificationButtonCell | 76 @implementation MCNotificationButtonCell |
| 77 - (BOOL)isOpaque { |
| 78 return YES; |
| 79 } |
| 80 |
62 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { | 81 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { |
63 // Else mouseEntered: and mouseExited: won't be called and hovered_ won't be | 82 // Else mouseEntered: and mouseExited: won't be called and hovered_ won't be |
64 // valid. | 83 // valid. |
65 DCHECK([self showsBorderOnlyWhileMouseInside]); | 84 DCHECK([self showsBorderOnlyWhileMouseInside]); |
66 | 85 |
67 if (!hovered_) | 86 if (!hovered_) |
68 return; | 87 return; |
69 [gfx::SkColorToCalibratedNSColor( | 88 [gfx::SkColorToCalibratedNSColor( |
70 message_center::kHoveredButtonBackgroundColor) set]; | 89 message_center::kHoveredButtonBackgroundColor) set]; |
71 NSRectFill(frame); | 90 NSRectFill(frame); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 bottomView_.reset([[NSView alloc] initWithFrame:frame]); | 498 bottomView_.reset([[NSView alloc] initWithFrame:frame]); |
480 CGFloat y = 0; | 499 CGFloat y = 0; |
481 | 500 |
482 // Create action buttons if appropriate, bottom-up. | 501 // Create action buttons if appropriate, bottom-up. |
483 std::vector<message_center::ButtonInfo> buttons = notification->buttons(); | 502 std::vector<message_center::ButtonInfo> buttons = notification->buttons(); |
484 for (int i = buttons.size() - 1; i >= 0; --i) { | 503 for (int i = buttons.size() - 1; i >= 0; --i) { |
485 message_center::ButtonInfo buttonInfo = buttons[i]; | 504 message_center::ButtonInfo buttonInfo = buttons[i]; |
486 NSRect buttonFrame = frame; | 505 NSRect buttonFrame = frame; |
487 buttonFrame.origin = NSMakePoint(0, y); | 506 buttonFrame.origin = NSMakePoint(0, y); |
488 buttonFrame.size.height = message_center::kButtonHeight; | 507 buttonFrame.size.height = message_center::kButtonHeight; |
489 base::scoped_nsobject<NSButton> button( | 508 base::scoped_nsobject<MCNotificationButton> button( |
490 [[NSButton alloc] initWithFrame:buttonFrame]); | 509 [[MCNotificationButton alloc] initWithFrame:buttonFrame]); |
491 base::scoped_nsobject<MCNotificationButtonCell> cell( | 510 base::scoped_nsobject<MCNotificationButtonCell> cell( |
492 [[MCNotificationButtonCell alloc] | 511 [[MCNotificationButtonCell alloc] |
493 initTextCell:base::SysUTF16ToNSString(buttonInfo.title)]); | 512 initTextCell:base::SysUTF16ToNSString(buttonInfo.title)]); |
494 [cell setShowsBorderOnlyWhileMouseInside:YES]; | 513 [cell setShowsBorderOnlyWhileMouseInside:YES]; |
495 [button setCell:cell]; | 514 [button setCell:cell]; |
496 [button setImage:buttonInfo.icon.AsNSImage()]; | 515 [button setImage:buttonInfo.icon.AsNSImage()]; |
497 [button setBezelStyle:NSSmallSquareBezelStyle]; | 516 [button setBezelStyle:NSSmallSquareBezelStyle]; |
498 [button setImagePosition:NSImageLeft]; | 517 [button setImagePosition:NSImageLeft]; |
499 [button setTag:i]; | 518 [button setTag:i]; |
500 [button setTarget:self]; | 519 [button setTarget:self]; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 if (gfx::GetStringWidth(last, font_list) > width) | 799 if (gfx::GetStringWidth(last, font_list) > width) |
781 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END); | 800 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END); |
782 wrapped.resize(lines - 1); | 801 wrapped.resize(lines - 1); |
783 wrapped.push_back(last); | 802 wrapped.push_back(last); |
784 } | 803 } |
785 | 804 |
786 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n'); | 805 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n'); |
787 } | 806 } |
788 | 807 |
789 @end | 808 @end |
OLD | NEW |