Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: ash/system/web_notification/web_notification_tray.cc

Issue 10704199: Implement remaining SkBitmapOperations as ImageSkiaOperations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/wm/workspace/frame_maximize_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 24 matching lines...) Expand all
53 const int kWebNotificationWidth = 400; 54 const int kWebNotificationWidth = 400;
54 const int kWebNotificationButtonWidth = 32; 55 const int kWebNotificationButtonWidth = 32;
55 const int kWebNotificationIconSize = 40; 56 const int kWebNotificationIconSize = 40;
56 57
57 // Menu constants 58 // Menu constants
58 const int kTogglePermissionCommand = 0; 59 const int kTogglePermissionCommand = 0;
59 const int kToggleExtensionCommand = 1; 60 const int kToggleExtensionCommand = 1;
60 const int kShowSettingsCommand = 2; 61 const int kShowSettingsCommand = 2;
61 62
62 // The image has three icons: 1 notifiaction, 2 notifications, and 3+. 63 // The image has three icons: 1 notifiaction, 2 notifications, and 3+.
63 SkBitmap GetNotificationImage(int notification_count) { 64 gfx::ImageSkia GetNotificationImage(int notification_count) {
64 SkBitmap image; 65 const gfx::ImageSkia* image = ui::ResourceBundle::GetSharedInstance().
65 gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( 66 GetImageSkiaNamed(IDR_AURA_UBER_TRAY_WEB_NOTIFICATON);
66 IDR_AURA_UBER_TRAY_WEB_NOTIFICATON);
67 int image_index = notification_count - 1; 67 int image_index = notification_count - 1;
68 image_index = std::max(0, std::min(image_index, 2)); 68 image_index = std::max(0, std::min(image_index, 2));
69 // The original width of the image looks too big, so we need to inset 69 // The original width of the image looks too big, so we need to inset
70 // it somewhat. 70 // it somewhat.
71 SkIRect region = SkIRect::MakeXYWH( 71 gfx::Rect region(
72 kNotificationImageIconInset, image_index * kNotificationImageIconHeight, 72 kNotificationImageIconInset,
73 kNotificationImageIconWidth - 2 * kNotificationImageIconInset, 73 image_index * kNotificationImageIconHeight,
74 kNotificationImageIconHeight); 74 kNotificationImageIconWidth - 2 * kNotificationImageIconInset,
75 75 kNotificationImageIconHeight);
76 all.ToSkBitmap()->extractSubset(&image, region); 76 return gfx::ImageSkiaOperations::ExtractSubset(*image, region);
77 return image;
78 } 77 }
79 78
80 } // namespace 79 } // namespace
81 80
82 namespace ash { 81 namespace ash {
83 82
84 namespace internal { 83 namespace internal {
85 84
86 struct WebNotification { 85 struct WebNotification {
87 WebNotification(const std::string& i, 86 WebNotification(const std::string& i,
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 int WebNotificationTray::GetNotificationCount() const { 870 int WebNotificationTray::GetNotificationCount() const {
872 return notification_list()->notifications().size(); 871 return notification_list()->notifications().size();
873 } 872 }
874 873
875 void WebNotificationTray::UpdateIcon() { 874 void WebNotificationTray::UpdateIcon() {
876 int count = GetNotificationCount(); 875 int count = GetNotificationCount();
877 if (count == 0 || 876 if (count == 0 ||
878 status_area_widget_->login_status() == user::LOGGED_IN_LOCKED) { 877 status_area_widget_->login_status() == user::LOGGED_IN_LOCKED) {
879 SetVisible(false); 878 SetVisible(false);
880 } else { 879 } else {
881 icon_->SetImage(gfx::ImageSkia(GetNotificationImage(count))); 880 icon_->SetImage(GetNotificationImage(count));
882 SetVisible(true); 881 SetVisible(true);
883 } 882 }
884 PreferredSizeChanged(); 883 PreferredSizeChanged();
885 } 884 }
886 885
887 void WebNotificationTray::UpdateBubbleAndIcon() { 886 void WebNotificationTray::UpdateBubbleAndIcon() {
888 UpdateIcon(); 887 UpdateIcon();
889 if (!bubble()) 888 if (!bubble())
890 return; 889 return;
891 if (GetNotificationCount() == 0) 890 if (GetNotificationCount() == 0)
892 status_area_widget_->HideWebNotificationBubble(); 891 status_area_widget_->HideWebNotificationBubble();
893 else 892 else
894 bubble_->ScheduleUpdate(); 893 bubble_->ScheduleUpdate();
895 } 894 }
896 895
897 } // namespace ash 896 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/wm/workspace/frame_maximize_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698