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