1// Copyright (c) 2011 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#ifndef CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ 6#define CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ 7#pragma once 8 9#include "chrome/browser/chromeos/status/status_area_host.h" 10#include "views/controls/button/menu_button.h" 11#include "views/controls/menu/view_menu_delegate.h" 12 13namespace chromeos { 14 15// Button to be used to represent status and allow menus to be popped up. 16// Shows current button state by drawing a border around the current icon. 17class StatusAreaButton : public views::MenuButton { 18 public: 19 explicit StatusAreaButton(StatusAreaHost* host, 20 views::ViewMenuDelegate* menu_delegate); 21 virtual ~StatusAreaButton() {} 22 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); 23 24 // Overrides TextButton's SetText to clear max text size before seting new 25 // text content so that the button size would fit the new text size. 26 virtual void SetText(const std::wstring& text); 27 28 void set_use_menu_button_paint(bool use_menu_button_paint) { 29 use_menu_button_paint_ = use_menu_button_paint; 30 } 31 32 // views::MenuButton overrides. 33 virtual bool Activate() OVERRIDE; 34 35 // View overrides. 36 virtual gfx::Size GetPreferredSize() OVERRIDE; 37 virtual gfx::Insets GetInsets() const OVERRIDE; 38 virtual void OnThemeChanged() OVERRIDE; 39 40 // Controls whether or not this status area button is able to be pressed. 41 void set_active(bool active) { active_ = active; } 42 bool active() const { return active_; } 43 44 protected: 45 // Subclasses should override these methods to return the correct dimensions. 46 virtual int icon_height() { return 24; } 47 virtual int icon_width() { return 23; } 48 49 // Subclasses can override this method to return more or less padding. 50 // The padding is added to both the left and right side. 51 virtual int horizontal_padding() { return 1; } 52 53 // True if the button wants to use views::MenuButton drawings. 54 bool use_menu_button_paint_; 55 56 // Insets to use for this button. 57 gfx::Insets insets_; 58 59 // Indicates when this button can be pressed. Independent of 60 // IsEnabled state, so that when IsEnabled is true, this can still 61 // be false, and vice versa. 62 bool active_; 63 64 // The status area host, 65 StatusAreaHost* host_; 66 67 private: 68 void UpdateTextStyle(); 69 70 DISALLOW_COPY_AND_ASSIGN(StatusAreaButton); 71}; 72 73} // namespace chromeos 74 75#endif // CHROME_BROWSER_CHROMEOS_STATUS_STATUS_AREA_BUTTON_H_ 76