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" |
| 11 #include "grit/ui_resources.h" | 11 #include "grit/ui_resources.h" |
| 12 #include "grit/ui_strings.h" | 12 #include "grit/ui_strings.h" |
| 13 #include "skia/ext/skia_utils_mac.h" | 13 #include "skia/ext/skia_utils_mac.h" |
| 14 #import "ui/base/cocoa/hover_image_button.h" | 14 #import "ui/base/cocoa/hover_image_button.h" |
| 15 #include "ui/base/l10n/l10n_util_mac.h" | 15 #include "ui/base/l10n/l10n_util_mac.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/base/text/text_elider.h" | 17 #include "ui/base/text/text_elider.h" |
| 18 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
| 19 #include "ui/message_center/message_center_style.h" | 19 #include "ui/message_center/message_center_style.h" |
| 20 #include "ui/message_center/notification.h" | 20 #include "ui/message_center/notification.h" |
| 21 | 21 |
| 22 const CGFloat kProgressBarThickness = 8; | |
| 23 const CGFloat kProgressBarTopPadding = 12; | |
| 24 const SkColor kProgressBarBackgroundColor = SkColorSetRGB(230, 230, 230); | |
|
Robert Sesek
2013/07/29 18:50:26
Should these be shared in the constants file?
jianli
2013/07/29 19:05:40
The constants used to paint progress bar for Windo
| |
| 25 const SkColor kProgressBarBackgroundBorderColor = SkColorSetRGB(208, 208, 208); | |
| 26 const SkColor kProgressBarSliceColor = SkColorSetRGB(78, 156, 245); | |
| 27 const SkColor kProgressBarSliceBorderColor = SkColorSetRGB(110, 188, 249); | |
| 28 | |
| 29 @interface MCNotificationProgressBar : NSProgressIndicator { | |
|
Robert Sesek
2013/07/29 18:50:26
nit: remove {}
jianli
2013/07/29 19:05:40
Done.
| |
| 30 } | |
| 31 @end | |
| 32 | |
| 33 @implementation MCNotificationProgressBar | |
| 34 - (void)drawRect:(NSRect)dirtyRect { | |
| 35 NSRect sliceRect, remainderRect; | |
| 36 double progressFraction = ([self doubleValue] - [self minValue]) / | |
| 37 ([self maxValue] - [self minValue]); | |
| 38 NSDivideRect(dirtyRect, &sliceRect, &remainderRect, | |
| 39 NSWidth(dirtyRect) * progressFraction, NSMinXEdge); | |
| 40 | |
| 41 // For slice part. | |
| 42 [gfx::SkColorToCalibratedNSColor(kProgressBarSliceBorderColor) | |
| 43 drawSwatchInRect:sliceRect]; | |
| 44 [gfx::SkColorToCalibratedNSColor(kProgressBarSliceColor) | |
| 45 drawSwatchInRect:NSInsetRect(sliceRect, 1.0, 1.0)]; | |
| 46 | |
| 47 // For remainder part. | |
| 48 [gfx::SkColorToCalibratedNSColor(kProgressBarBackgroundBorderColor) | |
| 49 drawSwatchInRect:remainderRect]; | |
| 50 [gfx::SkColorToCalibratedNSColor(kProgressBarBackgroundColor) | |
| 51 drawSwatchInRect:NSInsetRect(remainderRect, 1.0, 1.0)]; | |
| 52 } | |
| 53 @end | |
| 54 | |
| 55 //////////////////////////////////////////////////////////////////////////////// | |
| 56 | |
| 22 @interface MCNotificationButtonCell : NSButtonCell { | 57 @interface MCNotificationButtonCell : NSButtonCell { |
| 23 BOOL hovered_; | 58 BOOL hovered_; |
| 24 } | 59 } |
| 25 @end | 60 @end |
| 26 | 61 |
| 27 @implementation MCNotificationButtonCell | 62 @implementation MCNotificationButtonCell |
| 28 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { | 63 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { |
| 29 // Else mouseEntered: and mouseExited: won't be called and hovered_ won't be | 64 // Else mouseEntered: and mouseExited: won't be called and hovered_ won't be |
| 30 // valid. | 65 // valid. |
| 31 DCHECK([self showsBorderOnlyWhileMouseInside]); | 66 DCHECK([self showsBorderOnlyWhileMouseInside]); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 // TODO(thakis): The spacing is not completely right. | 346 // TODO(thakis): The spacing is not completely right. |
| 312 CGFloat listTopPadding = | 347 CGFloat listTopPadding = |
| 313 message_center::kTextTopPadding - messageTopGap; | 348 message_center::kTextTopPadding - messageTopGap; |
| 314 listFrame.size.height = y; | 349 listFrame.size.height = y; |
| 315 listFrame.origin.y = | 350 listFrame.origin.y = |
| 316 NSMinY(messageFrame) - listTopPadding - NSHeight(listFrame); | 351 NSMinY(messageFrame) - listTopPadding - NSHeight(listFrame); |
| 317 [listItemView_ setFrame:listFrame]; | 352 [listItemView_ setFrame:listFrame]; |
| 318 [[self view] addSubview:listItemView_]; | 353 [[self view] addSubview:listItemView_]; |
| 319 } | 354 } |
| 320 | 355 |
| 356 // Create the progress bar view if needed. | |
| 357 [progressBarView_ removeFromSuperview]; | |
| 358 NSRect progressBarFrame = NSZeroRect; | |
| 359 if (notification->type() == message_center::NOTIFICATION_TYPE_PROGRESS) { | |
| 360 progressBarFrame = [self currentContentRect]; | |
| 361 progressBarFrame.origin.y = NSMinY(messageFrame) - | |
| 362 kProgressBarTopPadding - kProgressBarThickness; | |
| 363 progressBarFrame.size.height = kProgressBarThickness; | |
| 364 progressBarView_.reset([[MCNotificationProgressBar alloc] | |
| 365 initWithFrame:progressBarFrame]); | |
|
Robert Sesek
2013/07/29 18:50:26
nit: does this fit if you break after the .reset(
jianli
2013/07/29 19:05:40
Done.
| |
| 366 // Setting indeterminate to NO does not work with custom drawRect. | |
| 367 [progressBarView_ setIndeterminate:YES]; | |
| 368 [progressBarView_ setStyle:NSProgressIndicatorBarStyle]; | |
| 369 [progressBarView_ setDoubleValue:notification->progress()]; | |
| 370 [[self view] addSubview:progressBarView_]; | |
| 371 } | |
| 372 | |
| 321 // If the bottom-most element so far is out of the rootView's bounds, resize | 373 // If the bottom-most element so far is out of the rootView's bounds, resize |
| 322 // the view. | 374 // the view. |
| 323 CGFloat minY = NSMinY(messageFrame); | 375 CGFloat minY = NSMinY(messageFrame); |
| 324 if (listItemView_ && NSMinY(listFrame) < minY) | 376 if (listItemView_ && NSMinY(listFrame) < minY) |
| 325 minY = NSMinY(listFrame); | 377 minY = NSMinY(listFrame); |
| 378 if (progressBarView_ && NSMinY(progressBarFrame) < minY) | |
| 379 minY = NSMinY(progressBarFrame); | |
| 326 if (minY < messagePadding) { | 380 if (minY < messagePadding) { |
| 327 CGFloat delta = messagePadding - minY; | 381 CGFloat delta = messagePadding - minY; |
| 328 rootFrame.size.height += delta; | 382 rootFrame.size.height += delta; |
| 329 titleFrame.origin.y += delta; | 383 titleFrame.origin.y += delta; |
| 330 messageFrame.origin.y += delta; | 384 messageFrame.origin.y += delta; |
| 331 listFrame.origin.y += delta; | 385 listFrame.origin.y += delta; |
| 386 progressBarFrame.origin.y += delta; | |
| 332 } | 387 } |
| 333 | 388 |
| 334 // Add the bottom container view. | 389 // Add the bottom container view. |
| 335 NSRect frame = rootFrame; | 390 NSRect frame = rootFrame; |
| 336 frame.size.height = 0; | 391 frame.size.height = 0; |
| 337 [bottomView_ removeFromSuperview]; | 392 [bottomView_ removeFromSuperview]; |
| 338 bottomView_.reset([[NSView alloc] initWithFrame:frame]); | 393 bottomView_.reset([[NSView alloc] initWithFrame:frame]); |
| 339 CGFloat y = 0; | 394 CGFloat y = 0; |
| 340 | 395 |
| 341 // Create action buttons if appropriate, bottom-up. | 396 // Create action buttons if appropriate, bottom-up. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 [bottomView_ addSubview:imageView]; | 446 [bottomView_ addSubview:imageView]; |
| 392 } | 447 } |
| 393 | 448 |
| 394 [bottomView_ setFrame:frame]; | 449 [bottomView_ setFrame:frame]; |
| 395 [[self view] addSubview:bottomView_]; | 450 [[self view] addSubview:bottomView_]; |
| 396 | 451 |
| 397 rootFrame.size.height += NSHeight(frame); | 452 rootFrame.size.height += NSHeight(frame); |
| 398 titleFrame.origin.y += NSHeight(frame); | 453 titleFrame.origin.y += NSHeight(frame); |
| 399 messageFrame.origin.y += NSHeight(frame); | 454 messageFrame.origin.y += NSHeight(frame); |
| 400 listFrame.origin.y += NSHeight(frame); | 455 listFrame.origin.y += NSHeight(frame); |
| 456 progressBarFrame.origin.y += NSHeight(frame); | |
| 401 | 457 |
| 402 [[self view] setFrame:rootFrame]; | 458 [[self view] setFrame:rootFrame]; |
| 403 [title_ setFrame:titleFrame]; | 459 [title_ setFrame:titleFrame]; |
| 404 [message_ setFrame:messageFrame]; | 460 [message_ setFrame:messageFrame]; |
| 405 [listItemView_ setFrame:listFrame]; | 461 [listItemView_ setFrame:listFrame]; |
| 462 [progressBarView_ setFrame:progressBarFrame]; | |
| 406 | 463 |
| 407 return rootFrame; | 464 return rootFrame; |
| 408 } | 465 } |
| 409 | 466 |
| 410 - (void)close:(id)sender { | 467 - (void)close:(id)sender { |
| 411 [closeButton_ setTarget:nil]; | 468 [closeButton_ setTarget:nil]; |
| 412 messageCenter_->RemoveNotification([self notificationID], /*by_user=*/true); | 469 messageCenter_->RemoveNotification([self notificationID], /*by_user=*/true); |
| 413 } | 470 } |
| 414 | 471 |
| 415 - (void)buttonClicked:(id)button { | 472 - (void)buttonClicked:(id)button { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 if (font.GetStringWidth(last) > width) | 639 if (font.GetStringWidth(last) > width) |
| 583 last = ui::ElideText(last, font, width, ui::ELIDE_AT_END); | 640 last = ui::ElideText(last, font, width, ui::ELIDE_AT_END); |
| 584 wrapped.resize(lines - 1); | 641 wrapped.resize(lines - 1); |
| 585 wrapped.push_back(last); | 642 wrapped.push_back(last); |
| 586 } | 643 } |
| 587 | 644 |
| 588 return JoinString(wrapped, '\n'); | 645 return JoinString(wrapped, '\n'); |
| 589 } | 646 } |
| 590 | 647 |
| 591 @end | 648 @end |
| OLD | NEW |