Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: ash/common/system/tray/tray_item_more.cc

Issue 2244003002: Materialized font style for TrayItemMore type system tray rows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated TrayPopupItemStyle to use the default FontList. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ash/resources/vector_icons/vector_icons.h" 11 #include "ash/resources/vector_icons/vector_icons.h"
12 #include "grit/ash_resources.h" 12 #include "grit/ash_resources.h"
13 #include "ui/accessibility/ax_view_state.h" 13 #include "ui/accessibility/ax_view_state.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/paint_vector_icon.h" 16 #include "ui/gfx/paint_vector_icon.h"
17 #include "ui/gfx/vector_icons_public.h"
18 #include "ui/native_theme/native_theme.h"
17 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
19 #include "ui/views/layout/box_layout.h" 21 #include "ui/views/layout/box_layout.h"
20 22
21 namespace ash { 23 namespace ash {
22 24
23 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more) 25 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more)
24 : owner_(owner), 26 : owner_(owner),
25 show_more_(show_more), 27 show_more_(show_more),
26 icon_(NULL), 28 icon_(nullptr),
27 label_(NULL), 29 label_(nullptr),
28 more_(NULL) { 30 more_(nullptr) {
31 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
32 style_.reset(new TrayPopupItemStyle(GetNativeTheme(),
33 TrayPopupItemStyle::FontStyle::TITLE));
34 style_->AddObserver(this);
35 }
36
29 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 37 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
30 kTrayPopupPaddingHorizontal, 0, 38 kTrayPopupPaddingHorizontal, 0,
31 kTrayPopupPaddingBetweenItems)); 39 kTrayPopupPaddingBetweenItems));
32 40
33 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); 41 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
34 AddChildView(icon_); 42 AddChildView(icon_);
35 43
36 label_ = new views::Label; 44 label_ = new views::Label;
37 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 45 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
38 AddChildView(label_); 46 AddChildView(label_);
39 47
40 if (show_more) { 48 UpdateContent();
tdanderson 2016/09/12 18:51:47 If I'm not mistaken, this call to UpdateContent()
41 more_ = new views::ImageView;
42 more_->EnableCanvasFlippingForRTLUI(true);
43 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
44 more_->SetImage(
45 gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, kMenuIconColor));
46 } else {
47 more_->SetImage(ui::ResourceBundle::GetSharedInstance()
48 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE)
49 .ToImageSkia());
50 }
51 AddChildView(more_);
52 }
53 } 49 }
54 50
55 TrayItemMore::~TrayItemMore() {} 51 TrayItemMore::~TrayItemMore() {
52 if (MaterialDesignController::IsSystemTrayMenuMaterial())
53 style_->RemoveObserver(this);
54 }
56 55
57 void TrayItemMore::SetLabel(const base::string16& label) { 56 void TrayItemMore::SetLabel(const base::string16& label) {
58 label_->SetText(label); 57 label_->SetText(label);
59 Layout(); 58 Layout();
60 SchedulePaint(); 59 SchedulePaint();
61 } 60 }
62 61
63 void TrayItemMore::SetImage(const gfx::ImageSkia& image_skia) { 62 void TrayItemMore::SetImage(const gfx::ImageSkia& image_skia) {
64 icon_->SetImage(image_skia); 63 icon_->SetImage(image_skia);
65 SchedulePaint(); 64 SchedulePaint();
66 } 65 }
67 66
68 void TrayItemMore::SetAccessibleName(const base::string16& name) { 67 void TrayItemMore::SetAccessibleName(const base::string16& name) {
69 accessible_name_ = name; 68 accessible_name_ = name;
70 } 69 }
71 70
72 void TrayItemMore::ReplaceIcon(views::View* view) { 71 void TrayItemMore::SetStyle(std::unique_ptr<TrayPopupItemStyle> style) {
73 delete icon_; 72 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial() && style);
74 icon_ = NULL; 73 style_ = std::move(style);
75 AddChildViewAt(view, 0); 74 style_->AddObserver(this);
75 OnTrayPopupItemStyleUpdated();
76 }
77
78 void TrayItemMore::OnTrayPopupItemStyleUpdated() {
79 SetEnabled(style_->color_style() != TrayPopupItemStyle::ColorStyle::DISABLED);
80 UpdateContent();
81 }
82
83 void TrayItemMore::UpdateContent() {
84 if (more_) {
85 delete more_;
86 more_ = nullptr;
87 }
88
89 if (MaterialDesignController::IsSystemTrayMenuMaterial())
90 style()->SetupLabel(label_);
91
92 if (show_more_) {
93 more_ = new views::ImageView;
94 more_->EnableCanvasFlippingForRTLUI(true);
95
96 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
97 more_->SetImage(gfx::CreateVectorIcon(kSystemMenuArrowRightIcon,
98 style()->GetForegroundColor()));
99 } else {
100 more_->SetImage(ui::ResourceBundle::GetSharedInstance()
101 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE)
102 .ToImageSkia());
103 }
104 AddChildView(more_);
105 }
76 } 106 }
77 107
78 bool TrayItemMore::PerformAction(const ui::Event& event) { 108 bool TrayItemMore::PerformAction(const ui::Event& event) {
79 if (!show_more_) 109 if (!show_more_)
80 return false; 110 return false;
81 111
82 owner()->TransitionDetailedView(); 112 owner()->TransitionDetailedView();
83 return true; 113 return true;
84 } 114 }
85 115
(...skipping 19 matching lines...) Expand all
105 label_->SetBoundsRect(bounds); 135 label_->SetBoundsRect(bounds);
106 } 136 }
107 } 137 }
108 138
109 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) { 139 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) {
110 ActionableView::GetAccessibleState(state); 140 ActionableView::GetAccessibleState(state);
111 if (!accessible_name_.empty()) 141 if (!accessible_name_.empty())
112 state->name = accessible_name_; 142 state->name = accessible_name_;
113 } 143 }
114 144
145 void TrayItemMore::OnThemeChanged() {
146 if (MaterialDesignController::IsSystemTrayMenuMaterial())
147 style_->SetTheme(GetNativeTheme());
148 }
149
115 } // namespace ash 150 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698