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

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

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 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/common/system/tray/size_range_layout.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/label_tray_view.h"
6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/system/tray/hover_highlight_view.h"
9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/view_click_listener.h"
11 #include "ash/resources/grit/ash_resources.h"
12 #include "ash/resources/vector_icons/vector_icons.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/font.h"
15 #include "ui/gfx/paint_vector_icon.h"
16 #include "ui/views/border.h"
17 #include "ui/views/controls/label.h"
18 #include "ui/views/layout/fill_layout.h"
19
20 namespace ash {
21
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,
47 int icon_resource_id)
48 : click_listener_(click_listener), icon_resource_id_(icon_resource_id) {
49 SetLayoutManager(new views::FillLayout());
50 SetVisible(false);
51 }
52
53 LabelTrayView::~LabelTrayView() {}
54
55 void LabelTrayView::SetMessage(const base::string16& message) {
56 if (message_ == message)
57 return;
58
59 message_ = message;
60 RemoveAllChildViews(true);
61
62 if (!message_.empty()) {
63 AddChildView(CreateChildView(message_));
64 SetVisible(true);
65 } else {
66 SetVisible(false);
67 }
68 }
69
70 views::View* LabelTrayView::CreateChildView(
71 const base::string16& message) const {
72 HoverHighlightView* child = new HoverHighlightView(click_listener_);
73 if (icon_resource_id_) {
74 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial();
75 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
76 gfx::ImageSkia icon =
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);
94 child->SetExpandable(true);
95 child->SetVisible(true);
96 return child;
97 }
98
99 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/label_tray_view.h ('k') | ash/common/system/tray/size_range_layout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698