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