| 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/system/chromeos/label_tray_view.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/hover_highlight_view.h" | |
| 8 #include "ash/common/system/tray/tray_constants.h" | |
| 9 #include "ash/common/system/tray/view_click_listener.h" | |
| 10 #include "ui/base/resource/resource_bundle.h" | |
| 11 #include "ui/gfx/font.h" | |
| 12 #include "ui/views/border.h" | |
| 13 #include "ui/views/controls/label.h" | |
| 14 #include "ui/views/layout/fill_layout.h" | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 LabelTrayView::LabelTrayView(ViewClickListener* click_listener, | |
| 19 int icon_resource_id) | |
| 20 : click_listener_(click_listener), icon_resource_id_(icon_resource_id) { | |
| 21 SetLayoutManager(new views::FillLayout()); | |
| 22 SetVisible(false); | |
| 23 } | |
| 24 | |
| 25 LabelTrayView::~LabelTrayView() {} | |
| 26 | |
| 27 void LabelTrayView::SetMessage(const base::string16& message) { | |
| 28 if (message_ == message) | |
| 29 return; | |
| 30 | |
| 31 message_ = message; | |
| 32 RemoveAllChildViews(true); | |
| 33 if (!message_.empty()) { | |
| 34 AddChildView(CreateChildView(message_)); | |
| 35 SetVisible(true); | |
| 36 } else { | |
| 37 SetVisible(false); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 views::View* LabelTrayView::CreateChildView( | |
| 42 const base::string16& message) const { | |
| 43 HoverHighlightView* child = new HoverHighlightView(click_listener_); | |
| 44 if (icon_resource_id_) { | |
| 45 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 46 const gfx::ImageSkia* icon = rb.GetImageSkiaNamed(icon_resource_id_); | |
| 47 child->AddIconAndLabel(*icon, message, false /* highlight */); | |
| 48 child->SetBorder(views::Border::CreateEmptyBorder( | |
| 49 0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); | |
| 50 child->text_label()->SetMultiLine(true); | |
| 51 child->text_label()->SizeToFit(kTrayNotificationContentsWidth); | |
| 52 } else { | |
| 53 child->AddLabel(message, gfx::ALIGN_LEFT, false /* highlight */); | |
| 54 child->text_label()->SetMultiLine(true); | |
| 55 child->text_label()->SizeToFit(kTrayNotificationContentsWidth + | |
| 56 kNotificationIconWidth); | |
| 57 } | |
| 58 child->text_label()->SetAllowCharacterBreak(true); | |
| 59 child->SetExpandable(true); | |
| 60 child->SetVisible(true); | |
| 61 return child; | |
| 62 } | |
| 63 | |
| 64 } // namespace ash | |
| OLD | NEW |