- add sources.
[platform/framework/web/crosswalk.git] / src / ash / system / tray / tray_popup_label_button_border.cc
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.
4
5 #include "ash/system/tray/tray_popup_label_button_border.h"
6
7 #include "base/i18n/rtl.h"
8 #include "grit/ash_resources.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/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"
14
15 namespace ash {
16 namespace internal {
17
18 namespace {
19
20 const int kTrayPopupLabelButtonPaddingHorizontal = 16;
21 const int kTrayPopupLabelButtonPaddingVertical = 8;
22
23 const int kTrayPopupLabelButtonBorderImagesNormal[] = {
24     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
25     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
26     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
27     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
28     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
29     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
30     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
31     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
32     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
33 };
34
35 const int kTrayPopupLabelButtonBorderImagesHovered[] = {
36     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
37     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
38     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
39     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
40     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND,
41     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
42     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
43     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
44     IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
45 };
46
47 }  // namespace
48
49 TrayPopupLabelButtonBorder::TrayPopupLabelButtonBorder()
50     : LabelButtonBorder(views::Button::STYLE_TEXTBUTTON) {
51   SetPainter(false, views::Button::STATE_NORMAL,
52              views::Painter::CreateImageGridPainter(
53                  kTrayPopupLabelButtonBorderImagesNormal));
54   SetPainter(false, views::Button::STATE_DISABLED,
55              views::Painter::CreateImageGridPainter(
56                  kTrayPopupLabelButtonBorderImagesNormal));
57   SetPainter(false, views::Button::STATE_HOVERED,
58              views::Painter::CreateImageGridPainter(
59                  kTrayPopupLabelButtonBorderImagesHovered));
60   SetPainter(false, views::Button::STATE_PRESSED,
61              views::Painter::CreateImageGridPainter(
62                  kTrayPopupLabelButtonBorderImagesHovered));
63 }
64
65 TrayPopupLabelButtonBorder::~TrayPopupLabelButtonBorder() {}
66
67 void TrayPopupLabelButtonBorder::Paint(const views::View& view,
68                                        gfx::Canvas* canvas) {
69   const views::NativeThemeDelegate* native_theme_delegate =
70       static_cast<const views::LabelButton*>(&view);
71   ui::NativeTheme::ExtraParams extra;
72   const ui::NativeTheme::State state =
73       native_theme_delegate->GetThemeState(&extra);
74   if (state == ui::NativeTheme::kNormal ||
75       state == ui::NativeTheme::kDisabled) {
76     // In normal and disabled state, the border is a vertical bar separating the
77     // button from the preceding sibling. If this button is its parent's first
78     // visible child, the separator bar should be omitted.
79     const views::View* first_visible_child = NULL;
80     for (int i = 0; i < view.parent()->child_count(); ++i) {
81       const views::View* child = view.parent()->child_at(i);
82       if (child->visible()) {
83         first_visible_child = child;
84         break;
85       }
86     }
87     if (first_visible_child == &view)
88       return;
89   }
90   if (base::i18n::IsRTL()) {
91     canvas->Save();
92     canvas->Translate(gfx::Vector2d(view.width(), 0));
93     canvas->Scale(-1, 1);
94     LabelButtonBorder::Paint(view, canvas);
95     canvas->Restore();
96   } else {
97     LabelButtonBorder::Paint(view, canvas);
98   }
99 }
100
101 gfx::Insets TrayPopupLabelButtonBorder::GetInsets() const {
102   return gfx::Insets(kTrayPopupLabelButtonPaddingVertical,
103                      kTrayPopupLabelButtonPaddingHorizontal,
104                      kTrayPopupLabelButtonPaddingVertical,
105                      kTrayPopupLabelButtonPaddingHorizontal);
106 }
107
108 }  // namespace internal
109 }  // namespace ash