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/common/system/update/tray_update.h" | 5 #include "ash/common/system/update/tray_update.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | |
7 #include "ash/common/metrics/user_metrics_action.h" | 8 #include "ash/common/metrics/user_metrics_action.h" |
8 #include "ash/common/system/tray/fixed_sized_image_view.h" | 9 #include "ash/common/system/tray/fixed_sized_image_view.h" |
9 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
10 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
11 #include "ash/common/system/tray/system_tray_notifier.h" | 12 #include "ash/common/system/tray/system_tray_notifier.h" |
12 #include "ash/common/system/tray/tray_constants.h" | 13 #include "ash/common/system/tray/tray_constants.h" |
13 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
14 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
15 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/color_palette.h" | |
17 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
20 #include "ui/gfx/paint_vector_icon.h" | |
21 #include "ui/gfx/vector_icons_public.h" | |
18 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
19 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
20 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
21 | 25 |
22 namespace ash { | 26 namespace ash { |
23 namespace { | 27 namespace { |
24 | 28 |
25 // TODO(tdanderson): The material design update icon needs to be colored | 29 // Decides the non-material design image resource to use for a given update |
26 // programmatically. See crbug.com/625692. | 30 // severity. |
31 // TODO(tdanderson): This is only used for non-material design, so remove it | |
32 // when material design is the default. See crbug.com/625692. | |
27 int DecideResource(UpdateInfo::UpdateSeverity severity, bool dark) { | 33 int DecideResource(UpdateInfo::UpdateSeverity severity, bool dark) { |
28 switch (severity) { | 34 switch (severity) { |
29 case UpdateInfo::UPDATE_NORMAL: | 35 case UpdateInfo::UPDATE_NONE: |
36 case UpdateInfo::UPDATE_LOW: | |
30 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE; | 37 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE; |
31 | 38 |
32 case UpdateInfo::UPDATE_LOW_GREEN: | 39 case UpdateInfo::UPDATE_ELEVATED: |
33 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN | 40 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN |
34 : IDR_AURA_UBER_TRAY_UPDATE_GREEN; | 41 : IDR_AURA_UBER_TRAY_UPDATE_GREEN; |
35 | 42 |
36 case UpdateInfo::UPDATE_HIGH_ORANGE: | 43 case UpdateInfo::UPDATE_HIGH: |
37 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE | 44 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE |
38 : IDR_AURA_UBER_TRAY_UPDATE_ORANGE; | 45 : IDR_AURA_UBER_TRAY_UPDATE_ORANGE; |
39 | 46 |
40 case UpdateInfo::UPDATE_SEVERE_RED: | 47 case UpdateInfo::UPDATE_SEVERE: |
48 case UpdateInfo::UPDATE_CRITICAL: | |
41 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED | 49 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED |
42 : IDR_AURA_UBER_TRAY_UPDATE_RED; | 50 : IDR_AURA_UBER_TRAY_UPDATE_RED; |
43 } | 51 } |
44 | 52 |
45 NOTREACHED() << "Unknown update severity level."; | 53 NOTREACHED() << "Unknown update severity level."; |
46 return 0; | 54 return 0; |
47 } | 55 } |
48 | 56 |
57 // Returns the color to use for the material design update icon when the update | |
58 // severity is |severity|. If |for_menu| is true, the icon color for the system | |
59 // menu is given, otherwise the icon color for the system tray is given. | |
60 SkColor IconColorForUpdateSeverity(UpdateInfo::UpdateSeverity severity, | |
61 bool for_menu) { | |
62 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; | |
63 switch (severity) { | |
64 case UpdateInfo::UPDATE_NONE: | |
65 return default_color; | |
66 case UpdateInfo::UPDATE_LOW: | |
67 return for_menu ? gfx::kGoogleGreen700 : gfx::kGoogleGreen300; | |
tdanderson
2016/08/16 21:18:45
Any suggestions for the best place to put the colo
Evan Stade
2016/08/16 21:39:20
I'm not sure how we can get around separate switch
| |
68 case UpdateInfo::UPDATE_ELEVATED: | |
69 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300; | |
70 case UpdateInfo::UPDATE_HIGH: | |
71 case UpdateInfo::UPDATE_SEVERE: | |
72 case UpdateInfo::UPDATE_CRITICAL: | |
73 return for_menu ? gfx::kGoogleRed700 : gfx::kGoogleRed300; | |
74 default: | |
75 NOTREACHED(); | |
76 break; | |
77 } | |
78 return default_color; | |
79 } | |
80 | |
49 class UpdateView : public ActionableView { | 81 class UpdateView : public ActionableView { |
50 public: | 82 public: |
51 explicit UpdateView(const UpdateInfo& info) { | 83 explicit UpdateView(const UpdateInfo& info) { |
52 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 84 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
53 kTrayPopupPaddingHorizontal, 0, | 85 kTrayPopupPaddingHorizontal, 0, |
54 kTrayPopupPaddingBetweenItems)); | 86 kTrayPopupPaddingBetweenItems)); |
55 | 87 |
56 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 88 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
57 views::ImageView* image = | 89 views::ImageView* image = |
58 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 90 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
59 image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true)) | 91 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
60 .ToImageSkia()); | 92 image->SetImage(gfx::CreateVectorIcon( |
61 | 93 gfx::VectorIconId::SYSTEM_MENU_UPDATE, |
94 IconColorForUpdateSeverity(info.severity, true))); | |
95 } else { | |
96 image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true)) | |
97 .ToImageSkia()); | |
98 } | |
62 AddChildView(image); | 99 AddChildView(image); |
63 | 100 |
64 base::string16 label = | 101 base::string16 label = |
65 info.factory_reset_required | 102 info.factory_reset_required |
66 ? bundle.GetLocalizedString( | 103 ? bundle.GetLocalizedString( |
67 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) | 104 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) |
68 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); | 105 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); |
69 AddChildView(new views::Label(label)); | 106 AddChildView(new views::Label(label)); |
70 SetAccessibleName(label); | 107 SetAccessibleName(label); |
71 } | 108 } |
(...skipping 29 matching lines...) Expand all Loading... | |
101 return info.update_required; | 138 return info.update_required; |
102 } | 139 } |
103 | 140 |
104 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { | 141 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { |
105 UpdateInfo info; | 142 UpdateInfo info; |
106 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info); | 143 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info); |
107 return info.update_required ? new UpdateView(info) : nullptr; | 144 return info.update_required ? new UpdateView(info) : nullptr; |
108 } | 145 } |
109 | 146 |
110 void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) { | 147 void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) { |
111 SetImageFromResourceId(DecideResource(info.severity, false)); | 148 if (MaterialDesignController::UseMaterialDesignSystemIcons()) |
149 SetIconColor(IconColorForUpdateSeverity(info.severity, false)); | |
150 else | |
151 SetImageFromResourceId(DecideResource(info.severity, false)); | |
112 tray_view()->SetVisible(true); | 152 tray_view()->SetVisible(true); |
113 } | 153 } |
114 | 154 |
115 } // namespace ash | 155 } // namespace ash |
OLD | NEW |