OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/system/update/tray_update.h" | |
6 | |
7 #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/system_tray.h" | |
10 #include "ash/common/system/tray/system_tray_controller.h" | |
11 #include "ash/common/system/tray/system_tray_delegate.h" | |
12 #include "ash/common/system/tray/tray_constants.h" | |
13 #include "ash/common/system/tray/tray_popup_item_style.h" | |
14 #include "ash/common/system/tray/tray_popup_utils.h" | |
15 #include "ash/common/wm_shell.h" | |
16 #include "ash/public/interfaces/update.mojom.h" | |
17 #include "ash/resources/vector_icons/vector_icons.h" | |
18 #include "ash/strings/grit/ash_strings.h" | |
19 #include "ui/base/resource/resource_bundle.h" | |
20 #include "ui/gfx/color_palette.h" | |
21 #include "ui/gfx/image/image.h" | |
22 #include "ui/gfx/paint_vector_icon.h" | |
23 #include "ui/views/controls/image_view.h" | |
24 #include "ui/views/controls/label.h" | |
25 #include "ui/views/layout/fill_layout.h" | |
26 | |
27 namespace ash { | |
28 namespace { | |
29 | |
30 // Returns the color to use for the update icon when the update severity is | |
31 // |severity|. If |for_menu| is true, the icon color for the system menu is | |
32 // given, otherwise the icon color for the system tray is given. | |
33 SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity, | |
34 bool for_menu) { | |
35 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; | |
36 switch (severity) { | |
37 case mojom::UpdateSeverity::NONE: | |
38 return default_color; | |
39 case mojom::UpdateSeverity::LOW: | |
40 return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor; | |
41 case mojom::UpdateSeverity::ELEVATED: | |
42 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300; | |
43 case mojom::UpdateSeverity::HIGH: | |
44 case mojom::UpdateSeverity::SEVERE: | |
45 case mojom::UpdateSeverity::CRITICAL: | |
46 return for_menu ? gfx::kGoogleRed700 : gfx::kGoogleRed300; | |
47 default: | |
48 NOTREACHED(); | |
49 break; | |
50 } | |
51 return default_color; | |
52 } | |
53 | |
54 } // namespace | |
55 | |
56 // static | |
57 bool TrayUpdate::update_required_ = false; | |
58 // static | |
59 mojom::UpdateSeverity TrayUpdate::severity_ = mojom::UpdateSeverity::NONE; | |
60 // static | |
61 bool TrayUpdate::factory_reset_required_ = false; | |
62 | |
63 // The "restart to update" item in the system tray menu. | |
64 class TrayUpdate::UpdateView : public ActionableView { | |
65 public: | |
66 explicit UpdateView(TrayUpdate* owner) | |
67 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS) { | |
68 SetLayoutManager(new views::FillLayout); | |
69 | |
70 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
71 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | |
72 AddChildView(tri_view); | |
73 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); | |
74 image->SetImage(gfx::CreateVectorIcon( | |
75 kSystemMenuUpdateIcon, | |
76 IconColorForUpdateSeverity(owner->severity_, true))); | |
77 tri_view->AddView(TriView::Container::START, image); | |
78 | |
79 base::string16 label_text = | |
80 owner->factory_reset_required_ | |
81 ? bundle.GetLocalizedString( | |
82 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) | |
83 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); | |
84 SetAccessibleName(label_text); | |
85 auto* label = TrayPopupUtils::CreateDefaultLabel(); | |
86 label->SetText(label_text); | |
87 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | |
88 style.SetupLabel(label); | |
89 tri_view->AddView(TriView::Container::CENTER, label); | |
90 | |
91 SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
92 } | |
93 | |
94 ~UpdateView() override {} | |
95 | |
96 private: | |
97 // Overridden from ActionableView. | |
98 bool PerformAction(const ui::Event& event) override { | |
99 WmShell::Get()->system_tray_controller()->RequestRestartForUpdate(); | |
100 WmShell::Get()->RecordUserMetricsAction( | |
101 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); | |
102 CloseSystemBubble(); | |
103 return true; | |
104 } | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(UpdateView); | |
107 }; | |
108 | |
109 TrayUpdate::TrayUpdate(SystemTray* system_tray) | |
110 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} | |
111 | |
112 TrayUpdate::~TrayUpdate() {} | |
113 | |
114 bool TrayUpdate::GetInitialVisibility() { | |
115 // If chrome tells ash there is an update available before this item's system | |
116 // tray is constructed then show the icon. | |
117 return update_required_; | |
118 } | |
119 | |
120 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { | |
121 return update_required_ ? new UpdateView(this) : nullptr; | |
122 } | |
123 | |
124 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, | |
125 bool factory_reset_required) { | |
126 // Cache update info so we can create the default view when the menu opens. | |
127 update_required_ = true; | |
128 severity_ = severity; | |
129 factory_reset_required_ = factory_reset_required; | |
130 | |
131 // Show the icon in the tray. | |
132 SetIconColor(IconColorForUpdateSeverity(severity_, false)); | |
133 tray_view()->SetVisible(true); | |
134 } | |
135 | |
136 } // namespace ash | |
OLD | NEW |