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/tray/tray_views.h" |
| 6 |
| 7 #include "ash/system/tray/tray_constants.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "ui/views/controls/label.h" |
| 10 #include "ui/views/layout/box_layout.h" |
| 11 #include "ui/views/layout/fill_layout.h" |
| 12 |
| 13 namespace ash { |
| 14 namespace internal { |
| 15 |
| 16 namespace { |
| 17 const int kIconPaddingLeft = 5; |
| 18 } |
| 19 |
| 20 //////////////////////////////////////////////////////////////////////////////// |
| 21 // FixedWidthImageView |
| 22 |
| 23 FixedWidthImageView::FixedWidthImageView() { |
| 24 SetHorizontalAlignment(views::ImageView::CENTER); |
| 25 SetVerticalAlignment(views::ImageView::CENTER); |
| 26 } |
| 27 |
| 28 FixedWidthImageView::~FixedWidthImageView() { |
| 29 } |
| 30 |
| 31 gfx::Size FixedWidthImageView::GetPreferredSize() { |
| 32 gfx::Size size = views::ImageView::GetPreferredSize(); |
| 33 return gfx::Size(kTrayPopupDetailsIconWidth, size.height()); |
| 34 } |
| 35 |
| 36 //////////////////////////////////////////////////////////////////////////////// |
| 37 // HoverHighlightView |
| 38 |
| 39 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) |
| 40 : listener_(listener) { |
| 41 set_notify_enter_exit_on_child(true); |
| 42 } |
| 43 |
| 44 HoverHighlightView::~HoverHighlightView() { |
| 45 } |
| 46 |
| 47 void HoverHighlightView::AddIconAndLabel(const SkBitmap& image, |
| 48 const string16& text, |
| 49 gfx::Font::FontStyle style) { |
| 50 SetLayoutManager(new views::BoxLayout( |
| 51 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); |
| 52 views::ImageView* image_view = new FixedWidthImageView; |
| 53 image_view->SetImage(image); |
| 54 AddChildView(image_view); |
| 55 |
| 56 views::Label* label = new views::Label(text); |
| 57 label->SetFont(label->font().DeriveFont(0, style)); |
| 58 AddChildView(label); |
| 59 } |
| 60 |
| 61 void HoverHighlightView::AddLabel(const string16& text) { |
| 62 SetLayoutManager(new views::FillLayout()); |
| 63 views::Label* label = new views::Label(text); |
| 64 label->set_border(views::Border::CreateEmptyBorder( |
| 65 5, kTrayPopupDetailsIconWidth + kIconPaddingLeft, 5, 0)); |
| 66 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 67 AddChildView(label); |
| 68 } |
| 69 |
| 70 bool HoverHighlightView::OnMousePressed(const views::MouseEvent& event) { |
| 71 if (!listener_) |
| 72 return false; |
| 73 listener_->ClickedOn(this); |
| 74 return true; |
| 75 } |
| 76 |
| 77 void HoverHighlightView::OnMouseEntered(const views::MouseEvent& event) { |
| 78 set_background(views::Background::CreateSolidBackground( |
| 79 ash::kHoverBackgroundColor)); |
| 80 SchedulePaint(); |
| 81 } |
| 82 |
| 83 void HoverHighlightView::OnMouseExited(const views::MouseEvent& event) { |
| 84 set_background(NULL); |
| 85 SchedulePaint(); |
| 86 } |
| 87 |
| 88 } // namespace internal |
| 89 } // namespace ash |
OLD | NEW |