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 | |
37 // in the notification. | |
yoshiki
2016/09/07 08:57:46
nit: could you move "in the" to the first line in
yhanada
2016/09/07 09:08:03
Done.
| |
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 accessible_lines.push_back(notification.title()); | |
46 accessible_lines.push_back(notification.message()); | |
47 accessible_lines.push_back(notification.context_message()); | |
48 std::vector<message_center::NotificationItem> items = notification.items(); | |
49 for (size_t i = 0; | |
50 i < items.size() && i < message_center::kNotificationMaximumItems; | |
51 ++i) { | |
52 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") + | |
53 items[i].message); | |
54 } | |
55 return base::JoinString(accessible_lines, base::ASCIIToUTF16("\n")); | |
56 } | |
57 | |
35 } // namespace | 58 } // namespace |
36 | 59 |
37 namespace message_center { | 60 namespace message_center { |
38 | 61 |
39 MessageView::MessageView(MessageCenterController* controller, | 62 MessageView::MessageView(MessageCenterController* controller, |
40 const Notification& notification) | 63 const Notification& notification) |
41 : controller_(controller), | 64 : controller_(controller), |
42 notification_id_(notification.id()), | 65 notification_id_(notification.id()), |
43 notifier_id_(notification.notifier_id()), | 66 notifier_id_(notification.notifier_id()), |
44 display_source_(notification.display_source()) { | 67 display_source_(notification.display_source()) { |
45 SetFocusBehavior(FocusBehavior::ALWAYS); | 68 SetFocusBehavior(FocusBehavior::ALWAYS); |
46 | 69 |
47 // Create the opaque background that's above the view's shadow. | 70 // Create the opaque background that's above the view's shadow. |
48 background_view_ = new views::View(); | 71 background_view_ = new views::View(); |
49 background_view_->set_background( | 72 background_view_->set_background( |
50 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); | 73 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); |
51 AddChildView(background_view_); | 74 AddChildView(background_view_); |
52 | 75 |
53 views::ImageView* small_image_view = new views::ImageView(); | 76 views::ImageView* small_image_view = new views::ImageView(); |
54 small_image_view->SetImage(notification.small_image().AsImageSkia()); | 77 small_image_view->SetImage(notification.small_image().AsImageSkia()); |
55 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); | 78 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); |
56 // The small image view should be added to view hierarchy by the derived | 79 // 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. | 80 // class. This ensures that it is on top of other views. |
58 small_image_view->set_owned_by_client(); | 81 small_image_view->set_owned_by_client(); |
59 small_image_view_.reset(small_image_view); | 82 small_image_view_.reset(small_image_view); |
60 | 83 |
61 focus_painter_ = views::Painter::CreateSolidFocusPainter( | 84 focus_painter_ = views::Painter::CreateSolidFocusPainter( |
62 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); | 85 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); |
86 | |
87 accessible_name_ = CreateAccessibleName(notification); | |
63 } | 88 } |
64 | 89 |
65 MessageView::~MessageView() { | 90 MessageView::~MessageView() { |
66 } | 91 } |
67 | 92 |
68 void MessageView::UpdateWithNotification(const Notification& notification) { | 93 void MessageView::UpdateWithNotification(const Notification& notification) { |
69 small_image_view_->SetImage(notification.small_image().AsImageSkia()); | 94 small_image_view_->SetImage(notification.small_image().AsImageSkia()); |
70 display_source_ = notification.display_source(); | 95 display_source_ = notification.display_source(); |
71 CreateOrUpdateCloseButtonView(notification); | 96 CreateOrUpdateCloseButtonView(notification); |
97 accessible_name_ = CreateAccessibleName(notification); | |
72 } | 98 } |
73 | 99 |
74 // static | 100 // static |
75 gfx::Insets MessageView::GetShadowInsets() { | 101 gfx::Insets MessageView::GetShadowInsets() { |
76 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, | 102 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, |
77 kShadowBlur / 2, | 103 kShadowBlur / 2, |
78 kShadowBlur / 2 + kShadowOffset, | 104 kShadowBlur / 2 + kShadowOffset, |
79 kShadowBlur / 2); | 105 kShadowBlur / 2); |
80 } | 106 } |
81 | 107 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 280 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
255 close->set_owned_by_client(); | 281 close->set_owned_by_client(); |
256 AddChildView(close); | 282 AddChildView(close); |
257 close_button_.reset(close); | 283 close_button_.reset(close); |
258 } else if (notification.pinned() && close_button_) { | 284 } else if (notification.pinned() && close_button_) { |
259 close_button_.reset(); | 285 close_button_.reset(); |
260 } | 286 } |
261 } | 287 } |
262 | 288 |
263 } // namespace message_center | 289 } // namespace message_center |
OLD | NEW |