ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / ash / system / tray / tray_image_item.cc
blob386897c46fb925d63bc8c3db726b0c33d4ae9670
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"
15 namespace ash {
17 TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id)
18 : SystemTrayItem(system_tray),
19 resource_id_(resource_id),
20 tray_view_(NULL) {
23 TrayImageItem::~TrayImageItem() {}
25 views::View* TrayImageItem::tray_view() {
26 return tray_view_;
29 void TrayImageItem::SetImageFromResourceId(int resource_id) {
30 resource_id_ = resource_id;
31 if (!tray_view_)
32 return;
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());
45 return tray_view_;
48 views::View* TrayImageItem::CreateDefaultView(user::LoginStatus status) {
49 return NULL;
52 views::View* TrayImageItem::CreateDetailedView(user::LoginStatus status) {
53 return NULL;
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() {
65 tray_view_ = NULL;
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;
77 switch (alignment) {
78 case ash::SHELF_ALIGNMENT_BOTTOM:
79 case ash::SHELF_ALIGNMENT_TOP:
80 layout = views::BoxLayout::kHorizontal;
81 break;
82 case ash::SHELF_ALIGNMENT_LEFT:
83 case ash::SHELF_ALIGNMENT_RIGHT:
84 layout = views::BoxLayout::kVertical;
85 break;
87 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
88 tray_view_->Layout();
91 } // namespace ash