| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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/special_popup_row.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/tray_constants.h" | |
| 8 #include "ash/system/tray/hover_highlight_view.h" | |
| 9 #include "ash/system/tray/throbber_view.h" | |
| 10 #include "ash/system/tray/tray_popup_header_button.h" | |
| 11 #include "grit/ash_resources.h" | |
| 12 #include "grit/ash_strings.h" | |
| 13 #include "ui/base/resource/resource_bundle.h" | |
| 14 #include "ui/gfx/canvas.h" | |
| 15 #include "ui/gfx/geometry/insets.h" | |
| 16 #include "ui/gfx/geometry/rect.h" | |
| 17 #include "ui/views/background.h" | |
| 18 #include "ui/views/border.h" | |
| 19 #include "ui/views/controls/separator.h" | |
| 20 #include "ui/views/layout/box_layout.h" | |
| 21 #include "ui/views/painter.h" | |
| 22 | |
| 23 namespace ash { | |
| 24 namespace { | |
| 25 | |
| 26 const int kIconPaddingLeft = 5; | |
| 27 const int kSeparatorInset = 10; | |
| 28 const int kSpecialPopupRowHeight = 55; | |
| 29 const int kBorderHeight = 1; | |
| 30 const SkColor kBorderColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | |
| 31 | |
| 32 views::View* CreatePopupHeaderButtonsContainer() { | |
| 33 views::View* view = new views::View; | |
| 34 view->SetLayoutManager( | |
| 35 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 36 view->SetBorder(views::Border::CreateEmptyBorder(4, 0, 4, 5)); | |
| 37 return view; | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 SpecialPopupRow::SpecialPopupRow() | |
| 43 : content_(NULL), | |
| 44 button_container_(NULL) { | |
| 45 set_background(views::Background::CreateSolidBackground( | |
| 46 kHeaderBackgroundColor)); | |
| 47 SetBorder(views::Border::CreateSolidSidedBorder( | |
| 48 kBorderHeight, 0, 0, 0, kBorderColor)); | |
| 49 SetLayoutManager( | |
| 50 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 51 } | |
| 52 | |
| 53 SpecialPopupRow::~SpecialPopupRow() { | |
| 54 } | |
| 55 | |
| 56 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) { | |
| 57 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 58 HoverHighlightView* container = new HoverHighlightView(listener); | |
| 59 container->SetLayoutManager(new | |
| 60 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); | |
| 61 | |
| 62 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); | |
| 63 container->set_default_color(SkColorSetARGB(0, 0, 0, 0)); | |
| 64 container->set_text_highlight_color(kHeaderTextColorHover); | |
| 65 container->set_text_default_color(kHeaderTextColorNormal); | |
| 66 | |
| 67 container->AddIconAndLabel( | |
| 68 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(), | |
| 69 rb.GetLocalizedString(string_id), true /* highlight */); | |
| 70 | |
| 71 container->SetBorder( | |
| 72 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); | |
| 73 | |
| 74 container->SetAccessibleName( | |
| 75 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU)); | |
| 76 SetContent(container); | |
| 77 } | |
| 78 | |
| 79 void SpecialPopupRow::SetContent(views::View* view) { | |
| 80 CHECK(!content_); | |
| 81 content_ = view; | |
| 82 AddChildViewAt(content_, 0); | |
| 83 } | |
| 84 | |
| 85 void SpecialPopupRow::AddView(views::View* view, bool add_separator) { | |
| 86 if (!button_container_) { | |
| 87 button_container_ = CreatePopupHeaderButtonsContainer(); | |
| 88 AddChildView(button_container_); | |
| 89 } | |
| 90 if (add_separator) { | |
| 91 views::Separator* separator = | |
| 92 new views::Separator(views::Separator::VERTICAL); | |
| 93 separator->SetColor(ash::kBorderDarkColor); | |
| 94 separator->SetBorder(views::Border::CreateEmptyBorder(kSeparatorInset, 0, | |
| 95 kSeparatorInset, 0)); | |
| 96 button_container_->AddChildView(separator); | |
| 97 } | |
| 98 button_container_->AddChildView(view); | |
| 99 } | |
| 100 | |
| 101 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { | |
| 102 AddView(button, true /* add_separator */); | |
| 103 } | |
| 104 | |
| 105 gfx::Size SpecialPopupRow::GetPreferredSize() const { | |
| 106 gfx::Size size = views::View::GetPreferredSize(); | |
| 107 size.set_height(kSpecialPopupRowHeight); | |
| 108 return size; | |
| 109 } | |
| 110 | |
| 111 int SpecialPopupRow::GetHeightForWidth(int width) const { | |
| 112 return kSpecialPopupRowHeight; | |
| 113 } | |
| 114 | |
| 115 void SpecialPopupRow::Layout() { | |
| 116 views::View::Layout(); | |
| 117 gfx::Rect content_bounds = GetContentsBounds(); | |
| 118 if (content_bounds.IsEmpty()) | |
| 119 return; | |
| 120 if (!button_container_) { | |
| 121 content_->SetBoundsRect(GetContentsBounds()); | |
| 122 return; | |
| 123 } | |
| 124 | |
| 125 gfx::Rect bounds(button_container_->GetPreferredSize()); | |
| 126 bounds.set_height(content_bounds.height()); | |
| 127 gfx::Rect container_bounds = content_bounds; | |
| 128 container_bounds.ClampToCenteredSize(bounds.size()); | |
| 129 container_bounds.set_x(content_bounds.width() - container_bounds.width()); | |
| 130 button_container_->SetBoundsRect(container_bounds); | |
| 131 | |
| 132 bounds = content_->bounds(); | |
| 133 bounds.set_width(button_container_->x()); | |
| 134 content_->SetBoundsRect(bounds); | |
| 135 } | |
| 136 | |
| 137 } // namespace ash | |
| OLD | NEW |