| 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 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 // Helpers -------------------------------------------------------------------- | 57 // Helpers -------------------------------------------------------------------- |
| 58 | 58 |
| 59 const int kFixedMenuWidth = 250; | 59 const int kFixedMenuWidth = 250; |
| 60 const int kButtonHeight = 29; | 60 const int kButtonHeight = 29; |
| 61 const int kProfileAvatarTutorialShowMax = 5; | 61 const int kProfileAvatarTutorialShowMax = 5; |
| 62 const int kFixedGaiaViewHeight = 400; | 62 const int kFixedGaiaViewHeight = 400; |
| 63 const int kFixedGaiaViewWidth = 360; | 63 const int kFixedGaiaViewWidth = 360; |
| 64 const int kFixedAccountRemovalViewWidth = 280; | 64 const int kFixedAccountRemovalViewWidth = 280; |
| 65 const int kLargeImageSide = 88; |
| 65 | 66 |
| 66 // Creates a GridLayout with a single column. This ensures that all the child | 67 // Creates a GridLayout with a single column. This ensures that all the child |
| 67 // views added get auto-expanded to fill the full width of the bubble. | 68 // views added get auto-expanded to fill the full width of the bubble. |
| 68 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { | 69 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { |
| 69 views::GridLayout* layout = new views::GridLayout(view); | 70 views::GridLayout* layout = new views::GridLayout(view); |
| 70 view->SetLayoutManager(layout); | 71 view->SetLayoutManager(layout); |
| 71 | 72 |
| 72 views::ColumnSet* columns = layout->AddColumnSet(0); | 73 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 73 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 74 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 74 views::GridLayout::FIXED, width, width); | 75 views::GridLayout::FIXED, width, width); |
| 75 return layout; | 76 return layout; |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Creates a GridLayout with two columns. | |
| 79 views::GridLayout* CreateDoubleColumnLayout(views::View* view) { | |
| 80 views::GridLayout* layout = new views::GridLayout(view); | |
| 81 view->SetLayoutManager(layout); | |
| 82 | |
| 83 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 84 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | |
| 85 views::GridLayout::USE_PREF, 0, 0); | |
| 86 columns->AddPaddingColumn(0, views::kUnrelatedControlLargeHorizontalSpacing); | |
| 87 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
| 88 views::GridLayout::USE_PREF, 0, 0); | |
| 89 return layout; | |
| 90 } | |
| 91 | |
| 92 views::Link* CreateLink(const base::string16& link_text, | 79 views::Link* CreateLink(const base::string16& link_text, |
| 93 views::LinkListener* listener) { | 80 views::LinkListener* listener) { |
| 94 views::Link* link_button = new views::Link(link_text); | 81 views::Link* link_button = new views::Link(link_text); |
| 95 link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 82 link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 96 link_button->SetUnderline(false); | 83 link_button->SetUnderline(false); |
| 97 link_button->set_listener(listener); | 84 link_button->set_listener(listener); |
| 98 return link_button; | 85 return link_button; |
| 99 } | 86 } |
| 100 | 87 |
| 88 gfx::ImageSkia CreateSquarePlaceholderImage(int size) { |
| 89 SkBitmap bitmap; |
| 90 bitmap.setConfig(SkBitmap::kA8_Config, size, size); |
| 91 bitmap.allocPixels(); |
| 92 bitmap.eraseARGB(0, 0, 0, 0); |
| 93 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 94 } |
| 101 | 95 |
| 102 // BackgroundColorHoverButton ------------------------------------------------- | 96 // BackgroundColorHoverButton ------------------------------------------------- |
| 103 | 97 |
| 104 // A custom button that allows for setting a background color when hovered over. | 98 // A custom button that allows for setting a background color when hovered over. |
| 105 class BackgroundColorHoverButton : public views::LabelButton { | 99 class BackgroundColorHoverButton : public views::LabelButton { |
| 106 public: | 100 public: |
| 107 BackgroundColorHoverButton(views::ButtonListener* listener, | 101 BackgroundColorHoverButton(views::ButtonListener* listener, |
| 108 const base::string16& text, | 102 const base::string16& text, |
| 109 const gfx::ImageSkia& normal_icon, | 103 const gfx::ImageSkia& normal_icon, |
| 110 const gfx::ImageSkia& hover_icon); | 104 const gfx::ImageSkia& hover_icon); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 SetImage(STATE_NORMAL, normal_icon); | 123 SetImage(STATE_NORMAL, normal_icon); |
| 130 SetImage(STATE_HOVERED, hover_icon); | 124 SetImage(STATE_HOVERED, hover_icon); |
| 131 SetImage(STATE_PRESSED, hover_icon); | 125 SetImage(STATE_PRESSED, hover_icon); |
| 132 } | 126 } |
| 133 | 127 |
| 134 BackgroundColorHoverButton::~BackgroundColorHoverButton() {} | 128 BackgroundColorHoverButton::~BackgroundColorHoverButton() {} |
| 135 | 129 |
| 136 void BackgroundColorHoverButton::OnPaint(gfx::Canvas* canvas) { | 130 void BackgroundColorHoverButton::OnPaint(gfx::Canvas* canvas) { |
| 137 if ((state() == STATE_PRESSED) || (state() == STATE_HOVERED) || HasFocus()) { | 131 if ((state() == STATE_PRESSED) || (state() == STATE_HOVERED) || HasFocus()) { |
| 138 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 132 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
| 139 ui::NativeTheme::kColorId_MenuSeparatorColor)); | 133 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor)); |
| 140 } | 134 } |
| 141 LabelButton::OnPaint(canvas); | 135 LabelButton::OnPaint(canvas); |
| 142 } | 136 } |
| 143 | 137 |
| 144 } // namespace | 138 } // namespace |
| 145 | 139 |
| 146 | 140 |
| 147 // EditableProfilePhoto ------------------------------------------------- | 141 // EditableProfilePhoto ------------------------------------------------- |
| 148 | 142 |
| 149 // A custom Image control that shows a "change" button when moused over. | 143 // A custom Image control that shows a "change" button when moused over. |
| 150 class EditableProfilePhoto : public views::ImageView { | 144 class EditableProfilePhoto : public views::ImageView { |
| 151 public: | 145 public: |
| 152 EditableProfilePhoto(views::ButtonListener* listener, | 146 EditableProfilePhoto(views::ButtonListener* listener, |
| 153 const gfx::Image& icon, | 147 const gfx::Image& icon, |
| 154 bool is_editing_allowed) | 148 bool is_editing_allowed, |
| 149 const gfx::Rect& bounds) |
| 155 : views::ImageView(), | 150 : views::ImageView(), |
| 156 change_photo_button_(NULL) { | 151 change_photo_button_(NULL) { |
| 157 const int kLargeImageSide = 64; | |
| 158 gfx::Image image = profiles::GetSizedAvatarIcon( | 152 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 159 icon, true, | 153 icon, true, |
| 160 kLargeImageSide + profiles::kAvatarIconPadding, | 154 kLargeImageSide + profiles::kAvatarIconPadding, |
| 161 kLargeImageSide + profiles::kAvatarIconPadding); | 155 kLargeImageSide + profiles::kAvatarIconPadding); |
| 162 SetImage(image.ToImageSkia()); | 156 SetImage(image.ToImageSkia()); |
| 157 SetBoundsRect(bounds); |
| 163 | 158 |
| 164 if (!is_editing_allowed) | 159 if (!is_editing_allowed) |
| 165 return; | 160 return; |
| 166 | 161 |
| 167 set_notify_enter_exit_on_child(true); | 162 set_notify_enter_exit_on_child(true); |
| 168 | 163 |
| 169 // Button overlay that appears when hovering over the image. | 164 // Button overlay that appears when hovering over the image. |
| 170 change_photo_button_ = new views::LabelButton(listener, | 165 change_photo_button_ = new views::LabelButton(listener, |
| 171 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_CHANGE_PHOTO_BUTTON)); | 166 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_CHANGE_PHOTO_BUTTON)); |
| 172 change_photo_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 167 change_photo_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 173 change_photo_button_->SetBorder(views::Border::NullBorder()); | 168 change_photo_button_->SetBorder(views::Border::NullBorder()); |
| 174 const SkColor color = SK_ColorWHITE; | 169 const SkColor color = SK_ColorWHITE; |
| 175 change_photo_button_->SetTextColor(views::Button::STATE_NORMAL, color); | 170 change_photo_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
| 176 change_photo_button_->SetTextColor(views::Button::STATE_HOVERED, color); | 171 change_photo_button_->SetTextColor(views::Button::STATE_HOVERED, color); |
| 177 | 172 |
| 178 const SkColor kBackgroundColor = SkColorSetARGB(125, 0, 0, 0); | 173 const SkColor kBackgroundColor = SkColorSetARGB(125, 0, 0, 0); |
| 179 change_photo_button_->set_background( | 174 change_photo_button_->set_background( |
| 180 views::Background::CreateSolidBackground(kBackgroundColor)); | 175 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 181 // Need to take into account the border padding on the avatar. | 176 // Need to take into account the border padding on the avatar. |
| 182 const int kOverlayHeight = 20; | 177 const int kOverlayHeight = 20; |
| 183 change_photo_button_->SetBounds( | 178 change_photo_button_->SetBounds( |
| 184 profiles::kAvatarIconPadding, | 179 bounds.origin().x(), |
| 185 kLargeImageSide - kOverlayHeight, | 180 bounds.origin().y() + kLargeImageSide - kOverlayHeight, |
| 186 kLargeImageSide - profiles::kAvatarIconPadding, | 181 kLargeImageSide, |
| 187 kOverlayHeight); | 182 kOverlayHeight); |
| 188 change_photo_button_->SetVisible(false); | 183 change_photo_button_->SetVisible(false); |
| 189 AddChildView(change_photo_button_); | 184 AddChildView(change_photo_button_); |
| 190 } | 185 } |
| 191 | 186 |
| 192 views::LabelButton* change_photo_button() { return change_photo_button_; } | 187 views::LabelButton* change_photo_button() { return change_photo_button_; } |
| 193 | 188 |
| 194 private: | 189 private: |
| 195 // views::View: | 190 // views::View: |
| 196 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { | 191 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 219 public: | 214 public: |
| 220 EditableProfileName(views::TextfieldController* controller, | 215 EditableProfileName(views::TextfieldController* controller, |
| 221 const base::string16& text, | 216 const base::string16& text, |
| 222 bool is_editing_allowed) | 217 bool is_editing_allowed) |
| 223 : views::LabelButton(this, text), | 218 : views::LabelButton(this, text), |
| 224 profile_name_textfield_(NULL) { | 219 profile_name_textfield_(NULL) { |
| 225 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 220 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 226 const gfx::FontList& medium_font_list = | 221 const gfx::FontList& medium_font_list = |
| 227 rb->GetFontList(ui::ResourceBundle::MediumFont); | 222 rb->GetFontList(ui::ResourceBundle::MediumFont); |
| 228 SetFontList(medium_font_list); | 223 SetFontList(medium_font_list); |
| 229 SetBorder(views::Border::NullBorder()); | 224 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 230 | 225 |
| 231 if (!is_editing_allowed) | 226 if (!is_editing_allowed) |
| 232 return; | 227 return; |
| 233 | 228 |
| 234 SetImage(STATE_HOVERED, | 229 // Show an "edit" pencil icon when hovering over. In the default state, |
| 235 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_HOVER)); | 230 // we need to create an empty placeholder of the correct size, so that |
| 231 // the text doesn't jump around when the hovered icon appears. |
| 232 gfx::ImageSkia hover_image = |
| 233 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_HOVER); |
| 234 SetImage(STATE_NORMAL, CreateSquarePlaceholderImage(hover_image.width())); |
| 235 SetImage(STATE_HOVERED, hover_image); |
| 236 SetImage(STATE_PRESSED, | 236 SetImage(STATE_PRESSED, |
| 237 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_PRESSED)); | 237 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_PRESSED)); |
| 238 // To center the text, we need to offest it by the width of the icon we |
| 239 // are adding. We need to also add a small top/bottom padding to account |
| 240 // for the textfield's border. |
| 241 SetBorder(views::Border::CreateEmptyBorder(2, hover_image.width(), 2, 0)); |
| 238 | 242 |
| 239 // Textfield that overlaps the button. | 243 // Textfield that overlaps the button. |
| 240 profile_name_textfield_ = new views::Textfield(); | 244 profile_name_textfield_ = new views::Textfield(); |
| 241 profile_name_textfield_->set_controller(controller); | 245 profile_name_textfield_->set_controller(controller); |
| 242 profile_name_textfield_->SetFontList(medium_font_list); | 246 profile_name_textfield_->SetFontList(medium_font_list); |
| 247 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 248 |
| 243 profile_name_textfield_->SetVisible(false); | 249 profile_name_textfield_->SetVisible(false); |
| 244 AddChildView(profile_name_textfield_); | 250 AddChildView(profile_name_textfield_); |
| 245 } | 251 } |
| 246 | 252 |
| 247 views::Textfield* profile_name_textfield() { | 253 views::Textfield* profile_name_textfield() { |
| 248 return profile_name_textfield_; | 254 return profile_name_textfield_; |
| 249 } | 255 } |
| 250 | 256 |
| 251 // Hide the editable textfield to show the profile name button instead. | 257 // Hide the editable textfield to show the profile name button instead. |
| 252 void ShowReadOnlyView() { | 258 void ShowReadOnlyView() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 273 // part of the new profile name typed in the textfield. | 279 // part of the new profile name typed in the textfield. |
| 274 return false; | 280 return false; |
| 275 } | 281 } |
| 276 | 282 |
| 277 virtual void Layout() OVERRIDE { | 283 virtual void Layout() OVERRIDE { |
| 278 if (profile_name_textfield_) | 284 if (profile_name_textfield_) |
| 279 profile_name_textfield_->SetBounds(0, 0, width(), height()); | 285 profile_name_textfield_->SetBounds(0, 0, width(), height()); |
| 280 // This layout trick keeps the text left-aligned and the icon right-aligned. | 286 // This layout trick keeps the text left-aligned and the icon right-aligned. |
| 281 SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 287 SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 282 views::LabelButton::Layout(); | 288 views::LabelButton::Layout(); |
| 283 label()->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 289 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 284 } | 290 } |
| 285 | 291 |
| 286 // Button that is shown when hovering over the image view. Can be NULL if | 292 // Textfield that is shown when editing the profile name. Can be NULL if |
| 287 // the profile name isn't allowed to be edited (e.g. for guest profiles). | 293 // the profile name isn't allowed to be edited (e.g. for guest profiles). |
| 288 views::Textfield* profile_name_textfield_; | 294 views::Textfield* profile_name_textfield_; |
| 289 | 295 |
| 290 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); | 296 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); |
| 291 }; | 297 }; |
| 292 | 298 |
| 293 // A title card with one back button right aligned and one label center aligned. | 299 // A title card with one back button right aligned and one label center aligned. |
| 294 class TitleCard : public views::View { | 300 class TitleCard : public views::View { |
| 295 public: | 301 public: |
| 296 TitleCard(int message_id, views::ButtonListener* listener, | 302 TitleCard(int message_id, views::ButtonListener* listener, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); | 414 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); |
| 409 if (oauth2_token_service) | 415 if (oauth2_token_service) |
| 410 oauth2_token_service->RemoveObserver(this); | 416 oauth2_token_service->RemoveObserver(this); |
| 411 } | 417 } |
| 412 | 418 |
| 413 void ProfileChooserView::ResetView() { | 419 void ProfileChooserView::ResetView() { |
| 414 manage_accounts_link_ = NULL; | 420 manage_accounts_link_ = NULL; |
| 415 signin_current_profile_link_ = NULL; | 421 signin_current_profile_link_ = NULL; |
| 416 users_button_ = NULL; | 422 users_button_ = NULL; |
| 417 lock_button_ = NULL; | 423 lock_button_ = NULL; |
| 418 add_account_button_ = NULL; | 424 add_account_link_ = NULL; |
| 419 current_profile_photo_ = NULL; | 425 current_profile_photo_ = NULL; |
| 420 current_profile_name_ = NULL; | 426 current_profile_name_ = NULL; |
| 421 tutorial_ok_button_ = NULL; | 427 tutorial_ok_button_ = NULL; |
| 422 tutorial_learn_more_link_ = NULL; | 428 tutorial_learn_more_link_ = NULL; |
| 423 tutorial_enable_new_profile_management_button_ = NULL; | 429 tutorial_enable_new_profile_management_button_ = NULL; |
| 424 account_removal_cancel_button_ = NULL; | 430 account_removal_cancel_button_ = NULL; |
| 425 gaia_signin_cancel_button_ = NULL; | 431 gaia_signin_cancel_button_ = NULL; |
| 426 open_other_profile_indexes_map_.clear(); | 432 open_other_profile_indexes_map_.clear(); |
| 427 current_profile_accounts_map_.clear(); | 433 current_profile_accounts_map_.clear(); |
| 428 tutorial_showing_ = false; | 434 tutorial_showing_ = false; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // Disable button after clicking so that it doesn't get clicked twice and | 515 // Disable button after clicking so that it doesn't get clicked twice and |
| 510 // start a second action... which can crash Chrome. But don't disable if it | 516 // start a second action... which can crash Chrome. But don't disable if it |
| 511 // has no parent (like in tests) because that will also crash. | 517 // has no parent (like in tests) because that will also crash. |
| 512 if (sender->parent()) | 518 if (sender->parent()) |
| 513 sender->SetEnabled(false); | 519 sender->SetEnabled(false); |
| 514 | 520 |
| 515 if (sender == users_button_) { | 521 if (sender == users_button_) { |
| 516 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); | 522 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); |
| 517 } else if (sender == lock_button_) { | 523 } else if (sender == lock_button_) { |
| 518 profiles::LockProfile(browser_->profile()); | 524 profiles::LockProfile(browser_->profile()); |
| 519 } else if (sender == add_account_button_) { | |
| 520 ShowView(BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); | |
| 521 } else if (sender == tutorial_ok_button_) { | 525 } else if (sender == tutorial_ok_button_) { |
| 522 // If the user manually dismissed the tutorial, never show it again by | 526 // If the user manually dismissed the tutorial, never show it again by |
| 523 // setting the number of times shown to the maximum plus 1, so that later we | 527 // setting the number of times shown to the maximum plus 1, so that later we |
| 524 // could distinguish between the dismiss case and the case when the tutorial | 528 // could distinguish between the dismiss case and the case when the tutorial |
| 525 // is indeed shown for the maximum number of times. | 529 // is indeed shown for the maximum number of times. |
| 526 browser_->profile()->GetPrefs()->SetInteger( | 530 browser_->profile()->GetPrefs()->SetInteger( |
| 527 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); | 531 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); |
| 528 ShowView(BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); | 532 ShowView(BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); |
| 529 } else if (sender == tutorial_enable_new_profile_management_button_) { | 533 } else if (sender == tutorial_enable_new_profile_management_button_) { |
| 530 profiles::EnableNewProfileManagementPreview(); | 534 profiles::EnableNewProfileManagementPreview(); |
| 531 } else if (sender == remove_account_and_relaunch_button_) { | 535 } else if (sender == remove_account_and_relaunch_button_) { |
| 532 RemoveAccount(); | 536 RemoveAccount(); |
| 533 } else if (sender == account_removal_cancel_button_) { | 537 } else if (sender == account_removal_cancel_button_) { |
| 534 account_id_to_remove_.clear(); | 538 account_id_to_remove_.clear(); |
| 535 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); | 539 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); |
| 536 } else if (sender == gaia_signin_cancel_button_) { | 540 } else if (sender == gaia_signin_cancel_button_) { |
| 537 std::string primary_account = | 541 std::string primary_account = |
| 538 SigninManagerFactory::GetForProfile(browser_->profile())-> | 542 SigninManagerFactory::GetForProfile(browser_->profile())-> |
| 539 GetAuthenticatedUsername(); | 543 GetAuthenticatedUsername(); |
| 540 ShowView(primary_account.empty() ? BUBBLE_VIEW_MODE_PROFILE_CHOOSER : | 544 ShowView(primary_account.empty() ? BUBBLE_VIEW_MODE_PROFILE_CHOOSER : |
| 541 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, | 545 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, |
| 542 avatar_menu_.get()); | 546 avatar_menu_.get()); |
| 543 } else if (current_profile_photo_ && | 547 } else if (current_profile_photo_ && |
| 544 sender == current_profile_photo_->change_photo_button()) { | 548 sender == current_profile_photo_->change_photo_button()) { |
| 545 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); | 549 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
| 550 } else if (sender == signin_current_profile_link_) { |
| 551 ShowView(BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); |
| 546 } else { | 552 } else { |
| 547 // One of the "other profiles" buttons was pressed. | 553 // Either one of the "other profiles", or one of the profile accounts |
| 548 ButtonIndexes::const_iterator match = | 554 // buttons was pressed. |
| 555 ButtonIndexes::const_iterator profile_match = |
| 549 open_other_profile_indexes_map_.find(sender); | 556 open_other_profile_indexes_map_.find(sender); |
| 550 DCHECK(match != open_other_profile_indexes_map_.end()); | 557 if (profile_match != open_other_profile_indexes_map_.end()) { |
| 551 avatar_menu_->SwitchToProfile( | 558 avatar_menu_->SwitchToProfile( |
| 552 match->second, | 559 profile_match->second, |
| 553 ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW, | 560 ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW, |
| 554 ProfileMetrics::SWITCH_PROFILE_ICON); | 561 ProfileMetrics::SWITCH_PROFILE_ICON); |
| 562 } else { |
| 563 // This was a profile accounts button. |
| 564 AccountButtonIndexes::const_iterator account_match = |
| 565 current_profile_accounts_map_.find(sender); |
| 566 DCHECK(account_match != current_profile_accounts_map_.end()); |
| 567 account_id_to_remove_ = account_match->second; |
| 568 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, avatar_menu_.get()); |
| 569 } |
| 555 } | 570 } |
| 556 } | 571 } |
| 557 | 572 |
| 558 void ProfileChooserView::OnMenuButtonClicked(views::View* source, | |
| 559 const gfx::Point& point) { | |
| 560 AccountButtonIndexes::const_iterator match = | |
| 561 current_profile_accounts_map_.find(source); | |
| 562 DCHECK(match != current_profile_accounts_map_.end()); | |
| 563 account_id_to_remove_ = match->second; | |
| 564 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, avatar_menu_.get()); | |
| 565 } | |
| 566 | |
| 567 void ProfileChooserView::RemoveAccount() { | 573 void ProfileChooserView::RemoveAccount() { |
| 568 DCHECK(!account_id_to_remove_.empty()); | 574 DCHECK(!account_id_to_remove_.empty()); |
| 569 MutableProfileOAuth2TokenService* oauth2_token_service = | 575 MutableProfileOAuth2TokenService* oauth2_token_service = |
| 570 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( | 576 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( |
| 571 browser_->profile()); | 577 browser_->profile()); |
| 572 if (oauth2_token_service) | 578 if (oauth2_token_service) |
| 573 oauth2_token_service->RevokeCredentials(account_id_to_remove_); | 579 oauth2_token_service->RevokeCredentials(account_id_to_remove_); |
| 574 account_id_to_remove_.clear(); | 580 account_id_to_remove_.clear(); |
| 575 | 581 |
| 576 chrome::AttemptRestart(); | 582 chrome::AttemptRestart(); |
| 577 } | 583 } |
| 578 | 584 |
| 579 void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { | 585 void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { |
| 580 if (sender == manage_accounts_link_) { | 586 if (sender == manage_accounts_link_) { |
| 581 // ShowView() will DCHECK if this view is displayed for non signed-in users. | 587 // This link can either mean show/hide the account management view, |
| 582 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); | 588 // depending on which view it is displayed. ShowView() will DCHECK if |
| 583 } else if (sender == tutorial_learn_more_link_) { | 589 // the account management view is displayed for non signed-in users. |
| 590 ShowView( |
| 591 view_mode_ == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? |
| 592 BUBBLE_VIEW_MODE_PROFILE_CHOOSER : |
| 593 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, |
| 594 avatar_menu_.get()); |
| 595 } else if (sender == add_account_link_) { |
| 596 ShowView(BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); |
| 597 } else { |
| 598 DCHECK(sender == tutorial_learn_more_link_); |
| 584 // TODO(guohui): update |learn_more_url| once it is decided. | 599 // TODO(guohui): update |learn_more_url| once it is decided. |
| 585 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); | 600 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); |
| 586 chrome::NavigateParams params( | 601 chrome::NavigateParams params( |
| 587 browser_->profile(), | 602 browser_->profile(), |
| 588 lear_more_url, | 603 lear_more_url, |
| 589 content::PAGE_TRANSITION_LINK); | 604 content::PAGE_TRANSITION_LINK); |
| 590 params.disposition = NEW_FOREGROUND_TAB; | 605 params.disposition = NEW_FOREGROUND_TAB; |
| 591 chrome::Navigate(¶ms); | 606 chrome::Navigate(¶ms); |
| 592 } else { | |
| 593 DCHECK(sender == signin_current_profile_link_); | |
| 594 ShowView(BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); | |
| 595 } | 607 } |
| 596 } | 608 } |
| 597 | 609 |
| 598 void ProfileChooserView::StyledLabelLinkClicked( | 610 void ProfileChooserView::StyledLabelLinkClicked( |
| 599 const gfx::Range& range, int event_flags) { | 611 const gfx::Range& range, int event_flags) { |
| 600 chrome::ShowSettings(browser_); | 612 chrome::ShowSettings(browser_); |
| 601 } | 613 } |
| 602 | 614 |
| 603 bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, | 615 bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, |
| 604 const ui::KeyEvent& key_event) { | 616 const ui::KeyEvent& key_event) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 // Separate items into active and alternatives. | 651 // Separate items into active and alternatives. |
| 640 Indexes other_profiles; | 652 Indexes other_profiles; |
| 641 views::View* tutorial_view = NULL; | 653 views::View* tutorial_view = NULL; |
| 642 views::View* current_profile_view = NULL; | 654 views::View* current_profile_view = NULL; |
| 643 views::View* current_profile_accounts = NULL; | 655 views::View* current_profile_accounts = NULL; |
| 644 views::View* option_buttons_view = NULL; | 656 views::View* option_buttons_view = NULL; |
| 645 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 657 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| 646 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 658 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| 647 if (item.active) { | 659 if (item.active) { |
| 648 option_buttons_view = CreateOptionsView(item.signed_in); | 660 option_buttons_view = CreateOptionsView(item.signed_in); |
| 661 current_profile_view = CreateCurrentProfileView(item, false); |
| 649 if (view_mode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 662 if (view_mode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { |
| 650 tutorial_view = switches::IsNewProfileManagement() ? | 663 tutorial_view = switches::IsNewProfileManagement() ? |
| 651 CreatePreviewEnabledTutorialView(item, tutorial_shown) : | 664 CreatePreviewEnabledTutorialView(item, tutorial_shown) : |
| 652 CreateNewProfileManagementPreviewView(); | 665 CreateNewProfileManagementPreviewView(); |
| 653 current_profile_view = CreateCurrentProfileView(item, false); | |
| 654 } else { | 666 } else { |
| 655 current_profile_view = CreateCurrentProfileEditableView(item); | |
| 656 current_profile_accounts = CreateCurrentProfileAccountsView(item); | 667 current_profile_accounts = CreateCurrentProfileAccountsView(item); |
| 657 } | 668 } |
| 658 } else { | 669 } else { |
| 659 other_profiles.push_back(i); | 670 other_profiles.push_back(i); |
| 660 } | 671 } |
| 661 } | 672 } |
| 662 | 673 |
| 663 if (tutorial_view) { | 674 if (tutorial_view) { |
| 664 layout->StartRow(1, 0); | 675 layout->StartRow(1, 0); |
| 665 layout->AddView(tutorial_view); | 676 layout->AddView(tutorial_view); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 682 DCHECK(current_profile_accounts); | 693 DCHECK(current_profile_accounts); |
| 683 layout->StartRow(0, 0); | 694 layout->StartRow(0, 0); |
| 684 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 695 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 685 layout->StartRow(1, 0); | 696 layout->StartRow(1, 0); |
| 686 layout->AddView(current_profile_accounts); | 697 layout->AddView(current_profile_accounts); |
| 687 } | 698 } |
| 688 | 699 |
| 689 layout->StartRow(0, 0); | 700 layout->StartRow(0, 0); |
| 690 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 701 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 691 | 702 |
| 692 // Action buttons. | 703 // Option buttons. Only available with the new profile management flag. |
| 693 layout->StartRow(0, 0); | 704 if (switches::IsNewProfileManagement()) { |
| 694 layout->AddView(option_buttons_view); | 705 layout->StartRow(0, 0); |
| 706 layout->AddView(option_buttons_view); |
| 707 } |
| 695 | 708 |
| 696 return view; | 709 return view; |
| 697 } | 710 } |
| 698 | 711 |
| 699 views::View* ProfileChooserView::CreatePreviewEnabledTutorialView( | 712 views::View* ProfileChooserView::CreatePreviewEnabledTutorialView( |
| 700 const AvatarMenu::Item& current_avatar_item, | 713 const AvatarMenu::Item& current_avatar_item, |
| 701 bool tutorial_shown) { | 714 bool tutorial_shown) { |
| 702 if (!switches::IsNewProfileManagementPreviewEnabled()) | 715 if (!switches::IsNewProfileManagementPreviewEnabled()) |
| 703 return NULL; | 716 return NULL; |
| 704 | 717 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 layout_with_caret->AddView(view); | 828 layout_with_caret->AddView(view); |
| 816 layout_with_caret->StartRow(1, 0); | 829 layout_with_caret->StartRow(1, 0); |
| 817 layout_with_caret->AddView(padded_caret_view); | 830 layout_with_caret->AddView(padded_caret_view); |
| 818 return view_with_caret; | 831 return view_with_caret; |
| 819 } | 832 } |
| 820 | 833 |
| 821 views::View* ProfileChooserView::CreateCurrentProfileView( | 834 views::View* ProfileChooserView::CreateCurrentProfileView( |
| 822 const AvatarMenu::Item& avatar_item, | 835 const AvatarMenu::Item& avatar_item, |
| 823 bool is_guest) { | 836 bool is_guest) { |
| 824 views::View* view = new views::View(); | 837 views::View* view = new views::View(); |
| 825 views::GridLayout* layout = CreateDoubleColumnLayout(view); | 838 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; |
| 839 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); |
| 826 layout->SetInsets(views::kButtonVEdgeMarginNew, | 840 layout->SetInsets(views::kButtonVEdgeMarginNew, |
| 827 views::kButtonHEdgeMarginNew, | 841 views::kButtonHEdgeMarginNew, |
| 828 views::kButtonVEdgeMarginNew, | 842 views::kRelatedControlVerticalSpacing, |
| 829 views::kButtonHEdgeMarginNew); | 843 views::kButtonHEdgeMarginNew); |
| 830 | 844 |
| 831 current_profile_photo_ = | 845 // Profile icon, centered. |
| 832 new EditableProfilePhoto(this, avatar_item.icon, !is_guest); | 846 float x_offset = (column_width - kLargeImageSide) / 2; |
| 833 view->SetBoundsRect(current_profile_photo_->bounds()); | 847 current_profile_photo_ = new EditableProfilePhoto( |
| 848 this, avatar_item.icon, !is_guest, |
| 849 gfx::Rect(x_offset, 0, kLargeImageSide, kLargeImageSide)); |
| 850 layout->StartRow(1, 0); |
| 851 layout->AddView(current_profile_photo_); |
| 852 |
| 853 // Profile name, centered. |
| 834 current_profile_name_ = new EditableProfileName( | 854 current_profile_name_ = new EditableProfileName( |
| 835 this, profiles::GetAvatarNameForProfile(browser_->profile()), !is_guest); | 855 this, profiles::GetAvatarNameForProfile(browser_->profile()), !is_guest); |
| 836 layout->StartRow(1, 0); | 856 layout->StartRow(1, 0); |
| 837 layout->AddView(current_profile_photo_, 1, 3); | |
| 838 layout->AddView(current_profile_name_); | 857 layout->AddView(current_profile_name_); |
| 839 | 858 |
| 840 if (is_guest) { | 859 if (is_guest) |
| 841 layout->StartRow(1, 0); | 860 return view; |
| 842 layout->SkipColumns(1); | 861 |
| 843 layout->StartRow(1, 0); | 862 // The available links depend on the type of profile that is active. |
| 844 layout->SkipColumns(1); | 863 layout->StartRow(1, 0); |
| 845 } else if (avatar_item.signed_in) { | 864 if (avatar_item.signed_in) { |
| 846 manage_accounts_link_ = CreateLink( | 865 if (switches::IsNewProfileManagement()) { |
| 847 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON), | 866 base::string16 link_title = l10n_util::GetStringUTF16( |
| 848 this); | 867 view_mode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? |
| 849 layout->StartRow(1, 0); | 868 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
| 850 layout->SkipColumns(1); | 869 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 851 layout->AddView(manage_accounts_link_); | 870 manage_accounts_link_ = CreateLink(link_title, this); |
| 852 layout->StartRow(1, 0); | 871 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 853 layout->SkipColumns(1); | 872 layout->AddView(manage_accounts_link_); |
| 873 } else { |
| 874 views::Label* email_label = new views::Label(avatar_item.sync_state); |
| 875 email_label->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 876 layout->AddView(email_label); |
| 877 } |
| 854 } else { | 878 } else { |
| 855 signin_current_profile_link_ = CreateLink( | 879 signin_current_profile_link_ = new views::BlueButton( |
| 856 l10n_util::GetStringFUTF16( | 880 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 857 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 881 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 858 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), | |
| 859 this); | |
| 860 layout->StartRow(1, 0); | |
| 861 layout->SkipColumns(1); | |
| 862 layout->AddView(signin_current_profile_link_); | 882 layout->AddView(signin_current_profile_link_); |
| 863 layout->StartRow(1, 0); | |
| 864 layout->SkipColumns(1); | |
| 865 } | 883 } |
| 866 | 884 |
| 867 return view; | 885 return view; |
| 868 } | 886 } |
| 869 | 887 |
| 870 views::View* ProfileChooserView::CreateCurrentProfileEditableView( | |
| 871 const AvatarMenu::Item& avatar_item) { | |
| 872 DCHECK(avatar_item.signed_in); | |
| 873 views::View* view = new views::View(); | |
| 874 views::GridLayout* layout = CreateDoubleColumnLayout(view); | |
| 875 layout->SetInsets(views::kButtonVEdgeMarginNew, | |
| 876 views::kButtonHEdgeMarginNew, | |
| 877 views::kButtonVEdgeMarginNew, | |
| 878 views::kButtonHEdgeMarginNew); | |
| 879 | |
| 880 current_profile_photo_ = | |
| 881 new EditableProfilePhoto(this, avatar_item.icon, true); | |
| 882 view->SetBoundsRect(current_profile_photo_->bounds()); | |
| 883 current_profile_name_ = new EditableProfileName( | |
| 884 this, profiles::GetAvatarNameForProfile(browser_->profile()), true); | |
| 885 | |
| 886 layout->StartRow(1, 0); | |
| 887 layout->AddView(current_profile_photo_, 1, 3); | |
| 888 layout->AddView(current_profile_name_); | |
| 889 | |
| 890 layout->StartRow(1, 0); | |
| 891 layout->SkipColumns(1); | |
| 892 | |
| 893 layout->StartRow(1, 0); | |
| 894 layout->SkipColumns(1); | |
| 895 return view; | |
| 896 } | |
| 897 | |
| 898 views::View* ProfileChooserView::CreateGuestProfileView() { | 888 views::View* ProfileChooserView::CreateGuestProfileView() { |
| 899 gfx::Image guest_icon = | 889 gfx::Image guest_icon = |
| 900 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 890 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 901 profiles::GetPlaceholderAvatarIconResourceID()); | 891 profiles::GetPlaceholderAvatarIconResourceID()); |
| 902 AvatarMenu::Item guest_avatar_item(0, 0, guest_icon); | 892 AvatarMenu::Item guest_avatar_item(0, 0, guest_icon); |
| 903 guest_avatar_item.active = true; | 893 guest_avatar_item.active = true; |
| 904 guest_avatar_item.name = l10n_util::GetStringUTF16( | 894 guest_avatar_item.name = l10n_util::GetStringUTF16( |
| 905 IDS_PROFILES_GUEST_PROFILE_NAME); | 895 IDS_PROFILES_GUEST_PROFILE_NAME); |
| 906 guest_avatar_item.signed_in = false; | 896 guest_avatar_item.signed_in = false; |
| 907 | 897 |
| 908 return CreateCurrentProfileView(guest_avatar_item, true); | 898 return CreateCurrentProfileView(guest_avatar_item, true); |
| 909 } | 899 } |
| 910 | 900 |
| 911 views::View* ProfileChooserView::CreateOtherProfilesView( | 901 views::View* ProfileChooserView::CreateOtherProfilesView( |
| 912 const Indexes& avatars_to_show) { | 902 const Indexes& avatars_to_show) { |
| 913 views::View* view = new views::View(); | 903 views::View* view = new views::View(); |
| 914 views::GridLayout* layout = CreateSingleColumnLayout( | 904 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 915 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); | 905 |
| 916 layout->SetInsets(0, views::kButtonHEdgeMarginNew, | |
| 917 views::kButtonVEdgeMarginNew, views::kButtonHEdgeMarginNew); | |
| 918 int num_avatars_to_show = avatars_to_show.size(); | 906 int num_avatars_to_show = avatars_to_show.size(); |
| 919 for (int i = 0; i < num_avatars_to_show; ++i) { | 907 for (int i = 0; i < num_avatars_to_show; ++i) { |
| 920 const size_t index = avatars_to_show[i]; | 908 const size_t index = avatars_to_show[i]; |
| 921 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); | 909 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); |
| 922 const int kSmallImageSide = 32; | 910 const int kSmallImageSide = 32; |
| 923 | 911 |
| 924 gfx::Image image = profiles::GetSizedAvatarIcon( | 912 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 925 item.icon, true, | 913 item.icon, true, |
| 926 kSmallImageSide + profiles::kAvatarIconPadding, | 914 kSmallImageSide + profiles::kAvatarIconPadding, |
| 927 kSmallImageSide + profiles::kAvatarIconPadding); | 915 kSmallImageSide + profiles::kAvatarIconPadding); |
| 928 | 916 |
| 929 views::LabelButton* button = new views::LabelButton(this, item.name); | 917 views::LabelButton* button = new BackgroundColorHoverButton( |
| 918 this, |
| 919 item.name, |
| 920 *image.ToImageSkia(), |
| 921 *image.ToImageSkia()); |
| 922 button->set_min_size(gfx::Size( |
| 923 0, kButtonHeight + views::kRelatedControlVerticalSpacing)); |
| 924 |
| 930 open_other_profile_indexes_map_[button] = index; | 925 open_other_profile_indexes_map_[button] = index; |
| 931 button->SetImage(views::Button::STATE_NORMAL, *image.ToImageSkia()); | |
| 932 button->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 933 ui::ResourceBundle::MediumFont)); | |
| 934 button->SetBorder(views::Border::NullBorder()); | |
| 935 | 926 |
| 936 layout->StartRow(1, 0); | 927 layout->StartRow(1, 0); |
| 928 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 929 layout->StartRow(1, 0); |
| 937 layout->AddView(button); | 930 layout->AddView(button); |
| 938 | |
| 939 // The last avatar in the list does not need any bottom padding. | |
| 940 if (i < num_avatars_to_show - 1) | |
| 941 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 942 } | 931 } |
| 943 | 932 |
| 944 return view; | 933 return view; |
| 945 } | 934 } |
| 946 | 935 |
| 947 views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) { | 936 views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) { |
| 948 views::View* view = new views::View(); | 937 views::View* view = new views::View(); |
| 949 views::GridLayout* layout; | 938 views::GridLayout* layout; |
| 950 | 939 |
| 951 // Only signed-in users have the ability to lock. | 940 // Only signed-in users have the ability to lock. |
| 952 if (enable_lock) { | 941 if (enable_lock) { |
| 953 layout = new views::GridLayout(view); | 942 layout = new views::GridLayout(view); |
| 954 views::ColumnSet* columns = layout->AddColumnSet(0); | 943 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 955 int width_of_lock_button = | 944 int width_of_lock_button = |
| 956 2 * views::kUnrelatedControlLargeHorizontalSpacing + 12; | 945 2 * views::kUnrelatedControlLargeHorizontalSpacing + 12; |
| 957 int width_of_users_button = kFixedMenuWidth - width_of_lock_button; | 946 int width_of_users_button = kFixedMenuWidth - width_of_lock_button; |
| 958 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 947 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 959 views::GridLayout::FIXED, width_of_users_button, | 948 views::GridLayout::FIXED, width_of_users_button, |
| 960 width_of_users_button); | 949 width_of_users_button); |
| 961 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 950 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 962 views::GridLayout::FIXED, width_of_lock_button, | 951 views::GridLayout::FIXED, width_of_lock_button, |
| 963 width_of_lock_button); | 952 width_of_lock_button); |
| 964 view->SetLayoutManager(layout); | 953 view->SetLayoutManager(layout); |
| 965 } else { | 954 } else { |
| 966 layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 955 layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 967 } | 956 } |
| 968 | 957 |
| 969 // The horizontal padding will be set by each button individually, so that | |
| 970 // in the hovered state the button spans the entire parent view. | |
| 971 layout->SetInsets(views::kRelatedControlVerticalSpacing, 0, | |
| 972 views::kRelatedControlVerticalSpacing, 0); | |
| 973 | |
| 974 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 958 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 975 users_button_ = new BackgroundColorHoverButton( | 959 users_button_ = new BackgroundColorHoverButton( |
| 976 this, | 960 this, |
| 977 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU_BUTTON, | 961 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU_BUTTON, |
| 978 profiles::GetAvatarNameForProfile(browser_->profile())), | 962 profiles::GetAvatarNameForProfile(browser_->profile())), |
| 979 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR), | 963 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR), |
| 980 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); | 964 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); |
| 965 users_button_->set_min_size(gfx::Size( |
| 966 0, kButtonHeight + views::kRelatedControlVerticalSpacing)); |
| 981 | 967 |
| 982 layout->StartRow(1, 0); | 968 layout->StartRow(1, 0); |
| 983 layout->AddView(users_button_); | 969 layout->AddView(users_button_); |
| 984 | 970 |
| 985 if (enable_lock) { | 971 if (enable_lock) { |
| 986 lock_button_ = new BackgroundColorHoverButton( | 972 lock_button_ = new BackgroundColorHoverButton( |
| 987 this, | 973 this, |
| 988 base::string16(), | 974 base::string16(), |
| 989 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK), | 975 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK), |
| 990 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK)); | 976 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK)); |
| 977 lock_button_->set_min_size(gfx::Size( |
| 978 0, kButtonHeight + views::kRelatedControlVerticalSpacing)); |
| 991 layout->AddView(lock_button_); | 979 layout->AddView(lock_button_); |
| 992 } | 980 } |
| 993 return view; | 981 return view; |
| 994 } | 982 } |
| 995 | 983 |
| 996 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( | 984 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( |
| 997 const AvatarMenu::Item& avatar_item) { | 985 const AvatarMenu::Item& avatar_item) { |
| 998 DCHECK(avatar_item.signed_in); | 986 DCHECK(avatar_item.signed_in); |
| 999 views::View* view = new views::View(); | 987 views::View* view = new views::View(); |
| 1000 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; | 988 view->set_background(views::Background::CreateSolidBackground( |
| 1001 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); | 989 profiles::kAvatarBubbleAccountsBackgroundColor)); |
| 1002 layout->SetInsets(views::kButtonVEdgeMarginNew, | 990 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 1003 views::kButtonHEdgeMarginNew, | |
| 1004 views::kButtonVEdgeMarginNew, | |
| 1005 views::kButtonHEdgeMarginNew); | |
| 1006 | 991 |
| 1007 Profile* profile = browser_->profile(); | 992 Profile* profile = browser_->profile(); |
| 1008 std::string primary_account = | 993 std::string primary_account = |
| 1009 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); | 994 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
| 1010 DCHECK(!primary_account.empty()); | 995 DCHECK(!primary_account.empty()); |
| 1011 std::vector<std::string>accounts = | 996 std::vector<std::string>accounts = |
| 1012 profiles::GetSecondaryAccountsForProfile(profile, primary_account); | 997 profiles::GetSecondaryAccountsForProfile(profile, primary_account); |
| 1013 | 998 |
| 1014 // The primary account should always be listed first. | 999 // The primary account should always be listed first. |
| 1015 // TODO(rogerta): we still need to further differentiate the primary account | 1000 // TODO(rogerta): we still need to further differentiate the primary account |
| 1016 // from the others in the UI, so more work is likely required here: | 1001 // from the others in the UI, so more work is likely required here: |
| 1017 // crbug.com/311124. | 1002 // crbug.com/311124. |
| 1018 CreateAccountButton(layout, primary_account, true, column_width); | 1003 CreateAccountButton(layout, primary_account, true, kFixedMenuWidth); |
| 1019 for (size_t i = 0; i < accounts.size(); ++i) | 1004 for (size_t i = 0; i < accounts.size(); ++i) |
| 1020 CreateAccountButton(layout, accounts[i], false, column_width); | 1005 CreateAccountButton(layout, accounts[i], false, kFixedMenuWidth); |
| 1021 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 1006 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1022 | 1007 |
| 1023 add_account_button_ = new views::BlueButton( | 1008 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( |
| 1024 this, | 1009 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); |
| 1025 l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, | 1010 add_account_link_->SetBorder(views::Border::CreateEmptyBorder( |
| 1026 avatar_item.name)); | 1011 0, views::kButtonVEdgeMarginNew, |
| 1012 views::kRelatedControlVerticalSpacing, 0)); |
| 1027 layout->StartRow(1, 0); | 1013 layout->StartRow(1, 0); |
| 1028 layout->AddView(add_account_button_); | 1014 layout->AddView(add_account_link_); |
| 1029 return view; | 1015 return view; |
| 1030 } | 1016 } |
| 1031 | 1017 |
| 1032 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, | 1018 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, |
| 1033 const std::string& account, | 1019 const std::string& account, |
| 1034 bool is_primary_account, | 1020 bool is_primary_account, |
| 1035 int width) { | 1021 int width) { |
| 1036 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1022 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 1037 const gfx::ImageSkia* menu_marker = | 1023 const gfx::ImageSkia* menu_marker = |
| 1038 rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia(); | 1024 rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia(); |
| 1039 // Use a MenuButtonListener and not a regular ButtonListener to be | 1025 |
| 1040 // able to distinguish between the unnamed "other profile" buttons and the | 1026 views::LabelButton* email_button = new BackgroundColorHoverButton( |
| 1041 // unnamed "multiple accounts" buttons. | 1027 this, |
| 1042 views::MenuButton* email_button = new views::MenuButton( | |
| 1043 NULL, | |
| 1044 gfx::ElideEmail(base::UTF8ToUTF16(account), | 1028 gfx::ElideEmail(base::UTF8ToUTF16(account), |
| 1045 rb->GetFontList(ui::ResourceBundle::BaseFont), | 1029 rb->GetFontList(ui::ResourceBundle::BaseFont), |
| 1046 width - menu_marker->width()), | 1030 width - menu_marker->width()), |
| 1047 this, | 1031 gfx::ImageSkia(), |
| 1048 true /* show_menu_marker */); | 1032 gfx::ImageSkia()); |
| 1049 email_button->SetBorder(views::Border::CreateEmptyBorder(0, 0, 0, 0)); | |
| 1050 email_button->set_menu_marker(menu_marker); | |
| 1051 if (!is_primary_account) | |
| 1052 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 1053 layout->StartRow(1, 0); | 1033 layout->StartRow(1, 0); |
| 1054 layout->AddView(email_button); | 1034 layout->AddView(email_button); |
| 1055 | 1035 |
| 1056 // Save the original email address, as the button text could be elided. | 1036 // Save the original email address, as the button text could be elided. |
| 1057 current_profile_accounts_map_[email_button] = account; | 1037 current_profile_accounts_map_[email_button] = account; |
| 1058 } | 1038 } |
| 1059 | 1039 |
| 1060 views::View* ProfileChooserView::CreateGaiaSigninView( | 1040 views::View* ProfileChooserView::CreateGaiaSigninView( |
| 1061 bool add_secondary_account) { | 1041 bool add_secondary_account) { |
| 1062 views::View* view = new views::View(); | 1042 views::View* view = new views::View(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 | 1148 |
| 1169 views::View* ProfileChooserView::CreateNewProfileManagementPreviewView() { | 1149 views::View* ProfileChooserView::CreateNewProfileManagementPreviewView() { |
| 1170 return CreateTutorialView( | 1150 return CreateTutorialView( |
| 1171 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_TITLE), | 1151 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_TITLE), |
| 1172 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_CONTENT_TEXT), | 1152 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_CONTENT_TEXT), |
| 1173 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), | 1153 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), |
| 1174 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_TRY_BUTTON), | 1154 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_TRY_BUTTON), |
| 1175 &tutorial_learn_more_link_, | 1155 &tutorial_learn_more_link_, |
| 1176 &tutorial_enable_new_profile_management_button_); | 1156 &tutorial_enable_new_profile_management_button_); |
| 1177 } | 1157 } |
| OLD | NEW |