OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/message_center/views/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 284 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
285 // Don't create shadows for notification toasts on linux wih aura. | 285 // Don't create shadows for notification toasts on linux wih aura. |
286 if (top_level) | 286 if (top_level) |
287 return notification_view; | 287 return notification_view; |
288 #endif | 288 #endif |
289 | 289 |
290 notification_view->CreateShadowBorder(); | 290 notification_view->CreateShadowBorder(); |
291 return notification_view; | 291 return notification_view; |
292 } | 292 } |
293 | 293 |
| 294 void NotificationView::CreateOrUpdateViews(const Notification& notification) { |
| 295 CreateOrUpdateTitleView(notification); |
| 296 CreateOrUpdateMessageView(notification); |
| 297 CreateOrUpdateContextMessageView(notification); |
| 298 CreateOrUpdateProgressBarView(notification); |
| 299 CreateOrUpdateListItemViews(notification); |
| 300 CreateOrUpdateIconView(notification); |
| 301 CreateOrUpdateImageView(notification); |
| 302 CreateOrUpdateActionButtonViews(notification); |
| 303 } |
| 304 |
| 305 void NotificationView::SetAccessibleName(const Notification& notification) { |
| 306 std::vector<base::string16> accessible_lines; |
| 307 accessible_lines.push_back(notification.title()); |
| 308 accessible_lines.push_back(notification.message()); |
| 309 accessible_lines.push_back(notification.context_message()); |
| 310 std::vector<NotificationItem> items = notification.items(); |
| 311 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
| 312 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") + |
| 313 items[i].message); |
| 314 } |
| 315 set_accessible_name(JoinString(accessible_lines, '\n')); |
| 316 } |
| 317 |
294 NotificationView::NotificationView(MessageCenterController* controller, | 318 NotificationView::NotificationView(MessageCenterController* controller, |
295 const Notification& notification) | 319 const Notification& notification) |
296 : MessageView(this, | 320 : MessageView(this, |
297 notification.id(), | 321 notification.id(), |
298 notification.notifier_id(), | 322 notification.notifier_id(), |
299 notification.small_image().AsImageSkia(), | 323 notification.small_image().AsImageSkia(), |
300 notification.display_source()), | 324 notification.display_source()), |
301 controller_(controller), | 325 controller_(controller), |
302 clickable_(notification.clickable()) { | 326 clickable_(notification.clickable()), |
303 std::vector<base::string16> accessible_lines; | 327 top_view_(NULL), |
| 328 title_view_(NULL), |
| 329 message_view_(NULL), |
| 330 context_message_view_(NULL), |
| 331 icon_view_(NULL), |
| 332 bottom_view_(NULL), |
| 333 image_view_(NULL), |
| 334 progress_bar_view_(NULL) { |
304 // Create the top_view_, which collects into a vertical box all content | 335 // Create the top_view_, which collects into a vertical box all content |
305 // at the top of the notification (to the right of the icon) except for the | 336 // at the top of the notification (to the right of the icon) except for the |
306 // close button. | 337 // close button. |
307 top_view_ = new views::View(); | 338 top_view_ = new views::View(); |
308 top_view_->SetLayoutManager( | 339 top_view_->SetLayoutManager( |
309 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 340 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
310 top_view_->SetBorder( | 341 top_view_->SetBorder( |
311 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); | 342 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); |
312 | 343 AddChildView(top_view_); |
313 const gfx::FontList default_label_font_list = views::Label().font_list(); | |
314 | |
315 // Create the title view if appropriate. | |
316 title_view_ = NULL; | |
317 if (!notification.title().empty()) { | |
318 const gfx::FontList& font_list = | |
319 default_label_font_list.DeriveWithSizeDelta(2); | |
320 int padding = kTitleLineHeight - font_list.GetHeight(); | |
321 int title_character_limit = | |
322 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; | |
323 title_view_ = new BoundedLabel( | |
324 gfx::TruncateString(notification.title(), title_character_limit), | |
325 font_list); | |
326 title_view_->SetLineHeight(kTitleLineHeight); | |
327 title_view_->SetLineLimit(kMaxTitleLines); | |
328 title_view_->SetColors(message_center::kRegularTextColor, | |
329 kRegularTextBackgroundColor); | |
330 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); | |
331 top_view_->AddChildView(title_view_); | |
332 accessible_lines.push_back(notification.title()); | |
333 } | |
334 | |
335 // Create the message view if appropriate. | |
336 message_view_ = NULL; | |
337 if (!notification.message().empty()) { | |
338 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); | |
339 message_view_ = new BoundedLabel( | |
340 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); | |
341 message_view_->SetLineHeight(kMessageLineHeight); | |
342 message_view_->SetVisible(!notification.items().size()); | |
343 message_view_->SetColors(message_center::kRegularTextColor, | |
344 kDimTextBackgroundColor); | |
345 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | |
346 top_view_->AddChildView(message_view_); | |
347 accessible_lines.push_back(notification.message()); | |
348 } | |
349 | |
350 // Create the context message view if appropriate. | |
351 context_message_view_ = NULL; | |
352 if (!notification.context_message().empty()) { | |
353 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); | |
354 context_message_view_ = | |
355 new BoundedLabel(gfx::TruncateString(notification.context_message(), | |
356 kContextMessageCharacterLimit), | |
357 default_label_font_list); | |
358 context_message_view_->SetLineLimit( | |
359 message_center::kContextMessageLineLimit); | |
360 context_message_view_->SetLineHeight(kMessageLineHeight); | |
361 context_message_view_->SetColors(message_center::kDimTextColor, | |
362 kContextTextBackgroundColor); | |
363 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | |
364 top_view_->AddChildView(context_message_view_); | |
365 accessible_lines.push_back(notification.context_message()); | |
366 } | |
367 | |
368 // Create the progress bar view. | |
369 progress_bar_view_ = NULL; | |
370 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { | |
371 progress_bar_view_ = new NotificationProgressBar(); | |
372 progress_bar_view_->SetBorder(MakeProgressBarBorder( | |
373 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); | |
374 progress_bar_view_->SetValue(notification.progress() / 100.0); | |
375 top_view_->AddChildView(progress_bar_view_); | |
376 } | |
377 | |
378 // Create the list item views (up to a maximum). | |
379 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); | |
380 std::vector<NotificationItem> items = notification.items(); | |
381 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | |
382 ItemView* item_view = new ItemView(items[i]); | |
383 item_view->SetBorder(MakeTextBorder(padding, i ? 0 : 4, 0)); | |
384 item_views_.push_back(item_view); | |
385 top_view_->AddChildView(item_view); | |
386 accessible_lines.push_back( | |
387 items[i].title + base::ASCIIToUTF16(" ") + items[i].message); | |
388 } | |
389 | |
390 // Create the notification icon view. | |
391 gfx::ImageSkia icon = notification.icon().AsImageSkia(); | |
392 if (notification.type() == NOTIFICATION_TYPE_SIMPLE && | |
393 (icon.width() != kIconSize || | |
394 icon.height() != kIconSize || | |
395 HasAlpha(icon, GetWidget()))) { | |
396 views::ImageView* icon_view = new views::ImageView(); | |
397 icon_view->SetImage(icon); | |
398 icon_view->SetImageSize(gfx::Size(kLegacyIconSize, kLegacyIconSize)); | |
399 icon_view->SetHorizontalAlignment(views::ImageView::CENTER); | |
400 icon_view->SetVerticalAlignment(views::ImageView::CENTER); | |
401 icon_view_ = icon_view; | |
402 } else { | |
403 icon_view_ = | |
404 new ProportionalImageView(icon, gfx::Size(kIconSize, kIconSize)); | |
405 } | |
406 | |
407 icon_view_->set_background( | |
408 views::Background::CreateSolidBackground(kIconBackgroundColor)); | |
409 | |
410 // Create the bottom_view_, which collects into a vertical box all content | 344 // Create the bottom_view_, which collects into a vertical box all content |
411 // below the notification icon. | 345 // below the notification icon. |
412 bottom_view_ = new views::View(); | 346 bottom_view_ = new views::View(); |
413 bottom_view_->SetLayoutManager( | 347 bottom_view_->SetLayoutManager( |
414 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 348 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 349 AddChildView(bottom_view_); |
415 | 350 |
416 // Create the image view if appropriate. | 351 CreateOrUpdateViews(notification); |
417 image_view_ = NULL; | |
418 if (!notification.image().IsEmpty()) { | |
419 gfx::Size image_size( | |
420 kNotificationPreferredImageWidth, kNotificationPreferredImageHeight); | |
421 image_view_ = MakeNotificationImage(notification.image(), image_size); | |
422 bottom_view_->AddChildView(image_view_); | |
423 } | |
424 | |
425 // Create action buttons if appropriate. | |
426 std::vector<ButtonInfo> buttons = notification.buttons(); | |
427 for (size_t i = 0; i < buttons.size(); ++i) { | |
428 views::View* separator = new views::ImageView(); | |
429 separator->SetBorder(MakeSeparatorBorder(1, 0, kButtonSeparatorColor)); | |
430 bottom_view_->AddChildView(separator); | |
431 NotificationButton* button = new NotificationButton(this); | |
432 ButtonInfo button_info = buttons[i]; | |
433 button->SetTitle(button_info.title); | |
434 button->SetIcon(button_info.icon.AsImageSkia()); | |
435 action_buttons_.push_back(button); | |
436 bottom_view_->AddChildView(button); | |
437 } | |
438 | 352 |
439 // Put together the different content and control views. Layering those allows | 353 // Put together the different content and control views. Layering those allows |
440 // for proper layout logic and it also allows the close button and small | 354 // for proper layout logic and it also allows the close button and small |
441 // image to overlap the content as needed to provide large enough click and | 355 // image to overlap the content as needed to provide large enough click and |
442 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). | 356 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). |
443 AddChildView(top_view_); | |
444 AddChildView(icon_view_); | |
445 AddChildView(bottom_view_); | |
446 AddChildView(small_image()); | 357 AddChildView(small_image()); |
447 AddChildView(close_button()); | 358 AddChildView(close_button()); |
448 set_accessible_name(JoinString(accessible_lines, '\n')); | 359 SetAccessibleName(notification); |
449 } | 360 } |
450 | 361 |
451 NotificationView::~NotificationView() { | 362 NotificationView::~NotificationView() { |
452 } | 363 } |
453 | 364 |
454 gfx::Size NotificationView::GetPreferredSize() { | 365 gfx::Size NotificationView::GetPreferredSize() { |
455 int top_width = top_view_->GetPreferredSize().width(); | 366 int top_width = top_view_->GetPreferredSize().width() + |
| 367 icon_view_->GetPreferredSize().width(); |
456 int bottom_width = bottom_view_->GetPreferredSize().width(); | 368 int bottom_width = bottom_view_->GetPreferredSize().width(); |
457 int preferred_width = std::max(top_width, bottom_width) + GetInsets().width(); | 369 int preferred_width = std::max(top_width, bottom_width) + GetInsets().width(); |
458 return gfx::Size(preferred_width, GetHeightForWidth(preferred_width)); | 370 return gfx::Size(preferred_width, GetHeightForWidth(preferred_width)); |
459 } | 371 } |
460 | 372 |
461 int NotificationView::GetHeightForWidth(int width) { | 373 int NotificationView::GetHeightForWidth(int width) { |
462 // Get the height assuming no line limit changes. | 374 // Get the height assuming no line limit changes. |
463 int content_width = width - GetInsets().width(); | 375 int content_width = width - GetInsets().width(); |
464 int top_height = top_view_->GetHeightForWidth(content_width); | 376 int top_height = top_view_->GetHeightForWidth(content_width); |
465 int bottom_height = bottom_view_->GetHeightForWidth(content_width); | 377 int bottom_height = bottom_view_->GetHeightForWidth(content_width); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 return this; | 464 return this; |
553 } | 465 } |
554 | 466 |
555 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { | 467 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { |
556 if (!clickable_ || !controller_->HasClickedListener(notification_id())) | 468 if (!clickable_ || !controller_->HasClickedListener(notification_id())) |
557 return views::View::GetCursor(event); | 469 return views::View::GetCursor(event); |
558 | 470 |
559 return ui::kCursorHand; | 471 return ui::kCursorHand; |
560 } | 472 } |
561 | 473 |
| 474 void NotificationView::UpdateWithNotification( |
| 475 const Notification& notification) { |
| 476 MessageView::UpdateWithNotification(notification); |
| 477 |
| 478 CreateOrUpdateViews(notification); |
| 479 SetAccessibleName(notification); |
| 480 Layout(); |
| 481 SchedulePaint(); |
| 482 } |
| 483 |
562 void NotificationView::ButtonPressed(views::Button* sender, | 484 void NotificationView::ButtonPressed(views::Button* sender, |
563 const ui::Event& event) { | 485 const ui::Event& event) { |
564 // Certain operations can cause |this| to be destructed, so copy the members | 486 // Certain operations can cause |this| to be destructed, so copy the members |
565 // we send to other parts of the code. | 487 // we send to other parts of the code. |
566 // TODO(dewittj): Remove this hack. | 488 // TODO(dewittj): Remove this hack. |
567 std::string id(notification_id()); | 489 std::string id(notification_id()); |
568 // See if the button pressed was an action button. | 490 // See if the button pressed was an action button. |
569 for (size_t i = 0; i < action_buttons_.size(); ++i) { | 491 for (size_t i = 0; i < action_buttons_.size(); ++i) { |
570 if (sender == action_buttons_[i]) { | 492 if (sender == action_buttons_[i]) { |
571 controller_->ClickOnNotificationButton(id, i); | 493 controller_->ClickOnNotificationButton(id, i); |
572 return; | 494 return; |
573 } | 495 } |
574 } | 496 } |
575 | 497 |
576 // Let the superclass handled anything other than action buttons. | 498 // Let the superclass handled anything other than action buttons. |
577 // Warning: This may cause the NotificationView itself to be deleted, | 499 // Warning: This may cause the NotificationView itself to be deleted, |
578 // so don't do anything afterwards. | 500 // so don't do anything afterwards. |
579 MessageView::ButtonPressed(sender, event); | 501 MessageView::ButtonPressed(sender, event); |
580 } | 502 } |
581 | 503 |
582 void NotificationView::ClickOnNotification(const std::string& notification_id) { | 504 void NotificationView::ClickOnNotification(const std::string& notification_id) { |
583 controller_->ClickOnNotification(notification_id); | 505 controller_->ClickOnNotification(notification_id); |
584 } | 506 } |
585 | 507 |
586 void NotificationView::RemoveNotification(const std::string& notification_id, | 508 void NotificationView::RemoveNotification(const std::string& notification_id, |
587 bool by_user) { | 509 bool by_user) { |
588 controller_->RemoveNotification(notification_id, by_user); | 510 controller_->RemoveNotification(notification_id, by_user); |
589 } | 511 } |
590 | 512 |
| 513 void NotificationView::CreateOrUpdateTitleView( |
| 514 const Notification& notification) { |
| 515 if (notification.title().empty()) { |
| 516 if (title_view_) { |
| 517 // Deletion will also remove |title_view_| from its parent. |
| 518 delete title_view_; |
| 519 title_view_ = NULL; |
| 520 } |
| 521 return; |
| 522 } |
| 523 |
| 524 DCHECK(top_view_ != NULL); |
| 525 |
| 526 const gfx::FontList& font_list = |
| 527 views::Label().font_list().DeriveWithSizeDelta(2); |
| 528 |
| 529 int title_character_limit = |
| 530 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; |
| 531 |
| 532 if (!title_view_) { |
| 533 int padding = kTitleLineHeight - font_list.GetHeight(); |
| 534 |
| 535 title_view_ = new BoundedLabel( |
| 536 gfx::TruncateString(notification.title(), title_character_limit), |
| 537 font_list); |
| 538 title_view_->SetLineHeight(kTitleLineHeight); |
| 539 title_view_->SetLineLimit(kMaxTitleLines); |
| 540 title_view_->SetColors(message_center::kRegularTextColor, |
| 541 kRegularTextBackgroundColor); |
| 542 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); |
| 543 top_view_->AddChildView(title_view_); |
| 544 } else { |
| 545 title_view_->SetText( |
| 546 gfx::TruncateString(notification.title(), title_character_limit)); |
| 547 } |
| 548 } |
| 549 |
| 550 void NotificationView::CreateOrUpdateMessageView( |
| 551 const Notification& notification) { |
| 552 if (notification.message().empty()) { |
| 553 if (message_view_) { |
| 554 // Deletion will also remove |message_view_| from its parent. |
| 555 delete message_view_; |
| 556 message_view_ = NULL; |
| 557 } |
| 558 return; |
| 559 } |
| 560 |
| 561 DCHECK(top_view_ != NULL); |
| 562 |
| 563 if (!message_view_) { |
| 564 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
| 565 message_view_ = new BoundedLabel( |
| 566 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); |
| 567 message_view_->SetLineHeight(kMessageLineHeight); |
| 568 message_view_->SetColors(message_center::kRegularTextColor, |
| 569 kDimTextBackgroundColor); |
| 570 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
| 571 top_view_->AddChildView(message_view_); |
| 572 } else { |
| 573 message_view_->SetText( |
| 574 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); |
| 575 } |
| 576 |
| 577 message_view_->SetVisible(!notification.items().size()); |
| 578 } |
| 579 |
| 580 void NotificationView::CreateOrUpdateContextMessageView( |
| 581 const Notification& notification) { |
| 582 if (notification.context_message().empty()) { |
| 583 if (context_message_view_) { |
| 584 // Deletion will also remove |context_message_view_| from its parent. |
| 585 delete context_message_view_; |
| 586 context_message_view_ = NULL; |
| 587 } |
| 588 return; |
| 589 } |
| 590 |
| 591 DCHECK(top_view_ != NULL); |
| 592 |
| 593 if (!context_message_view_) { |
| 594 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
| 595 context_message_view_ = new BoundedLabel(gfx::TruncateString( |
| 596 notification.context_message(), kContextMessageCharacterLimit)); |
| 597 context_message_view_->SetLineLimit( |
| 598 message_center::kContextMessageLineLimit); |
| 599 context_message_view_->SetLineHeight(kMessageLineHeight); |
| 600 context_message_view_->SetColors(message_center::kDimTextColor, |
| 601 kContextTextBackgroundColor); |
| 602 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
| 603 top_view_->AddChildView(context_message_view_); |
| 604 } else { |
| 605 context_message_view_->SetText(gfx::TruncateString( |
| 606 notification.context_message(), kContextMessageCharacterLimit)); |
| 607 } |
| 608 } |
| 609 |
| 610 void NotificationView::CreateOrUpdateProgressBarView( |
| 611 const Notification& notification) { |
| 612 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
| 613 if (progress_bar_view_) { |
| 614 // Deletion will also remove |progress_bar_view_| from its parent. |
| 615 delete progress_bar_view_; |
| 616 progress_bar_view_ = NULL; |
| 617 } |
| 618 return; |
| 619 } |
| 620 |
| 621 DCHECK(top_view_ != NULL); |
| 622 |
| 623 if (!progress_bar_view_) { |
| 624 progress_bar_view_ = new NotificationProgressBar(); |
| 625 progress_bar_view_->SetBorder(MakeProgressBarBorder( |
| 626 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); |
| 627 top_view_->AddChildView(progress_bar_view_); |
| 628 } |
| 629 |
| 630 progress_bar_view_->SetValue(notification.progress() / 100.0); |
| 631 progress_bar_view_->SetVisible(!notification.items().size()); |
| 632 } |
| 633 |
| 634 void NotificationView::CreateOrUpdateListItemViews( |
| 635 const Notification& notification) { |
| 636 for (size_t i = 0; i < item_views_.size(); ++i) |
| 637 delete item_views_[i]; |
| 638 item_views_.clear(); |
| 639 |
| 640 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
| 641 std::vector<NotificationItem> items = notification.items(); |
| 642 |
| 643 if (items.size() == 0) |
| 644 return; |
| 645 |
| 646 DCHECK(top_view_); |
| 647 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
| 648 ItemView* item_view = new ItemView(items[i]); |
| 649 item_view->SetBorder(MakeTextBorder(padding, i ? 0 : 4, 0)); |
| 650 item_views_.push_back(item_view); |
| 651 top_view_->AddChildView(item_view); |
| 652 } |
| 653 } |
| 654 |
| 655 void NotificationView::CreateOrUpdateIconView( |
| 656 const Notification& notification) { |
| 657 if (icon_view_) { |
| 658 delete icon_view_; |
| 659 icon_view_ = NULL; |
| 660 } |
| 661 |
| 662 // TODO(dewittj): Detect a compatible update and use the existing icon view. |
| 663 gfx::ImageSkia icon = notification.icon().AsImageSkia(); |
| 664 if (notification.type() == NOTIFICATION_TYPE_SIMPLE && |
| 665 (icon.width() != kIconSize || icon.height() != kIconSize || |
| 666 HasAlpha(icon, GetWidget()))) { |
| 667 views::ImageView* icon_view = new views::ImageView(); |
| 668 icon_view->SetImage(icon); |
| 669 icon_view->SetImageSize(gfx::Size(kLegacyIconSize, kLegacyIconSize)); |
| 670 icon_view->SetHorizontalAlignment(views::ImageView::CENTER); |
| 671 icon_view->SetVerticalAlignment(views::ImageView::CENTER); |
| 672 icon_view_ = icon_view; |
| 673 } else { |
| 674 icon_view_ = |
| 675 new ProportionalImageView(icon, gfx::Size(kIconSize, kIconSize)); |
| 676 } |
| 677 |
| 678 icon_view_->set_background( |
| 679 views::Background::CreateSolidBackground(kIconBackgroundColor)); |
| 680 |
| 681 AddChildView(icon_view_); |
| 682 } |
| 683 |
| 684 void NotificationView::CreateOrUpdateImageView( |
| 685 const Notification& notification) { |
| 686 if (image_view_) { |
| 687 delete image_view_; |
| 688 image_view_ = NULL; |
| 689 } |
| 690 |
| 691 DCHECK(bottom_view_); |
| 692 DCHECK_EQ(this, bottom_view_->parent()); |
| 693 |
| 694 // TODO(dewittj): Detect a compatible update and use the existing image view. |
| 695 if (!notification.image().IsEmpty()) { |
| 696 gfx::Size image_size(kNotificationPreferredImageWidth, |
| 697 kNotificationPreferredImageHeight); |
| 698 image_view_ = MakeNotificationImage(notification.image(), image_size); |
| 699 bottom_view_->AddChildView(image_view_); |
| 700 } |
| 701 } |
| 702 |
| 703 void NotificationView::CreateOrUpdateActionButtonViews( |
| 704 const Notification& notification) { |
| 705 for (size_t i = 0; i < separators_.size(); ++i) |
| 706 delete separators_[i]; |
| 707 separators_.clear(); |
| 708 |
| 709 for (size_t i = 0; i < action_buttons_.size(); ++i) |
| 710 delete action_buttons_[i]; |
| 711 action_buttons_.clear(); |
| 712 |
| 713 DCHECK(bottom_view_); |
| 714 DCHECK_EQ(this, bottom_view_->parent()); |
| 715 |
| 716 std::vector<ButtonInfo> buttons = notification.buttons(); |
| 717 for (size_t i = 0; i < buttons.size(); ++i) { |
| 718 views::View* separator = new views::ImageView(); |
| 719 separator->SetBorder(MakeSeparatorBorder(1, 0, kButtonSeparatorColor)); |
| 720 separators_.push_back(separator); |
| 721 bottom_view_->AddChildView(separator); |
| 722 NotificationButton* button = new NotificationButton(this); |
| 723 ButtonInfo button_info = buttons[i]; |
| 724 button->SetTitle(button_info.title); |
| 725 button->SetIcon(button_info.icon.AsImageSkia()); |
| 726 action_buttons_.push_back(button); |
| 727 bottom_view_->AddChildView(button); |
| 728 } |
| 729 } |
| 730 |
591 int NotificationView::GetMessageLineLimit(int title_lines, int width) { | 731 int NotificationView::GetMessageLineLimit(int title_lines, int width) { |
592 // Image notifications require that the image must be kept flush against | 732 // Image notifications require that the image must be kept flush against |
593 // their icons, but we can allow more text if no image. | 733 // their icons, but we can allow more text if no image. |
594 int effective_title_lines = std::max(0, title_lines - 1); | 734 int effective_title_lines = std::max(0, title_lines - 1); |
595 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; | 735 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; |
596 if (!image_view_) { | 736 if (!image_view_) { |
597 // Title lines are counted as twice as big as message lines for the purpose | 737 // Title lines are counted as twice as big as message lines for the purpose |
598 // of this calculation. | 738 // of this calculation. |
599 // The effect from the title reduction here should be: | 739 // The effect from the title reduction here should be: |
600 // * 0 title lines: 5 max lines message. | 740 // * 0 title lines: 5 max lines message. |
(...skipping 22 matching lines...) Expand all Loading... |
623 | 763 |
624 return message_line_limit; | 764 return message_line_limit; |
625 } | 765 } |
626 | 766 |
627 int NotificationView::GetMessageHeight(int width, int limit) { | 767 int NotificationView::GetMessageHeight(int width, int limit) { |
628 return message_view_ ? | 768 return message_view_ ? |
629 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 769 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
630 } | 770 } |
631 | 771 |
632 } // namespace message_center | 772 } // namespace message_center |
OLD | NEW |