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.
5 #include "ash/system/tray/tray_views.h"
7 #include "ash/ash_constants.h"
8 #include "ash/system/tray/tray_constants.h"
9 #include "ash/system/tray/tray_item_view.h"
10 #include "base/i18n/rtl.h"
11 #include "grit/ash_resources.h"
12 #include "grit/ash_strings.h"
13 #include "grit/ui_resources.h"
14 #include "ui/base/accessibility/accessible_view_state.h"
15 #include "ui/base/events/event.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/rect.h"
21 #include "ui/gfx/text_constants.h"
22 #include "ui/gfx/vector2d.h"
23 #include "ui/native_theme/native_theme.h"
24 #include "ui/views/border.h"
25 #include "ui/views/controls/button/image_button.h"
26 #include "ui/views/controls/label.h"
27 #include "ui/views/layout/box_layout.h"
28 #include "ui/views/layout/fill_layout.h"
29 #include "ui/views/layout/grid_layout.h"
30 #include "ui/views/painter.h"
36 const int kIconPaddingLeft
= 5;
37 const int kPopupDetailLabelExtraLeftMargin
= 8;
38 const int kCheckLabelPadding
= 4;
39 const int kSpecialPopupRowHeight
= 55;
40 const int kTrayPopupLabelButtonPaddingHorizontal
= 16;
41 const int kTrayPopupLabelButtonPaddingVertical
= 8;
43 const int kBarImagesActive
[] = {
44 IDR_SLIDER_ACTIVE_LEFT
,
45 IDR_SLIDER_ACTIVE_CENTER
,
46 IDR_SLIDER_ACTIVE_RIGHT
,
49 const int kBarImagesDisabled
[] = {
50 IDR_SLIDER_DISABLED_LEFT
,
51 IDR_SLIDER_DISABLED_CENTER
,
52 IDR_SLIDER_DISABLED_RIGHT
,
55 const int kTrayPopupLabelButtonBorderImagesNormal
[] = {
56 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
57 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND
,
58 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND
,
59 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
60 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND
,
61 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND
,
62 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
63 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND
,
64 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND
,
66 const int kTrayPopupLabelButtonBorderImagesHovered
[] = {
67 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
68 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
69 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
70 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
71 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND
,
72 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
73 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
74 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
75 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER
,
78 views::View
* CreatePopupHeaderButtonsContainer() {
79 views::View
* view
= new views::View
;
80 view
->SetLayoutManager(new
81 views::BoxLayout(views::BoxLayout::kHorizontal
, 0, 0, -1));
82 view
->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5));
86 const int kBorderHeight
= 3;
87 const SkColor kBorderGradientDark
= SkColorSetRGB(0xae, 0xae, 0xae);
88 const SkColor kBorderGradientLight
= SkColorSetRGB(0xe8, 0xe8, 0xe8);
90 class SpecialPopupRowBorder
: public views::Border
{
92 SpecialPopupRowBorder()
93 : painter_(views::Painter::CreateVerticalGradient(kBorderGradientDark
,
94 kBorderGradientLight
)) {
97 virtual ~SpecialPopupRowBorder() {}
100 virtual void Paint(const views::View
& view
, gfx::Canvas
* canvas
) OVERRIDE
{
101 views::Painter::PaintPainterAt(canvas
, painter_
.get(),
102 gfx::Rect(gfx::Size(view
.width(), kBorderHeight
)));
105 virtual gfx::Insets
GetInsets() const OVERRIDE
{
106 return gfx::Insets(kBorderHeight
, 0, 0, 0);
109 scoped_ptr
<views::Painter
> painter_
;
111 DISALLOW_COPY_AND_ASSIGN(SpecialPopupRowBorder
);
116 ////////////////////////////////////////////////////////////////////////////////
117 // FixedSizedImageView
119 FixedSizedImageView::FixedSizedImageView(int width
, int height
)
122 SetHorizontalAlignment(views::ImageView::CENTER
);
123 SetVerticalAlignment(views::ImageView::CENTER
);
126 FixedSizedImageView::~FixedSizedImageView() {
129 gfx::Size
FixedSizedImageView::GetPreferredSize() {
130 gfx::Size size
= views::ImageView::GetPreferredSize();
131 return gfx::Size(width_
? width_
: size
.width(),
132 height_
? height_
: size
.height());
135 ////////////////////////////////////////////////////////////////////////////////
138 ActionableView::ActionableView()
139 : has_capture_(false) {
143 ActionableView::~ActionableView() {
146 void ActionableView::DrawBorder(gfx::Canvas
* canvas
, const gfx::Rect
& bounds
) {
147 gfx::Rect rect
= bounds
;
148 rect
.Inset(1, 1, 3, 3);
149 canvas
->DrawRect(rect
, kFocusBorderColor
);
152 bool ActionableView::OnKeyPressed(const ui::KeyEvent
& event
) {
153 if (event
.key_code() == ui::VKEY_SPACE
||
154 event
.key_code() == ui::VKEY_RETURN
) {
155 return PerformAction(event
);
160 bool ActionableView::OnMousePressed(const ui::MouseEvent
& event
) {
161 // Return true so that this view starts capturing the events.
166 void ActionableView::OnMouseReleased(const ui::MouseEvent
& event
) {
167 if (has_capture_
&& GetLocalBounds().Contains(event
.location()))
168 PerformAction(event
);
171 void ActionableView::OnMouseCaptureLost() {
172 has_capture_
= false;
175 void ActionableView::SetAccessibleName(const string16
& name
) {
176 accessible_name_
= name
;
179 void ActionableView::OnPaintFocusBorder(gfx::Canvas
* canvas
) {
180 if (HasFocus() && (focusable() || IsAccessibilityFocusable()))
181 DrawBorder(canvas
, GetLocalBounds());
184 void ActionableView::OnGestureEvent(ui::GestureEvent
* event
) {
185 if (event
->type() == ui::ET_GESTURE_TAP
&& PerformAction(*event
))
189 void ActionableView::GetAccessibleState(ui::AccessibleViewState
* state
) {
190 state
->role
= ui::AccessibilityTypes::ROLE_PUSHBUTTON
;
191 state
->name
= accessible_name_
;
194 ////////////////////////////////////////////////////////////////////////////////
195 // HoverHighlightView
197 HoverHighlightView::HoverHighlightView(ViewClickListener
* listener
)
198 : listener_(listener
),
200 highlight_color_(kHoverBackgroundColor
),
202 text_highlight_color_(0),
203 text_default_color_(0),
206 set_notify_enter_exit_on_child(true);
209 HoverHighlightView::~HoverHighlightView() {
212 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia
& image
,
213 const string16
& text
,
214 gfx::Font::FontStyle style
) {
215 SetLayoutManager(new views::BoxLayout(
216 views::BoxLayout::kHorizontal
, 0, 3, kTrayPopupPaddingBetweenItems
));
217 views::ImageView
* image_view
=
218 new FixedSizedImageView(kTrayPopupDetailsIconWidth
, 0);
219 image_view
->SetImage(image
);
220 AddChildView(image_view
);
222 text_label_
= new views::Label(text
);
223 text_label_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
224 text_label_
->SetFont(text_label_
->font().DeriveFont(0, style
));
225 if (text_default_color_
)
226 text_label_
->SetEnabledColor(text_default_color_
);
227 AddChildView(text_label_
);
229 SetAccessibleName(text
);
232 views::Label
* HoverHighlightView::AddLabel(const string16
& text
,
233 gfx::Font::FontStyle style
) {
234 SetLayoutManager(new views::FillLayout());
235 text_label_
= new views::Label(text
);
236 int margin
= kTrayPopupPaddingHorizontal
+ kPopupDetailLabelExtraLeftMargin
;
238 int right_margin
= 0;
239 if (base::i18n::IsRTL())
240 right_margin
= margin
;
242 left_margin
= margin
;
243 text_label_
->set_border(
244 views::Border::CreateEmptyBorder(5, left_margin
, 5, right_margin
));
245 text_label_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
246 text_label_
->SetFont(text_label_
->font().DeriveFont(0, style
));
247 text_label_
->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0));
248 if (text_default_color_
)
249 text_label_
->SetEnabledColor(text_default_color_
);
250 AddChildView(text_label_
);
252 SetAccessibleName(text
);
256 views::Label
* HoverHighlightView::AddCheckableLabel(const string16
& text
,
257 gfx::Font::FontStyle style
,
260 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
261 const gfx::ImageSkia
* check
=
262 rb
.GetImageNamed(IDR_MENU_CHECK
).ToImageSkia();
263 int margin
= kTrayPopupPaddingHorizontal
+ kPopupDetailLabelExtraLeftMargin
264 - kCheckLabelPadding
;
265 SetLayoutManager(new views::BoxLayout(
266 views::BoxLayout::kHorizontal
, 0, 3, kCheckLabelPadding
));
267 views::ImageView
* image_view
= new FixedSizedImageView(margin
, 0);
268 image_view
->SetImage(check
);
269 image_view
->SetHorizontalAlignment(views::ImageView::TRAILING
);
270 AddChildView(image_view
);
272 text_label_
= new views::Label(text
);
273 text_label_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
274 text_label_
->SetFont(text_label_
->font().DeriveFont(0, style
));
275 text_label_
->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0));
276 if (text_default_color_
)
277 text_label_
->SetEnabledColor(text_default_color_
);
278 AddChildView(text_label_
);
280 SetAccessibleName(text
);
283 return AddLabel(text
, style
);
287 bool HoverHighlightView::PerformAction(const ui::Event
& event
) {
290 listener_
->ClickedOn(this);
294 gfx::Size
HoverHighlightView::GetPreferredSize() {
295 gfx::Size size
= ActionableView::GetPreferredSize();
297 size
.set_height(fixed_height_
);
301 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent
& event
) {
303 if (text_highlight_color_
&& text_label_
)
304 text_label_
->SetEnabledColor(text_highlight_color_
);
308 void HoverHighlightView::OnMouseExited(const ui::MouseEvent
& event
) {
310 if (text_default_color_
&& text_label_
)
311 text_label_
->SetEnabledColor(text_default_color_
);
315 void HoverHighlightView::OnEnabledChanged() {
316 for (int i
= 0; i
< child_count(); ++i
)
317 child_at(i
)->SetEnabled(enabled());
320 void HoverHighlightView::OnPaintBackground(gfx::Canvas
* canvas
) {
321 canvas
->DrawColor(hover_
? highlight_color_
: default_color_
);
324 void HoverHighlightView::OnFocus() {
325 ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
326 ActionableView::OnFocus();
329 ////////////////////////////////////////////////////////////////////////////////
330 // FixedSizedScrollView
332 FixedSizedScrollView::FixedSizedScrollView() {
334 set_notify_enter_exit_on_child(true);
337 FixedSizedScrollView::~FixedSizedScrollView() {}
339 void FixedSizedScrollView::SetContentsView(View
* view
) {
341 view
->SetBoundsRect(gfx::Rect(view
->GetPreferredSize()));
344 void FixedSizedScrollView::SetFixedSize(const gfx::Size
& size
) {
345 if (fixed_size_
== size
)
348 PreferredSizeChanged();
351 gfx::Size
FixedSizedScrollView::GetPreferredSize() {
352 gfx::Size size
= fixed_size_
.IsEmpty() ?
353 contents()->GetPreferredSize() : fixed_size_
;
354 gfx::Insets insets
= GetInsets();
355 size
.Enlarge(insets
.width(), insets
.height());
359 void FixedSizedScrollView::Layout() {
360 gfx::Rect bounds
= gfx::Rect(contents()->GetPreferredSize());
361 bounds
.set_width(std::max(0, width() - GetScrollBarWidth()));
362 contents()->SetBoundsRect(bounds
);
364 views::ScrollView::Layout();
365 if (!vertical_scroll_bar()->visible()) {
366 gfx::Rect bounds
= contents()->bounds();
367 bounds
.set_width(bounds
.width() + GetScrollBarWidth());
368 contents()->SetBoundsRect(bounds
);
372 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect
& previous_bounds
) {
373 gfx::Rect bounds
= gfx::Rect(contents()->GetPreferredSize());
374 bounds
.set_width(std::max(0, width() - GetScrollBarWidth()));
375 contents()->SetBoundsRect(bounds
);
378 void FixedSizedScrollView::OnMouseEntered(const ui::MouseEvent
& event
) {
379 // TODO(sad): This is done to make sure that the scroll view scrolls on
380 // mouse-wheel events. This is ugly, and Ben thinks this is weird. There
381 // should be a better fix for this.
385 void FixedSizedScrollView::OnPaintFocusBorder(gfx::Canvas
* canvas
) {
386 // Do not paint the focus border.
389 ////////////////////////////////////////////////////////////////////////////////
390 // TrayPopupLabelButtonBorder
392 TrayPopupLabelButtonBorder::TrayPopupLabelButtonBorder() {
393 SetPainter(views::CustomButton::STATE_NORMAL
,
394 views::Painter::CreateImageGridPainter(
395 kTrayPopupLabelButtonBorderImagesNormal
));
396 SetPainter(views::CustomButton::STATE_DISABLED
,
397 views::Painter::CreateImageGridPainter(
398 kTrayPopupLabelButtonBorderImagesNormal
));
399 SetPainter(views::CustomButton::STATE_HOVERED
,
400 views::Painter::CreateImageGridPainter(
401 kTrayPopupLabelButtonBorderImagesHovered
));
402 SetPainter(views::CustomButton::STATE_PRESSED
,
403 views::Painter::CreateImageGridPainter(
404 kTrayPopupLabelButtonBorderImagesHovered
));
407 TrayPopupLabelButtonBorder::~TrayPopupLabelButtonBorder() {}
409 void TrayPopupLabelButtonBorder::Paint(const views::View
& view
,
410 gfx::Canvas
* canvas
) {
411 const views::NativeThemeDelegate
* native_theme_delegate
=
412 static_cast<const views::LabelButton
*>(&view
);
413 ui::NativeTheme::ExtraParams extra
;
414 const ui::NativeTheme::State state
=
415 native_theme_delegate
->GetThemeState(&extra
);
416 if (state
== ui::NativeTheme::kNormal
||
417 state
== ui::NativeTheme::kDisabled
) {
418 // In normal and disabled state, the border is a vertical bar separating the
419 // button from the preceding sibling. If this button is its parent's first
420 // visible child, the separator bar should be omitted.
421 const views::View
* first_visible_child
= NULL
;
422 for (int i
= 0; i
< view
.parent()->child_count(); ++i
) {
423 const views::View
* child
= view
.parent()->child_at(i
);
424 if (child
->visible()) {
425 first_visible_child
= child
;
429 if (first_visible_child
== &view
)
432 if (base::i18n::IsRTL()) {
434 canvas
->Translate(gfx::Vector2d(view
.width(), 0));
435 canvas
->Scale(-1, 1);
436 LabelButtonBorder::Paint(view
, canvas
);
439 LabelButtonBorder::Paint(view
, canvas
);
443 gfx::Insets
TrayPopupLabelButtonBorder::GetInsets() const {
444 return gfx::Insets(kTrayPopupLabelButtonPaddingVertical
,
445 kTrayPopupLabelButtonPaddingHorizontal
,
446 kTrayPopupLabelButtonPaddingVertical
,
447 kTrayPopupLabelButtonPaddingHorizontal
);
450 ////////////////////////////////////////////////////////////////////////////////
451 // TrayPopupLabelButton
453 TrayPopupLabelButton::TrayPopupLabelButton(views::ButtonListener
* listener
,
454 const string16
& text
)
455 : views::LabelButton(listener
, text
) {
456 set_border(new TrayPopupLabelButtonBorder
);
458 set_request_focus_on_press(false);
459 set_animate_on_state_change(false);
460 SetHorizontalAlignment(gfx::ALIGN_CENTER
);
463 TrayPopupLabelButton::~TrayPopupLabelButton() {}
465 void TrayPopupLabelButton::OnPaintFocusBorder(gfx::Canvas
* canvas
) {
466 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) {
467 canvas
->DrawRect(gfx::Rect(1, 1, width() - 3, height() - 3),
468 ash::kFocusBorderColor
);
472 ////////////////////////////////////////////////////////////////////////////////
473 // TrayPopupHeaderButton
475 TrayPopupHeaderButton::TrayPopupHeaderButton(views::ButtonListener
* listener
,
476 int enabled_resource_id
,
477 int disabled_resource_id
,
478 int enabled_resource_id_hover
,
479 int disabled_resource_id_hover
,
480 int accessible_name_id
)
481 : views::ToggleImageButton(listener
) {
482 ui::ResourceBundle
& bundle
= ui::ResourceBundle::GetSharedInstance();
483 SetImage(views::CustomButton::STATE_NORMAL
,
484 bundle
.GetImageNamed(enabled_resource_id
).ToImageSkia());
485 SetToggledImage(views::CustomButton::STATE_NORMAL
,
486 bundle
.GetImageNamed(disabled_resource_id
).ToImageSkia());
487 SetImage(views::CustomButton::STATE_HOVERED
,
488 bundle
.GetImageNamed(enabled_resource_id_hover
).ToImageSkia());
489 SetToggledImage(views::CustomButton::STATE_HOVERED
,
490 bundle
.GetImageNamed(disabled_resource_id_hover
).ToImageSkia());
491 SetImageAlignment(views::ImageButton::ALIGN_CENTER
,
492 views::ImageButton::ALIGN_MIDDLE
);
493 SetAccessibleName(bundle
.GetLocalizedString(accessible_name_id
));
495 set_request_focus_on_press(false);
498 TrayPopupHeaderButton::~TrayPopupHeaderButton() {}
500 gfx::Size
TrayPopupHeaderButton::GetPreferredSize() {
501 return gfx::Size(ash::kTrayPopupItemHeight
, ash::kTrayPopupItemHeight
);
504 void TrayPopupHeaderButton::OnPaintBorder(gfx::Canvas
* canvas
) {
505 // Just the left border.
506 const int kBorderHeight
= 25;
507 int padding
= (height() - kBorderHeight
) / 2;
508 canvas
->FillRect(gfx::Rect(0, padding
, 1, height() - padding
* 2),
509 ash::kBorderDarkColor
);
512 void TrayPopupHeaderButton::OnPaintFocusBorder(gfx::Canvas
* canvas
) {
513 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) {
514 canvas
->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3),
519 void TrayPopupHeaderButton::StateChanged() {
523 ////////////////////////////////////////////////////////////////////////////////
524 // TrayBarButtonWithTitle
526 class TrayBarButtonWithTitle::TrayBarButton
527 : public views::View
{
529 TrayBarButton(const int bar_active_images
[], const int bar_disabled_images
[])
531 bar_active_images_(bar_active_images
),
532 bar_disabled_images_(bar_disabled_images
),
533 painter_(new views::HorizontalPainter(bar_active_images_
)){
535 virtual ~TrayBarButton() {}
537 // Overriden from views::View
538 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
{
539 painter_
->Paint(canvas
, size());
542 void Update(bool control_on
) {
543 painter_
.reset(new views::HorizontalPainter(
544 control_on
? bar_active_images_
: bar_disabled_images_
));
549 const int* bar_active_images_
;
550 const int* bar_disabled_images_
;
551 scoped_ptr
<views::HorizontalPainter
> painter_
;
553 DISALLOW_COPY_AND_ASSIGN(TrayBarButton
);
556 TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener
* listener
,
559 : views::CustomButton(listener
),
560 image_(new TrayBarButton(kBarImagesActive
, kBarImagesDisabled
)),
563 AddChildView(image_
);
564 if (title_id
!= -1) {
565 title_
= new views::Label
;
566 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
567 string16 text
= rb
.GetLocalizedString(title_id
);
568 title_
->SetText(text
);
569 AddChildView(title_
);
572 image_height_
= ui::ResourceBundle::GetSharedInstance().GetImageNamed(
573 kBarImagesActive
[0]).ToImageSkia()->height();
576 TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {}
578 gfx::Size
TrayBarButtonWithTitle::GetPreferredSize() {
579 return gfx::Size(width_
, kTrayPopupItemHeight
);
582 void TrayBarButtonWithTitle::Layout() {
583 gfx::Rect
rect(GetContentsBounds());
584 int bar_image_y
= rect
.height() / 2 - image_height_
/ 2;
585 gfx::Rect
bar_image_rect(rect
.x(),
589 image_
->SetBoundsRect(bar_image_rect
);
591 // The image_ has some empty space below the bar image, move the title
592 // a little bit up to look closer to the bar.
593 gfx::Size title_size
= title_
->GetPreferredSize();
594 title_
->SetBounds(rect
.x(),
595 bar_image_y
+ image_height_
- 3,
597 title_size
.height());
601 void TrayBarButtonWithTitle::UpdateButton(bool control_on
) {
602 image_
->Update(control_on
);
605 ////////////////////////////////////////////////////////////////////////////////
608 SpecialPopupRow::SpecialPopupRow()
610 button_container_(NULL
) {
611 views::Background
* background
= views::Background::CreateBackgroundPainter(
612 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight
,
613 kHeaderBackgroundColorDark
));
614 background
->SetNativeControlColor(kHeaderBackgroundColorDark
);
615 set_background(background
);
616 set_border(new SpecialPopupRowBorder
);
618 new views::BoxLayout(views::BoxLayout::kHorizontal
, 0, 0, 0));
621 SpecialPopupRow::~SpecialPopupRow() {
624 void SpecialPopupRow::SetTextLabel(int string_id
, ViewClickListener
* listener
) {
625 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
626 HoverHighlightView
* container
= new HoverHighlightView(listener
);
627 container
->set_fixed_height(kTrayPopupItemHeight
);
628 container
->SetLayoutManager(new
629 views::BoxLayout(views::BoxLayout::kHorizontal
, 0, 3, kIconPaddingLeft
));
631 container
->set_highlight_color(SkColorSetARGB(0, 0, 0, 0));
632 container
->set_default_color(SkColorSetARGB(0, 0, 0, 0));
633 container
->set_text_highlight_color(kHeaderTextColorHover
);
634 container
->set_text_default_color(kHeaderTextColorNormal
);
636 container
->AddIconAndLabel(
637 *rb
.GetImageNamed(IDR_AURA_UBER_TRAY_LESS
).ToImageSkia(),
638 rb
.GetLocalizedString(string_id
),
641 container
->set_border(views::Border::CreateEmptyBorder(0,
642 kTrayPopupPaddingHorizontal
, 0, 0));
644 container
->SetAccessibleName(
645 rb
.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU
));
646 SetContent(container
);
649 void SpecialPopupRow::SetContent(views::View
* view
) {
652 AddChildViewAt(content_
, 0);
655 void SpecialPopupRow::AddButton(TrayPopupHeaderButton
* button
) {
656 if (!button_container_
) {
657 button_container_
= CreatePopupHeaderButtonsContainer();
658 AddChildView(button_container_
);
661 button_container_
->AddChildView(button
);
664 gfx::Size
SpecialPopupRow::GetPreferredSize() {
665 gfx::Size size
= views::View::GetPreferredSize();
666 size
.set_height(kSpecialPopupRowHeight
);
670 void SpecialPopupRow::Layout() {
671 views::View::Layout();
672 gfx::Rect content_bounds
= GetContentsBounds();
673 if (content_bounds
.IsEmpty())
675 if (!button_container_
) {
676 content_
->SetBoundsRect(GetContentsBounds());
680 gfx::Rect
bounds(button_container_
->GetPreferredSize());
681 bounds
.set_height(content_bounds
.height());
682 gfx::Rect container_bounds
= content_bounds
;
683 container_bounds
.ClampToCenteredSize(bounds
.size());
684 container_bounds
.set_x(content_bounds
.width() - container_bounds
.width());
685 button_container_
->SetBoundsRect(container_bounds
);
687 bounds
= content_
->bounds();
688 bounds
.set_width(button_container_
->x());
689 content_
->SetBoundsRect(bounds
);
692 void SetupLabelForTray(views::Label
* label
) {
693 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
694 label
->SetFont(rb
.GetFont(ui::ResourceBundle::BoldFont
));
695 label
->SetAutoColorReadabilityEnabled(false);
696 label
->SetEnabledColor(SK_ColorWHITE
);
697 label
->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
698 label
->SetShadowColors(SkColorSetARGB(64, 0, 0, 0),
699 SkColorSetARGB(64, 0, 0, 0));
700 label
->SetShadowOffset(0, 1);
703 void SetTrayImageItemBorder(views::View
* tray_view
,
704 ShelfAlignment alignment
) {
705 if (alignment
== SHELF_ALIGNMENT_BOTTOM
) {
706 tray_view
->set_border(views::Border::CreateEmptyBorder(
707 0, kTrayImageItemHorizontalPaddingBottomAlignment
,
708 0, kTrayImageItemHorizontalPaddingBottomAlignment
));
710 tray_view
->set_border(views::Border::CreateEmptyBorder(
711 kTrayImageItemVerticalPaddingVerticalAlignment
,
712 kTrayImageItemHorizontalPaddingVerticalAlignment
,
713 kTrayImageItemVerticalPaddingVerticalAlignment
,
714 kTrayImageItemHorizontalPaddingVerticalAlignment
));
718 void SetTrayLabelItemBorder(TrayItemView
* tray_view
,
719 ShelfAlignment alignment
) {
720 if (alignment
== SHELF_ALIGNMENT_BOTTOM
) {
721 tray_view
->set_border(views::Border::CreateEmptyBorder(
722 0, kTrayLabelItemHorizontalPaddingBottomAlignment
,
723 0, kTrayLabelItemHorizontalPaddingBottomAlignment
));
725 // Center the label for vertical launcher alignment.
726 int horizontal_padding
= (tray_view
->GetPreferredSize().width() -
727 tray_view
->label()->GetPreferredSize().width()) / 2;
728 tray_view
->set_border(views::Border::CreateEmptyBorder(
729 kTrayLabelItemVerticalPaddingVeriticalAlignment
,
731 kTrayLabelItemVerticalPaddingVeriticalAlignment
,
732 horizontal_padding
));
736 } // namespace internal