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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | |
14 #include "build/build_config.h" | 13 #include "build/build_config.h" |
15 #include "components/url_formatter/elide_url.h" | 14 #include "components/url_formatter/elide_url.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
17 #include "third_party/skia/include/core/SkPath.h" | 16 #include "third_party/skia/include/core/SkPath.h" |
18 #include "ui/base/cursor/cursor.h" | 17 #include "ui/base/cursor/cursor.h" |
19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/layout.h" | 19 #include "ui/base/layout.h" |
21 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
23 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 CreateOrUpdateMessageView(notification); | 174 CreateOrUpdateMessageView(notification); |
176 CreateOrUpdateProgressBarView(notification); | 175 CreateOrUpdateProgressBarView(notification); |
177 CreateOrUpdateListItemViews(notification); | 176 CreateOrUpdateListItemViews(notification); |
178 CreateOrUpdateIconView(notification); | 177 CreateOrUpdateIconView(notification); |
179 CreateOrUpdateImageView(notification); | 178 CreateOrUpdateImageView(notification); |
180 CreateOrUpdateContextMessageView(notification); | 179 CreateOrUpdateContextMessageView(notification); |
181 CreateOrUpdateSettingsButtonView(notification); | 180 CreateOrUpdateSettingsButtonView(notification); |
182 CreateOrUpdateActionButtonViews(notification); | 181 CreateOrUpdateActionButtonViews(notification); |
183 } | 182 } |
184 | 183 |
185 void NotificationView::SetAccessibleName(const Notification& notification) { | |
186 std::vector<base::string16> accessible_lines; | |
187 accessible_lines.push_back(notification.title()); | |
188 accessible_lines.push_back(notification.message()); | |
189 accessible_lines.push_back(notification.context_message()); | |
190 std::vector<NotificationItem> items = notification.items(); | |
191 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | |
192 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") + | |
193 items[i].message); | |
194 } | |
195 set_accessible_name( | |
196 base::JoinString(accessible_lines, base::ASCIIToUTF16("\n"))); | |
197 } | |
198 | |
199 NotificationView::NotificationView(MessageCenterController* controller, | 184 NotificationView::NotificationView(MessageCenterController* controller, |
200 const Notification& notification) | 185 const Notification& notification) |
201 : MessageView(controller, notification), | 186 : MessageView(controller, notification), |
202 clickable_(notification.clickable()) { | 187 clickable_(notification.clickable()) { |
203 // Create the top_view_, which collects into a vertical box all content | 188 // Create the top_view_, which collects into a vertical box all content |
204 // at the top of the notification (to the right of the icon) except for the | 189 // at the top of the notification (to the right of the icon) except for the |
205 // close button. | 190 // close button. |
206 top_view_ = new views::View(); | 191 top_view_ = new views::View(); |
207 top_view_->SetLayoutManager( | 192 top_view_->SetLayoutManager( |
208 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 193 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
209 top_view_->SetBorder( | 194 top_view_->SetBorder( |
210 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); | 195 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); |
211 AddChildView(top_view_); | 196 AddChildView(top_view_); |
212 // Create the bottom_view_, which collects into a vertical box all content | 197 // Create the bottom_view_, which collects into a vertical box all content |
213 // below the notification icon. | 198 // below the notification icon. |
214 bottom_view_ = new views::View(); | 199 bottom_view_ = new views::View(); |
215 bottom_view_->SetLayoutManager( | 200 bottom_view_->SetLayoutManager( |
216 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 201 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
217 AddChildView(bottom_view_); | 202 AddChildView(bottom_view_); |
218 | 203 |
219 CreateOrUpdateViews(notification); | 204 CreateOrUpdateViews(notification); |
220 | 205 |
221 // Put together the different content and control views. Layering those allows | 206 // Put together the different content and control views. Layering those allows |
222 // for proper layout logic and it also allows the close button and small | 207 // for proper layout logic and it also allows the close button and small |
223 // image to overlap the content as needed to provide large enough click and | 208 // image to overlap the content as needed to provide large enough click and |
224 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). | 209 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). |
225 AddChildView(small_image()); | 210 AddChildView(small_image()); |
226 CreateOrUpdateCloseButtonView(notification); | 211 CreateOrUpdateCloseButtonView(notification); |
227 SetAccessibleName(notification); | |
228 | 212 |
229 SetEventTargeter( | 213 SetEventTargeter( |
230 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 214 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
231 } | 215 } |
232 | 216 |
233 NotificationView::~NotificationView() { | 217 NotificationView::~NotificationView() { |
234 } | 218 } |
235 | 219 |
236 gfx::Size NotificationView::GetPreferredSize() const { | 220 gfx::Size NotificationView::GetPreferredSize() const { |
237 int top_width = top_view_->GetPreferredSize().width() + | 221 int top_width = top_view_->GetPreferredSize().width() + |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 return views::View::GetCursor(event); | 316 return views::View::GetCursor(event); |
333 | 317 |
334 return views::GetNativeHandCursor(); | 318 return views::GetNativeHandCursor(); |
335 } | 319 } |
336 | 320 |
337 void NotificationView::UpdateWithNotification( | 321 void NotificationView::UpdateWithNotification( |
338 const Notification& notification) { | 322 const Notification& notification) { |
339 MessageView::UpdateWithNotification(notification); | 323 MessageView::UpdateWithNotification(notification); |
340 | 324 |
341 CreateOrUpdateViews(notification); | 325 CreateOrUpdateViews(notification); |
342 SetAccessibleName(notification); | |
343 Layout(); | 326 Layout(); |
344 SchedulePaint(); | 327 SchedulePaint(); |
345 } | 328 } |
346 | 329 |
347 void NotificationView::ButtonPressed(views::Button* sender, | 330 void NotificationView::ButtonPressed(views::Button* sender, |
348 const ui::Event& event) { | 331 const ui::Event& event) { |
349 // Certain operations can cause |this| to be destructed, so copy the members | 332 // Certain operations can cause |this| to be destructed, so copy the members |
350 // we send to other parts of the code. | 333 // we send to other parts of the code. |
351 // TODO(dewittj): Remove this hack. | 334 // TODO(dewittj): Remove this hack. |
352 std::string id(notification_id()); | 335 std::string id(notification_id()); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 | 687 |
705 return message_line_limit; | 688 return message_line_limit; |
706 } | 689 } |
707 | 690 |
708 int NotificationView::GetMessageHeight(int width, int limit) const { | 691 int NotificationView::GetMessageHeight(int width, int limit) const { |
709 return message_view_ ? | 692 return message_view_ ? |
710 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 693 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
711 } | 694 } |
712 | 695 |
713 } // namespace message_center | 696 } // namespace message_center |
OLD | NEW |