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/system/tray/fixed_sized_image_view.h" | 7 #include "ash/common/system/tray/fixed_sized_image_view.h" |
8 #include "ash/common/system/tray/system_tray_delegate.h" | 8 #include "ash/common/system/tray/system_tray_delegate.h" |
9 #include "ash/common/system/tray/system_tray_notifier.h" | 9 #include "ash/common/system/tray/system_tray_notifier.h" |
10 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/system/tray/system_tray.h" | 12 #include "ash/system/tray/system_tray.h" |
13 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
14 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
17 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
18 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
19 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 int DecideResource(ash::UpdateInfo::UpdateSeverity severity, bool dark) { | 23 int DecideResource(ash::UpdateInfo::UpdateSeverity severity, bool dark) { |
24 switch (severity) { | 24 switch (severity) { |
25 case ash::UpdateInfo::UPDATE_NORMAL: | 25 case ash::UpdateInfo::UPDATE_NORMAL: |
26 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK: | 26 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE; |
27 IDR_AURA_UBER_TRAY_UPDATE; | |
28 | 27 |
29 case ash::UpdateInfo::UPDATE_LOW_GREEN: | 28 case ash::UpdateInfo::UPDATE_LOW_GREEN: |
30 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN : | 29 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN |
31 IDR_AURA_UBER_TRAY_UPDATE_GREEN; | 30 : IDR_AURA_UBER_TRAY_UPDATE_GREEN; |
32 | 31 |
33 case ash::UpdateInfo::UPDATE_HIGH_ORANGE: | 32 case ash::UpdateInfo::UPDATE_HIGH_ORANGE: |
34 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE : | 33 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE |
35 IDR_AURA_UBER_TRAY_UPDATE_ORANGE; | 34 : IDR_AURA_UBER_TRAY_UPDATE_ORANGE; |
36 | 35 |
37 case ash::UpdateInfo::UPDATE_SEVERE_RED: | 36 case ash::UpdateInfo::UPDATE_SEVERE_RED: |
38 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED : | 37 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED |
39 IDR_AURA_UBER_TRAY_UPDATE_RED; | 38 : IDR_AURA_UBER_TRAY_UPDATE_RED; |
40 } | 39 } |
41 | 40 |
42 NOTREACHED() << "Unknown update severity level."; | 41 NOTREACHED() << "Unknown update severity level."; |
43 return 0; | 42 return 0; |
44 } | 43 } |
45 | 44 |
46 class UpdateView : public ash::ActionableView { | 45 class UpdateView : public ash::ActionableView { |
47 public: | 46 public: |
48 explicit UpdateView(const ash::UpdateInfo& info) { | 47 explicit UpdateView(const ash::UpdateInfo& info) { |
49 SetLayoutManager(new | 48 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
50 views::BoxLayout(views::BoxLayout::kHorizontal, | 49 ash::kTrayPopupPaddingHorizontal, 0, |
51 ash::kTrayPopupPaddingHorizontal, 0, | 50 ash::kTrayPopupPaddingBetweenItems)); |
52 ash::kTrayPopupPaddingBetweenItems)); | |
53 | 51 |
54 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 52 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
55 views::ImageView* image = | 53 views::ImageView* image = |
56 new ash::FixedSizedImageView(0, ash::kTrayPopupItemHeight); | 54 new ash::FixedSizedImageView(0, ash::kTrayPopupItemHeight); |
57 image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true)) | 55 image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true)) |
58 .ToImageSkia()); | 56 .ToImageSkia()); |
59 | 57 |
60 AddChildView(image); | 58 AddChildView(image); |
61 | 59 |
62 base::string16 label = | 60 base::string16 label = |
63 info.factory_reset_required | 61 info.factory_reset_required |
64 ? bundle.GetLocalizedString( | 62 ? bundle.GetLocalizedString( |
65 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) | 63 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) |
66 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); | 64 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); |
67 AddChildView(new views::Label(label)); | 65 AddChildView(new views::Label(label)); |
68 SetAccessibleName(label); | 66 SetAccessibleName(label); |
69 } | 67 } |
70 | 68 |
71 ~UpdateView() override {} | 69 ~UpdateView() override {} |
72 | 70 |
73 private: | 71 private: |
74 // Overridden from ActionableView. | 72 // Overridden from ActionableView. |
75 bool PerformAction(const ui::Event& event) override { | 73 bool PerformAction(const ui::Event& event) override { |
76 ash::WmShell::Get()->system_tray_delegate()->RequestRestartForUpdate(); | 74 ash::WmShell::Get()->system_tray_delegate()->RequestRestartForUpdate(); |
77 return true; | 75 return true; |
78 } | 76 } |
79 | 77 |
80 DISALLOW_COPY_AND_ASSIGN(UpdateView); | 78 DISALLOW_COPY_AND_ASSIGN(UpdateView); |
81 }; | 79 }; |
82 | |
83 } | 80 } |
84 | 81 |
85 namespace ash { | 82 namespace ash { |
86 | 83 |
87 TrayUpdate::TrayUpdate(SystemTray* system_tray) | 84 TrayUpdate::TrayUpdate(SystemTray* system_tray) |
88 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE) { | 85 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE) { |
89 WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this); | 86 WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this); |
90 } | 87 } |
91 | 88 |
92 TrayUpdate::~TrayUpdate() { | 89 TrayUpdate::~TrayUpdate() { |
(...skipping 11 matching lines...) Expand all Loading... |
104 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info); | 101 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info); |
105 return info.update_required ? new UpdateView(info) : nullptr; | 102 return info.update_required ? new UpdateView(info) : nullptr; |
106 } | 103 } |
107 | 104 |
108 void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) { | 105 void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) { |
109 SetImageFromResourceId(DecideResource(info.severity, false)); | 106 SetImageFromResourceId(DecideResource(info.severity, false)); |
110 tray_view()->SetVisible(true); | 107 tray_view()->SetVisible(true); |
111 } | 108 } |
112 | 109 |
113 } // namespace ash | 110 } // namespace ash |
OLD | NEW |