OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/system/tray/tray_image_item.h" | 5 #include "ash/common/system/tray/tray_image_item.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/shelf/wm_shelf_util.h" | 8 #include "ash/common/shelf/wm_shelf_util.h" |
9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
10 #include "ash/common/system/tray/tray_item_view.h" | 10 #include "ash/common/system/tray/tray_item_view.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace ash { | 21 namespace ash { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Maps a non-MD PNG resource id to its corresponding MD vector icon id. | 25 // Maps a non-MD PNG resource id to its corresponding MD vector icon id. |
26 // TODO(tdanderson): Remove this once material design is enabled by | 26 // TODO(tdanderson): Remove this once material design is enabled by |
27 // default. See crbug.com/614453. | 27 // default. See crbug.com/614453. |
28 gfx::VectorIconId ResourceIdToVectorIconId(int resource_id) { | 28 gfx::VectorIconId ResourceIdToVectorIconId(int resource_id) { |
29 gfx::VectorIconId vector_id = gfx::VectorIconId::VECTOR_ICON_NONE; | 29 gfx::VectorIconId vector_id = gfx::VectorIconId::VECTOR_ICON_NONE; |
30 switch (resource_id) { | 30 switch (resource_id) { |
| 31 case IDR_AURA_UBER_TRAY_ACCESSIBILITY: |
| 32 return gfx::VectorIconId::SYSTEM_TRAY_ACCESSIBILITY; |
| 33 case IDR_AURA_UBER_TRAY_UPDATE: |
| 34 return gfx::VectorIconId::SYSTEM_TRAY_UPDATE; |
31 case IDR_AURA_UBER_TRAY_VOLUME_MUTE: | 35 case IDR_AURA_UBER_TRAY_VOLUME_MUTE: |
32 return gfx::VectorIconId::SYSTEM_TRAY_VOLUME_MUTE; | 36 return gfx::VectorIconId::SYSTEM_TRAY_VOLUME_MUTE; |
| 37 #if defined(OS_CHROMEOS) |
| 38 case IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED: |
| 39 return gfx::VectorIconId::SYSTEM_TRAY_ROTATION_LOCK_LOCKED; |
| 40 case IDR_AURA_UBER_TRAY_CAPS_LOCK: |
| 41 return gfx::VectorIconId::SYSTEM_TRAY_CAPS_LOCK; |
33 case IDR_AURA_UBER_TRAY_TRACING: | 42 case IDR_AURA_UBER_TRAY_TRACING: |
34 // TODO(tdanderson): Update the icon used for tracing or remove it from | 43 // TODO(tdanderson): Update the icon used for tracing or remove it from |
35 // the system tray. See crbug.com/625691. | 44 // the system tray. See crbug.com/625691. |
36 return gfx::VectorIconId::CODE; | 45 return gfx::VectorIconId::CODE; |
37 case IDR_AURA_UBER_TRAY_ACCESSIBILITY: | 46 #endif |
38 return gfx::VectorIconId::SYSTEM_TRAY_ACCESSIBILITY; | |
39 case IDR_AURA_UBER_TRAY_UPDATE: | |
40 return gfx::VectorIconId::SYSTEM_TRAY_UPDATE; | |
41 case IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED: | |
42 return gfx::VectorIconId::SYSTEM_TRAY_ROTATION_LOCK_LOCKED; | |
43 case IDR_AURA_UBER_TRAY_CAPS_LOCK: | |
44 return gfx::VectorIconId::SYSTEM_TRAY_CAPS_LOCK; | |
45 default: | 47 default: |
46 NOTREACHED(); | 48 NOTREACHED(); |
47 break; | 49 break; |
48 } | 50 } |
49 | 51 |
50 return vector_id; | 52 return vector_id; |
51 } | 53 } |
52 | 54 |
53 } // namespace | 55 } // namespace |
54 | 56 |
55 TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id) | 57 TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id) |
56 : SystemTrayItem(system_tray), | 58 : SystemTrayItem(system_tray), |
57 resource_id_(resource_id), | 59 resource_id_(resource_id), |
58 tray_view_(NULL) {} | 60 tray_view_(nullptr) {} |
59 | 61 |
60 TrayImageItem::~TrayImageItem() {} | 62 TrayImageItem::~TrayImageItem() {} |
61 | 63 |
62 views::View* TrayImageItem::tray_view() { | 64 views::View* TrayImageItem::tray_view() { |
63 return tray_view_; | 65 return tray_view_; |
64 } | 66 } |
65 | 67 |
66 views::View* TrayImageItem::CreateTrayView(LoginStatus status) { | 68 views::View* TrayImageItem::CreateTrayView(LoginStatus status) { |
67 CHECK(tray_view_ == NULL); | 69 CHECK(!tray_view_); |
68 tray_view_ = new TrayItemView(this); | 70 tray_view_ = new TrayItemView(this); |
69 tray_view_->CreateImageView(); | 71 tray_view_->CreateImageView(); |
70 | 72 |
71 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 73 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
72 tray_view_->image_view()->SetImage(CreateVectorIcon( | 74 tray_view_->image_view()->SetImage(CreateVectorIcon( |
73 ResourceIdToVectorIconId(resource_id_), kTrayIconSize, kTrayIconColor)); | 75 ResourceIdToVectorIconId(resource_id_), kTrayIconSize, kTrayIconColor)); |
74 } else { | 76 } else { |
75 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | 77 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() |
76 .GetImageNamed(resource_id_) | 78 .GetImageNamed(resource_id_) |
77 .ToImageSkia()); | 79 .ToImageSkia()); |
(...skipping 13 matching lines...) Expand all Loading... |
91 } | 93 } |
92 | 94 |
93 void TrayImageItem::UpdateAfterLoginStatusChange(LoginStatus status) {} | 95 void TrayImageItem::UpdateAfterLoginStatusChange(LoginStatus status) {} |
94 | 96 |
95 void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 97 void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
96 SetTrayImageItemBorder(tray_view_, alignment); | 98 SetTrayImageItemBorder(tray_view_, alignment); |
97 SetItemAlignment(alignment); | 99 SetItemAlignment(alignment); |
98 } | 100 } |
99 | 101 |
100 void TrayImageItem::DestroyTrayView() { | 102 void TrayImageItem::DestroyTrayView() { |
101 tray_view_ = NULL; | 103 tray_view_ = nullptr; |
102 } | 104 } |
103 | 105 |
104 void TrayImageItem::DestroyDefaultView() {} | 106 void TrayImageItem::DestroyDefaultView() {} |
105 | 107 |
106 void TrayImageItem::DestroyDetailedView() {} | 108 void TrayImageItem::DestroyDetailedView() {} |
107 | 109 |
108 // TODO(tdanderson): Consider moving or renaming this function, as it is only | 110 // TODO(tdanderson): Consider moving or renaming this function, as it is only |
109 // used by TrayUpdate to modify the update severity. See crbug.com/625692. | 111 // used by TrayUpdate to modify the update severity. See crbug.com/625692. |
110 void TrayImageItem::SetImageFromResourceId(int resource_id) { | 112 void TrayImageItem::SetImageFromResourceId(int resource_id) { |
111 resource_id_ = resource_id; | 113 resource_id_ = resource_id; |
112 if (!tray_view_) | 114 if (!tray_view_) |
113 return; | 115 return; |
114 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | 116 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() |
115 .GetImageNamed(resource_id_) | 117 .GetImageNamed(resource_id_) |
116 .ToImageSkia()); | 118 .ToImageSkia()); |
117 } | 119 } |
118 | 120 |
119 void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) { | 121 void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) { |
120 // Center the item dependent on the orientation of the shelf. | 122 // Center the item dependent on the orientation of the shelf. |
121 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) | 123 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) |
122 ? views::BoxLayout::kHorizontal | 124 ? views::BoxLayout::kHorizontal |
123 : views::BoxLayout::kVertical; | 125 : views::BoxLayout::kVertical; |
124 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); | 126 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); |
125 tray_view_->Layout(); | 127 tray_view_->Layout(); |
126 } | 128 } |
127 | 129 |
128 } // namespace ash | 130 } // namespace ash |
OLD | NEW |