| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 views::View::ScrollRectToVisible(GetLocalBounds()); | 338 views::View::ScrollRectToVisible(GetLocalBounds()); |
| 339 } | 339 } |
| 340 | 340 |
| 341 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { | 341 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { |
| 342 if (!clickable_ || !controller()->HasClickedListener(notification_id())) | 342 if (!clickable_ || !controller()->HasClickedListener(notification_id())) |
| 343 return views::View::GetCursor(event); | 343 return views::View::GetCursor(event); |
| 344 | 344 |
| 345 return views::GetNativeHandCursor(); | 345 return views::GetNativeHandCursor(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void NotificationView::OnMouseEntered(const ui::MouseEvent& event) { |
| 349 MessageView::OnMouseEntered(event); |
| 350 UpdateControlButtonsVisibility(); |
| 351 } |
| 352 |
| 353 void NotificationView::OnMouseExited(const ui::MouseEvent& event) { |
| 354 MessageView::OnMouseExited(event); |
| 355 UpdateControlButtonsVisibility(); |
| 356 } |
| 357 |
| 348 void NotificationView::UpdateWithNotification( | 358 void NotificationView::UpdateWithNotification( |
| 349 const Notification& notification) { | 359 const Notification& notification) { |
| 350 MessageView::UpdateWithNotification(notification); | 360 MessageView::UpdateWithNotification(notification); |
| 351 | 361 |
| 352 CreateOrUpdateViews(notification); | 362 CreateOrUpdateViews(notification); |
| 353 CreateOrUpdateCloseButtonView(notification); | 363 CreateOrUpdateCloseButtonView(notification); |
| 354 Layout(); | 364 Layout(); |
| 355 SchedulePaint(); | 365 SchedulePaint(); |
| 356 } | 366 } |
| 357 | 367 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 notification.delegate()->ShouldDisplaySettingsButton()) { | 528 notification.delegate()->ShouldDisplaySettingsButton()) { |
| 519 PaddedButton* settings = new PaddedButton(this); | 529 PaddedButton* settings = new PaddedButton(this); |
| 520 settings->SetImage(views::Button::STATE_NORMAL, GetSettingsIcon()); | 530 settings->SetImage(views::Button::STATE_NORMAL, GetSettingsIcon()); |
| 521 settings->SetAccessibleName(l10n_util::GetStringUTF16( | 531 settings->SetAccessibleName(l10n_util::GetStringUTF16( |
| 522 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | 532 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
| 523 settings->SetTooltipText(l10n_util::GetStringUTF16( | 533 settings->SetTooltipText(l10n_util::GetStringUTF16( |
| 524 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | 534 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
| 525 settings_button_view_ = settings; | 535 settings_button_view_ = settings; |
| 526 AddChildView(settings_button_view_); | 536 AddChildView(settings_button_view_); |
| 527 } | 537 } |
| 538 UpdateControlButtonsVisibility(); |
| 528 } | 539 } |
| 529 | 540 |
| 530 void NotificationView::CreateOrUpdateProgressBarView( | 541 void NotificationView::CreateOrUpdateProgressBarView( |
| 531 const Notification& notification) { | 542 const Notification& notification) { |
| 532 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 543 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
| 533 // Deletion will also remove |progress_bar_view_| from its parent. | 544 // Deletion will also remove |progress_bar_view_| from its parent. |
| 534 delete progress_bar_view_; | 545 delete progress_bar_view_; |
| 535 progress_bar_view_ = nullptr; | 546 progress_bar_view_ = nullptr; |
| 536 return; | 547 return; |
| 537 } | 548 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 const Notification& notification) { | 693 const Notification& notification) { |
| 683 if (!notification.pinned() && !close_button_) { | 694 if (!notification.pinned() && !close_button_) { |
| 684 close_button_ = base::MakeUnique<PaddedButton>(this); | 695 close_button_ = base::MakeUnique<PaddedButton>(this); |
| 685 close_button_->SetImage(views::Button::STATE_NORMAL, GetCloseIcon()); | 696 close_button_->SetImage(views::Button::STATE_NORMAL, GetCloseIcon()); |
| 686 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( | 697 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
| 687 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 698 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
| 688 close_button_->SetTooltipText(l10n_util::GetStringUTF16( | 699 close_button_->SetTooltipText(l10n_util::GetStringUTF16( |
| 689 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); | 700 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); |
| 690 close_button_->set_owned_by_client(); | 701 close_button_->set_owned_by_client(); |
| 691 AddChildView(close_button_.get()); | 702 AddChildView(close_button_.get()); |
| 703 UpdateControlButtonsVisibility(); |
| 692 } else if (notification.pinned() && close_button_) { | 704 } else if (notification.pinned() && close_button_) { |
| 693 close_button_.reset(); | 705 close_button_.reset(); |
| 694 } | 706 } |
| 695 } | 707 } |
| 696 | 708 |
| 709 void NotificationView::UpdateControlButtonsVisibility() { |
| 710 const bool target_visibility = |
| 711 IsMouseHovered() || HasFocus() || |
| 712 (close_button_ && close_button_->HasFocus()) || |
| 713 (settings_button_view_ && settings_button_view_->HasFocus()); |
| 714 |
| 715 if (close_button_) { |
| 716 if (target_visibility != close_button_->visible()) |
| 717 close_button_->SetVisible(target_visibility); |
| 718 } |
| 719 |
| 720 if (settings_button_view_) { |
| 721 if (target_visibility != settings_button_view_->visible()) |
| 722 settings_button_view_->SetVisible(target_visibility); |
| 723 } |
| 724 } |
| 725 |
| 697 int NotificationView::GetMessageLineLimit(int title_lines, int width) const { | 726 int NotificationView::GetMessageLineLimit(int title_lines, int width) const { |
| 698 // Image notifications require that the image must be kept flush against | 727 // Image notifications require that the image must be kept flush against |
| 699 // their icons, but we can allow more text if no image. | 728 // their icons, but we can allow more text if no image. |
| 700 int effective_title_lines = std::max(0, title_lines - 1); | 729 int effective_title_lines = std::max(0, title_lines - 1); |
| 701 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; | 730 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; |
| 702 if (!image_view_) { | 731 if (!image_view_) { |
| 703 // Title lines are counted as twice as big as message lines for the purpose | 732 // Title lines are counted as twice as big as message lines for the purpose |
| 704 // of this calculation. | 733 // of this calculation. |
| 705 // The effect from the title reduction here should be: | 734 // The effect from the title reduction here should be: |
| 706 // * 0 title lines: 5 max lines message. | 735 // * 0 title lines: 5 max lines message. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 729 | 758 |
| 730 return message_line_limit; | 759 return message_line_limit; |
| 731 } | 760 } |
| 732 | 761 |
| 733 int NotificationView::GetMessageHeight(int width, int limit) const { | 762 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 734 return message_view_ ? | 763 return message_view_ ? |
| 735 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 764 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 736 } | 765 } |
| 737 | 766 |
| 738 } // namespace message_center | 767 } // namespace message_center |
| OLD | NEW |