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