| 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/tray/tray_image_item.h" | 5 #include "ash/common/system/tray/tray_image_item.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 7 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 11 #include "ash/common/system/tray/tray_item_view.h" | 10 #include "ash/common/system/tray/tray_item_view.h" |
| 12 #include "ash/common/system/tray/tray_utils.h" | 11 #include "ash/common/system/tray/tray_utils.h" |
| 13 #include "ash/resources/vector_icons/vector_icons.h" | 12 #include "ash/resources/vector_icons/vector_icons.h" |
| 14 #include "grit/ash_resources.h" | |
| 15 #include "ui/base/resource/resource_bundle.h" | |
| 16 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
| 17 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
| 18 #include "ui/views/controls/image_view.h" | 15 #include "ui/views/controls/image_view.h" |
| 19 #include "ui/views/layout/box_layout.h" | 16 #include "ui/views/layout/box_layout.h" |
| 20 | 17 |
| 21 namespace ash { | 18 namespace ash { |
| 22 | 19 |
| 23 namespace { | |
| 24 | |
| 25 // Maps a non-MD PNG resource id to its corresponding MD vector icon. | |
| 26 // TODO(tdanderson): Remove this once material design is enabled by | |
| 27 // default. See crbug.com/614453. | |
| 28 const gfx::VectorIcon& ResourceIdToVectorIcon(int resource_id) { | |
| 29 switch (resource_id) { | |
| 30 case IDR_AURA_UBER_TRAY_ACCESSIBILITY: | |
| 31 return kSystemTrayAccessibilityIcon; | |
| 32 case IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED: | |
| 33 return kSystemTrayRotationLockLockedIcon; | |
| 34 case IDR_AURA_UBER_TRAY_CAPS_LOCK: | |
| 35 return kSystemTrayCapsLockIcon; | |
| 36 case IDR_AURA_UBER_TRAY_TRACING: | |
| 37 return kSystemTrayTracingIcon; | |
| 38 case IDR_AURA_UBER_TRAY_UPDATE: | |
| 39 return kSystemTrayUpdateIcon; | |
| 40 case IDR_AURA_UBER_TRAY_VOLUME_MUTE: | |
| 41 return kSystemTrayVolumeMuteIcon; | |
| 42 default: | |
| 43 NOTREACHED(); | |
| 44 break; | |
| 45 } | |
| 46 | |
| 47 return gfx::kNoneIcon; | |
| 48 } | |
| 49 | |
| 50 } // namespace | |
| 51 | |
| 52 TrayImageItem::TrayImageItem(SystemTray* system_tray, | 20 TrayImageItem::TrayImageItem(SystemTray* system_tray, |
| 53 int resource_id, | 21 const gfx::VectorIcon& icon, |
| 54 UmaType uma_type) | 22 UmaType uma_type) |
| 55 : SystemTrayItem(system_tray, uma_type), | 23 : SystemTrayItem(system_tray, uma_type), |
| 56 resource_id_(resource_id), | 24 icon_(&icon), |
| 57 icon_color_(kTrayIconColor), | 25 icon_color_(kTrayIconColor), |
| 58 tray_view_(nullptr) {} | 26 tray_view_(nullptr) {} |
| 59 | 27 |
| 60 TrayImageItem::~TrayImageItem() {} | 28 TrayImageItem::~TrayImageItem() {} |
| 61 | 29 |
| 62 views::View* TrayImageItem::tray_view() { | 30 views::View* TrayImageItem::tray_view() { |
| 63 return tray_view_; | 31 return tray_view_; |
| 64 } | 32 } |
| 65 | 33 |
| 66 views::View* TrayImageItem::CreateTrayView(LoginStatus status) { | 34 views::View* TrayImageItem::CreateTrayView(LoginStatus status) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 92 | 60 |
| 93 void TrayImageItem::DestroyDefaultView() {} | 61 void TrayImageItem::DestroyDefaultView() {} |
| 94 | 62 |
| 95 void TrayImageItem::DestroyDetailedView() {} | 63 void TrayImageItem::DestroyDetailedView() {} |
| 96 | 64 |
| 97 void TrayImageItem::SetIconColor(SkColor color) { | 65 void TrayImageItem::SetIconColor(SkColor color) { |
| 98 icon_color_ = color; | 66 icon_color_ = color; |
| 99 UpdateImageOnImageView(); | 67 UpdateImageOnImageView(); |
| 100 } | 68 } |
| 101 | 69 |
| 102 void TrayImageItem::SetImageFromResourceId(int resource_id) { | |
| 103 resource_id_ = resource_id; | |
| 104 UpdateImageOnImageView(); | |
| 105 } | |
| 106 | |
| 107 void TrayImageItem::UpdateImageOnImageView() { | 70 void TrayImageItem::UpdateImageOnImageView() { |
| 108 if (!tray_view_) | 71 if (!tray_view_) |
| 109 return; | 72 return; |
| 110 | 73 |
| 111 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 74 tray_view_->image_view()->SetImage( |
| 112 tray_view_->image_view()->SetImage(gfx::CreateVectorIcon( | 75 gfx::CreateVectorIcon(*icon_, kTrayIconSize, icon_color_)); |
| 113 ResourceIdToVectorIcon(resource_id_), kTrayIconSize, icon_color_)); | |
| 114 } else { | |
| 115 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | |
| 116 .GetImageNamed(resource_id_) | |
| 117 .ToImageSkia()); | |
| 118 } | |
| 119 } | 76 } |
| 120 | 77 |
| 121 } // namespace ash | 78 } // namespace ash |
| OLD | NEW |