Video Player: Remove unnecessary script file
[chromium-blink-merge.git] / ash / system / tray / special_popup_row.cc
blobc7a0a14d1c16ba796c23973550268f9dafecf386
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/background.h"
17 #include "ui/views/border.h"
18 #include "ui/views/layout/box_layout.h"
19 #include "ui/views/painter.h"
21 namespace ash {
22 namespace {
24 const int kIconPaddingLeft = 5;
25 const int kSpecialPopupRowHeight = 55;
26 const int kBorderHeight = 1;
27 const SkColor kBorderColor = SkColorSetRGB(0xaa, 0xaa, 0xaa);
29 views::View* CreatePopupHeaderButtonsContainer() {
30 views::View* view = new views::View;
31 view->SetLayoutManager(new
32 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1));
33 view->SetBorder(views::Border::CreateEmptyBorder(0, 0, 0, 5));
34 return view;
37 } // namespace
39 SpecialPopupRow::SpecialPopupRow()
40 : content_(NULL),
41 button_container_(NULL) {
42 set_background(views::Background::CreateSolidBackground(
43 kHeaderBackgroundColor));
44 SetBorder(views::Border::CreateSolidSidedBorder(
45 kBorderHeight, 0, 0, 0, kBorderColor));
46 SetLayoutManager(
47 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
50 SpecialPopupRow::~SpecialPopupRow() {
53 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) {
54 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
55 HoverHighlightView* container = new HoverHighlightView(listener);
56 container->SetLayoutManager(new
57 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft));
59 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0));
60 container->set_default_color(SkColorSetARGB(0, 0, 0, 0));
61 container->set_text_highlight_color(kHeaderTextColorHover);
62 container->set_text_default_color(kHeaderTextColorNormal);
64 container->AddIconAndLabel(
65 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(),
66 rb.GetLocalizedString(string_id),
67 gfx::Font::BOLD);
69 container->SetBorder(
70 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
72 container->SetAccessibleName(
73 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU));
74 SetContent(container);
77 void SpecialPopupRow::SetContent(views::View* view) {
78 CHECK(!content_);
79 content_ = view;
80 AddChildViewAt(content_, 0);
83 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) {
84 if (!button_container_) {
85 button_container_ = CreatePopupHeaderButtonsContainer();
86 AddChildView(button_container_);
88 button_container_->AddChildView(button);
91 void SpecialPopupRow::AddThrobber(ThrobberView* throbber) {
92 if (!button_container_) {
93 button_container_ = CreatePopupHeaderButtonsContainer();
94 AddChildView(button_container_);
96 button_container_->AddChildView(throbber);
99 gfx::Size SpecialPopupRow::GetPreferredSize() const {
100 gfx::Size size = views::View::GetPreferredSize();
101 size.set_height(kSpecialPopupRowHeight);
102 return size;
105 int SpecialPopupRow::GetHeightForWidth(int width) const {
106 return kSpecialPopupRowHeight;
109 void SpecialPopupRow::Layout() {
110 views::View::Layout();
111 gfx::Rect content_bounds = GetContentsBounds();
112 if (content_bounds.IsEmpty())
113 return;
114 if (!button_container_) {
115 content_->SetBoundsRect(GetContentsBounds());
116 return;
119 gfx::Rect bounds(button_container_->GetPreferredSize());
120 bounds.set_height(content_bounds.height());
121 gfx::Rect container_bounds = content_bounds;
122 container_bounds.ClampToCenteredSize(bounds.size());
123 container_bounds.set_x(content_bounds.width() - container_bounds.width());
124 button_container_->SetBoundsRect(container_bounds);
126 bounds = content_->bounds();
127 bounds.set_width(button_container_->x());
128 content_->SetBoundsRect(bounds);
131 } // namespace ash