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. 4 5 #include "ash/system/tray/tray_image_item.h" 6 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" 14 15 namespace ash { 16 namespace internal { 17 18 TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id) 19 : SystemTrayItem(system_tray), 20 resource_id_(resource_id), 21 tray_view_(NULL) { 22 } 23 24 TrayImageItem::~TrayImageItem() {} 25 26 views::View* TrayImageItem::tray_view() { 27 return tray_view_; 28 } 29 30 void 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 38 views::View* TrayImageItem::CreateTrayView(user::LoginStatus status) { 39 CHECK(tray_view_ == NULL); 40 tray_view_ = new TrayItemView(this); 41 tray_view_->CreateImageView(); 42 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance(). 43 GetImageNamed(resource_id_).ToImageSkia()); 44 tray_view_->SetVisible(GetInitialVisibility()); 45 SetItemAlignment(system_tray()->shelf_alignment()); 46 return tray_view_; 47 } 48 49 views::View* TrayImageItem::CreateDefaultView(user::LoginStatus status) { 50 return NULL; 51 } 52 53 views::View* TrayImageItem::CreateDetailedView(user::LoginStatus status) { 54 return NULL; 55 } 56 57 void TrayImageItem::UpdateAfterLoginStatusChange(user::LoginStatus status) { 58 } 59 60 void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 61 SetTrayImageItemBorder(tray_view_, alignment); 62 SetItemAlignment(alignment); 63 } 64 65 void TrayImageItem::DestroyTrayView() { 66 tray_view_ = NULL; 67 } 68 69 void TrayImageItem::DestroyDefaultView() { 70 } 71 72 void TrayImageItem::DestroyDetailedView() { 73 } 74 75 void 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 92 } // namespace internal 93 } // namespace ash 94