Chromium Code Reviews| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 // Helpers -------------------------------------------------------------------- | 84 // Helpers -------------------------------------------------------------------- |
| 85 | 85 |
| 86 const int kButtonHeight = 32; | 86 const int kButtonHeight = 32; |
| 87 const int kPasswordCombinedFixedGaiaViewWidth = 360; | 87 const int kPasswordCombinedFixedGaiaViewWidth = 360; |
| 88 const int kFixedGaiaViewWidth = 448; | 88 const int kFixedGaiaViewWidth = 448; |
| 89 const int kFixedAccountRemovalViewWidth = 280; | 89 const int kFixedAccountRemovalViewWidth = 280; |
| 90 const int kFixedSwitchUserViewWidth = 320; | 90 const int kFixedSwitchUserViewWidth = 320; |
| 91 const int kLargeImageSide = 88; | 91 const int kLargeImageSide = 88; |
| 92 const int kMediumImageSide = 40; | 92 const int kMediumImageSide = 40; |
| 93 | 93 |
| 94 const int kTextfieldLabelHorizontalSpacing = 4; | 94 const int kProfileBarHeight = 56; |
| 95 const int kProfileHorizontalSpacing = 16; | 95 const int kProfileHorizontalSpacing = 16; |
| 96 const int kVerticalSpacing = 16; | 96 const int kVerticalSpacing = 16; |
| 97 | 97 |
| 98 const int kTitleViewNativeWidgetOffset = 8; | 98 const int kTitleViewNativeWidgetOffset = 8; |
| 99 | 99 |
| 100 bool IsProfileChooser(profiles::BubbleViewMode mode) { | 100 bool IsProfileChooser(profiles::BubbleViewMode mode) { |
| 101 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || | 101 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || |
| 102 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 102 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 103 } | 103 } |
| 104 | 104 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 SetImageLabelSpacing(views::kItemLabelSpacing); | 175 SetImageLabelSpacing(views::kItemLabelSpacing); |
| 176 SetBorder(views::Border::CreateEmptyBorder( | 176 SetBorder(views::Border::CreateEmptyBorder( |
| 177 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); | 177 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); |
| 178 SetMinSize(gfx::Size(0, | 178 SetMinSize(gfx::Size(0, |
| 179 kButtonHeight + views::kRelatedControlVerticalSpacing)); | 179 kButtonHeight + views::kRelatedControlVerticalSpacing)); |
| 180 SetImage(STATE_NORMAL, icon); | 180 SetImage(STATE_NORMAL, icon); |
| 181 SetFocusForPlatform(); | 181 SetFocusForPlatform(); |
| 182 set_request_focus_on_press(true); | 182 set_request_focus_on_press(true); |
| 183 } | 183 } |
| 184 | 184 |
| 185 explicit BackgroundColorHoverButton(views::ButtonListener* listener) | |
| 186 : views::LabelButton(listener, base::string16()) { | |
| 187 SetMinSize(gfx::Size(0, kProfileBarHeight)); | |
| 188 SetFocusForPlatform(); | |
| 189 set_request_focus_on_press(true); | |
| 190 } | |
| 191 | |
| 185 ~BackgroundColorHoverButton() override {} | 192 ~BackgroundColorHoverButton() override {} |
| 186 | 193 |
| 187 private: | 194 private: |
| 188 // views::LabelButton: | 195 // views::LabelButton: |
| 189 void OnPaint(gfx::Canvas* canvas) override { | 196 void OnPaint(gfx::Canvas* canvas) override { |
| 190 if ((state() == STATE_PRESSED) || | 197 if ((state() == STATE_PRESSED) || |
| 191 (state() == STATE_HOVERED)) { | 198 (state() == STATE_HOVERED)) { |
| 192 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 199 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
| 193 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor)); | 200 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor)); |
| 194 } | 201 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 // EditableProfilePhoto ------------------------------------------------- | 311 // EditableProfilePhoto ------------------------------------------------- |
| 305 | 312 |
| 306 // A custom Image control that shows a "change" button when moused over. | 313 // A custom Image control that shows a "change" button when moused over. |
| 307 class EditableProfilePhoto : public views::LabelButton { | 314 class EditableProfilePhoto : public views::LabelButton { |
| 308 public: | 315 public: |
| 309 EditableProfilePhoto(views::ButtonListener* listener, | 316 EditableProfilePhoto(views::ButtonListener* listener, |
| 310 const gfx::Image& icon, | 317 const gfx::Image& icon, |
| 311 bool is_editing_allowed, | 318 bool is_editing_allowed, |
| 312 const gfx::Rect& bounds) | 319 const gfx::Rect& bounds) |
| 313 : views::LabelButton(listener, base::string16()), | 320 : views::LabelButton(listener, base::string16()), |
| 321 interactive_(true), | |
| 314 photo_overlay_(NULL) { | 322 photo_overlay_(NULL) { |
| 315 const int icon_image_side = switches::IsMaterialDesignUserMenu() | 323 const int icon_image_side = switches::IsMaterialDesignUserMenu() |
| 316 ? kMediumImageSide : kLargeImageSide; | 324 ? kMediumImageSide : kLargeImageSide; |
| 317 gfx::Image image = profiles::GetSizedAvatarIcon( | 325 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 318 icon, true, icon_image_side, icon_image_side); | 326 icon, true, icon_image_side, icon_image_side); |
| 319 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); | 327 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); |
| 320 SetBorder(views::Border::NullBorder()); | 328 SetBorder(views::Border::NullBorder()); |
| 321 SetBoundsRect(bounds); | 329 SetBoundsRect(bounds); |
| 322 | 330 |
| 323 // Calculate the circular mask that will be used to display the photo. | 331 // Calculate the circular mask that will be used to display the photo. |
| 324 circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2), | 332 circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2), |
| 325 SkIntToScalar(bounds.height() / 2), | 333 SkIntToScalar(bounds.height() / 2), |
| 326 SkIntToScalar(bounds.width() / 2)); | 334 SkIntToScalar(bounds.width() / 2)); |
| 327 | 335 |
| 328 if (!is_editing_allowed) { | 336 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) { |
| 329 SetEnabled(false); | 337 SetEnabled(false); |
| 330 return; | 338 return; |
| 331 } | 339 } |
| 332 | 340 |
| 333 set_notify_enter_exit_on_child(true); | 341 set_notify_enter_exit_on_child(true); |
| 334 | 342 |
| 335 // Photo overlay that appears when hovering over the button. | 343 // Photo overlay that appears when hovering over the button. |
| 336 photo_overlay_ = new views::ImageView(); | 344 photo_overlay_ = new views::ImageView(); |
| 337 | 345 |
| 338 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); | 346 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); |
| 339 photo_overlay_->set_background( | 347 photo_overlay_->set_background( |
| 340 views::Background::CreateSolidBackground(kBackgroundColor)); | 348 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 341 photo_overlay_->SetImage(gfx::CreateVectorIcon( | 349 photo_overlay_->SetImage(gfx::CreateVectorIcon( |
| 342 gfx::VectorIconId::PHOTO_CAMERA, | 350 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); |
| 343 switches::IsMaterialDesignUserMenu() ? 22u : 48u, | |
| 344 SkColorSetRGB(0x33, 0x33, 0x33))); | |
| 345 | 351 |
| 346 photo_overlay_->SetSize(bounds.size()); | 352 photo_overlay_->SetSize(bounds.size()); |
| 347 photo_overlay_->SetVisible(false); | 353 photo_overlay_->SetVisible(false); |
| 348 AddChildView(photo_overlay_); | 354 AddChildView(photo_overlay_); |
| 349 } | 355 } |
| 350 | 356 |
| 351 void OnPaint(gfx::Canvas* canvas) override { | 357 void OnPaint(gfx::Canvas* canvas) override { |
| 352 // Display the profile picture as a circle. | 358 // Display the profile picture as a circle. |
| 353 canvas->ClipPath(circular_mask_, true); | 359 canvas->ClipPath(circular_mask_, true); |
| 354 views::LabelButton::OnPaint(canvas); | 360 views::LabelButton::OnPaint(canvas); |
| 355 } | 361 } |
| 356 | 362 |
| 357 void PaintChildren(const ui::PaintContext& context) override { | 363 void PaintChildren(const ui::PaintContext& context) override { |
| 358 // Display any children (the "change photo" overlay) as a circle. | 364 // Display any children (the "change photo" overlay) as a circle. |
| 359 ui::ClipRecorder clip_recorder(context); | 365 ui::ClipRecorder clip_recorder(context); |
| 360 clip_recorder.ClipPathWithAntiAliasing(circular_mask_); | 366 clip_recorder.ClipPathWithAntiAliasing(circular_mask_); |
| 361 View::PaintChildren(context); | 367 View::PaintChildren(context); |
| 362 } | 368 } |
| 363 | 369 |
| 370 bool CanProcessEventsWithinSubtree() const override { return interactive_; } | |
| 371 | |
| 372 void set_interactive(bool interactive) { interactive_ = interactive; } | |
| 373 | |
| 364 private: | 374 private: |
| 365 // views::CustomButton: | 375 // views::CustomButton: |
| 366 void StateChanged() override { | 376 void StateChanged() override { |
| 367 bool show_overlay = | 377 bool show_overlay = |
| 368 (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); | 378 (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); |
| 369 if (photo_overlay_) | 379 if (photo_overlay_) |
| 370 photo_overlay_->SetVisible(show_overlay); | 380 photo_overlay_->SetVisible(show_overlay); |
| 371 } | 381 } |
| 372 | 382 |
| 373 void OnFocus() override { | 383 void OnFocus() override { |
| 374 views::LabelButton::OnFocus(); | 384 views::LabelButton::OnFocus(); |
| 375 if (photo_overlay_) | 385 if (photo_overlay_) |
| 376 photo_overlay_->SetVisible(true); | 386 photo_overlay_->SetVisible(true); |
| 377 } | 387 } |
| 378 | 388 |
| 379 void OnBlur() override { | 389 void OnBlur() override { |
| 380 views::LabelButton::OnBlur(); | 390 views::LabelButton::OnBlur(); |
| 381 // Don't hide the overlay if it's being shown as a result of a mouseover. | 391 // Don't hide the overlay if it's being shown as a result of a mouseover. |
| 382 if (photo_overlay_ && state() != STATE_HOVERED) | 392 if (photo_overlay_ && state() != STATE_HOVERED) |
| 383 photo_overlay_->SetVisible(false); | 393 photo_overlay_->SetVisible(false); |
| 384 } | 394 } |
| 385 | 395 |
| 396 bool interactive_; | |
| 386 gfx::Path circular_mask_; | 397 gfx::Path circular_mask_; |
| 387 | 398 |
| 388 // Image that is shown when hovering over the image button. Can be NULL if | 399 // Image that is shown when hovering over the image button. Can be NULL if |
| 389 // the photo isn't allowed to be edited (e.g. for guest profiles). | 400 // the photo isn't allowed to be edited (e.g. for guest profiles). |
| 390 views::ImageView* photo_overlay_; | 401 views::ImageView* photo_overlay_; |
| 391 | 402 |
| 392 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); | 403 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); |
| 393 }; | 404 }; |
| 394 | 405 |
| 395 // EditableProfileName ------------------------------------------------- | 406 // EditableProfileName ------------------------------------------------- |
| 396 | 407 |
| 397 // A custom text control that turns into a textfield for editing when clicked. | 408 // A custom text control that turns into a textfield for editing when clicked. |
| 409 // For non-material-design user menu only. | |
| 398 class EditableProfileName : public views::View, | 410 class EditableProfileName : public views::View, |
| 399 public views::ButtonListener { | 411 public views::ButtonListener { |
| 400 public: | 412 public: |
| 401 EditableProfileName(views::TextfieldController* controller, | 413 EditableProfileName(views::TextfieldController* controller, |
| 402 const base::string16& text, | 414 const base::string16& text, |
| 403 bool is_editing_allowed) | 415 bool is_editing_allowed) |
| 404 : button_(nullptr), label_(nullptr), profile_name_textfield_(nullptr) { | 416 : button_(nullptr), label_(nullptr), profile_name_textfield_(nullptr) { |
| 405 SetLayoutManager( | 417 SetLayoutManager( |
| 406 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 418 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 407 | 419 |
| 408 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 420 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 409 const gfx::FontList& medium_font_list = | 421 const gfx::FontList& medium_font_list = |
| 410 rb->GetFontList(ui::ResourceBundle::MediumFont); | 422 rb->GetFontList(ui::ResourceBundle::MediumFont); |
| 411 | 423 |
| 412 if (!is_editing_allowed) { | 424 if (!is_editing_allowed) { |
| 413 label_ = new views::Label(text); | 425 label_ = new views::Label(text); |
| 414 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); | 426 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); |
| 415 label_->SetFontList(medium_font_list); | 427 label_->SetFontList(medium_font_list); |
| 416 if (switches::IsMaterialDesignUserMenu()) | |
| 417 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 418 AddChildView(label_); | 428 AddChildView(label_); |
| 419 return; | 429 return; |
| 420 } | 430 } |
| 421 | 431 |
| 422 button_ = new RightAlignedIconLabelButton(this, text); | 432 button_ = new RightAlignedIconLabelButton(this, text); |
| 423 button_->SetFontList(medium_font_list); | 433 button_->SetFontList(medium_font_list); |
| 424 // Show an "edit" pencil icon when hovering over. In the default state, | 434 // Show an "edit" pencil icon when hovering over. In the default state, |
| 425 // we need to create an empty placeholder of the correct size, so that | 435 // we need to create an empty placeholder of the correct size, so that |
| 426 // the text doesn't jump around when the hovered icon appears. | 436 // the text doesn't jump around when the hovered icon appears. |
| 427 // TODO(estade): revisit colors and press effect. | 437 // TODO(estade): revisit colors and press effect. |
| 428 const int kIconSize = 16; | 438 const int kIconSize = 16; |
| 429 button_->SetImage(views::LabelButton::STATE_NORMAL, | 439 button_->SetImage(views::LabelButton::STATE_NORMAL, |
| 430 CreateSquarePlaceholderImage(kIconSize)); | 440 CreateSquarePlaceholderImage(kIconSize)); |
| 431 button_->SetImage(views::LabelButton::STATE_HOVERED, | 441 button_->SetImage(views::LabelButton::STATE_HOVERED, |
| 432 gfx::CreateVectorIcon( | 442 gfx::CreateVectorIcon( |
| 433 gfx::VectorIconId::MODE_EDIT, kIconSize, | 443 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 434 SkColorSetRGB(0x33, 0x33, 0x33))); | 444 SkColorSetRGB(0x33, 0x33, 0x33))); |
| 435 button_->SetImage(views::LabelButton::STATE_PRESSED, | 445 button_->SetImage(views::LabelButton::STATE_PRESSED, |
| 436 gfx::CreateVectorIcon( | 446 gfx::CreateVectorIcon( |
| 437 gfx::VectorIconId::MODE_EDIT, kIconSize, | 447 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 438 SkColorSetRGB(0x20, 0x20, 0x20))); | 448 SkColorSetRGB(0x20, 0x20, 0x20))); |
| 439 // We need to add a left padding as well as a small top/bottom padding | 449 // We need to add a left padding as well as a small top/bottom padding |
| 440 // to the text to account for the textfield's border. | 450 // to the text to account for the textfield's border. |
| 441 if (switches::IsMaterialDesignUserMenu()) { | 451 const int kIconTextLabelButtonSpacing = 5; |
| 442 button_->SetBorder(views::Border::CreateEmptyBorder( | 452 button_->SetBorder(views::Border::CreateEmptyBorder( |
| 443 2, kTextfieldLabelHorizontalSpacing, 2, 0)); | 453 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); |
| 444 } else { | |
| 445 const int kIconTextLabelButtonSpacing = 5; | |
| 446 button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 447 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); | |
| 448 } | |
| 449 AddChildView(button_); | 454 AddChildView(button_); |
| 450 | 455 |
| 451 profile_name_textfield_ = new views::Textfield(); | 456 profile_name_textfield_ = new views::Textfield(); |
| 452 // Textfield that overlaps the button. | 457 // Textfield that overlaps the button. |
| 453 profile_name_textfield_->set_controller(controller); | 458 profile_name_textfield_->set_controller(controller); |
| 454 profile_name_textfield_->SetFontList(medium_font_list); | 459 profile_name_textfield_->SetFontList(medium_font_list); |
| 455 profile_name_textfield_->SetHorizontalAlignment( | 460 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 456 switches::IsMaterialDesignUserMenu() | |
| 457 ? gfx::ALIGN_LEFT : gfx::ALIGN_CENTER); | |
| 458 profile_name_textfield_->SetVisible(false); | 461 profile_name_textfield_->SetVisible(false); |
| 459 AddChildView(profile_name_textfield_); | 462 AddChildView(profile_name_textfield_); |
| 460 } | 463 } |
| 461 | 464 |
| 462 views::Textfield* profile_name_textfield() { | 465 views::Textfield* profile_name_textfield() { |
| 463 return profile_name_textfield_; | 466 return profile_name_textfield_; |
| 464 } | 467 } |
| 465 | 468 |
| 466 // Hide the editable textfield to show the profile name button instead. | 469 // Hide the editable textfield to show the profile name button instead. |
| 467 void ShowReadOnlyView() { | 470 void ShowReadOnlyView() { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 oauth2_token_service->RemoveObserver(this); | 720 oauth2_token_service->RemoveObserver(this); |
| 718 } | 721 } |
| 719 | 722 |
| 720 void ProfileChooserView::ResetView() { | 723 void ProfileChooserView::ResetView() { |
| 721 open_other_profile_indexes_map_.clear(); | 724 open_other_profile_indexes_map_.clear(); |
| 722 delete_account_button_map_.clear(); | 725 delete_account_button_map_.clear(); |
| 723 reauth_account_button_map_.clear(); | 726 reauth_account_button_map_.clear(); |
| 724 manage_accounts_link_ = NULL; | 727 manage_accounts_link_ = NULL; |
| 725 signin_current_profile_link_ = NULL; | 728 signin_current_profile_link_ = NULL; |
| 726 auth_error_email_button_ = NULL; | 729 auth_error_email_button_ = NULL; |
| 730 current_profile_card_ = NULL; | |
| 727 current_profile_photo_ = NULL; | 731 current_profile_photo_ = NULL; |
| 728 current_profile_name_ = NULL; | 732 current_profile_name_ = NULL; |
| 729 users_button_ = NULL; | 733 users_button_ = NULL; |
| 730 go_incognito_button_ = NULL; | 734 go_incognito_button_ = NULL; |
| 731 lock_button_ = NULL; | 735 lock_button_ = NULL; |
| 732 add_account_link_ = NULL; | 736 add_account_link_ = NULL; |
| 733 gaia_signin_cancel_button_ = NULL; | 737 gaia_signin_cancel_button_ = NULL; |
| 734 remove_account_button_ = NULL; | 738 remove_account_button_ = NULL; |
| 735 account_removal_cancel_button_ = NULL; | 739 account_removal_cancel_button_ = NULL; |
| 736 add_person_button_ = NULL; | 740 add_person_button_ = NULL; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 } else if (sender == gaia_signin_cancel_button_) { | 977 } else if (sender == gaia_signin_cancel_button_) { |
| 974 // The account management view is only available with the | 978 // The account management view is only available with the |
| 975 // --enable-account-consistency flag. | 979 // --enable-account-consistency flag. |
| 976 bool account_management_available = | 980 bool account_management_available = |
| 977 SigninManagerFactory::GetForProfile(browser_->profile())-> | 981 SigninManagerFactory::GetForProfile(browser_->profile())-> |
| 978 IsAuthenticated() && | 982 IsAuthenticated() && |
| 979 switches::IsEnableAccountConsistency(); | 983 switches::IsEnableAccountConsistency(); |
| 980 ShowViewFromMode(account_management_available ? | 984 ShowViewFromMode(account_management_available ? |
| 981 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : | 985 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : |
| 982 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); | 986 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); |
| 983 } else if (sender == current_profile_photo_) { | 987 } else if (sender == current_profile_photo_ || |
| 988 sender == current_profile_card_) { | |
| 984 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); | 989 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
| 985 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); | 990 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); |
| 986 } else if (sender == signin_current_profile_link_) { | 991 } else if (sender == signin_current_profile_link_) { |
| 987 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); | 992 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); |
| 988 } else if (sender == add_person_button_) { | 993 } else if (sender == add_person_button_) { |
| 989 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 994 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
| 990 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); | 995 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); |
| 991 UserManager::Show(base::FilePath(), | 996 UserManager::Show(base::FilePath(), |
| 992 profiles::USER_MANAGER_NO_TUTORIAL, | 997 profiles::USER_MANAGER_NO_TUTORIAL, |
| 993 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 998 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1480 } | 1485 } |
| 1481 } | 1486 } |
| 1482 | 1487 |
| 1483 return view; | 1488 return view; |
| 1484 } | 1489 } |
| 1485 | 1490 |
| 1486 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( | 1491 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( |
| 1487 const AvatarMenu::Item& avatar_item, | 1492 const AvatarMenu::Item& avatar_item, |
| 1488 bool is_guest) { | 1493 bool is_guest) { |
| 1489 views::View* view = new views::View(); | 1494 views::View* view = new views::View(); |
| 1490 int column_width = GetFixedMenuWidth() - 2 * views::kMaterialHorizontalMargin; | 1495 const int content_width = |
|
Roger Tawa OOO till Jul 10th
2016/06/09 14:21:06
|content_width| seems to be used only at line 1582
| |
| 1491 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); | 1496 GetFixedMenuWidth() - 2 * views::kMaterialHorizontalMargin; |
| 1492 layout->SetInsets(views::kRelatedControlVerticalSpacing, | 1497 views::GridLayout* layout = |
| 1493 views::kMaterialHorizontalMargin, | 1498 CreateSingleColumnLayout(view, GetFixedMenuWidth()); |
| 1494 views::kRelatedControlVerticalSpacing, | 1499 layout->SetInsets(views::kRelatedControlVerticalSpacing, 0, |
| 1495 views::kMaterialHorizontalMargin); | 1500 views::kRelatedControlVerticalSpacing, 0); |
| 1501 current_profile_card_ = new BackgroundColorHoverButton(this); | |
| 1496 | 1502 |
| 1497 // Profile picture, left-aligned. | 1503 // Profile picture, left-aligned. |
| 1498 const int profile_bar_height = 56; | 1504 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( |
| 1499 current_profile_photo_ = new EditableProfilePhoto( | |
| 1500 this, avatar_item.icon, !is_guest, | 1505 this, avatar_item.icon, !is_guest, |
| 1501 gfx::Rect(0, (profile_bar_height - kMediumImageSide) / 2, | 1506 gfx::Rect(0, (kProfileBarHeight - kMediumImageSide) / 2, |
| 1502 kMediumImageSide, kMediumImageSide)); | 1507 kMediumImageSide, kMediumImageSide)); |
| 1503 SizedContainer* profile_container = | 1508 current_profile_photo->SetX(views::kMaterialHorizontalMargin); |
| 1504 new SizedContainer(gfx::Size(column_width, profile_bar_height)); | 1509 gfx::Rect photo_bounds = current_profile_photo->bounds(); |
| 1505 profile_container->AddChildView(current_profile_photo_); | 1510 current_profile_card_->AddChildView(current_profile_photo); |
| 1511 current_profile_photo->set_interactive(false); | |
| 1506 | 1512 |
| 1507 // Add supervised badge for supervised profile. | 1513 // Add supervised badge for supervised profile. |
| 1508 if (browser_->profile()->IsSupervised()) { | 1514 if (browser_->profile()->IsSupervised()) { |
| 1509 const int badge_spacing = 4; | 1515 const int badge_spacing = 4; |
| 1510 views::ImageView* supervised_icon = new views::ImageView(); | 1516 views::ImageView* supervised_icon = new views::ImageView(); |
| 1511 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile())); | 1517 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile())); |
| 1512 gfx::Size preferred_size = supervised_icon->GetPreferredSize(); | 1518 gfx::Size preferred_size = supervised_icon->GetPreferredSize(); |
| 1513 gfx::Rect parent_bounds = current_profile_photo_->bounds(); | |
| 1514 supervised_icon->SetBounds( | 1519 supervised_icon->SetBounds( |
| 1515 parent_bounds.right() - preferred_size.width() + badge_spacing, | 1520 photo_bounds.right() - preferred_size.width() + badge_spacing, |
| 1516 parent_bounds.bottom() - preferred_size.height() + badge_spacing, | 1521 photo_bounds.bottom() - preferred_size.height() + badge_spacing, |
| 1517 preferred_size.width(), | 1522 preferred_size.width(), |
| 1518 preferred_size.height()); | 1523 preferred_size.height()); |
| 1519 profile_container->AddChildView(supervised_icon); | 1524 current_profile_card_->AddChildView(supervised_icon); |
| 1525 supervised_icon->set_interactive(false); | |
| 1520 } | 1526 } |
| 1521 | 1527 |
| 1522 // Profile name, left-aligned to the right of profile icon. | 1528 // Profile name, left-aligned to the right of profile icon. |
| 1523 bool editing_allowed = !is_guest && | 1529 views::Label* current_profile_name = new views::Label( |
| 1524 !browser_->profile()->IsLegacySupervised(); | 1530 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); |
| 1525 current_profile_name_ = new EditableProfileName( | 1531 current_profile_name->SetFontList( |
| 1526 this, | 1532 (&ui::ResourceBundle::GetSharedInstance()) |
| 1527 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()), | 1533 ->GetFontList(ui::ResourceBundle::MediumFont)); |
| 1528 editing_allowed); | 1534 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1529 gfx::Rect photo_bounds = current_profile_photo_->bounds(); | 1535 current_profile_name->SetBounds( |
| 1530 const int textfield_left_margin = | 1536 photo_bounds.right() + kProfileHorizontalSpacing, |
| 1531 kProfileHorizontalSpacing - | |
| 1532 (editing_allowed ? kTextfieldLabelHorizontalSpacing : 0); | |
| 1533 current_profile_name_->SetBounds( | |
| 1534 photo_bounds.width() + textfield_left_margin, | |
| 1535 views::kRelatedControlVerticalSpacing, | 1537 views::kRelatedControlVerticalSpacing, |
| 1536 profile_container->GetPreferredSize().width() - photo_bounds.width() | 1538 GetFixedMenuWidth() - photo_bounds.right() - kProfileHorizontalSpacing - |
| 1537 - textfield_left_margin, | 1539 views::kMaterialHorizontalMargin, |
| 1538 profile_container->GetPreferredSize().height() / 2 | 1540 kProfileBarHeight / 2 - views::kRelatedControlVerticalSpacing); |
| 1539 - views::kRelatedControlVerticalSpacing); | 1541 current_profile_card_->AddChildView(current_profile_name); |
| 1540 profile_container->AddChildView(current_profile_name_); | |
| 1541 | 1542 |
| 1542 // Center-align the avatar name if the profile is not signed in. | 1543 if (avatar_item.signed_in && !switches::IsEnableAccountConsistency()) { |
| 1543 if (is_guest || !avatar_item.signed_in) { | 1544 views::Label* email_label = new views::Label(avatar_item.username); |
| 1544 current_profile_name_->SetY( | 1545 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); |
| 1545 (profile_container->GetPreferredSize().height() | 1546 email_label->SetEnabled(false); |
| 1546 - current_profile_name_->height()) / 2); | 1547 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1548 email_label->SetBounds( | |
| 1549 photo_bounds.right() + kProfileHorizontalSpacing, | |
| 1550 kProfileBarHeight / 2, | |
| 1551 GetFixedMenuWidth() - photo_bounds.right() - kProfileHorizontalSpacing - | |
| 1552 views::kMaterialHorizontalMargin, | |
| 1553 kProfileBarHeight / 2 - views::kRelatedControlVerticalSpacing); | |
| 1554 current_profile_card_->AddChildView(email_label); | |
| 1547 layout->StartRow(1, 0); | 1555 layout->StartRow(1, 0); |
| 1548 layout->AddView(profile_container); | 1556 layout->AddView(current_profile_card_); |
| 1557 return view; | |
| 1558 } else { | |
| 1559 // Center-align the avatar name and add to the view. | |
| 1560 current_profile_name->SetY( | |
| 1561 (kProfileBarHeight - current_profile_name->height()) / 2); | |
| 1562 layout->StartRow(1, 0); | |
| 1563 layout->AddView(current_profile_card_); | |
| 1549 } | 1564 } |
| 1550 | 1565 |
| 1551 if (is_guest) | 1566 if (is_guest) { |
| 1567 current_profile_card_->SetEnabled(false); | |
| 1552 return view; | 1568 return view; |
| 1569 } | |
| 1553 | 1570 |
| 1554 // The available links depend on the type of profile that is active. | 1571 if (!avatar_item.signed_in) { |
| 1555 if (avatar_item.signed_in) { | |
| 1556 // Calculate the position and size for links available for signed-in | |
| 1557 // profiles. | |
| 1558 const int x_coordinate = photo_bounds.width() + kProfileHorizontalSpacing; | |
| 1559 const int y_coordinate = profile_container->GetPreferredSize().height() / 2; | |
| 1560 const int width = profile_container->GetPreferredSize().width() | |
| 1561 - photo_bounds.width() - kProfileHorizontalSpacing; | |
| 1562 const int height = profile_container->GetPreferredSize().height() / 2 | |
| 1563 - views::kRelatedControlVerticalSpacing; | |
| 1564 layout->StartRow(1, 0); | |
| 1565 | |
| 1566 if (switches::IsEnableAccountConsistency()) { | |
| 1567 base::string16 link_title = l10n_util::GetStringUTF16( | |
| 1568 IsProfileChooser(view_mode_) ? | |
| 1569 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : | |
| 1570 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | |
| 1571 manage_accounts_link_ = CreateLink(link_title, this); | |
| 1572 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1573 manage_accounts_link_->SetBounds( | |
| 1574 x_coordinate, y_coordinate, width, height); | |
| 1575 profile_container->AddChildView(manage_accounts_link_); | |
| 1576 } else { | |
| 1577 // Badge the email address if there's an authentication error. | |
| 1578 if (HasAuthError(browser_->profile())) { | |
| 1579 auth_error_email_button_ = | |
| 1580 new RightAlignedIconLabelButton(this, avatar_item.username); | |
| 1581 auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL); | |
| 1582 auth_error_email_button_->SetImage( | |
| 1583 views::LabelButton::STATE_NORMAL, | |
| 1584 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 12, | |
| 1585 gfx::kChromeIconGrey)); | |
| 1586 auth_error_email_button_->SetFocusForPlatform(); | |
| 1587 auth_error_email_button_->set_request_focus_on_press(true); | |
| 1588 gfx::Insets insets = | |
| 1589 views::LabelButtonAssetBorder::GetDefaultInsetsForStyle( | |
| 1590 views::Button::STYLE_TEXTBUTTON); | |
| 1591 auth_error_email_button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 1592 insets.top(), insets.left(), insets.bottom(), insets.right())); | |
| 1593 auth_error_email_button_->SetBounds( | |
| 1594 x_coordinate - insets.left(), y_coordinate, width, height); | |
| 1595 profile_container->AddChildView(auth_error_email_button_); | |
| 1596 } else { | |
| 1597 views::Label* email_label = new views::Label(avatar_item.username); | |
| 1598 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); | |
| 1599 email_label->SetEnabled(false); | |
| 1600 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1601 email_label->SetBounds(x_coordinate, y_coordinate, width, height); | |
| 1602 profile_container->AddChildView(email_label); | |
| 1603 } | |
| 1604 } | |
| 1605 layout->AddView(profile_container); | |
| 1606 } else { | |
| 1607 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( | 1572 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( |
| 1608 browser_->profile()->GetOriginalProfile()); | 1573 browser_->profile()->GetOriginalProfile()); |
| 1609 if (signin_manager->IsSigninAllowed()) { | 1574 if (!signin_manager->IsSigninAllowed()) |
| 1610 views::Label* promo = new views::Label( | 1575 return view; |
| 1611 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); | 1576 } |
| 1612 promo->SetMultiLine(true); | |
| 1613 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1614 layout->StartRowWithPadding(1, 0, 0, | |
| 1615 views::kRelatedControlVerticalSpacing); | |
| 1616 layout->StartRow(1, 0); | |
| 1617 layout->AddView(promo); | |
| 1618 | 1577 |
| 1619 signin_current_profile_link_ = new views::BlueButton( | 1578 // Add a layout with horizontal insets to accomodate the extra links under |
| 1579 // the active profile card. | |
| 1580 views::View* links_view = new views::View(); | |
| 1581 views::GridLayout* links_layout = | |
| 1582 CreateSingleColumnLayout(links_view, content_width); | |
| 1583 links_layout->SetInsets(0, views::kMaterialHorizontalMargin, | |
| 1584 0, views::kMaterialHorizontalMargin); | |
| 1585 | |
| 1586 if (avatar_item.signed_in) { | |
| 1587 // Implies that account consistency is turned on | |
| 1588 base::string16 link_title = l10n_util::GetStringUTF16( | |
| 1589 IsProfileChooser(view_mode_) ? | |
| 1590 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : | |
| 1591 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | |
| 1592 manage_accounts_link_ = CreateLink(link_title, this); | |
| 1593 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1594 links_layout->StartRowWithPadding(1, 0, 0, | |
| 1595 views::kRelatedControlVerticalSpacing); | |
| 1596 links_layout->StartRow(1, 0); | |
| 1597 links_layout->AddView(manage_accounts_link_); | |
| 1598 } else { | |
| 1599 // Implies that account is not signed in and signin is allowed | |
| 1600 views::Label* promo = new views::Label( | |
| 1601 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); | |
| 1602 promo->SetMultiLine(true); | |
| 1603 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1604 links_layout->StartRowWithPadding(1, 0, 0, | |
| 1605 views::kRelatedControlVerticalSpacing); | |
| 1606 links_layout->StartRow(1, 0); | |
| 1607 links_layout->AddView(promo); | |
| 1608 signin_current_profile_link_ = new views::BlueButton( | |
| 1620 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, | 1609 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 1621 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | 1610 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 1622 signin_current_profile_link_->SetMinSize(gfx::Size(0, 36)); | 1611 signin_current_profile_link_->SetMinSize(gfx::Size(0, 36)); |
| 1623 layout->StartRowWithPadding(1, 0, 0, | 1612 links_layout->StartRowWithPadding(1, 0, 0, |
| 1624 views::kRelatedControlVerticalSpacing); | 1613 views::kRelatedControlVerticalSpacing); |
| 1625 layout->StartRow(1, 0); | 1614 links_layout->StartRow(1, 0); |
| 1626 layout->AddView(signin_current_profile_link_); | 1615 links_layout->AddView(signin_current_profile_link_); |
| 1627 content::RecordAction( | 1616 content::RecordAction( |
| 1628 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | 1617 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| 1629 layout->StartRowWithPadding(1, 0, 0, | 1618 links_layout->StartRowWithPadding(1, 0, 0, |
| 1630 views::kLabelToControlVerticalSpacing); | 1619 views::kLabelToControlVerticalSpacing); |
| 1631 } | |
| 1632 } | 1620 } |
| 1621 layout->StartRow(1, 0); | |
| 1622 layout->AddView(links_view); | |
| 1633 | 1623 |
| 1634 return view; | 1624 return view; |
| 1635 } | 1625 } |
| 1636 | 1626 |
| 1637 views::View* ProfileChooserView::CreateGuestProfileView() { | 1627 views::View* ProfileChooserView::CreateGuestProfileView() { |
| 1638 gfx::Image guest_icon = | 1628 gfx::Image guest_icon = |
| 1639 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1629 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 1640 profiles::GetPlaceholderAvatarIconResourceID()); | 1630 profiles::GetPlaceholderAvatarIconResourceID()); |
| 1641 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); | 1631 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); |
| 1642 guest_avatar_item.active = true; | 1632 guest_avatar_item.active = true; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2091 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2081 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2092 IncognitoModePrefs::DISABLED; | 2082 IncognitoModePrefs::DISABLED; |
| 2093 return incognito_available && !browser_->profile()->IsGuestSession(); | 2083 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 2094 } | 2084 } |
| 2095 | 2085 |
| 2096 void ProfileChooserView::PostActionPerformed( | 2086 void ProfileChooserView::PostActionPerformed( |
| 2097 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2087 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 2098 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2088 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 2099 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2089 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 2100 } | 2090 } |
| OLD | NEW |