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_NEW_AVATAR_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "chrome/browser/profiles/profile_attributes_storage.h" | 9 #include "chrome/browser/profiles/profile_attributes_storage.h" |
10 #include "chrome/browser/ui/avatar_button_error_controller.h" | 10 #include "chrome/browser/ui/avatar_button_error_controller.h" |
11 #include "chrome/browser/ui/avatar_button_error_controller_delegate.h" | 11 #include "chrome/browser/ui/avatar_button_error_controller_delegate.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | |
12 #include "chrome/browser/ui/views/profiles/avatar_button_style.h" | 13 #include "chrome/browser/ui/views/profiles/avatar_button_style.h" |
13 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/animation/ink_drop.h" |
15 #include "ui/views/controls/button/menu_button.h" | |
14 | 16 |
15 class AvatarButtonDelegate; | 17 class AvatarButtonDelegate; |
16 class Profile; | 18 class Profile; |
17 | 19 |
18 // Avatar button that displays the active profile's name in the caption area. | 20 class AvatarButton : public views::MenuButton, |
19 class NewAvatarButton : public views::LabelButton, | 21 public AvatarButtonErrorControllerDelegate, |
20 public AvatarButtonErrorControllerDelegate, | 22 public ProfileAttributesStorage::Observer { |
21 public ProfileAttributesStorage::Observer { | |
22 public: | 23 public: |
23 NewAvatarButton(AvatarButtonDelegate* delegate, | 24 AvatarButton(AvatarButtonDelegate* delegate, Profile* profile); |
24 AvatarButtonStyle button_style, | 25 ~AvatarButton() override; |
25 Profile* profile); | |
26 ~NewAvatarButton() override; | |
27 | 26 |
28 // Views::LabelButton | 27 // Update the avatar button height previously calculated by GetPreferredSize, |
29 bool OnMousePressed(const ui::MouseEvent& event) override; | 28 // if needed, now that the button's position is known. |
30 void OnMouseReleased(const ui::MouseEvent& event) override; | 29 virtual void UpdateButtonHeightForPosition(const int button_x, |
30 int* button_height) const {} | |
31 | 31 |
32 // Views | 32 protected: |
33 void OnGestureEvent(ui::GestureEvent* event) override; | 33 // MenuButton |
34 bool IsTriggerableEvent(const ui::Event& event) override; | |
35 | |
36 // Called when the profile info cache or signin/sync error has changed, which | |
37 // means we might have to update the icon/text of the button. | |
38 void Update(); | |
39 | |
40 void SetButtonFromIdr(const int button_idr); | |
msarda
2017/04/25 08:26:02
It is not clear what this method does. May I ask y
| |
34 | 41 |
35 private: | 42 private: |
36 friend class ProfileChooserViewExtensionsTest; | 43 friend class ProfileChooserViewExtensionsTest; |
37 | 44 |
38 // AvatarButtonErrorControllerDelegate: | 45 // AvatarButtonErrorControllerDelegate: |
39 void OnAvatarErrorChanged() override; | 46 void OnAvatarErrorChanged() override; |
40 | 47 |
41 // ProfileAttributesStorage::Observer: | 48 // ProfileAttributesStorage::Observer: |
42 void OnProfileAdded(const base::FilePath& profile_path) override; | 49 void OnProfileAdded(const base::FilePath& profile_path) override; |
43 void OnProfileWasRemoved(const base::FilePath& profile_path, | 50 void OnProfileWasRemoved(const base::FilePath& profile_path, |
44 const base::string16& profile_name) override; | 51 const base::string16& profile_name) override; |
45 void OnProfileNameChanged(const base::FilePath& profile_path, | 52 void OnProfileNameChanged(const base::FilePath& profile_path, |
46 const base::string16& old_profile_name) override; | 53 const base::string16& old_profile_name) override; |
47 void OnProfileSupervisedUserIdChanged( | 54 void OnProfileSupervisedUserIdChanged( |
48 const base::FilePath& profile_path) override; | 55 const base::FilePath& profile_path) override; |
49 | 56 |
50 // Called when the profile info cache or signin/sync error has changed, which | 57 void UpdateButton(bool use_generic_button, |
51 // means we might have to update the icon/text of the button. | 58 Profile* profile, |
52 void Update(); | 59 AvatarButtonErrorController* error_controller); |
53 | 60 |
54 AvatarButtonDelegate* delegate_; | 61 AvatarButtonDelegate* delegate_; |
55 AvatarButtonErrorController error_controller_; | 62 AvatarButtonErrorController error_controller_; |
56 Profile* profile_; | 63 Profile* profile_; |
57 | 64 |
58 // The icon displayed instead of the profile name in the local profile case. | 65 // The icon displayed instead of the profile name in the local profile case. |
59 // Different assets are used depending on the OS version. | 66 // Different assets are used depending on the OS version. |
60 gfx::ImageSkia generic_avatar_; | 67 gfx::ImageSkia generic_avatar_; |
61 | 68 |
62 // This is used to check if the bubble was showing during the mouse pressed | 69 DISALLOW_COPY_AND_ASSIGN(AvatarButton); |
63 // event. If this is true then the mouse released event is ignored to prevent | 70 }; |
64 // the bubble from reshowing. | 71 |
65 bool suppress_mouse_released_action_; | 72 // Avatar button that displays the active profile's name in the caption area. |
73 class NewAvatarButton : public AvatarButton { | |
74 public: | |
75 NewAvatarButton(AvatarButtonDelegate* delegate, | |
76 AvatarButtonStyle button_style, | |
77 Profile* profile); | |
78 ~NewAvatarButton() override; | |
79 | |
80 protected: | |
81 gfx::Size GetPreferredSize() const override; | |
82 | |
83 private: | |
84 std::unique_ptr<views::Border> CreateBorder( | |
85 const int normal_image_set[], | |
86 const int hot_image_set[], | |
87 const int pushed_image_set[]) const; | |
66 | 88 |
67 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); | 89 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); |
68 }; | 90 }; |
69 | 91 |
92 class MaterialDesignAvatarButton : public AvatarButton { | |
93 public: | |
94 MaterialDesignAvatarButton(AvatarButtonDelegate* delegate, | |
95 Profile* profile, | |
96 BrowserView* browser_view); | |
97 ~MaterialDesignAvatarButton() override; | |
98 | |
99 void UpdateButtonHeightForPosition(const int button_x, | |
100 int* button_height) const override; | |
101 | |
102 protected: | |
103 gfx::Size GetPreferredSize() const override; | |
104 std::unique_ptr<views::InkDrop> CreateInkDrop() override; | |
105 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; | |
106 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | |
107 const override; | |
108 | |
109 private: | |
110 std::unique_ptr<views::Border> CreateBorder() const; | |
111 | |
112 BrowserView* browser_view_; | |
113 | |
114 DISALLOW_COPY_AND_ASSIGN(MaterialDesignAvatarButton); | |
115 }; | |
116 | |
70 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ | 117 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ |
OLD | NEW |