Add toplevel trace event to MessagePumpLibevent::OnLibeventNotification
[chromium-blink-merge.git] / ash / system / tray / tray_popup_label_button_border.cc
blobbcbf39fa658a1a5d5788d04acbebc8c18fe8ca3d
1 // Copyright 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/tray_popup_label_button_border.h"
7 #include "base/i18n/rtl.h"
8 #include "grit/ash_resources.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/geometry/vector2d.h"
11 #include "ui/native_theme/native_theme.h"
12 #include "ui/views/controls/button/label_button.h"
13 #include "ui/views/native_theme_delegate.h"
15 namespace ash {
17 TrayPopupLabelButtonBorder::TrayPopupLabelButtonBorder()
18 : LabelButtonBorder(views::Button::STYLE_TEXTBUTTON) {
19 const int kTrayPopupLabelButtonBorderImagesNormal[] = {
20 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
21 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
22 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
23 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
24 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
25 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
26 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
27 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
28 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
30 SetPainter(false, views::Button::STATE_NORMAL,
31 views::Painter::CreateImageGridPainter(
32 kTrayPopupLabelButtonBorderImagesNormal));
33 SetPainter(false, views::Button::STATE_DISABLED,
34 views::Painter::CreateImageGridPainter(
35 kTrayPopupLabelButtonBorderImagesNormal));
37 const int kTrayPopupLabelButtonBorderImagesHovered[] = {
38 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
39 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
40 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
41 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
42 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND,
43 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
44 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
45 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
46 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
48 SetPainter(false, views::Button::STATE_HOVERED,
49 views::Painter::CreateImageGridPainter(
50 kTrayPopupLabelButtonBorderImagesHovered));
51 SetPainter(false, views::Button::STATE_PRESSED,
52 views::Painter::CreateImageGridPainter(
53 kTrayPopupLabelButtonBorderImagesHovered));
55 const int kTrayPopupLabelButtonPaddingHorizontal = 16;
56 const int kTrayPopupLabelButtonPaddingVertical = 8;
57 set_insets(gfx::Insets(kTrayPopupLabelButtonPaddingVertical,
58 kTrayPopupLabelButtonPaddingHorizontal,
59 kTrayPopupLabelButtonPaddingVertical,
60 kTrayPopupLabelButtonPaddingHorizontal));
63 TrayPopupLabelButtonBorder::~TrayPopupLabelButtonBorder() {}
65 void TrayPopupLabelButtonBorder::Paint(const views::View& view,
66 gfx::Canvas* canvas) {
67 const views::NativeThemeDelegate* native_theme_delegate =
68 static_cast<const views::LabelButton*>(&view);
69 ui::NativeTheme::ExtraParams extra;
70 const ui::NativeTheme::State state =
71 native_theme_delegate->GetThemeState(&extra);
72 if (state == ui::NativeTheme::kNormal ||
73 state == ui::NativeTheme::kDisabled) {
74 // In normal and disabled state, the border is a vertical bar separating the
75 // button from the preceding sibling. If this button is its parent's first
76 // visible child, the separator bar should be omitted.
77 const views::View* first_visible_child = NULL;
78 for (int i = 0; i < view.parent()->child_count(); ++i) {
79 const views::View* child = view.parent()->child_at(i);
80 if (child->visible()) {
81 first_visible_child = child;
82 break;
85 if (first_visible_child == &view)
86 return;
88 if (base::i18n::IsRTL()) {
89 canvas->Save();
90 canvas->Translate(gfx::Vector2d(view.width(), 0));
91 canvas->Scale(-1, 1);
92 LabelButtonBorder::Paint(view, canvas);
93 canvas->Restore();
94 } else {
95 LabelButtonBorder::Paint(view, canvas);
99 } // namespace ash