[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 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 | |||||
[email protected] | d05a15a4 | 2013-08-14 05:48:31 | [diff] [blame^] | 7 | #include "ash/system/tray/system_tray.h" |
[email protected] | 5d1491d | 2012-04-23 21:51:00 | [diff] [blame] | 8 | #include "ash/system/tray/tray_item_view.h" |
[email protected] | eccf361 | 2013-05-06 13:06:12 | [diff] [blame] | 9 | #include "ash/system/tray/tray_utils.h" |
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 10 | #include "ui/base/resource/resource_bundle.h" |
11 | #include "ui/gfx/image/image.h" | ||||
12 | #include "ui/views/controls/image_view.h" | ||||
[email protected] | d05a15a4 | 2013-08-14 05:48:31 | [diff] [blame^] | 13 | #include "ui/views/layout/box_layout.h" |
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 14 | |
15 | namespace ash { | ||||
16 | namespace internal { | ||||
17 | |||||
[email protected] | 1dbddf4 | 2012-11-21 21:41:59 | [diff] [blame] | 18 | TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id) |
19 | : SystemTrayItem(system_tray), | ||||
20 | resource_id_(resource_id), | ||||
[email protected] | 1d06b181 | 2012-05-01 16:53:10 | [diff] [blame] | 21 | tray_view_(NULL) { |
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 22 | } |
23 | |||||
24 | TrayImageItem::~TrayImageItem() {} | ||||
25 | |||||
[email protected] | 5d1491d | 2012-04-23 21:51:00 | [diff] [blame] | 26 | views::View* TrayImageItem::tray_view() { |
[email protected] | 1d06b181 | 2012-05-01 16:53:10 | [diff] [blame] | 27 | return tray_view_; |
[email protected] | 5d1491d | 2012-04-23 21:51:00 | [diff] [blame] | 28 | } |
29 | |||||
[email protected] | 9cbc9bf1 | 2012-09-12 09:16:45 | [diff] [blame] | 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 | |||||
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 38 | views::View* TrayImageItem::CreateTrayView(user::LoginStatus status) { |
[email protected] | 1d06b181 | 2012-05-01 16:53:10 | [diff] [blame] | 39 | CHECK(tray_view_ == NULL); |
[email protected] | 1dbddf4 | 2012-11-21 21:41:59 | [diff] [blame] | 40 | tray_view_ = new TrayItemView(this); |
[email protected] | 5d1491d | 2012-04-23 21:51:00 | [diff] [blame] | 41 | tray_view_->CreateImageView(); |
42 | tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance(). | ||||
[email protected] | de2a55f | 2012-05-21 01:54:43 | [diff] [blame] | 43 | GetImageNamed(resource_id_).ToImageSkia()); |
[email protected] | 5d1491d | 2012-04-23 21:51:00 | [diff] [blame] | 44 | tray_view_->SetVisible(GetInitialVisibility()); |
[email protected] | d05a15a4 | 2013-08-14 05:48:31 | [diff] [blame^] | 45 | SetItemAlignment(system_tray()->shelf_alignment()); |
[email protected] | 1d06b181 | 2012-05-01 16:53:10 | [diff] [blame] | 46 | return tray_view_; |
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 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 | |||||
[email protected] | eee3e774 | 2012-04-24 17:25:16 | [diff] [blame] | 57 | void TrayImageItem::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
58 | } | ||||
59 | |||||
[email protected] | b17f430b | 2012-07-23 22:12:14 | [diff] [blame] | 60 | void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
61 | SetTrayImageItemBorder(tray_view_, alignment); | ||||
[email protected] | d05a15a4 | 2013-08-14 05:48:31 | [diff] [blame^] | 62 | SetItemAlignment(alignment); |
[email protected] | b17f430b | 2012-07-23 22:12:14 | [diff] [blame] | 63 | } |
64 | |||||
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 65 | void TrayImageItem::DestroyTrayView() { |
[email protected] | 1d06b181 | 2012-05-01 16:53:10 | [diff] [blame] | 66 | tray_view_ = NULL; |
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 67 | } |
68 | |||||
69 | void TrayImageItem::DestroyDefaultView() { | ||||
70 | } | ||||
71 | |||||
72 | void TrayImageItem::DestroyDetailedView() { | ||||
73 | } | ||||
74 | |||||
[email protected] | d05a15a4 | 2013-08-14 05:48:31 | [diff] [blame^] | 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 | |||||
[email protected] | 31a5e31 | 2012-03-19 16:23:14 | [diff] [blame] | 92 | } // namespace internal |
93 | } // namespace ash |