avatar_menu_button.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
1// Copyright 2014 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_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ 6#define CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ 7 8#include <string> 9 10#include "base/compiler_specific.h" 11#include "ui/base/models/simple_menu_model.h" 12#include "ui/views/controls/button/menu_button.h" 13#include "ui/views/controls/button/menu_button_listener.h" 14 15namespace gfx { 16class Canvas; 17class Image; 18} 19class Browser; 20 21// AvatarMenuButton 22// 23// A button used to show either the incognito avatar or the profile avatar. 24// The button can optionally have a menu attached to it. 25 26class AvatarMenuButton : public views::MenuButton, 27 public views::MenuButtonListener { 28 public: 29 // Internal class name. 30 static const char kViewClassName[]; 31 32 // Creates a new button. If |disabled| is true and we're not in managed mode, 33 // clicking on the button will cause the profile menu to be displayed. 34 AvatarMenuButton(Browser* browser, bool disabled); 35 36 virtual ~AvatarMenuButton(); 37 38 // views::MenuButton: 39 virtual const char* GetClassName() const OVERRIDE; 40 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 41 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE; 42 43 // Sets the image for the avatar button. Rectangular images, as opposed 44 // to Chrome avatar icons, will be resized and modified for the title bar. 45 virtual void SetAvatarIcon(const gfx::Image& icon, bool is_rectangle); 46 47 void set_button_on_right(bool button_on_right) { 48 button_on_right_ = button_on_right; 49 } 50 bool button_on_right() { return button_on_right_; } 51 52 void ShowAvatarBubble(); 53 54 private: 55 // views::MenuButtonListener: 56 virtual void OnMenuButtonClicked(views::View* source, 57 const gfx::Point& point) OVERRIDE; 58 59 Browser* browser_; 60 bool disabled_; 61 scoped_ptr<ui::MenuModel> menu_model_; 62 63 // Use a scoped ptr because gfx::Image doesn't have a default constructor. 64 scoped_ptr<gfx::Image> icon_; 65 gfx::ImageSkia button_icon_; 66 bool is_rectangle_; 67 int old_height_; 68 // True if the avatar button is on the right side of the browser window. 69 bool button_on_right_; 70 71 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButton); 72}; 73 74#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ 75