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/system/tray/tray_constants.h" | |
8 #include "ash/system/tray/tray_views.h" | |
9 #include "grit/ash_resources.h" | |
10 #include "grit/ash_strings.h" | |
11 #include "ui/base/resource/resource_bundle.h" | |
12 #include "ui/gfx/canvas.h" | |
13 #include "ui/gfx/rect.h" | |
14 #include "ui/views/border.h" | |
15 #include "ui/views/layout/box_layout.h" | |
16 #include "ui/views/painter.h" | |
17 | |
18 namespace ash { | |
19 namespace internal { | |
20 | |
21 namespace { | |
stevenjb
2013/02/13 23:13:16
nit: ws
jennyz
2013/02/13 23:36:57
Done.
| |
22 const int kIconPaddingLeft = 5; | |
23 const int kSpecialPopupRowHeight = 55; | |
24 const int kBorderHeight = 3; | |
25 const SkColor kBorderGradientDark = SkColorSetRGB(0xae, 0xae, 0xae); | |
26 const SkColor kBorderGradientLight = SkColorSetRGB(0xe8, 0xe8, 0xe8); | |
27 | |
28 views::View* CreatePopupHeaderButtonsContainer() { | |
29 views::View* view = new views::View; | |
30 view->SetLayoutManager(new | |
31 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1)); | |
32 view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5)); | |
33 return view; | |
34 } | |
35 | |
36 class SpecialPopupRowBorder : public views::Border { | |
37 public: | |
38 SpecialPopupRowBorder() | |
39 : painter_(views::Painter::CreateVerticalGradient(kBorderGradientDark, | |
40 kBorderGradientLight)) { | |
41 } | |
42 | |
43 virtual ~SpecialPopupRowBorder() {} | |
44 | |
45 private: | |
46 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE { | |
47 views::Painter::PaintPainterAt(canvas, painter_.get(), | |
48 gfx::Rect(gfx::Size(view.width(), kBorderHeight))); | |
49 } | |
50 | |
51 virtual gfx::Insets GetInsets() const OVERRIDE { | |
52 return gfx::Insets(kBorderHeight, 0, 0, 0); | |
53 } | |
54 | |
55 scoped_ptr<views::Painter> painter_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(SpecialPopupRowBorder); | |
58 }; | |
59 | |
60 } // namespace | |
61 | |
62 SpecialPopupRow::SpecialPopupRow() | |
63 : content_(NULL), | |
64 button_container_(NULL) { | |
65 views::Background* background = views::Background::CreateBackgroundPainter( | |
66 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, | |
67 kHeaderBackgroundColorDark)); | |
68 background->SetNativeControlColor(kHeaderBackgroundColorDark); | |
69 set_background(background); | |
70 set_border(new SpecialPopupRowBorder); | |
71 SetLayoutManager( | |
72 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
73 } | |
74 | |
75 SpecialPopupRow::~SpecialPopupRow() { | |
76 } | |
77 | |
78 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) { | |
79 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
80 HoverHighlightView* container = new HoverHighlightView(listener); | |
81 container->SetLayoutManager(new | |
82 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); | |
83 | |
84 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); | |
85 container->set_default_color(SkColorSetARGB(0, 0, 0, 0)); | |
86 container->set_text_highlight_color(kHeaderTextColorHover); | |
87 container->set_text_default_color(kHeaderTextColorNormal); | |
88 | |
89 container->AddIconAndLabel( | |
90 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(), | |
91 rb.GetLocalizedString(string_id), | |
92 gfx::Font::BOLD); | |
93 | |
94 container->set_border(views::Border::CreateEmptyBorder(0, | |
95 kTrayPopupPaddingHorizontal, 0, 0)); | |
96 | |
97 container->SetAccessibleName( | |
98 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU)); | |
99 SetContent(container); | |
100 } | |
101 | |
102 void SpecialPopupRow::SetContent(views::View* view) { | |
103 CHECK(!content_); | |
104 content_ = view; | |
105 AddChildViewAt(content_, 0); | |
106 } | |
107 | |
108 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { | |
109 if (!button_container_) { | |
110 button_container_ = CreatePopupHeaderButtonsContainer(); | |
111 AddChildView(button_container_); | |
112 } | |
113 | |
stevenjb
2013/02/13 23:13:16
nit: no need for extra WS here
jennyz
2013/02/13 23:36:57
Done.
| |
114 button_container_->AddChildView(button); | |
115 } | |
116 | |
117 void SpecialPopupRow::AddThrobber(ThrobberView* throbber) { | |
118 if (!button_container_) { | |
119 button_container_ = CreatePopupHeaderButtonsContainer(); | |
120 AddChildView(button_container_); | |
121 } | |
122 | |
stevenjb
2013/02/13 23:13:16
nit: no need for extra WS here
jennyz
2013/02/13 23:36:57
Done.
| |
123 button_container_->AddChildView(throbber); | |
124 } | |
125 | |
126 gfx::Size SpecialPopupRow::GetPreferredSize() { | |
127 gfx::Size size = views::View::GetPreferredSize(); | |
128 size.set_height(kSpecialPopupRowHeight); | |
129 return size; | |
130 } | |
131 | |
132 void SpecialPopupRow::Layout() { | |
133 views::View::Layout(); | |
134 gfx::Rect content_bounds = GetContentsBounds(); | |
135 if (content_bounds.IsEmpty()) | |
136 return; | |
137 if (!button_container_) { | |
138 content_->SetBoundsRect(GetContentsBounds()); | |
139 return; | |
140 } | |
141 | |
142 gfx::Rect bounds(button_container_->GetPreferredSize()); | |
143 bounds.set_height(content_bounds.height()); | |
144 gfx::Rect container_bounds = content_bounds; | |
145 container_bounds.ClampToCenteredSize(bounds.size()); | |
146 container_bounds.set_x(content_bounds.width() - container_bounds.width()); | |
147 button_container_->SetBoundsRect(container_bounds); | |
148 | |
149 bounds = content_->bounds(); | |
150 bounds.set_width(button_container_->x()); | |
151 content_->SetBoundsRect(bounds); | |
152 } | |
153 | |
154 } // namespace internal | |
155 } // namespace ash | |
OLD | NEW |