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