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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 @end | 189 @end |
| 190 | 190 |
| 191 //////////////////////////////////////////////////////////////////////////////// | 191 //////////////////////////////////////////////////////////////////////////////// |
| 192 | 192 |
| 193 @interface MCNotificationController (Private) | 193 @interface MCNotificationController (Private) |
| 194 // Configures a NSBox to be borderless, titleless, and otherwise appearance- | 194 // Configures a NSBox to be borderless, titleless, and otherwise appearance- |
| 195 // free. | 195 // free. |
| 196 - (void)configureCustomBox:(NSBox*)box; | 196 - (void)configureCustomBox:(NSBox*)box; |
| 197 | 197 |
| 198 // Initializes the icon_ ivar and returns the view to insert into the hierarchy. | 198 // Initializes the icon_ ivar and returns the view to insert into the hierarchy. |
| 199 - (NSView*)createImageView; | 199 - (NSView*)createIconView; |
| 200 | |
| 201 // Creates a box that shows a border when the icon is not big enough to fill the | |
| 202 // space. | |
| 203 - (NSBox*)createImageBox; | |
| 200 | 204 |
| 201 // Initializes the closeButton_ ivar with the configured button. | 205 // Initializes the closeButton_ ivar with the configured button. |
| 202 - (void)configureCloseButtonInFrame:(NSRect)rootFrame; | 206 - (void)configureCloseButtonInFrame:(NSRect)rootFrame; |
| 203 | 207 |
| 204 // Initializes title_ in the given frame. | 208 // Initializes title_ in the given frame. |
| 205 - (void)configureTitleInFrame:(NSRect)rootFrame; | 209 - (void)configureTitleInFrame:(NSRect)rootFrame; |
| 206 | 210 |
| 207 // Initializes message_ in the given frame. | 211 // Initializes message_ in the given frame. |
| 208 - (void)configureBodyInFrame:(NSRect)rootFrame; | 212 - (void)configureBodyInFrame:(NSRect)rootFrame; |
| 209 | 213 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 NSRect rootFrame = NSMakeRect(0, 0, | 251 NSRect rootFrame = NSMakeRect(0, 0, |
| 248 message_center::kNotificationPreferredImageSize, | 252 message_center::kNotificationPreferredImageSize, |
| 249 message_center::kNotificationIconSize); | 253 message_center::kNotificationIconSize); |
| 250 base::scoped_nsobject<MCNotificationView> rootView( | 254 base::scoped_nsobject<MCNotificationView> rootView( |
| 251 [[MCNotificationView alloc] initWithController:self frame:rootFrame]); | 255 [[MCNotificationView alloc] initWithController:self frame:rootFrame]); |
| 252 [self configureCustomBox:rootView]; | 256 [self configureCustomBox:rootView]; |
| 253 [rootView setFillColor:gfx::SkColorToCalibratedNSColor( | 257 [rootView setFillColor:gfx::SkColorToCalibratedNSColor( |
| 254 message_center::kNotificationBackgroundColor)]; | 258 message_center::kNotificationBackgroundColor)]; |
| 255 [self setView:rootView]; | 259 [self setView:rootView]; |
| 256 | 260 |
| 257 [rootView addSubview:[self createImageView]]; | 261 [rootView addSubview:[self createIconView]]; |
| 258 | 262 |
| 259 // Create the close button. | 263 // Create the close button. |
| 260 [self configureCloseButtonInFrame:rootFrame]; | 264 [self configureCloseButtonInFrame:rootFrame]; |
| 261 [rootView addSubview:closeButton_]; | 265 [rootView addSubview:closeButton_]; |
| 262 | 266 |
| 263 // Create the title. | 267 // Create the title. |
| 264 [self configureTitleInFrame:rootFrame]; | 268 [self configureTitleInFrame:rootFrame]; |
| 265 [rootView addSubview:title_]; | 269 [rootView addSubview:title_]; |
| 266 | 270 |
| 267 // Create the message body. | 271 // Create the message body. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 [[AccessibilityIgnoredBox alloc] initWithFrame:separatorFrame]); | 502 [[AccessibilityIgnoredBox alloc] initWithFrame:separatorFrame]); |
| 499 [self configureCustomBox:separator]; | 503 [self configureCustomBox:separator]; |
| 500 [separator setFillColor:gfx::SkColorToCalibratedNSColor( | 504 [separator setFillColor:gfx::SkColorToCalibratedNSColor( |
| 501 message_center::kButtonSeparatorColor)]; | 505 message_center::kButtonSeparatorColor)]; |
| 502 y += NSHeight(separatorFrame); | 506 y += NSHeight(separatorFrame); |
| 503 frame.size.height += NSHeight(separatorFrame); | 507 frame.size.height += NSHeight(separatorFrame); |
| 504 [bottomView_ addSubview:separator]; | 508 [bottomView_ addSubview:separator]; |
| 505 } | 509 } |
| 506 | 510 |
| 507 // Create the image view if appropriate. | 511 // Create the image view if appropriate. |
| 508 if (!notification->image().IsEmpty()) { | 512 gfx::Image notificationImage = notification->image(); |
| 509 NSImage* image = notification->image().AsNSImage(); | 513 if (!notificationImage.IsEmpty()) { |
| 510 NSRect imageFrame = frame; | 514 NSBox* imageBox = [self createImageBox:notificationImage]; |
| 511 imageFrame.origin = NSMakePoint(0, y); | 515 NSRect outerFrame = frame; |
| 512 imageFrame.size = NSSizeFromCGSize(message_center::GetImageSizeForWidth( | 516 outerFrame.origin = NSMakePoint(0, y); |
| 513 NSWidth(frame), notification->image().Size()).ToCGSize()); | 517 outerFrame.size = [imageBox frame].size; |
| 514 base::scoped_nsobject<NSImageView> imageView( | 518 [imageBox setFrame:outerFrame]; |
| 515 [[NSImageView alloc] initWithFrame:imageFrame]); | 519 |
| 516 [imageView setImage:image]; | 520 y += NSHeight(outerFrame); |
| 517 [imageView setImageScaling:NSImageScaleProportionallyUpOrDown]; | 521 frame.size.height += NSHeight(outerFrame); |
| 518 y += NSHeight(imageFrame); | 522 |
| 519 frame.size.height += NSHeight(imageFrame); | 523 [bottomView_ addSubview:imageBox]; |
| 520 [bottomView_ addSubview:imageView]; | |
| 521 } | 524 } |
| 522 | 525 |
| 523 [bottomView_ setFrame:frame]; | 526 [bottomView_ setFrame:frame]; |
| 524 [[self view] addSubview:bottomView_]; | 527 [[self view] addSubview:bottomView_]; |
| 525 | 528 |
| 526 rootFrame.size.height += NSHeight(frame); | 529 rootFrame.size.height += NSHeight(frame); |
| 527 titleFrame.origin.y += NSHeight(frame); | 530 titleFrame.origin.y += NSHeight(frame); |
| 528 messageFrame.origin.y += NSHeight(frame); | 531 messageFrame.origin.y += NSHeight(frame); |
| 529 contextMessageFrame.origin.y += NSHeight(frame); | 532 contextMessageFrame.origin.y += NSHeight(frame); |
| 530 listFrame.origin.y += NSHeight(frame); | 533 listFrame.origin.y += NSHeight(frame); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 | 580 |
| 578 // Private ///////////////////////////////////////////////////////////////////// | 581 // Private ///////////////////////////////////////////////////////////////////// |
| 579 | 582 |
| 580 - (void)configureCustomBox:(NSBox*)box { | 583 - (void)configureCustomBox:(NSBox*)box { |
| 581 [box setBoxType:NSBoxCustom]; | 584 [box setBoxType:NSBoxCustom]; |
| 582 [box setBorderType:NSNoBorder]; | 585 [box setBorderType:NSNoBorder]; |
| 583 [box setTitlePosition:NSNoTitle]; | 586 [box setTitlePosition:NSNoTitle]; |
| 584 [box setContentViewMargins:NSZeroSize]; | 587 [box setContentViewMargins:NSZeroSize]; |
| 585 } | 588 } |
| 586 | 589 |
| 587 - (NSView*)createImageView { | 590 - (NSView*)createIconView { |
| 588 // Create another box that shows a background color when the icon is not | 591 // Create another box that shows a background color when the icon is not |
| 589 // big enough to fill the space. | 592 // big enough to fill the space. |
| 590 NSRect imageFrame = NSMakeRect(0, 0, | 593 NSRect imageFrame = NSMakeRect(0, 0, |
| 591 message_center::kNotificationIconSize, | 594 message_center::kNotificationIconSize, |
| 592 message_center::kNotificationIconSize); | 595 message_center::kNotificationIconSize); |
| 593 base::scoped_nsobject<NSBox> imageBox( | 596 base::scoped_nsobject<NSBox> imageBox( |
| 594 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); | 597 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); |
| 595 [self configureCustomBox:imageBox]; | 598 [self configureCustomBox:imageBox]; |
| 596 [imageBox setFillColor:gfx::SkColorToCalibratedNSColor( | 599 [imageBox setFillColor:gfx::SkColorToCalibratedNSColor( |
| 597 message_center::kIconBackgroundColor)]; | 600 message_center::kIconBackgroundColor)]; |
| 598 [imageBox setAutoresizingMask:NSViewMinYMargin]; | 601 [imageBox setAutoresizingMask:NSViewMinYMargin]; |
| 599 | 602 |
| 600 // Inside the image box put the actual icon view. | 603 // Inside the image box put the actual icon view. |
| 601 icon_.reset([[NSImageView alloc] initWithFrame:imageFrame]); | 604 icon_.reset([[NSImageView alloc] initWithFrame:imageFrame]); |
| 602 [imageBox setContentView:icon_]; | 605 [imageBox setContentView:icon_]; |
| 603 | 606 |
| 604 return imageBox.autorelease(); | 607 return imageBox.autorelease(); |
| 605 } | 608 } |
| 606 | 609 |
| 610 - (NSBox*)createImageBox:(gfx::Image)notificationImage { | |
| 611 using message_center::kNotificationImageBorderSize; | |
| 612 using message_center::kNotificationPreferredImageSize; | |
| 613 using message_center::kNotificationPreferredImageRatio; | |
| 614 | |
| 615 NSRect imageFrame = NSMakeRect(0, 0, | |
| 616 kNotificationPreferredImageSize, | |
| 617 kNotificationPreferredImageSize * kNotificationPreferredImageRatio); | |
| 618 base::scoped_nsobject<NSBox> imageBox( | |
| 619 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); | |
| 620 [self configureCustomBox:imageBox]; | |
| 621 [imageBox setFillColor:gfx::SkColorToCalibratedNSColor( | |
| 622 message_center::kImageBackgroundColor)]; | |
| 623 | |
| 624 // Images with non-preferred aspect ratios get a border on all sides. | |
| 625 gfx::Size size = notificationImage.Size(); | |
| 626 int preferredImageHeight = size.width() * kNotificationPreferredImageRatio; | |
| 627 if (size.height() != preferredImageHeight) { | |
| 628 NSSize borderSize = | |
| 629 NSMakeSize(kNotificationImageBorderSize, kNotificationImageBorderSize); | |
| 630 [imageBox setContentViewMargins:borderSize]; | |
| 631 } | |
| 632 | |
| 633 NSImage* image = notificationImage.AsNSImage(); | |
| 634 base::scoped_nsobject<NSImageView> imageView( | |
| 635 [[NSImageView alloc] initWithFrame:imageFrame]); | |
| 636 [imageView setImage:image]; | |
| 637 [imageView setImageScaling:NSImageScaleProportionallyUpOrDown]; | |
| 638 [imageBox setContentView:imageView]; | |
| 639 | |
| 640 return imageBox.autorelease(); | |
| 641 } | |
| 642 | |
| 643 | |
|
Robert Sesek
2013/12/05 18:36:56
nit: extra line
dewittj
2013/12/10 02:47:04
Done.
| |
| 607 - (void)configureCloseButtonInFrame:(NSRect)rootFrame { | 644 - (void)configureCloseButtonInFrame:(NSRect)rootFrame { |
| 608 closeButton_.reset([[HoverImageButton alloc] initWithFrame:NSMakeRect( | 645 closeButton_.reset([[HoverImageButton alloc] initWithFrame:NSMakeRect( |
| 609 NSMaxX(rootFrame) - message_center::kControlButtonSize, | 646 NSMaxX(rootFrame) - message_center::kControlButtonSize, |
| 610 NSMaxY(rootFrame) - message_center::kControlButtonSize, | 647 NSMaxY(rootFrame) - message_center::kControlButtonSize, |
| 611 message_center::kControlButtonSize, | 648 message_center::kControlButtonSize, |
| 612 message_center::kControlButtonSize)]); | 649 message_center::kControlButtonSize)]); |
| 613 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 650 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 614 [closeButton_ setDefaultImage: | 651 [closeButton_ setDefaultImage: |
| 615 rb.GetNativeImageNamed(IDR_NOTIFICATION_CLOSE).ToNSImage()]; | 652 rb.GetNativeImageNamed(IDR_NOTIFICATION_CLOSE).ToNSImage()]; |
| 616 [closeButton_ setHoverImage: | 653 [closeButton_ setHoverImage: |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 if (gfx::GetStringWidth(last, font_list) > width) | 747 if (gfx::GetStringWidth(last, font_list) > width) |
| 711 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END); | 748 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END); |
| 712 wrapped.resize(lines - 1); | 749 wrapped.resize(lines - 1); |
| 713 wrapped.push_back(last); | 750 wrapped.push_back(last); |
| 714 } | 751 } |
| 715 | 752 |
| 716 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n'); | 753 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n'); |
| 717 } | 754 } |
| 718 | 755 |
| 719 @end | 756 @end |
| OLD | NEW |