| 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/tray_view_controller.h" | 5 #import "ui/message_center/cocoa/tray_view_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/mac/scoped_nsautorelease_pool.h" | 9 #include "base/mac/scoped_nsautorelease_pool.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return NSHeight(screenFrame) - kTrayBottomMargin - kControlAreaHeight; | 352 return NSHeight(screenFrame) - kTrayBottomMargin - kControlAreaHeight; |
| 353 } | 353 } |
| 354 | 354 |
| 355 + (CGFloat)trayWidth { | 355 + (CGFloat)trayWidth { |
| 356 return message_center::kNotificationWidth + | 356 return message_center::kNotificationWidth + |
| 357 2 * message_center::kMarginBetweenItems; | 357 2 * message_center::kMarginBetweenItems; |
| 358 } | 358 } |
| 359 | 359 |
| 360 // Testing API ///////////////////////////////////////////////////////////////// | 360 // Testing API ///////////////////////////////////////////////////////////////// |
| 361 | 361 |
| 362 - (NSBox*)divider { |
| 363 return divider_.get(); |
| 364 } |
| 365 |
| 366 - (NSTextField*)emptyDescription { |
| 367 return emptyDescription_.get(); |
| 368 } |
| 369 |
| 362 - (NSScrollView*)scrollView { | 370 - (NSScrollView*)scrollView { |
| 363 return scrollView_.get(); | 371 return scrollView_.get(); |
| 364 } | 372 } |
| 365 | 373 |
| 366 - (HoverImageButton*)pauseButton { | 374 - (HoverImageButton*)pauseButton { |
| 367 return pauseButton_.get(); | 375 return pauseButton_.get(); |
| 368 } | 376 } |
| 369 | 377 |
| 370 - (HoverImageButton*)clearAllButton { | 378 - (HoverImageButton*)clearAllButton { |
| 371 return clearAllButton_.get(); | 379 return clearAllButton_.get(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 383 (message_center::TrayAnimationEndedCallback)callback { | 391 (message_center::TrayAnimationEndedCallback)callback { |
| 384 testingAnimationEndedCallback_.reset(Block_copy(callback)); | 392 testingAnimationEndedCallback_.reset(Block_copy(callback)); |
| 385 } | 393 } |
| 386 | 394 |
| 387 // Private ///////////////////////////////////////////////////////////////////// | 395 // Private ///////////////////////////////////////////////////////////////////// |
| 388 | 396 |
| 389 - (void)layoutControlArea { | 397 - (void)layoutControlArea { |
| 390 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 398 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 391 NSView* view = [self view]; | 399 NSView* view = [self view]; |
| 392 | 400 |
| 401 auto configureLabel = ^(NSTextField* textField) { |
| 402 [textField setAutoresizingMask:NSViewMinYMargin]; |
| 403 [textField setBezeled:NO]; |
| 404 [textField setBordered:NO]; |
| 405 [textField setDrawsBackground:NO]; |
| 406 [textField setEditable:NO]; |
| 407 [textField setSelectable:NO]; |
| 408 }; |
| 409 |
| 393 // Create the "Notifications" label at the top of the tray. | 410 // Create the "Notifications" label at the top of the tray. |
| 394 NSFont* font = [NSFont labelFontOfSize:message_center::kTitleFontSize]; | 411 NSFont* font = [NSFont labelFontOfSize:message_center::kTitleFontSize]; |
| 395 title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); | 412 title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); |
| 396 [title_ setAutoresizingMask:NSViewMinYMargin]; | 413 configureLabel(title_); |
| 397 [title_ setBezeled:NO]; | 414 |
| 398 [title_ setBordered:NO]; | |
| 399 [title_ setDrawsBackground:NO]; | |
| 400 [title_ setEditable:NO]; | |
| 401 [title_ setFont:font]; | 415 [title_ setFont:font]; |
| 402 [title_ setSelectable:NO]; | |
| 403 [title_ setStringValue: | 416 [title_ setStringValue: |
| 404 l10n_util::GetNSString(IDS_MESSAGE_CENTER_FOOTER_TITLE)]; | 417 l10n_util::GetNSString(IDS_MESSAGE_CENTER_FOOTER_TITLE)]; |
| 405 [title_ setTextColor:gfx::SkColorToCalibratedNSColor( | 418 [title_ setTextColor:gfx::SkColorToCalibratedNSColor( |
| 406 message_center::kRegularTextColor)]; | 419 message_center::kRegularTextColor)]; |
| 407 [title_ sizeToFit]; | 420 [title_ sizeToFit]; |
| 408 | 421 |
| 409 NSRect titleFrame = [title_ frame]; | 422 NSRect titleFrame = [title_ frame]; |
| 410 titleFrame.origin.x = message_center::kMarginBetweenItems; | 423 titleFrame.origin.x = message_center::kMarginBetweenItems; |
| 411 titleFrame.origin.y = kControlAreaHeight/2 - NSMidY(titleFrame); | 424 titleFrame.origin.y = kControlAreaHeight/2 - NSMidY(titleFrame); |
| 412 [title_ setFrame:titleFrame]; | 425 [title_ setFrame:titleFrame]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 438 [backButton_ setHidden:YES]; | 451 [backButton_ setHidden:YES]; |
| 439 [backButton_ setKeyEquivalent:@"\e"]; | 452 [backButton_ setKeyEquivalent:@"\e"]; |
| 440 [backButton_ setToolTip:l10n_util::GetNSString( | 453 [backButton_ setToolTip:l10n_util::GetNSString( |
| 441 IDS_MESSAGE_CENTER_SETTINGS_GO_BACK_BUTTON_TOOLTIP)]; | 454 IDS_MESSAGE_CENTER_SETTINGS_GO_BACK_BUTTON_TOOLTIP)]; |
| 442 [[backButton_ cell] | 455 [[backButton_ cell] |
| 443 accessibilitySetOverrideValue:[backButton_ toolTip] | 456 accessibilitySetOverrideValue:[backButton_ toolTip] |
| 444 forAttribute:NSAccessibilityDescriptionAttribute]; | 457 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 445 [[self view] addSubview:backButton_]; | 458 [[self view] addSubview:backButton_]; |
| 446 | 459 |
| 447 // Create the divider line between the control area and the notifications. | 460 // Create the divider line between the control area and the notifications. |
| 448 base::scoped_nsobject<NSBox> divider( | 461 divider_.reset( |
| 449 [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, NSWidth([view frame]), 1)]); | 462 [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, NSWidth([view frame]), 1)]); |
| 450 [divider setAutoresizingMask:NSViewMinYMargin]; | 463 [divider_ setAutoresizingMask:NSViewMinYMargin]; |
| 451 [divider setBorderType:NSNoBorder]; | 464 [divider_ setBorderType:NSNoBorder]; |
| 452 [divider setBoxType:NSBoxCustom]; | 465 [divider_ setBoxType:NSBoxCustom]; |
| 453 [divider setContentViewMargins:NSZeroSize]; | 466 [divider_ setContentViewMargins:NSZeroSize]; |
| 454 [divider setFillColor:gfx::SkColorToCalibratedNSColor( | 467 [divider_ setFillColor:gfx::SkColorToCalibratedNSColor( |
| 455 message_center::kFooterDelimiterColor)]; | 468 message_center::kFooterDelimiterColor)]; |
| 456 [divider setTitlePosition:NSNoTitle]; | 469 [divider_ setTitlePosition:NSNoTitle]; |
| 457 [view addSubview:divider]; | 470 [view addSubview:divider_]; |
| 471 |
| 458 | 472 |
| 459 auto getButtonFrame = ^NSRect(CGFloat maxX, NSImage* image) { | 473 auto getButtonFrame = ^NSRect(CGFloat maxX, NSImage* image) { |
| 460 NSSize size = [image size]; | 474 NSSize size = [image size]; |
| 461 return NSMakeRect( | 475 return NSMakeRect( |
| 462 maxX - size.width, | 476 maxX - size.width, |
| 463 kControlAreaHeight/2 - size.height/2, | 477 kControlAreaHeight/2 - size.height/2, |
| 464 size.width, | 478 size.width, |
| 465 size.height); | 479 size.height); |
| 466 }; | 480 }; |
| 467 | 481 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 [pauseButton_ setHoverImage: rb.GetNativeImageNamed( | 531 [pauseButton_ setHoverImage: rb.GetNativeImageNamed( |
| 518 IDR_NOTIFICATION_DO_NOT_DISTURB_HOVER).ToNSImage()]; | 532 IDR_NOTIFICATION_DO_NOT_DISTURB_HOVER).ToNSImage()]; |
| 519 [pauseButton_ setToolTip: | 533 [pauseButton_ setToolTip: |
| 520 l10n_util::GetNSString(IDS_MESSAGE_CENTER_QUIET_MODE_BUTTON_TOOLTIP)]; | 534 l10n_util::GetNSString(IDS_MESSAGE_CENTER_QUIET_MODE_BUTTON_TOOLTIP)]; |
| 521 [[pauseButton_ cell] | 535 [[pauseButton_ cell] |
| 522 accessibilitySetOverrideValue:[pauseButton_ toolTip] | 536 accessibilitySetOverrideValue:[pauseButton_ toolTip] |
| 523 forAttribute:NSAccessibilityDescriptionAttribute]; | 537 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 524 [pauseButton_ setAction:@selector(toggleQuietMode:)]; | 538 [pauseButton_ setAction:@selector(toggleQuietMode:)]; |
| 525 configureButton(pauseButton_); | 539 configureButton(pauseButton_); |
| 526 [view addSubview:pauseButton_]; | 540 [view addSubview:pauseButton_]; |
| 541 |
| 542 // Create the description field for the empty message center. Initially it is |
| 543 // invisible. |
| 544 emptyDescription_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); |
| 545 configureLabel(emptyDescription_); |
| 546 |
| 547 NSFont* smallFont = |
| 548 [NSFont labelFontOfSize:message_center::kEmptyCenterFontSize]; |
| 549 [emptyDescription_ setFont:smallFont]; |
| 550 [emptyDescription_ setStringValue: |
| 551 l10n_util::GetNSString(IDS_MESSAGE_CENTER_NO_MESSAGES)]; |
| 552 [emptyDescription_ setTextColor:gfx::SkColorToCalibratedNSColor( |
| 553 message_center::kDimTextColor)]; |
| 554 [emptyDescription_ sizeToFit]; |
| 555 [emptyDescription_ setHidden:YES]; |
| 556 |
| 557 [view addSubview:emptyDescription_]; |
| 527 } | 558 } |
| 528 | 559 |
| 529 - (void)updateTrayViewAndWindow { | 560 - (void)updateTrayViewAndWindow { |
| 530 CGFloat scrollContentHeight = 0; | 561 CGFloat scrollContentHeight = message_center::kMinScrollViewHeight; |
| 531 if ([notifications_ count]) { | 562 if ([notifications_ count]) { |
| 563 [emptyDescription_ setHidden:YES]; |
| 564 [scrollView_ setHidden:NO]; |
| 565 [divider_ setHidden:NO]; |
| 532 scrollContentHeight = NSMaxY([[[notifications_ lastObject] view] frame]) + | 566 scrollContentHeight = NSMaxY([[[notifications_ lastObject] view] frame]) + |
| 533 message_center::kMarginBetweenItems;; | 567 message_center::kMarginBetweenItems;; |
| 568 } else { |
| 569 [emptyDescription_ setHidden:NO]; |
| 570 [scrollView_ setHidden:YES]; |
| 571 [divider_ setHidden:YES]; |
| 572 |
| 573 NSRect centeredFrame = [emptyDescription_ frame]; |
| 574 NSPoint centeredOrigin = NSMakePoint( |
| 575 floor((NSWidth([[self view] frame]) - NSWidth(centeredFrame))/2 + 0.5), |
| 576 floor((scrollContentHeight - NSHeight(centeredFrame))/2 + 0.5)); |
| 577 |
| 578 centeredFrame.origin = centeredOrigin; |
| 579 [emptyDescription_ setFrame:centeredFrame]; |
| 534 } | 580 } |
| 535 | 581 |
| 536 // Resize the scroll view's content. | 582 // Resize the scroll view's content. |
| 537 NSRect scrollViewFrame = [scrollView_ frame]; | 583 NSRect scrollViewFrame = [scrollView_ frame]; |
| 538 NSRect documentFrame = [[scrollView_ documentView] frame]; | 584 NSRect documentFrame = [[scrollView_ documentView] frame]; |
| 539 documentFrame.size.width = NSWidth(scrollViewFrame); | 585 documentFrame.size.width = NSWidth(scrollViewFrame); |
| 540 documentFrame.size.height = scrollContentHeight; | 586 documentFrame.size.height = scrollContentHeight; |
| 541 [[scrollView_ documentView] setFrame:documentFrame]; | 587 [[scrollView_ documentView] setFrame:documentFrame]; |
| 542 | 588 |
| 543 // Resize the container view. | 589 // Resize the container view. |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 [pauseButton_ setDefaultImage: rb.GetNativeImageNamed( | 805 [pauseButton_ setDefaultImage: rb.GetNativeImageNamed( |
| 760 IDR_NOTIFICATION_DO_NOT_DISTURB_PRESSED).ToNSImage()]; | 806 IDR_NOTIFICATION_DO_NOT_DISTURB_PRESSED).ToNSImage()]; |
| 761 } else { | 807 } else { |
| 762 [pauseButton_ setTrackingEnabled:YES]; | 808 [pauseButton_ setTrackingEnabled:YES]; |
| 763 [pauseButton_ setDefaultImage: | 809 [pauseButton_ setDefaultImage: |
| 764 rb.GetNativeImageNamed(IDR_NOTIFICATION_DO_NOT_DISTURB).ToNSImage()]; | 810 rb.GetNativeImageNamed(IDR_NOTIFICATION_DO_NOT_DISTURB).ToNSImage()]; |
| 765 } | 811 } |
| 766 } | 812 } |
| 767 | 813 |
| 768 @end | 814 @end |
| OLD | NEW |