summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/status/status_area_button.h
blob: 1aee80086091c861b9c7aa0215efad8091f62614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_
#define CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_
#pragma once

#include "base/string16.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/view_menu_delegate.h"

namespace chromeos {

// Button to be used to represent status and allow menus to be popped up.
// Shows current button state by drawing a border around the current icon.
class StatusAreaButton : public views::MenuButton {
 public:
  StatusAreaButton(StatusAreaHost* host,
                   views::ViewMenuDelegate* menu_delegate);
  virtual ~StatusAreaButton() {}
  virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode);

  // Overrides TextButton's SetText to clear max text size before seting new
  // text content so that the button size would fit the new text size.
  virtual void SetText(const string16& text);

  void set_use_menu_button_paint(bool use_menu_button_paint) {
    use_menu_button_paint_ = use_menu_button_paint;
  }

  // views::MenuButton overrides.
  virtual bool Activate() OVERRIDE;

  // View overrides.
  virtual gfx::Size GetPreferredSize() OVERRIDE;
  virtual gfx::Insets GetInsets() const OVERRIDE;
  virtual void OnThemeChanged() OVERRIDE;
  virtual void SetVisible(bool visible) OVERRIDE;
  virtual bool HitTest(const gfx::Point& l) const OVERRIDE;

  // Controls whether or not this status area button is able to be pressed.
  void set_active(bool active) { active_ = active; }
  bool active() const { return active_; }

 protected:
  // Subclasses should override these methods to return the correct dimensions.
  virtual int icon_height();
  virtual int icon_width();

  // Subclasses can override this method to return more or less padding.
  // The padding is added to both the left and right side.
  virtual int horizontal_padding();

  // True if the button wants to use views::MenuButton drawings.
  bool use_menu_button_paint_;

  // Insets to use for this button.
  gfx::Insets insets_;

  // Indicates when this button can be pressed.  Independent of
  // IsEnabled state, so that when IsEnabled is true, this can still
  // be false, and vice versa.
  bool active_;

  // The status area host,
  StatusAreaHost* host_;

 private:
  void UpdateTextStyle();

  DISALLOW_COPY_AND_ASSIGN(StatusAreaButton);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_