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" | |
8 #include "ash/common/metrics/user_metrics_action.h" | 7 #include "ash/common/metrics/user_metrics_action.h" |
9 #include "ash/common/system/tray/fixed_sized_image_view.h" | 8 #include "ash/common/system/tray/fixed_sized_image_view.h" |
10 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
11 #include "ash/common/system/tray/system_tray_controller.h" | 10 #include "ash/common/system/tray/system_tray_controller.h" |
12 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
13 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
14 #include "ash/common/system/tray/tray_popup_item_style.h" | 13 #include "ash/common/system/tray/tray_popup_item_style.h" |
15 #include "ash/common/system/tray/tray_popup_utils.h" | 14 #include "ash/common/system/tray/tray_popup_utils.h" |
16 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
17 #include "ash/public/interfaces/update.mojom.h" | 16 #include "ash/public/interfaces/update.mojom.h" |
18 #include "ash/resources/vector_icons/vector_icons.h" | 17 #include "ash/resources/vector_icons/vector_icons.h" |
19 #include "grit/ash_resources.h" | |
20 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
21 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/color_palette.h" | 20 #include "ui/gfx/color_palette.h" |
23 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
24 #include "ui/gfx/paint_vector_icon.h" | 22 #include "ui/gfx/paint_vector_icon.h" |
25 #include "ui/views/controls/image_view.h" | 23 #include "ui/views/controls/image_view.h" |
26 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
27 #include "ui/views/layout/fill_layout.h" | 25 #include "ui/views/layout/fill_layout.h" |
28 | 26 |
29 namespace ash { | 27 namespace ash { |
30 namespace { | 28 namespace { |
31 | 29 |
32 // Decides the non-material design image resource to use for a given update | 30 // Returns the color to use for the update icon when the update severity is |
33 // severity. | 31 // |severity|. If |for_menu| is true, the icon color for the system menu is |
34 // TODO(tdanderson): This is only used for non-material design, so remove it | 32 // given, otherwise the icon color for the system tray is given. |
35 // when material design is the default. See crbug.com/625692. | |
36 int DecideResource(mojom::UpdateSeverity severity, bool dark) { | |
37 switch (severity) { | |
38 case mojom::UpdateSeverity::NONE: | |
39 case mojom::UpdateSeverity::LOW: | |
40 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE; | |
41 | |
42 case mojom::UpdateSeverity::ELEVATED: | |
43 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN | |
44 : IDR_AURA_UBER_TRAY_UPDATE_GREEN; | |
45 | |
46 case mojom::UpdateSeverity::HIGH: | |
47 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE | |
48 : IDR_AURA_UBER_TRAY_UPDATE_ORANGE; | |
49 | |
50 case mojom::UpdateSeverity::SEVERE: | |
51 case mojom::UpdateSeverity::CRITICAL: | |
52 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED | |
53 : IDR_AURA_UBER_TRAY_UPDATE_RED; | |
54 } | |
55 | |
56 NOTREACHED() << "Unknown update severity level."; | |
57 return 0; | |
58 } | |
59 | |
60 // Returns the color to use for the material design update icon when the update | |
61 // severity is |severity|. If |for_menu| is true, the icon color for the system | |
62 // menu is given, otherwise the icon color for the system tray is given. | |
63 SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity, | 33 SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity, |
64 bool for_menu) { | 34 bool for_menu) { |
65 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; | 35 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; |
66 switch (severity) { | 36 switch (severity) { |
67 case mojom::UpdateSeverity::NONE: | 37 case mojom::UpdateSeverity::NONE: |
68 return default_color; | 38 return default_color; |
69 case mojom::UpdateSeverity::LOW: | 39 case mojom::UpdateSeverity::LOW: |
70 return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor; | 40 return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor; |
71 case mojom::UpdateSeverity::ELEVATED: | 41 case mojom::UpdateSeverity::ELEVATED: |
72 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300; | 42 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300; |
(...skipping 21 matching lines...) Expand all Loading... |
94 class TrayUpdate::UpdateView : public ActionableView { | 64 class TrayUpdate::UpdateView : public ActionableView { |
95 public: | 65 public: |
96 explicit UpdateView(TrayUpdate* owner) | 66 explicit UpdateView(TrayUpdate* owner) |
97 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS) { | 67 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS) { |
98 SetLayoutManager(new views::FillLayout); | 68 SetLayoutManager(new views::FillLayout); |
99 | 69 |
100 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 70 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
101 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | 71 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
102 AddChildView(tri_view); | 72 AddChildView(tri_view); |
103 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); | 73 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); |
104 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 74 image->SetImage(gfx::CreateVectorIcon( |
105 image->SetImage(gfx::CreateVectorIcon( | 75 kSystemMenuUpdateIcon, |
106 kSystemMenuUpdateIcon, | 76 IconColorForUpdateSeverity(owner->severity_, true))); |
107 IconColorForUpdateSeverity(owner->severity_, true))); | |
108 } else { | |
109 image->SetImage( | |
110 bundle.GetImageNamed(DecideResource(owner->severity_, true)) | |
111 .ToImageSkia()); | |
112 } | |
113 tri_view->AddView(TriView::Container::START, image); | 77 tri_view->AddView(TriView::Container::START, image); |
114 | 78 |
115 base::string16 label_text = | 79 base::string16 label_text = |
116 owner->factory_reset_required_ | 80 owner->factory_reset_required_ |
117 ? bundle.GetLocalizedString( | 81 ? bundle.GetLocalizedString( |
118 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) | 82 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) |
119 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); | 83 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); |
120 SetAccessibleName(label_text); | 84 SetAccessibleName(label_text); |
121 auto label = TrayPopupUtils::CreateDefaultLabel(); | 85 auto label = TrayPopupUtils::CreateDefaultLabel(); |
122 label->SetText(label_text); | 86 label->SetText(label_text); |
123 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 87 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
124 style.SetupLabel(label); | 88 style.SetupLabel(label); |
125 tri_view->AddView(TriView::Container::CENTER, label); | 89 tri_view->AddView(TriView::Container::CENTER, label); |
126 | 90 |
127 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 91 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
128 SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
129 } | |
130 } | 92 } |
131 | 93 |
132 ~UpdateView() override {} | 94 ~UpdateView() override {} |
133 | 95 |
134 private: | 96 private: |
135 // Overridden from ActionableView. | 97 // Overridden from ActionableView. |
136 bool PerformAction(const ui::Event& event) override { | 98 bool PerformAction(const ui::Event& event) override { |
137 WmShell::Get()->system_tray_controller()->RequestRestartForUpdate(); | 99 WmShell::Get()->system_tray_controller()->RequestRestartForUpdate(); |
138 WmShell::Get()->RecordUserMetricsAction( | 100 WmShell::Get()->RecordUserMetricsAction( |
139 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); | 101 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); |
140 CloseSystemBubble(); | 102 CloseSystemBubble(); |
141 return true; | 103 return true; |
142 } | 104 } |
143 | 105 |
144 DISALLOW_COPY_AND_ASSIGN(UpdateView); | 106 DISALLOW_COPY_AND_ASSIGN(UpdateView); |
145 }; | 107 }; |
146 | 108 |
147 TrayUpdate::TrayUpdate(SystemTray* system_tray) | 109 TrayUpdate::TrayUpdate(SystemTray* system_tray) |
148 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {} | 110 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} |
149 | 111 |
150 TrayUpdate::~TrayUpdate() {} | 112 TrayUpdate::~TrayUpdate() {} |
151 | 113 |
152 bool TrayUpdate::GetInitialVisibility() { | 114 bool TrayUpdate::GetInitialVisibility() { |
153 // If chrome tells ash there is an update available before this item's system | 115 // If chrome tells ash there is an update available before this item's system |
154 // tray is constructed then show the icon. | 116 // tray is constructed then show the icon. |
155 return update_required_; | 117 return update_required_; |
156 } | 118 } |
157 | 119 |
158 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { | 120 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { |
159 return update_required_ ? new UpdateView(this) : nullptr; | 121 return update_required_ ? new UpdateView(this) : nullptr; |
160 } | 122 } |
161 | 123 |
162 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, | 124 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, |
163 bool factory_reset_required) { | 125 bool factory_reset_required) { |
164 // Cache update info so we can create the default view when the menu opens. | 126 // Cache update info so we can create the default view when the menu opens. |
165 update_required_ = true; | 127 update_required_ = true; |
166 severity_ = severity; | 128 severity_ = severity; |
167 factory_reset_required_ = factory_reset_required; | 129 factory_reset_required_ = factory_reset_required; |
168 | 130 |
169 // Show the icon in the tray. | 131 // Show the icon in the tray. |
170 if (MaterialDesignController::UseMaterialDesignSystemIcons()) | 132 SetIconColor(IconColorForUpdateSeverity(severity_, false)); |
171 SetIconColor(IconColorForUpdateSeverity(severity_, false)); | |
172 else | |
173 SetImageFromResourceId(DecideResource(severity_, false)); | |
174 tray_view()->SetVisible(true); | 133 tray_view()->SetVisible(true); |
175 } | 134 } |
176 | 135 |
177 } // namespace ash | 136 } // namespace ash |
OLD | NEW |