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" |
11 #include "ui/base/layout.h" | 11 #include "ui/base/layout.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/base/text/text_elider.h" | 13 #include "ui/base/text/text_elider.h" |
14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
16 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
17 #include "ui/message_center/message_center_style.h" | 17 #include "ui/message_center/message_center_style.h" |
18 #include "ui/message_center/message_center_switches.h" | 18 #include "ui/message_center/message_center_switches.h" |
19 #include "ui/message_center/message_center_util.h" | 19 #include "ui/message_center/message_center_util.h" |
20 #include "ui/message_center/notification.h" | 20 #include "ui/message_center/notification.h" |
21 #include "ui/message_center/notification_types.h" | 21 #include "ui/message_center/notification_types.h" |
22 #include "ui/message_center/views/bounded_label.h" | 22 #include "ui/message_center/views/bounded_label.h" |
23 #include "ui/message_center/views/message_simple_view.h" | |
24 #include "ui/native_theme/native_theme.h" | 23 #include "ui/native_theme/native_theme.h" |
25 #include "ui/views/controls/button/image_button.h" | 24 #include "ui/views/controls/button/image_button.h" |
26 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
27 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
28 #include "ui/views/layout/box_layout.h" | 27 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/layout/fill_layout.h" | 28 #include "ui/views/layout/fill_layout.h" |
30 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 namespace message_center { | 333 namespace message_center { |
335 | 334 |
336 // NotificationView //////////////////////////////////////////////////////////// | 335 // NotificationView //////////////////////////////////////////////////////////// |
337 | 336 |
338 // static | 337 // static |
339 MessageView* NotificationView::Create(const Notification& notification, | 338 MessageView* NotificationView::Create(const Notification& notification, |
340 MessageCenter* message_center, | 339 MessageCenter* message_center, |
341 MessageCenterTray* tray, | 340 MessageCenterTray* tray, |
342 bool expanded, | 341 bool expanded, |
343 bool top_level) { | 342 bool top_level) { |
344 // Use MessageSimpleView for simple notifications unless rich style | |
345 // notifications are enabled. This preserves the appearance of notifications | |
346 // created by existing code that uses webkitNotifications. | |
347 if (!IsRichNotificationEnabled() && | |
348 notification.type() == NOTIFICATION_TYPE_SIMPLE) | |
349 return new MessageSimpleView(notification, message_center); | |
350 | |
351 switch (notification.type()) { | 343 switch (notification.type()) { |
352 case NOTIFICATION_TYPE_BASE_FORMAT: | 344 case NOTIFICATION_TYPE_BASE_FORMAT: |
353 case NOTIFICATION_TYPE_IMAGE: | 345 case NOTIFICATION_TYPE_IMAGE: |
354 case NOTIFICATION_TYPE_MULTIPLE: | 346 case NOTIFICATION_TYPE_MULTIPLE: |
355 case NOTIFICATION_TYPE_SIMPLE: | 347 case NOTIFICATION_TYPE_SIMPLE: |
356 break; | 348 break; |
357 default: | 349 default: |
358 // If the caller asks for an unrecognized kind of view (entirely possible | 350 // If the caller asks for an unrecognized kind of view (entirely possible |
359 // if an application is running on an older version of this code that | 351 // if an application is running on an older version of this code that |
360 // doesn't have the requested kind of notification template), we'll fall | 352 // doesn't have the requested kind of notification template), we'll fall |
361 // back to a notification instance that will provide at least basic | 353 // back to a notification instance that will provide at least basic |
362 // functionality. | 354 // functionality. |
363 LOG(WARNING) << "Unable to fulfill request for unrecognized " | 355 LOG(WARNING) << "Unable to fulfill request for unrecognized " |
364 << "notification type " << notification.type() << ". " | 356 << "notification type " << notification.type() << ". " |
365 << "Falling back to simple notification type."; | 357 << "Falling back to simple notification type."; |
366 } | 358 } |
367 | 359 |
368 // Currently all roads lead to the generic NotificationView. | 360 // Currently all roads lead to the generic NotificationView. |
369 MessageView* notification_view = | 361 MessageView* notification_view = |
370 new NotificationView(notification, message_center, tray, expanded); | 362 new NotificationView(notification, message_center, tray, expanded); |
371 | 363 |
372 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 364 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
373 // Don't create shadows for notification toasts on linux wih aura. | 365 // Don't create shadows for notification toasts on linux wih aura. |
374 if (top_level) | 366 if (top_level) |
375 return notification_view; | 367 return notification_view; |
376 #endif | 368 #endif |
377 | 369 |
378 if (IsRichNotificationEnabled()) | 370 notification_view->CreateShadowBorder(); |
379 notification_view->CreateShadowBorder(); | |
380 | |
381 return notification_view; | 371 return notification_view; |
382 } | 372 } |
383 | 373 |
384 NotificationView::NotificationView(const Notification& notification, | 374 NotificationView::NotificationView(const Notification& notification, |
385 MessageCenter* message_center, | 375 MessageCenter* message_center, |
386 MessageCenterTray* tray, | 376 MessageCenterTray* tray, |
387 bool expanded) | 377 bool expanded) |
388 : MessageView(notification, message_center, tray, expanded) { | 378 : MessageView(notification, message_center, tray, expanded) { |
389 std::vector<string16> accessible_lines; | 379 std::vector<string16> accessible_lines; |
390 | 380 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 return message_view_ ? | 675 return message_view_ ? |
686 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 676 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
687 } | 677 } |
688 | 678 |
689 int NotificationView::GetMessageHeight(int width, int limit) { | 679 int NotificationView::GetMessageHeight(int width, int limit) { |
690 return message_view_ ? | 680 return message_view_ ? |
691 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 681 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
692 } | 682 } |
693 | 683 |
694 } // namespace message_center | 684 } // namespace message_center |
OLD | NEW |