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

Side by Side Diff: ash/system/tray_update.cc

Issue 2059383002: mash: Move TrayUpdate to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ashconstants
Patch Set: rebase Created 4 years, 6 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
« no previous file with comments | « ash/system/tray_update.h ('k') | ash/system/tray_update_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/system/tray_update.h"
6
7 #include "ash/common/system/tray/fixed_sized_image_view.h"
8 #include "ash/common/system/tray/system_tray_delegate.h"
9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/wm_system_tray_notifier.h"
11 #include "ash/common/wm_shell.h"
12 #include "ash/system/tray/system_tray.h"
13 #include "grit/ash_resources.h"
14 #include "grit/ash_strings.h"
15 #include "ui/aura/window.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/image/image.h"
18 #include "ui/views/controls/image_view.h"
19 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/box_layout.h"
21 #include "ui/views/widget/widget.h"
22
23 namespace {
24
25 int DecideResource(ash::UpdateInfo::UpdateSeverity severity, bool dark) {
26 switch (severity) {
27 case ash::UpdateInfo::UPDATE_NORMAL:
28 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK:
29 IDR_AURA_UBER_TRAY_UPDATE;
30
31 case ash::UpdateInfo::UPDATE_LOW_GREEN:
32 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN :
33 IDR_AURA_UBER_TRAY_UPDATE_GREEN;
34
35 case ash::UpdateInfo::UPDATE_HIGH_ORANGE:
36 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE :
37 IDR_AURA_UBER_TRAY_UPDATE_ORANGE;
38
39 case ash::UpdateInfo::UPDATE_SEVERE_RED:
40 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED :
41 IDR_AURA_UBER_TRAY_UPDATE_RED;
42 }
43
44 NOTREACHED() << "Unknown update severity level.";
45 return 0;
46 }
47
48 class UpdateView : public ash::ActionableView {
49 public:
50 explicit UpdateView(const ash::UpdateInfo& info) {
51 SetLayoutManager(new
52 views::BoxLayout(views::BoxLayout::kHorizontal,
53 ash::kTrayPopupPaddingHorizontal, 0,
54 ash::kTrayPopupPaddingBetweenItems));
55
56 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
57 views::ImageView* image =
58 new ash::FixedSizedImageView(0, ash::kTrayPopupItemHeight);
59 image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true))
60 .ToImageSkia());
61
62 AddChildView(image);
63
64 base::string16 label =
65 info.factory_reset_required
66 ? bundle.GetLocalizedString(
67 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE)
68 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE);
69 AddChildView(new views::Label(label));
70 SetAccessibleName(label);
71 }
72
73 ~UpdateView() override {}
74
75 private:
76 // Overridden from ActionableView.
77 bool PerformAction(const ui::Event& event) override {
78 ash::WmShell::Get()->system_tray_delegate()->RequestRestartForUpdate();
79 return true;
80 }
81
82 DISALLOW_COPY_AND_ASSIGN(UpdateView);
83 };
84
85 }
86
87 namespace ash {
88
89 TrayUpdate::TrayUpdate(SystemTray* system_tray)
90 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE) {
91 WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this);
92 }
93
94 TrayUpdate::~TrayUpdate() {
95 WmShell::Get()->system_tray_notifier()->RemoveUpdateObserver(this);
96 }
97
98 bool TrayUpdate::GetInitialVisibility() {
99 UpdateInfo info;
100 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
101 return info.update_required;
102 }
103
104 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) {
105 UpdateInfo info;
106 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
107 return info.update_required ? new UpdateView(info) : nullptr;
108 }
109
110 void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) {
111 SetImageFromResourceId(DecideResource(info.severity, false));
112 tray_view()->SetVisible(true);
113 }
114
115 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_update.h ('k') | ash/system/tray_update_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698