Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / ash / system / tray / tray_popup_label_button_border.cc
blob275457dc25683bf78760f64d1b74c0878447ad60
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/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 {
16 namespace internal {
18 namespace {
20 const int kTrayPopupLabelButtonPaddingHorizontal = 16;
21 const int kTrayPopupLabelButtonPaddingVertical = 8;
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,
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,
47 } // namespace
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));
65 TrayPopupLabelButtonBorder::~TrayPopupLabelButtonBorder() {}
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;
87 if (first_visible_child == &view)
88 return;
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);
101 gfx::Insets TrayPopupLabelButtonBorder::GetInsets() const {
102 return gfx::Insets(kTrayPopupLabelButtonPaddingVertical,
103 kTrayPopupLabelButtonPaddingHorizontal,
104 kTrayPopupLabelButtonPaddingVertical,
105 kTrayPopupLabelButtonPaddingHorizontal);
108 } // namespace internal
109 } // namespace ash