blob: c863cda02df63a93aeee964d4dde338426f2d515 [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"
tdanderson1bc521b52016-07-07 00:16:069#include "ash/common/system/tray/tray_constants.h"
jamescook63936fe2016-06-13 19:11:2510#include "ash/common/system/tray/tray_item_view.h"
11#include "ash/common/system/tray/tray_utils.h"
[email protected]d05a15a42013-08-14 05:48:3112#include "ash/system/tray/system_tray.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) {
31 case IDR_AURA_UBER_TRAY_VOLUME_MUTE:
32 return gfx::VectorIconId::SYSTEM_TRAY_VOLUME_MUTE;
33 case IDR_AURA_UBER_TRAY_TRACING:
34 // TODO(tdanderson): Update the icon used for tracing or remove it from
35 // the system tray. See crbug.com/625691.
36 return gfx::VectorIconId::CODE;
37 case IDR_AURA_UBER_TRAY_ACCESSIBILITY:
38 return gfx::VectorIconId::SYSTEM_TRAY_ACCESSIBILITY;
39 case IDR_AURA_UBER_TRAY_UPDATE:
40 return gfx::VectorIconId::SYSTEM_TRAY_UPDATE;
41 case IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED:
42 return gfx::VectorIconId::SYSTEM_TRAY_ROTATION_LOCK_LOCKED;
43 case IDR_AURA_UBER_TRAY_CAPS_LOCK:
44 return gfx::VectorIconId::SYSTEM_TRAY_CAPS_LOCK;
45 default:
46 NOTREACHED();
47 break;
48 }
49
50 return vector_id;
51}
52
53} // namespace
54
[email protected]1dbddf42012-11-21 21:41:5955TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id)
56 : SystemTrayItem(system_tray),
57 resource_id_(resource_id),
jamescookb8dcef522016-06-25 14:42:5558 tray_view_(NULL) {}
[email protected]31a5e312012-03-19 16:23:1459
60TrayImageItem::~TrayImageItem() {}
61
[email protected]5d1491d2012-04-23 21:51:0062views::View* TrayImageItem::tray_view() {
[email protected]1d06b1812012-05-01 16:53:1063 return tray_view_;
[email protected]5d1491d2012-04-23 21:51:0064}
65
skye79274a2016-06-08 05:39:0266views::View* TrayImageItem::CreateTrayView(LoginStatus status) {
[email protected]1d06b1812012-05-01 16:53:1067 CHECK(tray_view_ == NULL);
[email protected]1dbddf42012-11-21 21:41:5968 tray_view_ = new TrayItemView(this);
[email protected]5d1491d2012-04-23 21:51:0069 tray_view_->CreateImageView();
tdanderson1bc521b52016-07-07 00:16:0670
71 if (MaterialDesignController::UseMaterialDesignSystemIcons()) {
72 tray_view_->image_view()->SetImage(CreateVectorIcon(
73 ResourceIdToVectorIconId(resource_id_), kTrayIconSize, kTrayIconColor));
74 } else {
75 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance()
76 .GetImageNamed(resource_id_)
77 .ToImageSkia());
78 }
79
[email protected]5d1491d2012-04-23 21:51:0080 tray_view_->SetVisible(GetInitialVisibility());
[email protected]d05a15a42013-08-14 05:48:3181 SetItemAlignment(system_tray()->shelf_alignment());
[email protected]1d06b1812012-05-01 16:53:1082 return tray_view_;
[email protected]31a5e312012-03-19 16:23:1483}
84
skye79274a2016-06-08 05:39:0285views::View* TrayImageItem::CreateDefaultView(LoginStatus status) {
86 return nullptr;
[email protected]31a5e312012-03-19 16:23:1487}
88
skye79274a2016-06-08 05:39:0289views::View* TrayImageItem::CreateDetailedView(LoginStatus status) {
90 return nullptr;
[email protected]31a5e312012-03-19 16:23:1491}
92
skye79274a2016-06-08 05:39:0293void TrayImageItem::UpdateAfterLoginStatusChange(LoginStatus status) {}
[email protected]eee3e7742012-04-24 17:25:1694
jamescook1b474d6a2016-06-04 05:56:0095void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
[email protected]b17f430b2012-07-23 22:12:1496 SetTrayImageItemBorder(tray_view_, alignment);
[email protected]d05a15a42013-08-14 05:48:3197 SetItemAlignment(alignment);
[email protected]b17f430b2012-07-23 22:12:1498}
99
[email protected]31a5e312012-03-19 16:23:14100void TrayImageItem::DestroyTrayView() {
[email protected]1d06b1812012-05-01 16:53:10101 tray_view_ = NULL;
[email protected]31a5e312012-03-19 16:23:14102}
103
jamescookb8dcef522016-06-25 14:42:55104void TrayImageItem::DestroyDefaultView() {}
[email protected]31a5e312012-03-19 16:23:14105
jamescookb8dcef522016-06-25 14:42:55106void TrayImageItem::DestroyDetailedView() {}
[email protected]31a5e312012-03-19 16:23:14107
tdanderson1bc521b52016-07-07 00:16:06108// TODO(tdanderson): Consider moving or renaming this function, as it is only
109// used by TrayUpdate to modify the update severity. See crbug.com/625692.
110void TrayImageItem::SetImageFromResourceId(int resource_id) {
111 resource_id_ = resource_id;
112 if (!tray_view_)
113 return;
114 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance()
115 .GetImageNamed(resource_id_)
116 .ToImageSkia());
117}
118
jamescook1b474d6a2016-06-04 05:56:00119void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) {
[email protected]d05a15a42013-08-14 05:48:31120 // Center the item dependent on the orientation of the shelf.
jamescook1b474d6a2016-06-04 05:56:00121 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment)
msw67a576242016-04-18 21:06:13122 ? views::BoxLayout::kHorizontal
123 : views::BoxLayout::kVertical;
[email protected]d05a15a42013-08-14 05:48:31124 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
125 tray_view_->Layout();
126}
127
[email protected]31a5e312012-03-19 16:23:14128} // namespace ash