Home | History | Annotate | Download | only in tray
      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 
     17 TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id)
     18     : SystemTrayItem(system_tray),
     19       resource_id_(resource_id),
     20       tray_view_(NULL) {
     21 }
     22 
     23 TrayImageItem::~TrayImageItem() {}
     24 
     25 views::View* TrayImageItem::tray_view() {
     26   return tray_view_;
     27 }
     28 
     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());
     35 }
     36 
     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_;
     46 }
     47 
     48 views::View* TrayImageItem::CreateDefaultView(user::LoginStatus status) {
     49   return NULL;
     50 }
     51 
     52 views::View* TrayImageItem::CreateDetailedView(user::LoginStatus status) {
     53   return NULL;
     54 }
     55 
     56 void TrayImageItem::UpdateAfterLoginStatusChange(user::LoginStatus status) {
     57 }
     58 
     59 void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
     60   SetTrayImageItemBorder(tray_view_, alignment);
     61   SetItemAlignment(alignment);
     62 }
     63 
     64 void TrayImageItem::DestroyTrayView() {
     65   tray_view_ = NULL;
     66 }
     67 
     68 void TrayImageItem::DestroyDefaultView() {
     69 }
     70 
     71 void TrayImageItem::DestroyDetailedView() {
     72 }
     73 
     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;
     86   }
     87   tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
     88   tray_view_->Layout();
     89 }
     90 
     91 }  // namespace ash
     92