blob: 7c5e216c9428dbc68190657300cf87cbbe53fc79 [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
5#include "ash/system/tray/tray_image_item.h"
6
[email protected]d05a15a42013-08-14 05:48:317#include "ash/system/tray/system_tray.h"
[email protected]5d1491d2012-04-23 21:51:008#include "ash/system/tray/tray_item_view.h"
[email protected]eccf3612013-05-06 13:06:129#include "ash/system/tray/tray_utils.h"
[email protected]31a5e312012-03-19 16:23:1410#include "ui/base/resource/resource_bundle.h"
11#include "ui/gfx/image/image.h"
12#include "ui/views/controls/image_view.h"
[email protected]d05a15a42013-08-14 05:48:3113#include "ui/views/layout/box_layout.h"
[email protected]31a5e312012-03-19 16:23:1414
15namespace ash {
16namespace internal {
17
[email protected]1dbddf42012-11-21 21:41:5918TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id)
19 : SystemTrayItem(system_tray),
20 resource_id_(resource_id),
[email protected]1d06b1812012-05-01 16:53:1021 tray_view_(NULL) {
[email protected]31a5e312012-03-19 16:23:1422}
23
24TrayImageItem::~TrayImageItem() {}
25
[email protected]5d1491d2012-04-23 21:51:0026views::View* TrayImageItem::tray_view() {
[email protected]1d06b1812012-05-01 16:53:1027 return tray_view_;
[email protected]5d1491d2012-04-23 21:51:0028}
29
[email protected]9cbc9bf12012-09-12 09:16:4530void TrayImageItem::SetImageFromResourceId(int resource_id) {
31 resource_id_ = resource_id;
32 if (!tray_view_)
33 return;
34 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance().
35 GetImageNamed(resource_id_).ToImageSkia());
36}
37
[email protected]31a5e312012-03-19 16:23:1438views::View* TrayImageItem::CreateTrayView(user::LoginStatus status) {
[email protected]1d06b1812012-05-01 16:53:1039 CHECK(tray_view_ == NULL);
[email protected]1dbddf42012-11-21 21:41:5940 tray_view_ = new TrayItemView(this);
[email protected]5d1491d2012-04-23 21:51:0041 tray_view_->CreateImageView();
42 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance().
[email protected]de2a55f2012-05-21 01:54:4343 GetImageNamed(resource_id_).ToImageSkia());
[email protected]5d1491d2012-04-23 21:51:0044 tray_view_->SetVisible(GetInitialVisibility());
[email protected]d05a15a42013-08-14 05:48:3145 SetItemAlignment(system_tray()->shelf_alignment());
[email protected]1d06b1812012-05-01 16:53:1046 return tray_view_;
[email protected]31a5e312012-03-19 16:23:1447}
48
49views::View* TrayImageItem::CreateDefaultView(user::LoginStatus status) {
50 return NULL;
51}
52
53views::View* TrayImageItem::CreateDetailedView(user::LoginStatus status) {
54 return NULL;
55}
56
[email protected]eee3e7742012-04-24 17:25:1657void TrayImageItem::UpdateAfterLoginStatusChange(user::LoginStatus status) {
58}
59
[email protected]b17f430b2012-07-23 22:12:1460void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
61 SetTrayImageItemBorder(tray_view_, alignment);
[email protected]d05a15a42013-08-14 05:48:3162 SetItemAlignment(alignment);
[email protected]b17f430b2012-07-23 22:12:1463}
64
[email protected]31a5e312012-03-19 16:23:1465void TrayImageItem::DestroyTrayView() {
[email protected]1d06b1812012-05-01 16:53:1066 tray_view_ = NULL;
[email protected]31a5e312012-03-19 16:23:1467}
68
69void TrayImageItem::DestroyDefaultView() {
70}
71
72void TrayImageItem::DestroyDetailedView() {
73}
74
[email protected]d05a15a42013-08-14 05:48:3175void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) {
76 // Center the item dependent on the orientation of the shelf.
77 views::BoxLayout::Orientation layout = views::BoxLayout::kHorizontal;
78 switch (alignment) {
79 case ash::SHELF_ALIGNMENT_BOTTOM:
80 case ash::SHELF_ALIGNMENT_TOP:
81 layout = views::BoxLayout::kHorizontal;
82 break;
83 case ash::SHELF_ALIGNMENT_LEFT:
84 case ash::SHELF_ALIGNMENT_RIGHT:
85 layout = views::BoxLayout::kVertical;
86 break;
87 }
88 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
89 tray_view_->Layout();
90}
91
[email protected]31a5e312012-03-19 16:23:1492} // namespace internal
93} // namespace ash