| 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/profiles/avatar_button_style.h" | 12 #include "chrome/browser/ui/views/profiles/avatar_button_style.h" |
| 13 #include "ui/views/controls/button/label_button.h" | 13 #include "ui/views/controls/button/label_button.h" |
| 14 | 14 |
| 15 class AvatarButtonDelegate; | 15 class AvatarButtonDelegate; |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 // Avatar button that displays the active profile's name in the caption area. | 18 class AvatarButton : public views::LabelButton, |
| 19 class NewAvatarButton : public views::LabelButton, | 19 public AvatarButtonErrorControllerDelegate, |
| 20 public AvatarButtonErrorControllerDelegate, | 20 public ProfileAttributesStorage::Observer { |
| 21 public ProfileAttributesStorage::Observer { | 21 public: |
| 22 public: | 22 AvatarButton(AvatarButtonDelegate* delegate, |
| 23 NewAvatarButton(AvatarButtonDelegate* delegate, | 23 AvatarButtonStyle button_style, |
| 24 AvatarButtonStyle button_style, | 24 Profile* profile); |
| 25 Profile* profile); | 25 ~AvatarButton() override; |
| 26 ~NewAvatarButton() override; | |
| 27 | 26 |
| 28 // Views::LabelButton | 27 // Views::LabelButton |
| 29 bool OnMousePressed(const ui::MouseEvent& event) override; | 28 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 30 void OnMouseReleased(const ui::MouseEvent& event) override; | 29 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 31 | 30 |
| 32 // Views | 31 // Views |
| 33 void OnGestureEvent(ui::GestureEvent* event) override; | 32 void OnGestureEvent(ui::GestureEvent* event) override; |
| 34 | 33 |
| 35 private: | 34 protected: |
| 35 virtual void UpdateButton(bool use_generic_button, Profile* profile, AvatarBut
tonErrorController* error_controller) = 0; |
| 36 |
| 37 // Called when the profile info cache or signin/sync error has changed, which |
| 38 // means we might have to update the icon/text of the button. |
| 39 void Update(); |
| 40 |
| 41 private: |
| 36 friend class ProfileChooserViewExtensionsTest; | 42 friend class ProfileChooserViewExtensionsTest; |
| 37 | 43 |
| 38 // AvatarButtonErrorControllerDelegate: | 44 // AvatarButtonErrorControllerDelegate: |
| 39 void OnAvatarErrorChanged() override; | 45 void OnAvatarErrorChanged() override; |
| 40 | 46 |
| 41 // ProfileAttributesStorage::Observer: | 47 // ProfileAttributesStorage::Observer: |
| 42 void OnProfileAdded(const base::FilePath& profile_path) override; | 48 void OnProfileAdded(const base::FilePath& profile_path) override; |
| 43 void OnProfileWasRemoved(const base::FilePath& profile_path, | 49 void OnProfileWasRemoved(const base::FilePath& profile_path, |
| 44 const base::string16& profile_name) override; | 50 const base::string16& profile_name) override; |
| 45 void OnProfileNameChanged(const base::FilePath& profile_path, | 51 void OnProfileNameChanged(const base::FilePath& profile_path, |
| 46 const base::string16& old_profile_name) override; | 52 const base::string16& old_profile_name) override; |
| 47 void OnProfileSupervisedUserIdChanged( | 53 void OnProfileSupervisedUserIdChanged( |
| 48 const base::FilePath& profile_path) override; | 54 const base::FilePath& profile_path) override; |
| 49 | |
| 50 // Called when the profile info cache or signin/sync error has changed, which | |
| 51 // means we might have to update the icon/text of the button. | |
| 52 void Update(); | |
| 53 | 55 |
| 54 AvatarButtonDelegate* delegate_; | 56 AvatarButtonDelegate* delegate_; |
| 55 AvatarButtonErrorController error_controller_; | 57 AvatarButtonErrorController error_controller_; |
| 56 Profile* profile_; | 58 Profile* profile_; |
| 57 | 59 |
| 58 // The icon displayed instead of the profile name in the local profile case. | |
| 59 // Different assets are used depending on the OS version. | |
| 60 gfx::ImageSkia generic_avatar_; | |
| 61 | |
| 62 // This is used to check if the bubble was showing during the mouse pressed | 60 // This is used to check if the bubble was showing during the mouse pressed |
| 63 // event. If this is true then the mouse released event is ignored to prevent | 61 // event. If this is true then the mouse released event is ignored to prevent |
| 64 // the bubble from reshowing. | 62 // the bubble from reshowing. |
| 65 bool suppress_mouse_released_action_; | 63 bool suppress_mouse_released_action_; |
| 66 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(AvatarButton); |
| 66 }; |
| 67 |
| 68 // Avatar button that displays the active profile's name in the caption area. |
| 69 class NewAvatarButton : public AvatarButton { |
| 70 public: |
| 71 NewAvatarButton(AvatarButtonDelegate* delegate, |
| 72 AvatarButtonStyle button_style, |
| 73 Profile* profile); |
| 74 ~NewAvatarButton() override; |
| 75 |
| 76 protected: |
| 77 void UpdateButton(bool use_generic_button, Profile* profile, AvatarButtonError
Controller* error_controller) override; |
| 78 |
| 79 private: |
| 80 // The icon displayed instead of the profile name in the local profile case. |
| 81 // Different assets are used depending on the OS version. |
| 82 gfx::ImageSkia generic_avatar_; |
| 83 |
| 67 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); | 84 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); |
| 68 }; | 85 }; |
| 69 | 86 |
| 87 //class MaterialDesignAvatarButton : public AvatarButton { |
| 88 //public: |
| 89 // MaterialDesignAvatarButton(AvatarButtonDelegate* delegate, |
| 90 // AvatarButtonStyle button_style, |
| 91 // Profile* profile); |
| 92 // ~MaterialDesignAvatarButton() override; |
| 93 // |
| 94 //protected: |
| 95 // void Update(bool use_generic_button) override; |
| 96 // |
| 97 //private: |
| 98 // DISALLOW_COPY_AND_ASSIGN(MaterialDesignAvatarButton); |
| 99 //}; |
| 100 |
| 70 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ | 101 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ |
| OLD | NEW |