| 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 "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/system/status_area_widget.h" | 7 #include "ash/system/status_area_widget.h" |
| 8 #include "ash/system/tray/tray_bubble_view.h" | 8 #include "ash/system/tray/tray_bubble_view.h" |
| 9 #include "ash/system/tray/tray_constants.h" | 9 #include "ash/system/tray/tray_constants.h" |
| 10 #include "ash/system/tray/tray_views.h" | 10 #include "ash/system/tray/tray_views.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
| 14 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/models/simple_menu_model.h" | 17 #include "ui/base/models/simple_menu_model.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/image/image_skia_operations.h" |
| 19 #include "ui/views/controls/button/button.h" | 20 #include "ui/views/controls/button/button.h" |
| 20 #include "ui/views/controls/button/menu_button.h" | 21 #include "ui/views/controls/button/menu_button.h" |
| 21 #include "ui/views/controls/button/menu_button_listener.h" | 22 #include "ui/views/controls/button/menu_button_listener.h" |
| 22 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/controls/menu/menu_model_adapter.h" | 24 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 24 #include "ui/views/controls/menu/menu_runner.h" | 25 #include "ui/views/controls/menu/menu_runner.h" |
| 25 #include "ui/views/layout/box_layout.h" | 26 #include "ui/views/layout/box_layout.h" |
| 26 #include "ui/views/layout/fill_layout.h" | 27 #include "ui/views/layout/fill_layout.h" |
| 27 #include "ui/views/layout/grid_layout.h" | 28 #include "ui/views/layout/grid_layout.h" |
| 28 #include "ui/views/painter.h" | 29 #include "ui/views/painter.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 const int kWebNotificationWidth = 400; | 48 const int kWebNotificationWidth = 400; |
| 48 const int kWebNotificationButtonWidth = 32; | 49 const int kWebNotificationButtonWidth = 32; |
| 49 const int kWebNotificationIconSize = 40; | 50 const int kWebNotificationIconSize = 40; |
| 50 | 51 |
| 51 // Menu constants | 52 // Menu constants |
| 52 const int kTogglePermissionCommand = 0; | 53 const int kTogglePermissionCommand = 0; |
| 53 const int kToggleExtensionCommand = 1; | 54 const int kToggleExtensionCommand = 1; |
| 54 const int kShowSettingsCommand = 2; | 55 const int kShowSettingsCommand = 2; |
| 55 | 56 |
| 56 // The image has three icons: 1 notifiaction, 2 notifications, and 3+. | 57 // The image has three icons: 1 notifiaction, 2 notifications, and 3+. |
| 57 SkBitmap GetNotificationImage(int notification_count) { | 58 gfx::ImageSkia GetNotificationImage(int notification_count) { |
| 58 SkBitmap image; | 59 const gfx::ImageSkia* image = ui::ResourceBundle::GetSharedInstance(). |
| 59 gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 60 GetImageSkiaNamed(IDR_AURA_UBER_TRAY_WEB_NOTIFICATON); |
| 60 IDR_AURA_UBER_TRAY_WEB_NOTIFICATON); | |
| 61 int image_index = notification_count - 1; | 61 int image_index = notification_count - 1; |
| 62 image_index = std::max(0, std::min(image_index, 2)); | 62 image_index = std::max(0, std::min(image_index, 2)); |
| 63 SkIRect region = SkIRect::MakeXYWH( | 63 gfx::Rect region( |
| 64 0, image_index * kNotificationImageIconHeight, | 64 0, image_index * kNotificationImageIconHeight, |
| 65 kNotificationImageIconWidth, kNotificationImageIconHeight); | 65 kNotificationImageIconWidth, kNotificationImageIconHeight); |
| 66 all.ToSkBitmap()->extractSubset(&image, region); | 66 return gfx::ImageSkiaOperations::ExtractSubset(*image, region); |
| 67 return image; | |
| 68 } | 67 } |
| 69 | 68 |
| 70 } // namespace | 69 } // namespace |
| 71 | 70 |
| 72 namespace ash { | 71 namespace ash { |
| 73 | 72 |
| 74 namespace internal { | 73 namespace internal { |
| 75 | 74 |
| 76 struct WebNotification { | 75 struct WebNotification { |
| 77 WebNotification(const std::string& i, | 76 WebNotification(const std::string& i, |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 int WebNotificationTray::GetNotificationCount() const { | 822 int WebNotificationTray::GetNotificationCount() const { |
| 824 return notification_list()->notifications().size(); | 823 return notification_list()->notifications().size(); |
| 825 } | 824 } |
| 826 | 825 |
| 827 void WebNotificationTray::UpdateIcon() { | 826 void WebNotificationTray::UpdateIcon() { |
| 828 int count = GetNotificationCount(); | 827 int count = GetNotificationCount(); |
| 829 if (count == 0 || | 828 if (count == 0 || |
| 830 status_area_widget_->login_status() == user::LOGGED_IN_LOCKED) { | 829 status_area_widget_->login_status() == user::LOGGED_IN_LOCKED) { |
| 831 SetVisible(false); | 830 SetVisible(false); |
| 832 } else { | 831 } else { |
| 833 icon_->SetImage(gfx::ImageSkia(GetNotificationImage(count))); | 832 icon_->SetImage(GetNotificationImage(count)); |
| 834 SetVisible(true); | 833 SetVisible(true); |
| 835 } | 834 } |
| 836 PreferredSizeChanged(); | 835 PreferredSizeChanged(); |
| 837 } | 836 } |
| 838 | 837 |
| 839 void WebNotificationTray::UpdateBubbleAndIcon() { | 838 void WebNotificationTray::UpdateBubbleAndIcon() { |
| 840 UpdateIcon(); | 839 UpdateIcon(); |
| 841 if (!bubble()) | 840 if (!bubble()) |
| 842 return; | 841 return; |
| 843 if (GetNotificationCount() == 0) | 842 if (GetNotificationCount() == 0) |
| 844 status_area_widget_->HideWebNotificationBubble(); | 843 status_area_widget_->HideWebNotificationBubble(); |
| 845 else | 844 else |
| 846 bubble_->ScheduleUpdate(); | 845 bubble_->ScheduleUpdate(); |
| 847 } | 846 } |
| 848 | 847 |
| 849 } // namespace ash | 848 } // namespace ash |
| OLD | NEW |