Chromium Code Reviews| 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_item_more.h" | 5 #include "ash/common/system/tray/tray_item_more.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 #include "ash/common/system/tray/system_tray_item.h" | 7 #include "ash/common/system/tray/system_tray_item.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 8 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/common/system/tray/tray_popup_item_style.h" | 9 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 11 #include "ash/common/system/tray/tray_popup_utils.h" | 10 #include "ash/common/system/tray/tray_popup_utils.h" |
| 12 #include "ash/common/system/tray/tri_view.h" | 11 #include "ash/common/system/tray/tri_view.h" |
| 13 #include "ash/resources/vector_icons/vector_icons.h" | 12 #include "ash/resources/vector_icons/vector_icons.h" |
| 14 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 15 #include "grit/ash_resources.h" | |
| 16 #include "ui/accessibility/ax_node_data.h" | 14 #include "ui/accessibility/ax_node_data.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | |
| 18 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 19 #include "ui/gfx/paint_vector_icon.h" | 16 #include "ui/gfx/paint_vector_icon.h" |
| 20 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
| 21 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/layout/box_layout.h" | |
| 23 #include "ui/views/layout/fill_layout.h" | 19 #include "ui/views/layout/fill_layout.h" |
| 24 | 20 |
| 25 namespace ash { | 21 namespace ash { |
| 26 | 22 |
| 27 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more) | 23 TrayItemMore::TrayItemMore(SystemTrayItem* owner) |
| 28 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), | 24 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), |
| 29 show_more_(show_more), | 25 tri_view_(TrayPopupUtils::CreateDefaultRowView()), |
| 30 icon_(nullptr), | 26 icon_(TrayPopupUtils::CreateMainImageView()), |
| 31 label_(nullptr), | 27 label_(TrayPopupUtils::CreateDefaultLabel()), |
| 32 more_(nullptr) { | 28 more_(TrayPopupUtils::CreateMoreImageView()) { |
| 33 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | 29 AddChildView(tri_view_); |
| 34 AddChildView(tri_view); | |
| 35 SetLayoutManager(new views::FillLayout); | 30 SetLayoutManager(new views::FillLayout); |
| 36 | 31 |
| 37 icon_ = TrayPopupUtils::CreateMainImageView(); | 32 more_->SetImage( |
| 38 tri_view->AddView(TriView::Container::START, icon_); | 33 gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, kMenuIconColor)); |
| 39 | 34 |
| 40 label_ = TrayPopupUtils::CreateDefaultLabel(); | 35 tri_view_->AddView(TriView::Container::START, icon_); |
| 41 tri_view->AddView(TriView::Container::CENTER, label_); | 36 tri_view_->AddView(TriView::Container::CENTER, label_); |
| 37 tri_view_->AddView(TriView::Container::END, more_); | |
| 42 | 38 |
| 43 if (show_more) { | 39 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
| 44 more_ = TrayPopupUtils::CreateMoreImageView(); | |
| 45 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 46 // The icon doesn't change in non-md. | |
| 47 more_->SetImage(ui::ResourceBundle::GetSharedInstance() | |
| 48 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) | |
| 49 .ToImageSkia()); | |
| 50 } | |
| 51 tri_view->AddView(TriView::Container::END, more_); | |
| 52 } else { | |
| 53 tri_view->SetContainerVisible(TriView::Container::END, false); | |
| 54 } | |
| 55 | |
| 56 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 57 SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
| 58 } | 40 } |
| 59 | 41 |
| 60 TrayItemMore::~TrayItemMore() {} | 42 TrayItemMore::~TrayItemMore() {} |
| 61 | 43 |
| 62 void TrayItemMore::SetLabel(const base::string16& label) { | 44 void TrayItemMore::SetLabel(const base::string16& label) { |
| 63 label_->SetText(label); | 45 label_->SetText(label); |
| 64 Layout(); | 46 Layout(); |
| 65 SchedulePaint(); | 47 SchedulePaint(); |
| 66 } | 48 } |
| 67 | 49 |
| 68 void TrayItemMore::SetImage(const gfx::ImageSkia& image_skia) { | 50 void TrayItemMore::SetImage(const gfx::ImageSkia& image_skia) { |
| 69 icon_->SetImage(image_skia); | 51 icon_->SetImage(image_skia); |
| 70 SchedulePaint(); | 52 SchedulePaint(); |
| 71 } | 53 } |
| 72 | 54 |
| 73 void TrayItemMore::SetAccessibleName(const base::string16& name) { | 55 void TrayItemMore::SetAccessibleName(const base::string16& name) { |
| 74 accessible_name_ = name; | 56 accessible_name_ = name; |
| 75 } | 57 } |
| 76 | 58 |
| 77 std::unique_ptr<TrayPopupItemStyle> TrayItemMore::CreateStyle() const { | 59 std::unique_ptr<TrayPopupItemStyle> TrayItemMore::CreateStyle() const { |
| 60 std::unique_ptr<TrayPopupItemStyle> style = HandleCreateStyle(); | |
| 61 if (!enabled()) | |
| 62 style->set_color_style(TrayPopupItemStyle::ColorStyle::DISABLED); | |
| 63 return style; | |
| 64 } | |
| 65 | |
| 66 std::unique_ptr<TrayPopupItemStyle> TrayItemMore::HandleCreateStyle() const { | |
| 78 return base::MakeUnique<TrayPopupItemStyle>( | 67 return base::MakeUnique<TrayPopupItemStyle>( |
| 79 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 68 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
| 80 } | 69 } |
| 81 | 70 |
| 82 void TrayItemMore::UpdateStyle() { | 71 void TrayItemMore::UpdateStyle() { |
| 83 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 84 return; | |
| 85 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); | 72 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); |
| 86 style->SetupLabel(label_); | 73 style->SetupLabel(label_); |
|
tdanderson
2017/02/17 22:29:47
Don't we also want to be theming |icon_| based on
mohsen
2017/02/21 21:04:56
Theming of the |icon_| happens in each subclass si
tdanderson
2017/02/21 21:30:41
Acknowledged. Might be worth a quick chat with Seb
| |
| 87 | |
| 88 if (more_) { | |
| 89 more_->SetImage( | |
| 90 gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, kMenuIconColor)); | |
| 91 } | |
| 92 } | 74 } |
| 93 | 75 |
| 94 bool TrayItemMore::PerformAction(const ui::Event& event) { | 76 bool TrayItemMore::PerformAction(const ui::Event& event) { |
| 95 if (!show_more_) | |
| 96 return false; | |
| 97 | |
| 98 owner()->TransitionDetailedView(); | 77 owner()->TransitionDetailedView(); |
| 99 return true; | 78 return true; |
| 100 } | 79 } |
| 101 | 80 |
| 102 void TrayItemMore::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 81 void TrayItemMore::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 103 ActionableView::GetAccessibleNodeData(node_data); | 82 ActionableView::GetAccessibleNodeData(node_data); |
| 104 if (!accessible_name_.empty()) | 83 if (!accessible_name_.empty()) |
| 105 node_data->SetName(accessible_name_); | 84 node_data->SetName(accessible_name_); |
| 106 } | 85 } |
| 107 | 86 |
| 87 void TrayItemMore::OnEnabledChanged() { | |
| 88 ActionableView::OnEnabledChanged(); | |
| 89 tri_view_->SetContainerVisible(TriView::Container::END, enabled()); | |
|
tdanderson
2017/02/17 22:29:47
If the enabled state were to ever change from disa
mohsen
2017/02/21 21:04:56
Right. Done.
| |
| 90 } | |
| 91 | |
| 108 void TrayItemMore::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 92 void TrayItemMore::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 109 ActionableView::OnNativeThemeChanged(theme); | 93 ActionableView::OnNativeThemeChanged(theme); |
| 110 UpdateStyle(); | 94 UpdateStyle(); |
| 111 } | 95 } |
| 112 | 96 |
| 113 } // namespace ash | 97 } // namespace ash |
| OLD | NEW |