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