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" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/system/tray/fixed_sized_image_view.h" | 8 #include "ash/common/system/tray/fixed_sized_image_view.h" |
9 #include "ash/common/system/tray/system_tray_item.h" | 9 #include "ash/common/system/tray/system_tray_item.h" |
10 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
11 #include "grit/ash_resources.h" | 11 #include "grit/ash_resources.h" |
12 #include "ui/accessibility/ax_view_state.h" | 12 #include "ui/accessibility/ax_view_state.h" |
13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
15 #include "ui/gfx/paint_vector_icon.h" | 15 #include "ui/gfx/paint_vector_icon.h" |
16 #include "ui/gfx/vector_icons_public.h" | 16 #include "ui/gfx/vector_icons_public.h" |
17 #include "ui/native_theme/native_theme.h" | |
17 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
18 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
19 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/box_layout.h" |
20 | 21 |
21 namespace ash { | 22 namespace ash { |
22 | 23 |
23 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more) | 24 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more) |
24 : owner_(owner), | 25 : owner_(owner), |
25 show_more_(show_more), | 26 show_more_(show_more), |
26 icon_(NULL), | 27 icon_(nullptr), |
27 label_(NULL), | 28 label_(nullptr), |
28 more_(NULL) { | 29 more_(nullptr), |
30 style_(new TrayPopupItemStyle(GetNativeTheme(), | |
31 TrayPopupItemStyle::FontStyle::TITLE)) { | |
29 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 32 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
30 kTrayPopupPaddingHorizontal, 0, | 33 kTrayPopupPaddingHorizontal, 0, |
31 kTrayPopupPaddingBetweenItems)); | 34 kTrayPopupPaddingBetweenItems)); |
32 | 35 |
33 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 36 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
34 AddChildView(icon_); | 37 AddChildView(icon_); |
35 | 38 |
36 label_ = new views::Label; | 39 label_ = new views::Label; |
37 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 40 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
38 AddChildView(label_); | 41 AddChildView(label_); |
39 | 42 |
40 if (show_more) { | 43 UpdateChildren(); |
41 more_ = new views::ImageView; | |
42 more_->EnableCanvasFlippingForRTLUI(true); | |
43 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
44 more_->SetImage(gfx::CreateVectorIcon( | |
45 gfx::VectorIconId::SYSTEM_MENU_ARROW_RIGHT, kMenuIconColor)); | |
46 } else { | |
47 more_->SetImage(ui::ResourceBundle::GetSharedInstance() | |
48 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) | |
49 .ToImageSkia()); | |
50 } | |
51 AddChildView(more_); | |
52 } | |
53 } | 44 } |
54 | 45 |
55 TrayItemMore::~TrayItemMore() {} | 46 TrayItemMore::~TrayItemMore() { |
47 style_->RemoveObserver(this); | |
48 } | |
56 | 49 |
57 void TrayItemMore::SetLabel(const base::string16& label) { | 50 void TrayItemMore::SetLabel(const base::string16& label) { |
58 label_->SetText(label); | 51 label_->SetText(label); |
59 Layout(); | 52 Layout(); |
60 SchedulePaint(); | 53 SchedulePaint(); |
61 } | 54 } |
62 | 55 |
63 void TrayItemMore::SetImage(const gfx::ImageSkia& image_skia) { | 56 void TrayItemMore::SetImage(const gfx::ImageSkia& image_skia) { |
64 icon_->SetImage(image_skia); | 57 icon_->SetImage(image_skia); |
65 SchedulePaint(); | 58 SchedulePaint(); |
66 } | 59 } |
67 | 60 |
68 void TrayItemMore::SetAccessibleName(const base::string16& name) { | 61 void TrayItemMore::SetAccessibleName(const base::string16& name) { |
69 accessible_name_ = name; | 62 accessible_name_ = name; |
70 } | 63 } |
71 | 64 |
72 void TrayItemMore::ReplaceIcon(views::View* view) { | 65 void TrayItemMore::SetStyle(std::unique_ptr<TrayPopupItemStyle> style) { |
73 delete icon_; | 66 DCHECK(style); |
74 icon_ = NULL; | 67 style_->RemoveObserver(this); |
75 AddChildViewAt(view, 0); | 68 style_ = std::move(style); |
69 style_->AddObserver(this); | |
70 OnTrayPopupItemStyleChanged(); | |
71 } | |
72 | |
73 void TrayItemMore::OnTrayPopupItemStyleChanged() { | |
74 SetEnabled(style_->color_style() != TrayPopupItemStyle::ColorStyle::DISABLED); | |
75 UpdateChildren(); | |
76 } | |
77 | |
78 void TrayItemMore::UpdateChildren() { | |
79 if (more_) { | |
80 delete more_; | |
81 more_ = nullptr; | |
82 } | |
83 | |
84 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
85 style()->SetupLabel(label_); | |
tdanderson
2016/09/08 16:11:02
I wonder if it would be better to invoke this when
bruthig
2016/09/12 13:45:34
I'm not sure I follow 100%. The style will need t
tdanderson
2016/09/12 18:51:46
Ah, disregard my comment then - in my first skim t
| |
86 | |
87 if (show_more_) { | |
88 more_ = new views::ImageView; | |
89 more_->EnableCanvasFlippingForRTLUI(true); | |
90 | |
91 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
92 more_->SetImage( | |
93 gfx::CreateVectorIcon(gfx::VectorIconId::SYSTEM_MENU_ARROW_RIGHT, | |
94 style()->GetForegroundColor())); | |
95 } else { | |
96 more_->SetImage(ui::ResourceBundle::GetSharedInstance() | |
97 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) | |
98 .ToImageSkia()); | |
99 } | |
100 AddChildView(more_); | |
101 } | |
76 } | 102 } |
77 | 103 |
78 bool TrayItemMore::PerformAction(const ui::Event& event) { | 104 bool TrayItemMore::PerformAction(const ui::Event& event) { |
79 if (!show_more_) | 105 if (!show_more_) |
80 return false; | 106 return false; |
81 | 107 |
82 owner()->TransitionDetailedView(); | 108 owner()->TransitionDetailedView(); |
83 return true; | 109 return true; |
84 } | 110 } |
85 | 111 |
(...skipping 19 matching lines...) Expand all Loading... | |
105 label_->SetBoundsRect(bounds); | 131 label_->SetBoundsRect(bounds); |
106 } | 132 } |
107 } | 133 } |
108 | 134 |
109 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) { | 135 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) { |
110 ActionableView::GetAccessibleState(state); | 136 ActionableView::GetAccessibleState(state); |
111 if (!accessible_name_.empty()) | 137 if (!accessible_name_.empty()) |
112 state->name = accessible_name_; | 138 state->name = accessible_name_; |
113 } | 139 } |
114 | 140 |
141 void TrayItemMore::OnThemeChanged() { | |
142 style_->SetTheme(GetNativeTheme()); | |
143 } | |
144 | |
115 } // namespace ash | 145 } // namespace ash |
OLD | NEW |