| 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_PROFILE_CHOOSER_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "chrome/browser/profiles/avatar_menu.h" | 11 #include "chrome/browser/profiles/avatar_menu.h" |
| 12 #include "chrome/browser/profiles/avatar_menu_observer.h" | 12 #include "chrome/browser/profiles/avatar_menu_observer.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/profile_chooser_constants.h" |
| 14 #include "google_apis/gaia/oauth2_token_service.h" | 15 #include "google_apis/gaia/oauth2_token_service.h" |
| 15 #include "ui/views/bubble/bubble_delegate.h" | 16 #include "ui/views/bubble/bubble_delegate.h" |
| 16 #include "ui/views/controls/button/button.h" | 17 #include "ui/views/controls/button/button.h" |
| 17 #include "ui/views/controls/link_listener.h" | 18 #include "ui/views/controls/link_listener.h" |
| 18 #include "ui/views/controls/styled_label_listener.h" | 19 #include "ui/views/controls/styled_label_listener.h" |
| 19 #include "ui/views/controls/textfield/textfield_controller.h" | 20 #include "ui/views/controls/textfield/textfield_controller.h" |
| 20 | 21 |
| 21 class EditableProfilePhoto; | 22 class EditableProfilePhoto; |
| 22 class EditableProfileName; | 23 class EditableProfileName; |
| 23 | 24 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 37 // This bubble view is displayed when the user clicks on the avatar button. | 38 // This bubble view is displayed when the user clicks on the avatar button. |
| 38 // It displays a list of profiles and allows users to switch between profiles. | 39 // It displays a list of profiles and allows users to switch between profiles. |
| 39 class ProfileChooserView : public views::BubbleDelegateView, | 40 class ProfileChooserView : public views::BubbleDelegateView, |
| 40 public views::ButtonListener, | 41 public views::ButtonListener, |
| 41 public views::LinkListener, | 42 public views::LinkListener, |
| 42 public views::StyledLabelListener, | 43 public views::StyledLabelListener, |
| 43 public views::TextfieldController, | 44 public views::TextfieldController, |
| 44 public AvatarMenuObserver, | 45 public AvatarMenuObserver, |
| 45 public OAuth2TokenService::Observer { | 46 public OAuth2TokenService::Observer { |
| 46 public: | 47 public: |
| 47 // Different views that can be displayed in the bubble. | |
| 48 enum BubbleViewMode { | |
| 49 // Shows a "fast profile switcher" view. | |
| 50 BUBBLE_VIEW_MODE_PROFILE_CHOOSER, | |
| 51 // Shows a list of accounts for the active user. | |
| 52 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, | |
| 53 // Shows a web view for primary sign in. | |
| 54 BUBBLE_VIEW_MODE_GAIA_SIGNIN, | |
| 55 // Shows a web view for adding secondary accounts. | |
| 56 BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, | |
| 57 // Shows a view for confirming account removal. | |
| 58 BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, | |
| 59 // Shows a view for ending new profile management preview. | |
| 60 BUBBLE_VIEW_MODE_END_PREVIEW | |
| 61 }; | |
| 62 | |
| 63 enum TutorialMode { | |
| 64 TUTORIAL_MODE_NONE, // No tutorial card shown. | |
| 65 TUTORIAL_MODE_ENABLE_PREVIEW, // The enable-mirror-preview tutorial shown. | |
| 66 TUTORIAL_MODE_PREVIEW_ENABLED, // The welcome-to-mirror tutorial shown. | |
| 67 TUTORIAL_MODE_SEND_FEEDBACK // The send-feedback tutorial shown. | |
| 68 }; | |
| 69 | |
| 70 // Shows the bubble if one is not already showing. This allows us to easily | 48 // Shows the bubble if one is not already showing. This allows us to easily |
| 71 // make a button toggle the bubble on and off when clicked: we unconditionally | 49 // make a button toggle the bubble on and off when clicked: we unconditionally |
| 72 // call this function when the button is clicked and if the bubble isn't | 50 // call this function when the button is clicked and if the bubble isn't |
| 73 // showing it will appear while if it is showing, nothing will happen here and | 51 // showing it will appear while if it is showing, nothing will happen here and |
| 74 // the existing bubble will auto-close due to focus loss. | 52 // the existing bubble will auto-close due to focus loss. |
| 75 static void ShowBubble(BubbleViewMode view_mode, | 53 static void ShowBubble(profiles::BubbleViewMode view_mode, |
| 76 views::View* anchor_view, | 54 views::View* anchor_view, |
| 77 views::BubbleBorder::Arrow arrow, | 55 views::BubbleBorder::Arrow arrow, |
| 78 views::BubbleBorder::BubbleAlignment border_alignment, | 56 views::BubbleBorder::BubbleAlignment border_alignment, |
| 79 const gfx::Rect& anchor_rect, | 57 const gfx::Rect& anchor_rect, |
| 80 Browser* browser); | 58 Browser* browser); |
| 81 static bool IsShowing(); | 59 static bool IsShowing(); |
| 82 static void Hide(); | 60 static void Hide(); |
| 83 | 61 |
| 84 // We normally close the bubble any time it becomes inactive but this can lead | 62 // We normally close the bubble any time it becomes inactive but this can lead |
| 85 // to flaky tests where unexpected UI events are triggering this behavior. | 63 // to flaky tests where unexpected UI events are triggering this behavior. |
| 86 // Tests should call this with "false" for more consistent operation. | 64 // Tests should call this with "false" for more consistent operation. |
| 87 static void clear_close_on_deactivate_for_testing() { | 65 static void clear_close_on_deactivate_for_testing() { |
| 88 close_on_deactivate_for_testing_ = false; | 66 close_on_deactivate_for_testing_ = false; |
| 89 } | 67 } |
| 90 | 68 |
| 91 private: | 69 private: |
| 92 friend class NewAvatarMenuButtonTest; | 70 friend class NewAvatarMenuButtonTest; |
| 93 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut); | 71 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut); |
| 94 | 72 |
| 95 typedef std::vector<size_t> Indexes; | 73 typedef std::vector<size_t> Indexes; |
| 96 typedef std::map<views::Button*, int> ButtonIndexes; | 74 typedef std::map<views::Button*, int> ButtonIndexes; |
| 97 typedef std::map<views::Button*, std::string> AccountButtonIndexes; | 75 typedef std::map<views::Button*, std::string> AccountButtonIndexes; |
| 98 | 76 |
| 99 ProfileChooserView(views::View* anchor_view, | 77 ProfileChooserView(views::View* anchor_view, |
| 100 views::BubbleBorder::Arrow arrow, | 78 views::BubbleBorder::Arrow arrow, |
| 101 const gfx::Rect& anchor_rect, | 79 const gfx::Rect& anchor_rect, |
| 102 Browser* browser, | 80 Browser* browser, |
| 103 BubbleViewMode view_mode); | 81 profiles::BubbleViewMode view_mode); |
| 104 virtual ~ProfileChooserView(); | 82 virtual ~ProfileChooserView(); |
| 105 | 83 |
| 106 // views::BubbleDelegateView: | 84 // views::BubbleDelegateView: |
| 107 virtual void Init() OVERRIDE; | 85 virtual void Init() OVERRIDE; |
| 108 virtual void WindowClosing() OVERRIDE; | 86 virtual void WindowClosing() OVERRIDE; |
| 109 | 87 |
| 110 // views::ButtonListener: | 88 // views::ButtonListener: |
| 111 virtual void ButtonPressed(views::Button* sender, | 89 virtual void ButtonPressed(views::Button* sender, |
| 112 const ui::Event& event) OVERRIDE; | 90 const ui::Event& event) OVERRIDE; |
| 113 | 91 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 128 // OAuth2TokenService::Observer overrides. | 106 // OAuth2TokenService::Observer overrides. |
| 129 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 107 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 130 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 108 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
| 131 | 109 |
| 132 static ProfileChooserView* profile_bubble_; | 110 static ProfileChooserView* profile_bubble_; |
| 133 static bool close_on_deactivate_for_testing_; | 111 static bool close_on_deactivate_for_testing_; |
| 134 | 112 |
| 135 void ResetView(); | 113 void ResetView(); |
| 136 | 114 |
| 137 // Shows the bubble with the |view_to_display|. | 115 // Shows the bubble with the |view_to_display|. |
| 138 void ShowView(BubbleViewMode view_to_display, | 116 void ShowView(profiles::BubbleViewMode view_to_display, |
| 139 AvatarMenu* avatar_menu); | 117 AvatarMenu* avatar_menu); |
| 140 | 118 |
| 141 // Creates the profile chooser view. |tutorial_shown| indicates if the "mirror | 119 // Creates the profile chooser view. |tutorial_shown| indicates if the "mirror |
| 142 // enabled" tutorial was shown or not in the last active view. | 120 // enabled" tutorial was shown or not in the last active view. |
| 143 views::View* CreateProfileChooserView(AvatarMenu* avatar_menu, | 121 views::View* CreateProfileChooserView(AvatarMenu* avatar_menu, |
| 144 TutorialMode last_tutorial_mode); | 122 profiles::TutorialMode last_tutorial_mode); |
| 145 | 123 |
| 146 // Creates the main profile card for the profile |avatar_item|. |is_guest| | 124 // Creates the main profile card for the profile |avatar_item|. |is_guest| |
| 147 // is used to determine whether to show any Sign in/Sign out/Manage accounts | 125 // is used to determine whether to show any Sign in/Sign out/Manage accounts |
| 148 // links. | 126 // links. |
| 149 views::View* CreateCurrentProfileView( | 127 views::View* CreateCurrentProfileView( |
| 150 const AvatarMenu::Item& avatar_item, | 128 const AvatarMenu::Item& avatar_item, |
| 151 bool is_guest); | 129 bool is_guest); |
| 152 views::View* CreateGuestProfileView(); | 130 views::View* CreateGuestProfileView(); |
| 153 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show); | 131 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show); |
| 154 views::View* CreateOptionsView(bool enable_lock); | 132 views::View* CreateOptionsView(bool enable_lock); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 184 // Creates a a tutorial card at the top prompting the user to send feedback | 162 // Creates a a tutorial card at the top prompting the user to send feedback |
| 185 // about the new profile management preview and/or to end preview. | 163 // about the new profile management preview and/or to end preview. |
| 186 views::View* CreateSendPreviewFeedbackView(); | 164 views::View* CreateSendPreviewFeedbackView(); |
| 187 | 165 |
| 188 // Creates a tutorial card with the specified |title_text|, |context_text|, | 166 // Creates a tutorial card with the specified |title_text|, |context_text|, |
| 189 // and a bottom row with a right-aligned link using the specified |link_text|, | 167 // and a bottom row with a right-aligned link using the specified |link_text|, |
| 190 // and a left aligned button using the specified |button_text|. The method | 168 // and a left aligned button using the specified |button_text|. The method |
| 191 // sets |link| to point to the newly created link, |button| to the newly | 169 // sets |link| to point to the newly created link, |button| to the newly |
| 192 // created button, and |tutorial_mode_| to the given |tutorial_mode|. | 170 // created button, and |tutorial_mode_| to the given |tutorial_mode|. |
| 193 views::View* CreateTutorialView( | 171 views::View* CreateTutorialView( |
| 194 TutorialMode tutorial_mode, | 172 profiles::TutorialMode tutorial_mode, |
| 195 const base::string16& title_text, | 173 const base::string16& title_text, |
| 196 const base::string16& content_text, | 174 const base::string16& content_text, |
| 197 const base::string16& link_text, | 175 const base::string16& link_text, |
| 198 const base::string16& button_text, | 176 const base::string16& button_text, |
| 199 views::Link** link, | 177 views::Link** link, |
| 200 views::LabelButton** button); | 178 views::LabelButton** button); |
| 201 | 179 |
| 202 views::View* CreateEndPreviewView(); | 180 views::View* CreateEndPreviewView(); |
| 203 | 181 |
| 204 scoped_ptr<AvatarMenu> avatar_menu_; | 182 scoped_ptr<AvatarMenu> avatar_menu_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 views::ImageButton* account_removal_cancel_button_; | 218 views::ImageButton* account_removal_cancel_button_; |
| 241 | 219 |
| 242 // Links and buttons displayed in the end-preview view. | 220 // Links and buttons displayed in the end-preview view. |
| 243 views::LabelButton* end_preview_and_relaunch_button_; | 221 views::LabelButton* end_preview_and_relaunch_button_; |
| 244 views::ImageButton* end_preview_cancel_button_; | 222 views::ImageButton* end_preview_cancel_button_; |
| 245 | 223 |
| 246 // Records the account id to remove. | 224 // Records the account id to remove. |
| 247 std::string account_id_to_remove_; | 225 std::string account_id_to_remove_; |
| 248 | 226 |
| 249 // Active view mode. | 227 // Active view mode. |
| 250 BubbleViewMode view_mode_; | 228 profiles::BubbleViewMode view_mode_; |
| 251 | 229 |
| 252 // The current tutorial mode. | 230 // The current tutorial mode. |
| 253 TutorialMode tutorial_mode_; | 231 profiles::TutorialMode tutorial_mode_; |
| 254 | 232 |
| 255 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView); | 233 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView); |
| 256 }; | 234 }; |
| 257 | 235 |
| 258 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ | 236 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ |
| OLD | NEW |