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
3 // found in the LICENSE file.
5 #include "ash/system/tray/tray_image_item.h"
7 #include "ash/system/tray/system_tray.h"
8 #include "ash/system/tray/tray_item_view.h"
9 #include "ash/system/tray/tray_utils.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image.h"
12 #include "ui/views/controls/image_view.h"
13 #include "ui/views/layout/box_layout.h"
17 TrayImageItem::TrayImageItem(SystemTray
* system_tray
, int resource_id
)
18 : SystemTrayItem(system_tray
),
19 resource_id_(resource_id
),
23 TrayImageItem::~TrayImageItem() {}
25 views::View
* TrayImageItem::tray_view() {
29 void TrayImageItem::SetImageFromResourceId(int resource_id
) {
30 resource_id_
= resource_id
;
33 tray_view_
->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance().
34 GetImageNamed(resource_id_
).ToImageSkia());
37 views::View
* TrayImageItem::CreateTrayView(user::LoginStatus status
) {
38 CHECK(tray_view_
== NULL
);
39 tray_view_
= new TrayItemView(this);
40 tray_view_
->CreateImageView();
41 tray_view_
->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance().
42 GetImageNamed(resource_id_
).ToImageSkia());
43 tray_view_
->SetVisible(GetInitialVisibility());
44 SetItemAlignment(system_tray()->shelf_alignment());
48 views::View
* TrayImageItem::CreateDefaultView(user::LoginStatus status
) {
52 views::View
* TrayImageItem::CreateDetailedView(user::LoginStatus status
) {
56 void TrayImageItem::UpdateAfterLoginStatusChange(user::LoginStatus status
) {
59 void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment
) {
60 SetTrayImageItemBorder(tray_view_
, alignment
);
61 SetItemAlignment(alignment
);
64 void TrayImageItem::DestroyTrayView() {
68 void TrayImageItem::DestroyDefaultView() {
71 void TrayImageItem::DestroyDetailedView() {
74 void TrayImageItem::SetItemAlignment(ShelfAlignment alignment
) {
75 // Center the item dependent on the orientation of the shelf.
76 views::BoxLayout::Orientation layout
= views::BoxLayout::kHorizontal
;
78 case ash::SHELF_ALIGNMENT_BOTTOM
:
79 case ash::SHELF_ALIGNMENT_TOP
:
80 layout
= views::BoxLayout::kHorizontal
;
82 case ash::SHELF_ALIGNMENT_LEFT
:
83 case ash::SHELF_ALIGNMENT_RIGHT
:
84 layout
= views::BoxLayout::kVertical
;
87 tray_view_
->SetLayoutManager(new views::BoxLayout(layout
, 0, 0, 0));