Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / profiles / avatar_menu_button.h
blob343e4670fda9704f7f6058763a114ec1241d9233
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_
8 #include <string>
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 #include "ui/views/view_targeter_delegate.h"
16 namespace gfx {
17 class Canvas;
18 class Image;
20 class Browser;
21 class Profile;
23 // AvatarMenuButton
25 // A button used to show either the incognito avatar or the profile avatar.
26 // The button can optionally have a menu attached to it.
28 class AvatarMenuButton : public views::MenuButton,
29 public views::MenuButtonListener,
30 public views::ViewTargeterDelegate {
31 public:
32 // Internal class name.
33 static const char kViewClassName[];
35 // Creates a new button. Unless |disabled| is true, clicking on the button
36 // will cause the profile menu to be displayed.
37 AvatarMenuButton(Browser* browser, bool disabled);
39 ~AvatarMenuButton() override;
41 // views::MenuButton:
42 const char* GetClassName() const override;
43 void OnPaint(gfx::Canvas* canvas) override;
45 // Sets the image for the avatar button. Rectangular images, as opposed
46 // to Chrome avatar icons, will be resized and modified for the title bar.
47 virtual void SetAvatarIcon(const gfx::Image& icon, bool is_rectangle);
49 void set_button_on_right(bool button_on_right) {
50 button_on_right_ = button_on_right;
52 bool button_on_right() { return button_on_right_; }
54 // Get avatar images for the profile. |avatar| is used in the browser window
55 // whereas |taskbar_badge_avatar| is used for the OS taskbar. If
56 // |taskbar_badge_avatar| is empty then |avatar| should be used for the
57 // taskbar as well. Returns false if the cache doesn't have an entry for a
58 // Profile::REGULAR_PROFILE type |profile|, otherwise return true.
59 static bool GetAvatarImages(Profile* profile,
60 bool should_show_avatar_menu,
61 gfx::Image* avatar,
62 gfx::Image* taskbar_badge_avatar,
63 bool* is_rectangle);
65 private:
66 // views::ViewTargeterDelegate:
67 bool DoesIntersectRect(const views::View* target,
68 const gfx::Rect& rect) const override;
70 // views::MenuButtonListener:
71 void OnMenuButtonClicked(views::View* source,
72 const gfx::Point& point) override;
74 Browser* browser_;
75 bool disabled_;
76 scoped_ptr<ui::MenuModel> menu_model_;
78 // Use a scoped ptr because gfx::Image doesn't have a default constructor.
79 scoped_ptr<gfx::Image> icon_;
80 gfx::ImageSkia button_icon_;
81 bool is_rectangle_;
82 int old_height_;
83 // True if the avatar button is on the right side of the browser window.
84 bool button_on_right_;
86 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButton);
89 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_