| 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/message_view.h" | 5 #include "ui/message_center/views/message_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 7 #include "ui/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_view_state.h" |
| 8 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 9 #include "ui/base/models/simple_menu_model.h" | 10 #include "ui/base/models/simple_menu_model.h" |
| 10 #include "ui/compositor/scoped_layer_animation_settings.h" | 11 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 11 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/shadow_value.h" | 13 #include "ui/gfx/shadow_value.h" |
| 13 #include "ui/message_center/message_center.h" | 14 #include "ui/message_center/message_center.h" |
| 14 #include "ui/message_center/message_center_style.h" | 15 #include "ui/message_center/message_center_style.h" |
| 15 #include "ui/message_center/views/message_center_controller.h" | 16 #include "ui/message_center/views/message_center_controller.h" |
| 16 #include "ui/message_center/views/padded_button.h" | 17 #include "ui/message_center/views/padded_button.h" |
| 17 #include "ui/resources/grit/ui_resources.h" | 18 #include "ui/resources/grit/ui_resources.h" |
| 18 #include "ui/strings/grit/ui_strings.h" | 19 #include "ui/strings/grit/ui_strings.h" |
| 19 #include "ui/views/background.h" | 20 #include "ui/views/background.h" |
| 20 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
| 21 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
| 22 #include "ui/views/controls/scroll_view.h" | 23 #include "ui/views/controls/scroll_view.h" |
| 23 #include "ui/views/focus/focus_manager.h" | 24 #include "ui/views/focus/focus_manager.h" |
| 24 #include "ui/views/painter.h" | 25 #include "ui/views/painter.h" |
| 25 #include "ui/views/shadow_border.h" | 26 #include "ui/views/shadow_border.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 constexpr int kCloseIconTopPadding = 5; | 30 constexpr int kCloseIconTopPadding = 5; |
| 30 constexpr int kCloseIconRightPadding = 5; | 31 constexpr int kCloseIconRightPadding = 5; |
| 31 | 32 |
| 32 constexpr int kShadowOffset = 1; | 33 constexpr int kShadowOffset = 1; |
| 33 constexpr int kShadowBlur = 4; | 34 constexpr int kShadowBlur = 4; |
| 34 | 35 |
| 36 // Creates a text for spoken feedback from the data contained in the |
| 37 // notification. |
| 38 base::string16 CreateAccessibleName( |
| 39 const message_center::Notification& notification) { |
| 40 if (!notification.accessible_name().empty()) |
| 41 return notification.accessible_name(); |
| 42 |
| 43 // Fall back to a text constructed from the notification. |
| 44 std::vector<base::string16> accessible_lines = { |
| 45 notification.title(), notification.message(), |
| 46 notification.context_message()}; |
| 47 std::vector<message_center::NotificationItem> items = notification.items(); |
| 48 for (size_t i = 0; |
| 49 i < items.size() && i < message_center::kNotificationMaximumItems; |
| 50 ++i) { |
| 51 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") + |
| 52 items[i].message); |
| 53 } |
| 54 return base::JoinString(accessible_lines, base::ASCIIToUTF16("\n")); |
| 55 } |
| 56 |
| 35 } // namespace | 57 } // namespace |
| 36 | 58 |
| 37 namespace message_center { | 59 namespace message_center { |
| 38 | 60 |
| 39 MessageView::MessageView(MessageCenterController* controller, | 61 MessageView::MessageView(MessageCenterController* controller, |
| 40 const Notification& notification) | 62 const Notification& notification) |
| 41 : controller_(controller), | 63 : controller_(controller), |
| 42 notification_id_(notification.id()), | 64 notification_id_(notification.id()), |
| 43 notifier_id_(notification.notifier_id()), | 65 notifier_id_(notification.notifier_id()), |
| 44 display_source_(notification.display_source()) { | 66 display_source_(notification.display_source()) { |
| 45 SetFocusBehavior(FocusBehavior::ALWAYS); | 67 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 46 | 68 |
| 47 // Create the opaque background that's above the view's shadow. | 69 // Create the opaque background that's above the view's shadow. |
| 48 background_view_ = new views::View(); | 70 background_view_ = new views::View(); |
| 49 background_view_->set_background( | 71 background_view_->set_background( |
| 50 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); | 72 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); |
| 51 AddChildView(background_view_); | 73 AddChildView(background_view_); |
| 52 | 74 |
| 53 views::ImageView* small_image_view = new views::ImageView(); | 75 views::ImageView* small_image_view = new views::ImageView(); |
| 54 small_image_view->SetImage(notification.small_image().AsImageSkia()); | 76 small_image_view->SetImage(notification.small_image().AsImageSkia()); |
| 55 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); | 77 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); |
| 56 // The small image view should be added to view hierarchy by the derived | 78 // The small image view should be added to view hierarchy by the derived |
| 57 // class. This ensures that it is on top of other views. | 79 // class. This ensures that it is on top of other views. |
| 58 small_image_view->set_owned_by_client(); | 80 small_image_view->set_owned_by_client(); |
| 59 small_image_view_.reset(small_image_view); | 81 small_image_view_.reset(small_image_view); |
| 60 | 82 |
| 61 focus_painter_ = views::Painter::CreateSolidFocusPainter( | 83 focus_painter_ = views::Painter::CreateSolidFocusPainter( |
| 62 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); | 84 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); |
| 85 |
| 86 accessible_name_ = CreateAccessibleName(notification); |
| 63 } | 87 } |
| 64 | 88 |
| 65 MessageView::~MessageView() { | 89 MessageView::~MessageView() { |
| 66 } | 90 } |
| 67 | 91 |
| 68 void MessageView::UpdateWithNotification(const Notification& notification) { | 92 void MessageView::UpdateWithNotification(const Notification& notification) { |
| 69 small_image_view_->SetImage(notification.small_image().AsImageSkia()); | 93 small_image_view_->SetImage(notification.small_image().AsImageSkia()); |
| 70 display_source_ = notification.display_source(); | 94 display_source_ = notification.display_source(); |
| 71 CreateOrUpdateCloseButtonView(notification); | 95 CreateOrUpdateCloseButtonView(notification); |
| 96 accessible_name_ = CreateAccessibleName(notification); |
| 72 } | 97 } |
| 73 | 98 |
| 74 // static | 99 // static |
| 75 gfx::Insets MessageView::GetShadowInsets() { | 100 gfx::Insets MessageView::GetShadowInsets() { |
| 76 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, | 101 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, |
| 77 kShadowBlur / 2, | 102 kShadowBlur / 2, |
| 78 kShadowBlur / 2 + kShadowOffset, | 103 kShadowBlur / 2 + kShadowOffset, |
| 79 kShadowBlur / 2); | 104 kShadowBlur / 2); |
| 80 } | 105 } |
| 81 | 106 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 279 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
| 255 close->set_owned_by_client(); | 280 close->set_owned_by_client(); |
| 256 AddChildView(close); | 281 AddChildView(close); |
| 257 close_button_.reset(close); | 282 close_button_.reset(close); |
| 258 } else if (notification.pinned() && close_button_) { | 283 } else if (notification.pinned() && close_button_) { |
| 259 close_button_.reset(); | 284 close_button_.reset(); |
| 260 } | 285 } |
| 261 } | 286 } |
| 262 | 287 |
| 263 } // namespace message_center | 288 } // namespace message_center |
| OLD | NEW |