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