blob: 3def7618719fc31ef3c3e271bb0b32773edf455d [file] [log] [blame]
[email protected]31a5e312012-03-19 16:23:141// 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
jamescook63936fe2016-06-13 19:11:255#include "ash/common/system/tray/tray_image_item.h"
[email protected]31a5e312012-03-19 16:23:146
tdanderson1bc521b52016-07-07 00:16:067#include "ash/common/material_design/material_design_controller.h"
jamescook1b474d6a2016-06-04 05:56:008#include "ash/common/shelf/wm_shelf_util.h"
jamescook625f7912016-07-14 01:00:529#include "ash/common/system/tray/system_tray.h"
tdanderson1bc521b52016-07-07 00:16:0610#include "ash/common/system/tray/tray_constants.h"
jamescook63936fe2016-06-13 19:11:2511#include "ash/common/system/tray/tray_item_view.h"
12#include "ash/common/system/tray/tray_utils.h"
tdanderson1bc521b52016-07-07 00:16:0613#include "grit/ash_resources.h"
[email protected]31a5e312012-03-19 16:23:1414#include "ui/base/resource/resource_bundle.h"
15#include "ui/gfx/image/image.h"
tdanderson1bc521b52016-07-07 00:16:0616#include "ui/gfx/paint_vector_icon.h"
17#include "ui/gfx/vector_icons_public.h"
[email protected]31a5e312012-03-19 16:23:1418#include "ui/views/controls/image_view.h"
[email protected]d05a15a42013-08-14 05:48:3119#include "ui/views/layout/box_layout.h"
[email protected]31a5e312012-03-19 16:23:1420
21namespace ash {
[email protected]31a5e312012-03-19 16:23:1422
tdanderson1bc521b52016-07-07 00:16:0623namespace {
24
25// Maps a non-MD PNG resource id to its corresponding MD vector icon id.
26// TODO(tdanderson): Remove this once material design is enabled by
27// default. See crbug.com/614453.
28gfx::VectorIconId ResourceIdToVectorIconId(int resource_id) {
29 gfx::VectorIconId vector_id = gfx::VectorIconId::VECTOR_ICON_NONE;
30 switch (resource_id) {
tdanderson1bc521b52016-07-07 00:16:0631 case IDR_AURA_UBER_TRAY_ACCESSIBILITY:
32 return gfx::VectorIconId::SYSTEM_TRAY_ACCESSIBILITY;
33 case IDR_AURA_UBER_TRAY_UPDATE:
34 return gfx::VectorIconId::SYSTEM_TRAY_UPDATE;
thestig6db17dc92016-07-12 03:37:0735 case IDR_AURA_UBER_TRAY_VOLUME_MUTE:
36 return gfx::VectorIconId::SYSTEM_TRAY_VOLUME_MUTE;
37#if defined(OS_CHROMEOS)
tdanderson1bc521b52016-07-07 00:16:0638 case IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED:
39 return gfx::VectorIconId::SYSTEM_TRAY_ROTATION_LOCK_LOCKED;
40 case IDR_AURA_UBER_TRAY_CAPS_LOCK:
41 return gfx::VectorIconId::SYSTEM_TRAY_CAPS_LOCK;
thestig6db17dc92016-07-12 03:37:0742 case IDR_AURA_UBER_TRAY_TRACING:
43 // TODO(tdanderson): Update the icon used for tracing or remove it from
44 // the system tray. See crbug.com/625691.
45 return gfx::VectorIconId::CODE;
46#endif
tdanderson1bc521b52016-07-07 00:16:0647 default:
48 NOTREACHED();
49 break;
50 }
51
52 return vector_id;
53}
54
55} // namespace
56
bruthig5c853162016-07-25 20:23:2657TrayImageItem::TrayImageItem(SystemTray* system_tray,
58 int resource_id,
59 UmaType uma_type)
60 : SystemTrayItem(system_tray, uma_type),
[email protected]1dbddf42012-11-21 21:41:5961 resource_id_(resource_id),
tdanderson78043942016-08-17 19:22:4762 icon_color_(kTrayIconColor),
thestig6db17dc92016-07-12 03:37:0763 tray_view_(nullptr) {}
[email protected]31a5e312012-03-19 16:23:1464
65TrayImageItem::~TrayImageItem() {}
66
[email protected]5d1491d2012-04-23 21:51:0067views::View* TrayImageItem::tray_view() {
[email protected]1d06b1812012-05-01 16:53:1068 return tray_view_;
[email protected]5d1491d2012-04-23 21:51:0069}
70
skye79274a2016-06-08 05:39:0271views::View* TrayImageItem::CreateTrayView(LoginStatus status) {
thestig6db17dc92016-07-12 03:37:0772 CHECK(!tray_view_);
[email protected]1dbddf42012-11-21 21:41:5973 tray_view_ = new TrayItemView(this);
[email protected]5d1491d2012-04-23 21:51:0074 tray_view_->CreateImageView();
tdanderson78043942016-08-17 19:22:4775 UpdateImageOnImageView();
[email protected]5d1491d2012-04-23 21:51:0076 tray_view_->SetVisible(GetInitialVisibility());
[email protected]d05a15a42013-08-14 05:48:3177 SetItemAlignment(system_tray()->shelf_alignment());
[email protected]1d06b1812012-05-01 16:53:1078 return tray_view_;
[email protected]31a5e312012-03-19 16:23:1479}
80
skye79274a2016-06-08 05:39:0281views::View* TrayImageItem::CreateDefaultView(LoginStatus status) {
82 return nullptr;
[email protected]31a5e312012-03-19 16:23:1483}
84
skye79274a2016-06-08 05:39:0285views::View* TrayImageItem::CreateDetailedView(LoginStatus status) {
86 return nullptr;
[email protected]31a5e312012-03-19 16:23:1487}
88
skye79274a2016-06-08 05:39:0289void TrayImageItem::UpdateAfterLoginStatusChange(LoginStatus status) {}
[email protected]eee3e7742012-04-24 17:25:1690
jamescook1b474d6a2016-06-04 05:56:0091void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
[email protected]b17f430b2012-07-23 22:12:1492 SetTrayImageItemBorder(tray_view_, alignment);
[email protected]d05a15a42013-08-14 05:48:3193 SetItemAlignment(alignment);
[email protected]b17f430b2012-07-23 22:12:1494}
95
[email protected]31a5e312012-03-19 16:23:1496void TrayImageItem::DestroyTrayView() {
thestig6db17dc92016-07-12 03:37:0797 tray_view_ = nullptr;
[email protected]31a5e312012-03-19 16:23:1498}
99
jamescookb8dcef522016-06-25 14:42:55100void TrayImageItem::DestroyDefaultView() {}
[email protected]31a5e312012-03-19 16:23:14101
jamescookb8dcef522016-06-25 14:42:55102void TrayImageItem::DestroyDetailedView() {}
[email protected]31a5e312012-03-19 16:23:14103
tdanderson78043942016-08-17 19:22:47104void TrayImageItem::SetIconColor(SkColor color) {
105 icon_color_ = color;
106 UpdateImageOnImageView();
107}
108
tdanderson1bc521b52016-07-07 00:16:06109void TrayImageItem::SetImageFromResourceId(int resource_id) {
110 resource_id_ = resource_id;
tdanderson78043942016-08-17 19:22:47111 UpdateImageOnImageView();
tdanderson1bc521b52016-07-07 00:16:06112}
113
jamescook1b474d6a2016-06-04 05:56:00114void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) {
[email protected]d05a15a42013-08-14 05:48:31115 // Center the item dependent on the orientation of the shelf.
jamescook1b474d6a2016-06-04 05:56:00116 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment)
msw67a576242016-04-18 21:06:13117 ? views::BoxLayout::kHorizontal
118 : views::BoxLayout::kVertical;
[email protected]d05a15a42013-08-14 05:48:31119 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
120 tray_view_->Layout();
121}
122
tdanderson78043942016-08-17 19:22:47123void TrayImageItem::UpdateImageOnImageView() {
124 if (!tray_view_)
125 return;
126
127 if (MaterialDesignController::UseMaterialDesignSystemIcons()) {
128 tray_view_->image_view()->SetImage(gfx::CreateVectorIcon(
129 ResourceIdToVectorIconId(resource_id_), kTrayIconSize, icon_color_));
130 } else {
131 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance()
132 .GetImageNamed(resource_id_)
133 .ToImageSkia());
134 }
135}
136
[email protected]31a5e312012-03-19 16:23:14137} // namespace ash