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

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

Issue 2715463004: Remove non-MD code from LabelTrayView (Closed)
Patch Set: estade comments Created 3 years, 8 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
« no previous file with comments | « ash/common/system/tray/label_tray_view.h ('k') | ash/resources/ash_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/label_tray_view.h" 5 #include "ash/common/system/tray/label_tray_view.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/system/tray/hover_highlight_view.h" 7 #include "ash/common/system/tray/hover_highlight_view.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/view_click_listener.h" 9 #include "ash/common/system/tray/view_click_listener.h"
11 #include "ash/resources/grit/ash_resources.h" 10 #include "ash/resources/grit/ash_resources.h"
12 #include "ash/resources/vector_icons/vector_icons.h" 11 #include "ash/resources/vector_icons/vector_icons.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/font.h" 12 #include "ui/gfx/font.h"
15 #include "ui/gfx/paint_vector_icon.h" 13 #include "ui/gfx/paint_vector_icon.h"
16 #include "ui/views/border.h"
17 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
18 #include "ui/views/layout/fill_layout.h" 15 #include "ui/views/layout/fill_layout.h"
19 16
20 namespace ash { 17 namespace ash {
21 18
22 namespace {
23
24 // Maps a non-MD PNG resource id to its corresponding MD vector icon.
25 // TODO(tdanderson): Remove this once material design is enabled by
26 // default. See crbug.com/614453.
27 const gfx::VectorIcon& ResourceIdToVectorIcon(int resource_id) {
28 switch (resource_id) {
29 case IDR_AURA_UBER_TRAY_ENTERPRISE:
30 return kSystemMenuBusinessIcon;
31 case IDR_AURA_UBER_TRAY_BUBBLE_SESSION_LENGTH_LIMIT:
32 return kSystemMenuTimerIcon;
33 case IDR_AURA_UBER_TRAY_CHILD_USER:
34 return kSystemMenuChildUserIcon;
35 case IDR_AURA_UBER_TRAY_SUPERVISED_USER:
36 return kSystemMenuSupervisedUserIcon;
37 default:
38 NOTREACHED();
39 break;
40 }
41 return gfx::kNoneIcon;
42 }
43
44 } // namespace
45
46 LabelTrayView::LabelTrayView(ViewClickListener* click_listener, 19 LabelTrayView::LabelTrayView(ViewClickListener* click_listener,
47 int icon_resource_id) 20 const gfx::VectorIcon& icon)
48 : click_listener_(click_listener), icon_resource_id_(icon_resource_id) { 21 : click_listener_(click_listener), icon_(icon) {
49 SetLayoutManager(new views::FillLayout()); 22 SetLayoutManager(new views::FillLayout());
50 SetVisible(false); 23 SetVisible(false);
51 } 24 }
52 25
53 LabelTrayView::~LabelTrayView() {} 26 LabelTrayView::~LabelTrayView() {}
54 27
55 void LabelTrayView::SetMessage(const base::string16& message) { 28 void LabelTrayView::SetMessage(const base::string16& message) {
56 if (message_ == message) 29 if (message_ == message)
57 return; 30 return;
58 31
59 message_ = message; 32 message_ = message;
60 RemoveAllChildViews(true); 33 RemoveAllChildViews(true);
61 34
62 if (!message_.empty()) { 35 if (!message_.empty()) {
63 AddChildView(CreateChildView(message_)); 36 AddChildView(CreateChildView(message_));
64 SetVisible(true); 37 SetVisible(true);
65 } else { 38 } else {
66 SetVisible(false); 39 SetVisible(false);
67 } 40 }
68 } 41 }
69 42
70 views::View* LabelTrayView::CreateChildView( 43 views::View* LabelTrayView::CreateChildView(
71 const base::string16& message) const { 44 const base::string16& message) const {
72 HoverHighlightView* child = new HoverHighlightView(click_listener_); 45 HoverHighlightView* child = new HoverHighlightView(click_listener_);
73 if (icon_resource_id_) { 46 gfx::ImageSkia icon_image = gfx::CreateVectorIcon(icon_, kMenuIconColor);
74 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); 47 child->AddIconAndLabelForDefaultView(icon_image, message,
75 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 48 false /* highlight */);
76 gfx::ImageSkia icon = 49 child->text_label()->SetMultiLine(true);
77 use_md ? gfx::CreateVectorIcon(
78 ResourceIdToVectorIcon(icon_resource_id_), kMenuIconColor)
79 : *rb.GetImageSkiaNamed(icon_resource_id_);
80 child->AddIconAndLabelForDefaultView(icon, message, false /* highlight */);
81 child->text_label()->SetMultiLine(true);
82 if (!use_md) {
83 child->SetBorder(views::CreateEmptyBorder(
84 0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal));
85 child->text_label()->SizeToFit(kTrayNotificationContentsWidth);
86 }
87 } else {
88 child->AddLabel(message, gfx::ALIGN_LEFT, false /* highlight */);
89 child->text_label()->SetMultiLine(true);
90 child->text_label()->SizeToFit(kTrayNotificationContentsWidth +
91 kNotificationIconWidth);
92 }
93 child->text_label()->SetAllowCharacterBreak(true); 50 child->text_label()->SetAllowCharacterBreak(true);
94 child->SetExpandable(true); 51 child->SetExpandable(true);
95 child->SetVisible(true); 52 child->SetVisible(true);
96 return child; 53 return child;
97 } 54 }
98 55
99 } // namespace ash 56 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/label_tray_view.h ('k') | ash/resources/ash_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698