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_header_button.h"
6
7#include "ash/ash_constants.h"
8#include "ash/system/tray/tray_constants.h"
9#include "ui/base/resource/resource_bundle.h"
10#include "ui/gfx/canvas.h"
11#include "ui/views/painter.h"
12
13namespace ash {
14namespace internal {
15
16// static
17const char TrayPopupHeaderButton::kViewClassName[] =
18    "tray/TrayPopupHeaderButton";
19
20TrayPopupHeaderButton::TrayPopupHeaderButton(views::ButtonListener* listener,
21                                             int enabled_resource_id,
22                                             int disabled_resource_id,
23                                             int enabled_resource_id_hover,
24                                             int disabled_resource_id_hover,
25                                             int accessible_name_id)
26    : views::ToggleImageButton(listener) {
27  ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
28  SetImage(views::Button::STATE_NORMAL,
29      bundle.GetImageNamed(enabled_resource_id).ToImageSkia());
30  SetToggledImage(views::Button::STATE_NORMAL,
31      bundle.GetImageNamed(disabled_resource_id).ToImageSkia());
32  SetImage(views::Button::STATE_HOVERED,
33      bundle.GetImageNamed(enabled_resource_id_hover).ToImageSkia());
34  SetToggledImage(views::Button::STATE_HOVERED,
35      bundle.GetImageNamed(disabled_resource_id_hover).ToImageSkia());
36  SetImageAlignment(views::ImageButton::ALIGN_CENTER,
37                    views::ImageButton::ALIGN_MIDDLE);
38  SetAccessibleName(bundle.GetLocalizedString(accessible_name_id));
39  SetFocusable(true);
40  set_request_focus_on_press(false);
41
42  SetFocusPainter(views::Painter::CreateSolidFocusPainter(
43                      kFocusBorderColor,
44                      gfx::Insets(1, 2, 2, 3)));
45}
46
47TrayPopupHeaderButton::~TrayPopupHeaderButton() {}
48
49const char* TrayPopupHeaderButton::GetClassName() const {
50  return kViewClassName;
51}
52
53gfx::Size TrayPopupHeaderButton::GetPreferredSize() {
54  return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight);
55}
56
57void TrayPopupHeaderButton::OnPaintBorder(gfx::Canvas* canvas) {
58  // Just the left border.
59  const int kBorderHeight = 25;
60  int padding = (height() - kBorderHeight) / 2;
61  canvas->FillRect(gfx::Rect(0, padding, 1, height() - padding * 2),
62      ash::kBorderDarkColor);
63}
64
65void TrayPopupHeaderButton::StateChanged() {
66  SchedulePaint();
67}
68
69}  // namespace internal
70}  // namespace ash
71