1// Copyright (c) 2010 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 "chrome/browser/chromeos/views/dropdown_button.h"
6#include "grit/theme_resources.h"
7#include "ui/base/resource/resource_bundle.h"
8#include "ui/gfx/canvas_skia.h"
9
10namespace {
11// Asset icon particularities makes us offset focus frame.
12const int kFocusFrameTopOffset = 0;
13const int kFocusFrameLeftOffset = 0;
14const int kFocusFrameRightOffset = 0;
15const int kFocusFrameBottomOffset = 1;
16
17// TextButtonBorder specification that uses different icons to draw the
18// button.
19class DropDownButtonBorder : public views::TextButtonBorder {
20 public:
21  DropDownButtonBorder();
22
23 private:
24  DISALLOW_COPY_AND_ASSIGN(DropDownButtonBorder);
25};
26
27DropDownButtonBorder::DropDownButtonBorder() {
28  ResourceBundle& rb = ResourceBundle::GetSharedInstance();
29
30  hot_set_.top_left = rb.GetBitmapNamed(IDR_DROPDOWN_TOP_LEFT_H);
31  hot_set_.top = rb.GetBitmapNamed(IDR_DROPDOWN_TOP_H);
32  hot_set_.top_right = rb.GetBitmapNamed(IDR_DROPDOWN_TOP_RIGHT_H);
33  hot_set_.left = rb.GetBitmapNamed(IDR_DROPDOWN_LEFT_H);
34  hot_set_.center = rb.GetBitmapNamed(IDR_DROPDOWN_CENTER_H);
35  hot_set_.right = rb.GetBitmapNamed(IDR_DROPDOWN_RIGHT_H);
36  hot_set_.bottom_left = rb.GetBitmapNamed(IDR_DROPDOWN_BOTTOM_LEFT_H);
37  hot_set_.bottom = rb.GetBitmapNamed(IDR_DROPDOWN_BOTTOM_H);
38  hot_set_.bottom_right = rb.GetBitmapNamed(IDR_DROPDOWN_BOTTOM_RIGHT_H);
39
40  pushed_set_.top_left = rb.GetBitmapNamed(IDR_DROPDOWN_TOP_LEFT_P);
41  pushed_set_.top = rb.GetBitmapNamed(IDR_DROPDOWN_TOP_P);
42  pushed_set_.top_right = rb.GetBitmapNamed(IDR_DROPDOWN_TOP_RIGHT_P);
43  pushed_set_.left = rb.GetBitmapNamed(IDR_DROPDOWN_LEFT_P);
44  pushed_set_.center = rb.GetBitmapNamed(IDR_DROPDOWN_CENTER_P);
45  pushed_set_.right = rb.GetBitmapNamed(IDR_DROPDOWN_RIGHT_P);
46  pushed_set_.bottom_left = rb.GetBitmapNamed(IDR_DROPDOWN_BOTTOM_LEFT_P);
47  pushed_set_.bottom = rb.GetBitmapNamed(IDR_DROPDOWN_BOTTOM_P);
48  pushed_set_.bottom_right = rb.GetBitmapNamed(IDR_DROPDOWN_BOTTOM_RIGHT_P);
49}
50
51}  // namespace
52
53namespace chromeos {
54
55DropDownButton::DropDownButton(views::ButtonListener* listener,
56                               const std::wstring& text,
57                               views::ViewMenuDelegate* menu_delegate,
58                               bool show_menu_marker)
59    : MenuButton(listener, text, menu_delegate, show_menu_marker) {
60  set_border(new DropDownButtonBorder);
61}
62
63DropDownButton::~DropDownButton() {
64}
65
66void DropDownButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
67  if (HasFocus() && (IsFocusable() || IsAccessibilityFocusableInRootView()))
68    canvas->DrawFocusRect(kFocusFrameLeftOffset, kFocusFrameTopOffset,
69                          width() - kFocusFrameRightOffset,
70                          height() - kFocusFrameBottomOffset);
71}
72
73void DropDownButton::SetText(const std::wstring& text) {
74  text_ = WideToUTF16Hack(text);
75  UpdateTextSize();
76}
77
78}  // namespace chromeos
79