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.
5 #include "ash/system/tray/special_popup_row.h"
7 #include "ash/system/tray/hover_highlight_view.h"
8 #include "ash/system/tray/throbber_view.h"
9 #include "ash/system/tray/tray_constants.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/rect.h"
16 #include "ui/views/border.h"
17 #include "ui/views/layout/box_layout.h"
18 #include "ui/views/painter.h"
25 const int kIconPaddingLeft
= 5;
26 const int kSpecialPopupRowHeight
= 55;
27 const int kBorderHeight
= 1;
28 const SkColor kBorderColor
= SkColorSetRGB(0xaa, 0xaa, 0xaa);
30 views::View
* CreatePopupHeaderButtonsContainer() {
31 views::View
* view
= new views::View
;
32 view
->SetLayoutManager(new
33 views::BoxLayout(views::BoxLayout::kHorizontal
, 0, 0, -1));
34 view
->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5));
40 SpecialPopupRow::SpecialPopupRow()
42 button_container_(NULL
) {
43 set_background(views::Background::CreateSolidBackground(
44 kHeaderBackgroundColor
));
45 set_border(views::Border::CreateSolidSidedBorder(
46 kBorderHeight
, 0, 0, 0, kBorderColor
));
48 new views::BoxLayout(views::BoxLayout::kHorizontal
, 0, 0, 0));
51 SpecialPopupRow::~SpecialPopupRow() {
54 void SpecialPopupRow::SetTextLabel(int string_id
, ViewClickListener
* listener
) {
55 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
56 HoverHighlightView
* container
= new HoverHighlightView(listener
);
57 container
->SetLayoutManager(new
58 views::BoxLayout(views::BoxLayout::kHorizontal
, 0, 3, kIconPaddingLeft
));
60 container
->set_highlight_color(SkColorSetARGB(0, 0, 0, 0));
61 container
->set_default_color(SkColorSetARGB(0, 0, 0, 0));
62 container
->set_text_highlight_color(kHeaderTextColorHover
);
63 container
->set_text_default_color(kHeaderTextColorNormal
);
65 container
->AddIconAndLabel(
66 *rb
.GetImageNamed(IDR_AURA_UBER_TRAY_LESS
).ToImageSkia(),
67 rb
.GetLocalizedString(string_id
),
70 container
->set_border(views::Border::CreateEmptyBorder(0,
71 kTrayPopupPaddingHorizontal
, 0, 0));
73 container
->SetAccessibleName(
74 rb
.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU
));
75 SetContent(container
);
78 void SpecialPopupRow::SetContent(views::View
* view
) {
81 AddChildViewAt(content_
, 0);
84 void SpecialPopupRow::AddButton(TrayPopupHeaderButton
* button
) {
85 if (!button_container_
) {
86 button_container_
= CreatePopupHeaderButtonsContainer();
87 AddChildView(button_container_
);
89 button_container_
->AddChildView(button
);
92 void SpecialPopupRow::AddThrobber(ThrobberView
* throbber
) {
93 if (!button_container_
) {
94 button_container_
= CreatePopupHeaderButtonsContainer();
95 AddChildView(button_container_
);
97 button_container_
->AddChildView(throbber
);
100 gfx::Size
SpecialPopupRow::GetPreferredSize() {
101 gfx::Size size
= views::View::GetPreferredSize();
102 size
.set_height(kSpecialPopupRowHeight
);
106 int SpecialPopupRow::GetHeightForWidth(int width
) {
107 return kSpecialPopupRowHeight
;
110 void SpecialPopupRow::Layout() {
111 views::View::Layout();
112 gfx::Rect content_bounds
= GetContentsBounds();
113 if (content_bounds
.IsEmpty())
115 if (!button_container_
) {
116 content_
->SetBoundsRect(GetContentsBounds());
120 gfx::Rect
bounds(button_container_
->GetPreferredSize());
121 bounds
.set_height(content_bounds
.height());
122 gfx::Rect container_bounds
= content_bounds
;
123 container_bounds
.ClampToCenteredSize(bounds
.size());
124 container_bounds
.set_x(content_bounds
.width() - container_bounds
.width());
125 button_container_
->SetBoundsRect(container_bounds
);
127 bounds
= content_
->bounds();
128 bounds
.set_width(button_container_
->x());
129 content_
->SetBoundsRect(bounds
);
132 } // namespace internal