| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
| 12 #include "ui/views/controls/button/menu_button.h" | 12 #include "ui/views/controls/button/menu_button.h" |
| 13 #include "ui/views/controls/button/menu_button_listener.h" | 13 #include "ui/views/controls/button/menu_button_listener.h" |
| 14 #include "ui/views/view_targeter_delegate.h" | 14 #include "ui/views/view_targeter_delegate.h" |
| 15 | 15 |
| 16 namespace gfx { | 16 namespace gfx { |
| 17 class Canvas; | 17 class Canvas; |
| 18 class Image; | 18 class Image; |
| 19 } | 19 } |
| 20 class Browser; | 20 class BrowserView; |
| 21 class Profile; | 21 class Profile; |
| 22 | 22 |
| 23 // AvatarMenuButton | 23 // AvatarMenuButton |
| 24 // | 24 // |
| 25 // A button used to show either the incognito avatar or the profile avatar. | 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. | 26 // The button can optionally have a menu attached to it. |
| 27 | 27 |
| 28 class AvatarMenuButton : public views::MenuButton, | 28 class AvatarMenuButton : public views::MenuButton, |
| 29 public views::MenuButtonListener, | 29 public views::MenuButtonListener, |
| 30 public views::ViewTargeterDelegate { | 30 public views::ViewTargeterDelegate { |
| 31 public: | 31 public: |
| 32 // Internal class name. | 32 // Internal class name. |
| 33 static const char kViewClassName[]; | 33 static const char kViewClassName[]; |
| 34 | 34 |
| 35 // Creates a new button. Unless |disabled| is true, clicking on the button | 35 // Creates a new button for the given browser view. |
| 36 // will cause the profile menu to be displayed. | 36 explicit AvatarMenuButton(BrowserView* browser_view); |
| 37 AvatarMenuButton(Browser* browser, bool disabled); | |
| 38 | 37 |
| 39 ~AvatarMenuButton() override; | 38 ~AvatarMenuButton() override; |
| 40 | 39 |
| 41 // views::MenuButton: | 40 // views::MenuButton: |
| 42 const char* GetClassName() const override; | 41 const char* GetClassName() const override; |
| 43 void OnPaint(gfx::Canvas* canvas) override; | 42 void OnPaint(gfx::Canvas* canvas) override; |
| 44 | 43 |
| 45 // Sets the image for the avatar button. Rectangular images, as opposed | 44 // 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. | 45 // to Chrome avatar icons, will be resized and modified for the title bar. |
| 47 virtual void SetAvatarIcon(const gfx::Image& icon, bool is_rectangle); | 46 virtual void SetAvatarIcon(const gfx::Image& icon, bool is_rectangle); |
| 48 | 47 |
| 49 void set_button_on_right(bool button_on_right) { | 48 void set_button_on_right(bool button_on_right) { |
| 50 button_on_right_ = button_on_right; | 49 button_on_right_ = button_on_right; |
| 51 } | 50 } |
| 52 bool button_on_right() { return button_on_right_; } | 51 bool button_on_right() { return button_on_right_; } |
| 53 | 52 |
| 54 // Get avatar images for the profile. |avatar| is used in the browser window | 53 // Get avatar images for the BrowserView. |avatar| is used in the browser |
| 55 // whereas |taskbar_badge_avatar| is used for the OS taskbar. If | 54 // window whereas |taskbar_badge_avatar| is used for the OS taskbar. If |
| 56 // |taskbar_badge_avatar| is empty then |avatar| should be used for the | 55 // |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 | 56 // taskbar as well. Returns false if the cache doesn't have an entry for a |
| 58 // Profile::REGULAR_PROFILE type |profile|, otherwise return true. | 57 // Profile::REGULAR_PROFILE type Profile, otherwise return true. |
| 59 static bool GetAvatarImages(Profile* profile, | 58 static bool GetAvatarImages(BrowserView* browser_view, |
| 60 bool should_show_avatar_menu, | 59 bool should_show_avatar_menu, |
| 61 gfx::Image* avatar, | 60 gfx::Image* avatar, |
| 62 gfx::Image* taskbar_badge_avatar, | 61 gfx::Image* taskbar_badge_avatar, |
| 63 bool* is_rectangle); | 62 bool* is_rectangle); |
| 64 | 63 |
| 65 private: | 64 private: |
| 66 // views::ViewTargeterDelegate: | 65 // views::ViewTargeterDelegate: |
| 67 bool DoesIntersectRect(const views::View* target, | 66 bool DoesIntersectRect(const views::View* target, |
| 68 const gfx::Rect& rect) const override; | 67 const gfx::Rect& rect) const override; |
| 69 | 68 |
| 70 // views::MenuButtonListener: | 69 // views::MenuButtonListener: |
| 71 void OnMenuButtonClicked(views::View* source, | 70 void OnMenuButtonClicked(views::View* source, |
| 72 const gfx::Point& point) override; | 71 const gfx::Point& point) override; |
| 73 | 72 |
| 74 Browser* browser_; | 73 BrowserView* browser_view_; |
| 75 bool disabled_; | 74 bool enabled_; |
| 76 scoped_ptr<ui::MenuModel> menu_model_; | 75 scoped_ptr<ui::MenuModel> menu_model_; |
| 77 | 76 |
| 78 // Use a scoped ptr because gfx::Image doesn't have a default constructor. | 77 // Use a scoped ptr because gfx::Image doesn't have a default constructor. |
| 79 scoped_ptr<gfx::Image> icon_; | 78 scoped_ptr<gfx::Image> icon_; |
| 80 gfx::ImageSkia button_icon_; | 79 gfx::ImageSkia button_icon_; |
| 81 bool is_rectangle_; | 80 bool is_rectangle_; |
| 82 int old_height_; | 81 int old_height_; |
| 83 // True if the avatar button is on the right side of the browser window. | 82 // True if the avatar button is on the right side of the browser window. |
| 84 bool button_on_right_; | 83 bool button_on_right_; |
| 85 | 84 |
| 86 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButton); | 85 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButton); |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ | 88 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUTTON_H_ |
| OLD | NEW |