| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 messageCenter_ = messageCenter; | 200 messageCenter_ = messageCenter; |
| 201 } | 201 } |
| 202 return self; | 202 return self; |
| 203 } | 203 } |
| 204 | 204 |
| 205 - (void)loadView { | 205 - (void)loadView { |
| 206 // Create the root view of the notification. | 206 // Create the root view of the notification. |
| 207 NSRect rootFrame = NSMakeRect(0, 0, | 207 NSRect rootFrame = NSMakeRect(0, 0, |
| 208 message_center::kNotificationPreferredImageSize, | 208 message_center::kNotificationPreferredImageSize, |
| 209 message_center::kNotificationIconSize); | 209 message_center::kNotificationIconSize); |
| 210 scoped_nsobject<MCNotificationView> rootView( | 210 base::scoped_nsobject<MCNotificationView> rootView( |
| 211 [[MCNotificationView alloc] initWithController:self | 211 [[MCNotificationView alloc] initWithController:self frame:rootFrame]); |
| 212 frame:rootFrame]); | |
| 213 [self configureCustomBox:rootView]; | 212 [self configureCustomBox:rootView]; |
| 214 [rootView setFillColor:gfx::SkColorToCalibratedNSColor( | 213 [rootView setFillColor:gfx::SkColorToCalibratedNSColor( |
| 215 message_center::kNotificationBackgroundColor)]; | 214 message_center::kNotificationBackgroundColor)]; |
| 216 [self setView:rootView]; | 215 [self setView:rootView]; |
| 217 | 216 |
| 218 [rootView addSubview:[self createImageView]]; | 217 [rootView addSubview:[self createImageView]]; |
| 219 | 218 |
| 220 // Create the close button. | 219 // Create the close button. |
| 221 [self configureCloseButtonInFrame:rootFrame]; | 220 [self configureCloseButtonInFrame:rootFrame]; |
| 222 [rootView addSubview:closeButton_]; | 221 [rootView addSubview:closeButton_]; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 bottomView_.reset([[NSView alloc] initWithFrame:frame]); | 338 bottomView_.reset([[NSView alloc] initWithFrame:frame]); |
| 340 CGFloat y = 0; | 339 CGFloat y = 0; |
| 341 | 340 |
| 342 // Create action buttons if appropriate, bottom-up. | 341 // Create action buttons if appropriate, bottom-up. |
| 343 std::vector<message_center::ButtonInfo> buttons = notification->buttons(); | 342 std::vector<message_center::ButtonInfo> buttons = notification->buttons(); |
| 344 for (int i = buttons.size() - 1; i >= 0; --i) { | 343 for (int i = buttons.size() - 1; i >= 0; --i) { |
| 345 message_center::ButtonInfo buttonInfo = buttons[i]; | 344 message_center::ButtonInfo buttonInfo = buttons[i]; |
| 346 NSRect buttonFrame = frame; | 345 NSRect buttonFrame = frame; |
| 347 buttonFrame.origin = NSMakePoint(0, y); | 346 buttonFrame.origin = NSMakePoint(0, y); |
| 348 buttonFrame.size.height = message_center::kButtonHeight; | 347 buttonFrame.size.height = message_center::kButtonHeight; |
| 349 scoped_nsobject<NSButton> button( | 348 base::scoped_nsobject<NSButton> button( |
| 350 [[NSButton alloc] initWithFrame:buttonFrame]); | 349 [[NSButton alloc] initWithFrame:buttonFrame]); |
| 351 scoped_nsobject<MCNotificationButtonCell> cell( | 350 base::scoped_nsobject<MCNotificationButtonCell> cell( |
| 352 [[MCNotificationButtonCell alloc] | 351 [[MCNotificationButtonCell alloc] |
| 353 initTextCell:base::SysUTF16ToNSString(buttonInfo.title)]); | 352 initTextCell:base::SysUTF16ToNSString(buttonInfo.title)]); |
| 354 [cell setShowsBorderOnlyWhileMouseInside:YES]; | 353 [cell setShowsBorderOnlyWhileMouseInside:YES]; |
| 355 [button setCell:cell]; | 354 [button setCell:cell]; |
| 356 [button setImage:buttonInfo.icon.AsNSImage()]; | 355 [button setImage:buttonInfo.icon.AsNSImage()]; |
| 357 [button setBezelStyle:NSSmallSquareBezelStyle]; | 356 [button setBezelStyle:NSSmallSquareBezelStyle]; |
| 358 [button setImagePosition:NSImageLeft]; | 357 [button setImagePosition:NSImageLeft]; |
| 359 [button setTag:i]; | 358 [button setTag:i]; |
| 360 [button setTarget:self]; | 359 [button setTarget:self]; |
| 361 [button setAction:@selector(buttonClicked:)]; | 360 [button setAction:@selector(buttonClicked:)]; |
| 362 y += NSHeight(buttonFrame); | 361 y += NSHeight(buttonFrame); |
| 363 frame.size.height += NSHeight(buttonFrame); | 362 frame.size.height += NSHeight(buttonFrame); |
| 364 [bottomView_ addSubview:button]; | 363 [bottomView_ addSubview:button]; |
| 365 | 364 |
| 366 NSRect separatorFrame = frame; | 365 NSRect separatorFrame = frame; |
| 367 separatorFrame.origin = NSMakePoint(0, y); | 366 separatorFrame.origin = NSMakePoint(0, y); |
| 368 separatorFrame.size.height = 1; | 367 separatorFrame.size.height = 1; |
| 369 scoped_nsobject<NSBox> separator( | 368 base::scoped_nsobject<NSBox> separator( |
| 370 [[AccessibilityIgnoredBox alloc] initWithFrame:separatorFrame]); | 369 [[AccessibilityIgnoredBox alloc] initWithFrame:separatorFrame]); |
| 371 [self configureCustomBox:separator]; | 370 [self configureCustomBox:separator]; |
| 372 [separator setFillColor:gfx::SkColorToCalibratedNSColor( | 371 [separator setFillColor:gfx::SkColorToCalibratedNSColor( |
| 373 message_center::kButtonSeparatorColor)]; | 372 message_center::kButtonSeparatorColor)]; |
| 374 y += NSHeight(separatorFrame); | 373 y += NSHeight(separatorFrame); |
| 375 frame.size.height += NSHeight(separatorFrame); | 374 frame.size.height += NSHeight(separatorFrame); |
| 376 [bottomView_ addSubview:separator]; | 375 [bottomView_ addSubview:separator]; |
| 377 } | 376 } |
| 378 | 377 |
| 379 // Create the image view if appropriate. | 378 // Create the image view if appropriate. |
| 380 if (!notification->image().IsEmpty()) { | 379 if (!notification->image().IsEmpty()) { |
| 381 NSImage* image = notification->image().AsNSImage(); | 380 NSImage* image = notification->image().AsNSImage(); |
| 382 NSRect imageFrame = frame; | 381 NSRect imageFrame = frame; |
| 383 imageFrame.origin = NSMakePoint(0, y); | 382 imageFrame.origin = NSMakePoint(0, y); |
| 384 imageFrame.size = NSSizeFromCGSize(message_center::GetImageSizeForWidth( | 383 imageFrame.size = NSSizeFromCGSize(message_center::GetImageSizeForWidth( |
| 385 NSWidth(frame), notification->image().Size()).ToCGSize()); | 384 NSWidth(frame), notification->image().Size()).ToCGSize()); |
| 386 scoped_nsobject<NSImageView> imageView( | 385 base::scoped_nsobject<NSImageView> imageView( |
| 387 [[NSImageView alloc] initWithFrame:imageFrame]); | 386 [[NSImageView alloc] initWithFrame:imageFrame]); |
| 388 [imageView setImage:image]; | 387 [imageView setImage:image]; |
| 389 [imageView setImageScaling:NSImageScaleProportionallyUpOrDown]; | 388 [imageView setImageScaling:NSImageScaleProportionallyUpOrDown]; |
| 390 y += NSHeight(imageFrame); | 389 y += NSHeight(imageFrame); |
| 391 frame.size.height += NSHeight(imageFrame); | 390 frame.size.height += NSHeight(imageFrame); |
| 392 [bottomView_ addSubview:imageView]; | 391 [bottomView_ addSubview:imageView]; |
| 393 } | 392 } |
| 394 | 393 |
| 395 [bottomView_ setFrame:frame]; | 394 [bottomView_ setFrame:frame]; |
| 396 [[self view] addSubview:bottomView_]; | 395 [[self view] addSubview:bottomView_]; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 // Private ///////////////////////////////////////////////////////////////////// | 432 // Private ///////////////////////////////////////////////////////////////////// |
| 434 | 433 |
| 435 + (NSAttributedString*) | 434 + (NSAttributedString*) |
| 436 attributedStringForItem:(const message_center::NotificationItem&)item | 435 attributedStringForItem:(const message_center::NotificationItem&)item |
| 437 font:(NSFont*)font { | 436 font:(NSFont*)font { |
| 438 NSString* text = base::SysUTF16ToNSString( | 437 NSString* text = base::SysUTF16ToNSString( |
| 439 item.title + base::UTF8ToUTF16(" ") + item.message); | 438 item.title + base::UTF8ToUTF16(" ") + item.message); |
| 440 NSMutableAttributedString* formattedText = | 439 NSMutableAttributedString* formattedText = |
| 441 [[[NSMutableAttributedString alloc] initWithString:text] autorelease]; | 440 [[[NSMutableAttributedString alloc] initWithString:text] autorelease]; |
| 442 | 441 |
| 443 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 442 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
| 444 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); | 443 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); |
| 445 [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; | 444 [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 446 NSDictionary* sharedAttribs = @{ | 445 NSDictionary* sharedAttribs = @{ |
| 447 NSFontAttributeName : font, | 446 NSFontAttributeName : font, |
| 448 NSParagraphStyleAttributeName : paragraphStyle, | 447 NSParagraphStyleAttributeName : paragraphStyle, |
| 449 }; | 448 }; |
| 450 const NSRange range = NSMakeRange(0, [formattedText length] - 1); | 449 const NSRange range = NSMakeRange(0, [formattedText length] - 1); |
| 451 [formattedText addAttributes:sharedAttribs range:range]; | 450 [formattedText addAttributes:sharedAttribs range:range]; |
| 452 | 451 |
| 453 NSDictionary* titleAttribs = @{ | 452 NSDictionary* titleAttribs = @{ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 474 [box setTitlePosition:NSNoTitle]; | 473 [box setTitlePosition:NSNoTitle]; |
| 475 [box setContentViewMargins:NSZeroSize]; | 474 [box setContentViewMargins:NSZeroSize]; |
| 476 } | 475 } |
| 477 | 476 |
| 478 - (NSView*)createImageView { | 477 - (NSView*)createImageView { |
| 479 // Create another box that shows a background color when the icon is not | 478 // Create another box that shows a background color when the icon is not |
| 480 // big enough to fill the space. | 479 // big enough to fill the space. |
| 481 NSRect imageFrame = NSMakeRect(0, 0, | 480 NSRect imageFrame = NSMakeRect(0, 0, |
| 482 message_center::kNotificationIconSize, | 481 message_center::kNotificationIconSize, |
| 483 message_center::kNotificationIconSize); | 482 message_center::kNotificationIconSize); |
| 484 scoped_nsobject<NSBox> imageBox( | 483 base::scoped_nsobject<NSBox> imageBox( |
| 485 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); | 484 [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]); |
| 486 [self configureCustomBox:imageBox]; | 485 [self configureCustomBox:imageBox]; |
| 487 [imageBox setFillColor:gfx::SkColorToCalibratedNSColor( | 486 [imageBox setFillColor:gfx::SkColorToCalibratedNSColor( |
| 488 message_center::kLegacyIconBackgroundColor)]; | 487 message_center::kLegacyIconBackgroundColor)]; |
| 489 [imageBox setAutoresizingMask:NSViewMinYMargin]; | 488 [imageBox setAutoresizingMask:NSViewMinYMargin]; |
| 490 | 489 |
| 491 // Inside the image box put the actual icon view. | 490 // Inside the image box put the actual icon view. |
| 492 icon_.reset([[NSImageView alloc] initWithFrame:imageFrame]); | 491 icon_.reset([[NSImageView alloc] initWithFrame:imageFrame]); |
| 493 [imageBox setContentView:icon_]; | 492 [imageBox setContentView:icon_]; |
| 494 | 493 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 if (font.GetStringWidth(last) > width) | 582 if (font.GetStringWidth(last) > width) |
| 584 last = ui::ElideText(last, font, width, ui::ELIDE_AT_END); | 583 last = ui::ElideText(last, font, width, ui::ELIDE_AT_END); |
| 585 wrapped.resize(lines - 1); | 584 wrapped.resize(lines - 1); |
| 586 wrapped.push_back(last); | 585 wrapped.push_back(last); |
| 587 } | 586 } |
| 588 | 587 |
| 589 return JoinString(wrapped, '\n'); | 588 return JoinString(wrapped, '\n'); |
| 590 } | 589 } |
| 591 | 590 |
| 592 @end | 591 @end |
| OLD | NEW |