| 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/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 views::View* TrayImageItem::tray_view() { | 66 views::View* TrayImageItem::tray_view() { |
| 67 return tray_view_; | 67 return tray_view_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 views::View* TrayImageItem::CreateTrayView(LoginStatus status) { | 70 views::View* TrayImageItem::CreateTrayView(LoginStatus status) { |
| 71 CHECK(!tray_view_); | 71 CHECK(!tray_view_); |
| 72 tray_view_ = new TrayItemView(this); | 72 tray_view_ = new TrayItemView(this); |
| 73 tray_view_->CreateImageView(); | 73 tray_view_->CreateImageView(); |
| 74 UpdateImageOnImageView(); | 74 UpdateImageOnImageView(); |
| 75 tray_view_->SetVisible(GetInitialVisibility()); | 75 tray_view_->SetVisible(GetInitialVisibility()); |
| 76 SetItemAlignment(system_tray()->shelf_alignment()); | |
| 77 return tray_view_; | 76 return tray_view_; |
| 78 } | 77 } |
| 79 | 78 |
| 80 views::View* TrayImageItem::CreateDefaultView(LoginStatus status) { | 79 views::View* TrayImageItem::CreateDefaultView(LoginStatus status) { |
| 81 return nullptr; | 80 return nullptr; |
| 82 } | 81 } |
| 83 | 82 |
| 84 views::View* TrayImageItem::CreateDetailedView(LoginStatus status) { | 83 views::View* TrayImageItem::CreateDetailedView(LoginStatus status) { |
| 85 return nullptr; | 84 return nullptr; |
| 86 } | 85 } |
| 87 | 86 |
| 88 void TrayImageItem::UpdateAfterLoginStatusChange(LoginStatus status) {} | 87 void TrayImageItem::UpdateAfterLoginStatusChange(LoginStatus status) {} |
| 89 | 88 |
| 90 void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 89 void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 91 SetTrayImageItemBorder(tray_view_, alignment); | 90 SetTrayImageItemBorder(tray_view_, alignment); |
| 92 SetItemAlignment(alignment); | |
| 93 } | 91 } |
| 94 | 92 |
| 95 void TrayImageItem::DestroyTrayView() { | 93 void TrayImageItem::DestroyTrayView() { |
| 96 tray_view_ = nullptr; | 94 tray_view_ = nullptr; |
| 97 } | 95 } |
| 98 | 96 |
| 99 void TrayImageItem::DestroyDefaultView() {} | 97 void TrayImageItem::DestroyDefaultView() {} |
| 100 | 98 |
| 101 void TrayImageItem::DestroyDetailedView() {} | 99 void TrayImageItem::DestroyDetailedView() {} |
| 102 | 100 |
| 103 void TrayImageItem::SetIconColor(SkColor color) { | 101 void TrayImageItem::SetIconColor(SkColor color) { |
| 104 icon_color_ = color; | 102 icon_color_ = color; |
| 105 UpdateImageOnImageView(); | 103 UpdateImageOnImageView(); |
| 106 } | 104 } |
| 107 | 105 |
| 108 void TrayImageItem::SetImageFromResourceId(int resource_id) { | 106 void TrayImageItem::SetImageFromResourceId(int resource_id) { |
| 109 resource_id_ = resource_id; | 107 resource_id_ = resource_id; |
| 110 UpdateImageOnImageView(); | 108 UpdateImageOnImageView(); |
| 111 } | 109 } |
| 112 | 110 |
| 113 void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) { | |
| 114 // Center the item dependent on the orientation of the shelf. | |
| 115 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) | |
| 116 ? views::BoxLayout::kHorizontal | |
| 117 : views::BoxLayout::kVertical; | |
| 118 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); | |
| 119 tray_view_->Layout(); | |
| 120 } | |
| 121 | |
| 122 void TrayImageItem::UpdateImageOnImageView() { | 111 void TrayImageItem::UpdateImageOnImageView() { |
| 123 if (!tray_view_) | 112 if (!tray_view_) |
| 124 return; | 113 return; |
| 125 | 114 |
| 126 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 115 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
| 127 tray_view_->image_view()->SetImage(gfx::CreateVectorIcon( | 116 tray_view_->image_view()->SetImage(gfx::CreateVectorIcon( |
| 128 ResourceIdToVectorIcon(resource_id_), kTrayIconSize, icon_color_)); | 117 ResourceIdToVectorIcon(resource_id_), kTrayIconSize, icon_color_)); |
| 129 } else { | 118 } else { |
| 130 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | 119 tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() |
| 131 .GetImageNamed(resource_id_) | 120 .GetImageNamed(resource_id_) |
| 132 .ToImageSkia()); | 121 .ToImageSkia()); |
| 133 } | 122 } |
| 134 } | 123 } |
| 135 | 124 |
| 136 } // namespace ash | 125 } // namespace ash |
| OLD | NEW |