15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_image_item.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/system/tray/system_tray.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_item_view.h"
9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/system/tray/tray_utils.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/image_view.h"
133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/views/layout/box_layout.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id)
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : SystemTrayItem(system_tray),
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      resource_id_(resource_id),
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      tray_view_(NULL) {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrayImageItem::~TrayImageItem() {}
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayImageItem::tray_view() {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return tray_view_;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayImageItem::SetImageFromResourceId(int resource_id) {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  resource_id_ = resource_id;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!tray_view_)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance().
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetImageNamed(resource_id_).ToImageSkia());
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayImageItem::CreateTrayView(user::LoginStatus status) {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CHECK(tray_view_ == NULL);
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tray_view_ = new TrayItemView(this);
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tray_view_->CreateImageView();
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance().
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetImageNamed(resource_id_).ToImageSkia());
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tray_view_->SetVisible(GetInitialVisibility());
443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  SetItemAlignment(system_tray()->shelf_alignment());
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return tray_view_;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayImageItem::CreateDefaultView(user::LoginStatus status) {
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return NULL;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayImageItem::CreateDetailedView(user::LoginStatus status) {
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return NULL;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayImageItem::UpdateAfterLoginStatusChange(user::LoginStatus status) {
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetTrayImageItemBorder(tray_view_, alignment);
613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  SetItemAlignment(alignment);
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayImageItem::DestroyTrayView() {
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tray_view_ = NULL;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayImageItem::DestroyDefaultView() {
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayImageItem::DestroyDetailedView() {
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) {
753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Center the item dependent on the orientation of the shelf.
763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  views::BoxLayout::Orientation layout = views::BoxLayout::kHorizontal;
773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  switch (alignment) {
783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    case ash::SHELF_ALIGNMENT_BOTTOM:
793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    case ash::SHELF_ALIGNMENT_TOP:
803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      layout = views::BoxLayout::kHorizontal;
813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      break;
823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    case ash::SHELF_ALIGNMENT_LEFT:
833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    case ash::SHELF_ALIGNMENT_RIGHT:
843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      layout = views::BoxLayout::kVertical;
853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      break;
863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  tray_view_->Layout();
893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
92