OLD | NEW |
| (Empty) |
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/common/system/tray/tray_item_more.h" | |
6 | |
7 #include "ash/common/system/tray/system_tray_item.h" | |
8 #include "ash/common/system/tray/tray_constants.h" | |
9 #include "ash/common/system/tray/tray_popup_item_style.h" | |
10 #include "ash/common/system/tray/tray_popup_utils.h" | |
11 #include "ash/common/system/tray/tri_view.h" | |
12 #include "base/memory/ptr_util.h" | |
13 #include "ui/accessibility/ax_node_data.h" | |
14 #include "ui/gfx/image/image.h" | |
15 #include "ui/views/controls/image_view.h" | |
16 #include "ui/views/controls/label.h" | |
17 #include "ui/views/layout/fill_layout.h" | |
18 | |
19 namespace ash { | |
20 | |
21 TrayItemMore::TrayItemMore(SystemTrayItem* owner) | |
22 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), | |
23 tri_view_(TrayPopupUtils::CreateDefaultRowView()), | |
24 icon_(TrayPopupUtils::CreateMainImageView()), | |
25 label_(TrayPopupUtils::CreateDefaultLabel()), | |
26 more_(TrayPopupUtils::CreateMoreImageView()) { | |
27 AddChildView(tri_view_); | |
28 SetLayoutManager(new views::FillLayout); | |
29 | |
30 tri_view_->AddView(TriView::Container::START, icon_); | |
31 tri_view_->AddView(TriView::Container::CENTER, label_); | |
32 tri_view_->AddView(TriView::Container::END, more_); | |
33 | |
34 SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
35 } | |
36 | |
37 TrayItemMore::~TrayItemMore() {} | |
38 | |
39 void TrayItemMore::SetLabel(const base::string16& label) { | |
40 label_->SetText(label); | |
41 Layout(); | |
42 SchedulePaint(); | |
43 } | |
44 | |
45 void TrayItemMore::SetImage(const gfx::ImageSkia& image_skia) { | |
46 icon_->SetImage(image_skia); | |
47 SchedulePaint(); | |
48 } | |
49 | |
50 void TrayItemMore::SetAccessibleName(const base::string16& name) { | |
51 accessible_name_ = name; | |
52 } | |
53 | |
54 std::unique_ptr<TrayPopupItemStyle> TrayItemMore::CreateStyle() const { | |
55 std::unique_ptr<TrayPopupItemStyle> style = HandleCreateStyle(); | |
56 if (!enabled()) | |
57 style->set_color_style(TrayPopupItemStyle::ColorStyle::DISABLED); | |
58 return style; | |
59 } | |
60 | |
61 std::unique_ptr<TrayPopupItemStyle> TrayItemMore::HandleCreateStyle() const { | |
62 return base::MakeUnique<TrayPopupItemStyle>( | |
63 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | |
64 } | |
65 | |
66 void TrayItemMore::UpdateStyle() { | |
67 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); | |
68 style->SetupLabel(label_); | |
69 } | |
70 | |
71 bool TrayItemMore::PerformAction(const ui::Event& event) { | |
72 owner()->TransitionDetailedView(); | |
73 return true; | |
74 } | |
75 | |
76 void TrayItemMore::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
77 ActionableView::GetAccessibleNodeData(node_data); | |
78 if (!accessible_name_.empty()) | |
79 node_data->SetName(accessible_name_); | |
80 } | |
81 | |
82 void TrayItemMore::OnEnabledChanged() { | |
83 ActionableView::OnEnabledChanged(); | |
84 tri_view_->SetContainerVisible(TriView::Container::END, enabled()); | |
85 UpdateStyle(); | |
86 } | |
87 | |
88 void TrayItemMore::OnNativeThemeChanged(const ui::NativeTheme* theme) { | |
89 ActionableView::OnNativeThemeChanged(theme); | |
90 UpdateStyle(); | |
91 } | |
92 | |
93 } // namespace ash | |
OLD | NEW |