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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 back_button->set_request_focus_on_press(true); | 175 back_button->set_request_focus_on_press(true); |
176 return back_button; | 176 return back_button; |
177 } | 177 } |
178 | 178 |
179 // BackgroundColorHoverButton ------------------------------------------------- | 179 // BackgroundColorHoverButton ------------------------------------------------- |
180 | 180 |
181 // A custom button that allows for setting a background color when hovered over. | 181 // A custom button that allows for setting a background color when hovered over. |
182 class BackgroundColorHoverButton : public views::LabelButton { | 182 class BackgroundColorHoverButton : public views::LabelButton { |
183 public: | 183 public: |
184 BackgroundColorHoverButton(views::ButtonListener* listener, | 184 BackgroundColorHoverButton(views::ButtonListener* listener, |
| 185 const base::string16& text) |
| 186 : views::LabelButton(listener, text) { |
| 187 SetImageLabelSpacing(views::kItemLabelSpacing); |
| 188 const int button_margin = switches::IsMaterialDesignUserMenu() |
| 189 ? kMaterialMenuEdgeMargin |
| 190 : views::kButtonHEdgeMarginNew; |
| 191 SetBorder( |
| 192 views::Border::CreateEmptyBorder(0, button_margin, 0, button_margin)); |
| 193 SetFocusForPlatform(); |
| 194 set_request_focus_on_press(true); |
| 195 } |
| 196 |
| 197 BackgroundColorHoverButton(views::ButtonListener* listener, |
185 const base::string16& text, | 198 const base::string16& text, |
186 const gfx::ImageSkia& icon) | 199 const gfx::ImageSkia& icon) |
187 : views::LabelButton(listener, text) { | 200 : BackgroundColorHoverButton(listener, text) { |
188 SetImageLabelSpacing(views::kItemLabelSpacing); | 201 SetMinSize(gfx::Size( |
189 SetBorder(views::Border::CreateEmptyBorder( | 202 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing)); |
190 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); | |
191 SetMinSize(gfx::Size(0, | |
192 kButtonHeight + views::kRelatedControlVerticalSpacing)); | |
193 SetImage(STATE_NORMAL, icon); | 203 SetImage(STATE_NORMAL, icon); |
194 SetFocusForPlatform(); | |
195 set_request_focus_on_press(true); | |
196 } | 204 } |
197 | 205 |
198 ~BackgroundColorHoverButton() override {} | 206 ~BackgroundColorHoverButton() override {} |
199 | 207 |
200 private: | 208 private: |
201 // views::LabelButton: | 209 // views::LabelButton: |
202 void OnPaint(gfx::Canvas* canvas) override { | 210 void OnPaint(gfx::Canvas* canvas) override { |
203 if ((state() == STATE_PRESSED) || | 211 if ((state() == STATE_PRESSED) || |
204 (state() == STATE_HOVERED)) { | 212 (state() == STATE_HOVERED)) { |
205 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 213 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
(...skipping 12 matching lines...) Expand all Loading... |
218 public: | 226 public: |
219 explicit SizedContainer(const gfx::Size& preferred_size) | 227 explicit SizedContainer(const gfx::Size& preferred_size) |
220 : preferred_size_(preferred_size) {} | 228 : preferred_size_(preferred_size) {} |
221 | 229 |
222 gfx::Size GetPreferredSize() const override { return preferred_size_; } | 230 gfx::Size GetPreferredSize() const override { return preferred_size_; } |
223 | 231 |
224 private: | 232 private: |
225 gfx::Size preferred_size_; | 233 gfx::Size preferred_size_; |
226 }; | 234 }; |
227 | 235 |
| 236 // NonInteractiveContainer ------------------------------------------------- |
| 237 |
| 238 // A simple container view that does not process events within subtree. |
| 239 class NonInteractiveContainer : public views::View { |
| 240 public: |
| 241 NonInteractiveContainer() {} |
| 242 |
| 243 // views::CanProcessEventsWithinSubtree: |
| 244 bool CanProcessEventsWithinSubtree() const override { return false; } |
| 245 |
| 246 private: |
| 247 DISALLOW_COPY_AND_ASSIGN(NonInteractiveContainer); |
| 248 }; |
| 249 |
228 // A view to host the GAIA webview overlapped with a back button. This class | 250 // A view to host the GAIA webview overlapped with a back button. This class |
229 // is needed to reparent the back button inside a native view so that on | 251 // is needed to reparent the back button inside a native view so that on |
230 // windows, user input can be be properly routed to the button. | 252 // windows, user input can be be properly routed to the button. |
231 class HostView : public views::View { | 253 class HostView : public views::View { |
232 public: | 254 public: |
233 HostView() {} | 255 HostView() {} |
234 | 256 |
235 void Initialize(views::View* title_view, views::View* main_view); | 257 void Initialize(views::View* title_view, views::View* main_view); |
236 | 258 |
237 private: | 259 private: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 gfx::Rect bounds(title_view_->GetPreferredSize()); | 293 gfx::Rect bounds(title_view_->GetPreferredSize()); |
272 title_view_->SetBoundsRect(bounds); | 294 title_view_->SetBoundsRect(bounds); |
273 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); | 295 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); |
274 title_widget_->SetBounds(bounds); | 296 title_widget_->SetBounds(bounds); |
275 } | 297 } |
276 | 298 |
277 } // namespace | 299 } // namespace |
278 | 300 |
279 // RightAlignedIconLabelButton ------------------------------------------------- | 301 // RightAlignedIconLabelButton ------------------------------------------------- |
280 | 302 |
281 // A custom LabelButton that has a left-aligned text and right aligned icon. | 303 // A custom LabelButton that has a center-aligned text and right aligned icon. |
282 // For non-material-design user menu, it has centered text instead. | 304 // Only used in non-material-design user menu. |
283 class RightAlignedIconLabelButton : public views::LabelButton { | 305 class RightAlignedIconLabelButton : public views::LabelButton { |
284 public: | 306 public: |
285 RightAlignedIconLabelButton(views::ButtonListener* listener, | 307 RightAlignedIconLabelButton(views::ButtonListener* listener, |
286 const base::string16& text) | 308 const base::string16& text) |
287 : views::LabelButton(listener, text) { | 309 : views::LabelButton(listener, text) { |
288 SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 310 SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
289 label()->SetHorizontalAlignment(switches::IsMaterialDesignUserMenu() | 311 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
290 ? gfx::ALIGN_LEFT | |
291 : gfx::ALIGN_CENTER); | |
292 } | 312 } |
293 | 313 |
294 protected: | 314 protected: |
295 void Layout() override { | 315 void Layout() override { |
296 views::LabelButton::Layout(); | 316 views::LabelButton::Layout(); |
297 | 317 |
298 // Keep the text centered and the icon right-aligned by stretching the label | 318 // Keep the text centered and the icon right-aligned by stretching the label |
299 // to take up more of the content area and centering its contents. | 319 // to take up more of the content area and centering its contents. |
300 gfx::Rect content_bounds = GetContentsBounds(); | 320 gfx::Rect content_bounds = GetContentsBounds(); |
301 gfx::Rect label_bounds = label()->bounds(); | 321 gfx::Rect label_bounds = label()->bounds(); |
(...skipping 18 matching lines...) Expand all Loading... |
320 const size_t kProfileBadgeWhitePadding = 2; | 340 const size_t kProfileBadgeWhitePadding = 2; |
321 | 341 |
322 // A custom Image control that shows a "change" button when moused over. | 342 // A custom Image control that shows a "change" button when moused over. |
323 class EditableProfilePhoto : public views::LabelButton { | 343 class EditableProfilePhoto : public views::LabelButton { |
324 public: | 344 public: |
325 EditableProfilePhoto(views::ButtonListener* listener, | 345 EditableProfilePhoto(views::ButtonListener* listener, |
326 const gfx::Image& icon, | 346 const gfx::Image& icon, |
327 bool is_editing_allowed, | 347 bool is_editing_allowed, |
328 Profile* profile) | 348 Profile* profile) |
329 : views::LabelButton(listener, base::string16()), | 349 : views::LabelButton(listener, base::string16()), |
| 350 interactive_(!switches::IsMaterialDesignUserMenu()), |
330 photo_overlay_(nullptr), | 351 photo_overlay_(nullptr), |
331 profile_(profile) { | 352 profile_(profile) { |
332 gfx::Image image = profiles::GetSizedAvatarIcon( | 353 gfx::Image image = profiles::GetSizedAvatarIcon( |
333 icon, true, icon_image_side(), icon_image_side()); | 354 icon, true, icon_image_side(), icon_image_side()); |
334 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); | 355 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); |
335 SetBorder(views::Border::NullBorder()); | 356 SetBorder(views::Border::NullBorder()); |
336 if (switches::IsMaterialDesignUserMenu()) { | 357 if (switches::IsMaterialDesignUserMenu()) { |
337 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(), | 358 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(), |
338 GetPreferredSize().height() + badge_spacing() + | 359 GetPreferredSize().height() + badge_spacing() + |
339 views::kRelatedControlSmallVerticalSpacing)); | 360 views::kRelatedControlSmallVerticalSpacing)); |
340 } else { | 361 } else { |
341 SetSize(GetPreferredSize()); | 362 SetSize(GetPreferredSize()); |
342 } | 363 } |
343 | 364 |
344 // Calculate the circular mask that will be used to display the photo. | 365 // Calculate the circular mask that will be used to display the photo. |
345 circular_mask_.addCircle( | 366 circular_mask_.addCircle( |
346 SkIntToScalar(icon_image_side() / 2), | 367 SkIntToScalar(icon_image_side() / 2), |
347 SkIntToScalar(icon_image_side() / 2) + badge_spacing(), | 368 SkIntToScalar(icon_image_side() / 2) + badge_spacing(), |
348 SkIntToScalar(icon_image_side() / 2)); | 369 SkIntToScalar(icon_image_side() / 2)); |
349 | 370 |
350 if (!is_editing_allowed) { | 371 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) { |
351 SetEnabled(false); | 372 SetEnabled(false); |
352 return; | 373 return; |
353 } | 374 } |
354 | 375 |
355 set_notify_enter_exit_on_child(true); | 376 set_notify_enter_exit_on_child(true); |
356 | 377 |
357 // Photo overlay that appears when hovering over the button. | 378 // Photo overlay that appears when hovering over the button. |
358 photo_overlay_ = new views::ImageView(); | 379 photo_overlay_ = new views::ImageView(); |
359 | 380 |
360 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); | 381 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); |
361 photo_overlay_->set_background( | 382 photo_overlay_->set_background( |
362 views::Background::CreateSolidBackground(kBackgroundColor)); | 383 views::Background::CreateSolidBackground(kBackgroundColor)); |
363 photo_overlay_->SetImage( | 384 photo_overlay_->SetImage(gfx::CreateVectorIcon( |
364 gfx::CreateVectorIcon(gfx::VectorIconId::PHOTO_CAMERA, | 385 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); |
365 switches::IsMaterialDesignUserMenu() ? 22u : 48u, | |
366 SkColorSetRGB(0x33, 0x33, 0x33))); | |
367 | 386 |
368 photo_overlay_->SetSize(gfx::Size(icon_image_side(), icon_image_side())); | 387 photo_overlay_->SetSize(gfx::Size(icon_image_side(), icon_image_side())); |
369 photo_overlay_->SetY(badge_spacing()); | 388 photo_overlay_->SetY(badge_spacing()); |
370 photo_overlay_->SetVisible(false); | 389 photo_overlay_->SetVisible(false); |
371 AddChildView(photo_overlay_); | 390 AddChildView(photo_overlay_); |
372 } | 391 } |
373 | 392 |
374 void OnPaint(gfx::Canvas* canvas) override { | 393 void OnPaint(gfx::Canvas* canvas) override { |
375 canvas->Save(); | 394 canvas->Save(); |
376 // Display the profile picture as a circle. | 395 // Display the profile picture as a circle. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 return switches::IsMaterialDesignUserMenu() ? kMdImageSide | 460 return switches::IsMaterialDesignUserMenu() ? kMdImageSide |
442 : kLargeImageSide; | 461 : kLargeImageSide; |
443 } | 462 } |
444 | 463 |
445 static int badge_spacing() { | 464 static int badge_spacing() { |
446 // The space between the right/bottom edge of the profile badge and the | 465 // The space between the right/bottom edge of the profile badge and the |
447 // right/bottom edge of the profile icon. | 466 // right/bottom edge of the profile icon. |
448 return switches::IsMaterialDesignUserMenu() ? 4 : 0; | 467 return switches::IsMaterialDesignUserMenu() ? 4 : 0; |
449 } | 468 } |
450 | 469 |
| 470 bool CanProcessEventsWithinSubtree() const override { return interactive_; } |
| 471 |
451 private: | 472 private: |
452 // views::CustomButton: | 473 // views::CustomButton: |
453 void StateChanged() override { | 474 void StateChanged() override { |
454 bool show_overlay = | 475 bool show_overlay = |
455 (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); | 476 (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); |
456 if (photo_overlay_) | 477 if (photo_overlay_) |
457 photo_overlay_->SetVisible(show_overlay); | 478 photo_overlay_->SetVisible(show_overlay); |
458 } | 479 } |
459 | 480 |
460 void OnFocus() override { | 481 void OnFocus() override { |
461 views::LabelButton::OnFocus(); | 482 views::LabelButton::OnFocus(); |
462 if (photo_overlay_) | 483 if (photo_overlay_) |
463 photo_overlay_->SetVisible(true); | 484 photo_overlay_->SetVisible(true); |
464 } | 485 } |
465 | 486 |
466 void OnBlur() override { | 487 void OnBlur() override { |
467 views::LabelButton::OnBlur(); | 488 views::LabelButton::OnBlur(); |
468 // Don't hide the overlay if it's being shown as a result of a mouseover. | 489 // Don't hide the overlay if it's being shown as a result of a mouseover. |
469 if (photo_overlay_ && state() != STATE_HOVERED) | 490 if (photo_overlay_ && state() != STATE_HOVERED) |
470 photo_overlay_->SetVisible(false); | 491 photo_overlay_->SetVisible(false); |
471 } | 492 } |
472 | 493 |
| 494 bool interactive_; |
473 gfx::Path circular_mask_; | 495 gfx::Path circular_mask_; |
474 | 496 |
475 // Image that is shown when hovering over the image button. Can be NULL if | 497 // Image that is shown when hovering over the image button. Can be NULL if |
476 // the photo isn't allowed to be edited (e.g. for guest profiles). | 498 // the photo isn't allowed to be edited (e.g. for guest profiles). |
477 views::ImageView* photo_overlay_; | 499 views::ImageView* photo_overlay_; |
478 | 500 |
479 Profile* profile_; | 501 Profile* profile_; |
480 | 502 |
481 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); | 503 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); |
482 }; | 504 }; |
483 | 505 |
484 // EditableProfileName ------------------------------------------------- | 506 // EditableProfileName ------------------------------------------------- |
485 | 507 |
486 // A custom text control that turns into a textfield for editing when clicked. | 508 // A custom text control that turns into a textfield for editing when clicked. |
| 509 // Only used in non-material-design user menu. |
487 class EditableProfileName : public views::View, | 510 class EditableProfileName : public views::View, |
488 public views::ButtonListener { | 511 public views::ButtonListener { |
489 public: | 512 public: |
490 EditableProfileName(views::TextfieldController* controller, | 513 EditableProfileName(views::TextfieldController* controller, |
491 const base::string16& text, | 514 const base::string16& text, |
492 bool is_editing_allowed) | 515 bool is_editing_allowed) |
493 : button_(nullptr), profile_name_textfield_(nullptr) { | 516 : button_(nullptr), profile_name_textfield_(nullptr) { |
494 SetLayoutManager( | 517 SetLayoutManager( |
495 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 518 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
496 | 519 |
497 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 520 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
498 const gfx::FontList& medium_font_list = | 521 const gfx::FontList& medium_font_list = |
499 rb->GetFontList(ui::ResourceBundle::MediumFont); | 522 rb->GetFontList(ui::ResourceBundle::MediumFont); |
500 const gfx::Insets textfield_border_insets = | 523 const gfx::Insets textfield_border_insets = |
501 views::Textfield().border()->GetInsets(); | 524 views::Textfield().border()->GetInsets(); |
502 | 525 |
503 if (!is_editing_allowed) { | 526 if (!is_editing_allowed) { |
504 views::Label* name_label = new views::Label(text); | 527 views::Label* name_label = new views::Label(text); |
505 name_label->SetBorder( | 528 name_label->SetBorder( |
506 views::Border::CreateEmptyBorder(textfield_border_insets)); | 529 views::Border::CreateEmptyBorder(textfield_border_insets)); |
507 name_label->SetFontList(medium_font_list); | 530 name_label->SetFontList(medium_font_list); |
508 if (switches::IsMaterialDesignUserMenu()) | |
509 name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
510 AddChildView(name_label); | 531 AddChildView(name_label); |
511 return; | 532 return; |
512 } | 533 } |
513 | 534 |
514 profile_name_textfield_ = new views::Textfield(); | 535 profile_name_textfield_ = new views::Textfield(); |
515 // Textfield that overlaps the button. | 536 // Textfield that overlaps the button. |
516 profile_name_textfield_->set_controller(controller); | 537 profile_name_textfield_->set_controller(controller); |
517 profile_name_textfield_->SetFontList(medium_font_list); | 538 profile_name_textfield_->SetFontList(medium_font_list); |
518 profile_name_textfield_->SetHorizontalAlignment( | 539 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
519 switches::IsMaterialDesignUserMenu() ? gfx::ALIGN_LEFT | |
520 : gfx::ALIGN_CENTER); | |
521 profile_name_textfield_->SetVisible(false); | 540 profile_name_textfield_->SetVisible(false); |
522 AddChildView(profile_name_textfield_); | 541 AddChildView(profile_name_textfield_); |
523 | 542 |
524 button_ = new RightAlignedIconLabelButton(this, text); | 543 button_ = new RightAlignedIconLabelButton(this, text); |
525 button_->SetFontList(medium_font_list); | 544 button_->SetFontList(medium_font_list); |
526 // Show an "edit" pencil icon when hovering over. In the default state, | 545 // Show an "edit" pencil icon when hovering over. In the default state, |
527 // we need to create an empty placeholder of the correct size, so that | 546 // we need to create an empty placeholder of the correct size, so that |
528 // the text doesn't jump around when the hovered icon appears. | 547 // the text doesn't jump around when the hovered icon appears. |
529 // TODO(estade): revisit colors and press effect. | 548 // TODO(estade): revisit colors and press effect. |
530 const int kIconSize = 16; | 549 const int kIconSize = 16; |
531 button_->SetImage(views::LabelButton::STATE_NORMAL, | 550 button_->SetImage(views::LabelButton::STATE_NORMAL, |
532 CreateSquarePlaceholderImage(kIconSize)); | 551 CreateSquarePlaceholderImage(kIconSize)); |
533 button_->SetImage(views::LabelButton::STATE_HOVERED, | 552 button_->SetImage(views::LabelButton::STATE_HOVERED, |
534 gfx::CreateVectorIcon( | 553 gfx::CreateVectorIcon( |
535 gfx::VectorIconId::MODE_EDIT, kIconSize, | 554 gfx::VectorIconId::MODE_EDIT, kIconSize, |
536 SkColorSetRGB(0x33, 0x33, 0x33))); | 555 SkColorSetRGB(0x33, 0x33, 0x33))); |
537 button_->SetImage(views::LabelButton::STATE_PRESSED, | 556 button_->SetImage(views::LabelButton::STATE_PRESSED, |
538 gfx::CreateVectorIcon( | 557 gfx::CreateVectorIcon( |
539 gfx::VectorIconId::MODE_EDIT, kIconSize, | 558 gfx::VectorIconId::MODE_EDIT, kIconSize, |
540 SkColorSetRGB(0x20, 0x20, 0x20))); | 559 SkColorSetRGB(0x20, 0x20, 0x20))); |
541 // We need to add a left padding as well as a small top/bottom padding | 560 // We need to add a left padding as well as a small top/bottom padding |
542 // to the text to account for the textfield's border. | 561 // to the text to account for the textfield's border. |
543 if (switches::IsMaterialDesignUserMenu()) { | 562 const int kIconTextLabelButtonSpacing = 5; |
544 button_->SetBorder(views::Border::CreateEmptyBorder( | 563 button_->SetBorder(views::Border::CreateEmptyBorder( |
545 textfield_border_insets + | 564 textfield_border_insets + |
546 gfx::Insets(0, profile_name_textfield_->GetInsets().left(), 0, 0))); | 565 gfx::Insets(0, kIconSize + kIconTextLabelButtonSpacing, 0, 0))); |
547 } else { | |
548 const int kIconTextLabelButtonSpacing = 5; | |
549 button_->SetBorder(views::Border::CreateEmptyBorder( | |
550 textfield_border_insets + | |
551 gfx::Insets(0, kIconSize + kIconTextLabelButtonSpacing, 0, 0))); | |
552 } | |
553 AddChildView(button_); | 566 AddChildView(button_); |
554 } | 567 } |
555 | 568 |
556 views::Textfield* profile_name_textfield() { | 569 views::Textfield* profile_name_textfield() { |
557 return profile_name_textfield_; | 570 return profile_name_textfield_; |
558 } | 571 } |
559 | 572 |
560 // Hide the editable textfield to show the profile name button instead. | 573 // Hide the editable textfield to show the profile name button instead. |
561 void ShowReadOnlyView() { | 574 void ShowReadOnlyView() { |
562 button_->SetVisible(true); | 575 button_->SetVisible(true); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 | 762 |
750 void ProfileChooserView::ResetView() { | 763 void ProfileChooserView::ResetView() { |
751 open_other_profile_indexes_map_.clear(); | 764 open_other_profile_indexes_map_.clear(); |
752 delete_account_button_map_.clear(); | 765 delete_account_button_map_.clear(); |
753 reauth_account_button_map_.clear(); | 766 reauth_account_button_map_.clear(); |
754 manage_accounts_link_ = nullptr; | 767 manage_accounts_link_ = nullptr; |
755 signin_current_profile_button_ = nullptr; | 768 signin_current_profile_button_ = nullptr; |
756 auth_error_email_button_ = nullptr; | 769 auth_error_email_button_ = nullptr; |
757 current_profile_photo_ = nullptr; | 770 current_profile_photo_ = nullptr; |
758 current_profile_name_ = nullptr; | 771 current_profile_name_ = nullptr; |
| 772 current_profile_card_ = nullptr; |
759 guest_profile_button_ = nullptr; | 773 guest_profile_button_ = nullptr; |
760 users_button_ = nullptr; | 774 users_button_ = nullptr; |
761 go_incognito_button_ = nullptr; | 775 go_incognito_button_ = nullptr; |
762 lock_button_ = nullptr; | 776 lock_button_ = nullptr; |
763 close_all_windows_button_ = nullptr; | 777 close_all_windows_button_ = nullptr; |
764 add_account_link_ = nullptr; | 778 add_account_link_ = nullptr; |
765 gaia_signin_cancel_button_ = nullptr; | 779 gaia_signin_cancel_button_ = nullptr; |
766 remove_account_button_ = nullptr; | 780 remove_account_button_ = nullptr; |
767 account_removal_cancel_button_ = nullptr; | 781 account_removal_cancel_button_ = nullptr; |
768 add_person_button_ = nullptr; | 782 add_person_button_ = nullptr; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 bool account_management_available = | 1029 bool account_management_available = |
1016 SigninManagerFactory::GetForProfile(browser_->profile())-> | 1030 SigninManagerFactory::GetForProfile(browser_->profile())-> |
1017 IsAuthenticated() && | 1031 IsAuthenticated() && |
1018 switches::IsEnableAccountConsistency(); | 1032 switches::IsEnableAccountConsistency(); |
1019 ShowViewFromMode(account_management_available ? | 1033 ShowViewFromMode(account_management_available ? |
1020 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : | 1034 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : |
1021 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); | 1035 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); |
1022 } else if (sender == current_profile_photo_) { | 1036 } else if (sender == current_profile_photo_) { |
1023 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); | 1037 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
1024 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); | 1038 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); |
| 1039 } else if (sender == current_profile_card_) { |
| 1040 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
| 1041 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); |
| 1042 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); |
| 1043 } else if (sender == manage_accounts_button_) { |
| 1044 // This button can either mean show/hide the account management view, |
| 1045 // depending on which view it is displayed. |
| 1046 ShowViewFromMode(view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT |
| 1047 ? profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER |
| 1048 : profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT); |
1025 } else if (sender == signin_current_profile_button_) { | 1049 } else if (sender == signin_current_profile_button_) { |
1026 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); | 1050 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); |
1027 } else if (sender == add_person_button_) { | 1051 } else if (sender == add_person_button_) { |
1028 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 1052 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
1029 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); | 1053 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); |
1030 UserManager::Show(base::FilePath(), | 1054 UserManager::Show(base::FilePath(), |
1031 profiles::USER_MANAGER_NO_TUTORIAL, | 1055 profiles::USER_MANAGER_NO_TUTORIAL, |
1032 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1056 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
1033 } else if (sender == disconnect_button_) { | 1057 } else if (sender == disconnect_button_) { |
1034 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 1058 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 } | 1538 } |
1515 | 1539 |
1516 return view; | 1540 return view; |
1517 } | 1541 } |
1518 | 1542 |
1519 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( | 1543 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( |
1520 const AvatarMenu::Item& avatar_item, | 1544 const AvatarMenu::Item& avatar_item, |
1521 bool is_guest) { | 1545 bool is_guest) { |
1522 views::View* view = new views::View(); | 1546 views::View* view = new views::View(); |
1523 view->SetLayoutManager( | 1547 view->SetLayoutManager( |
1524 new views::BoxLayout(views::BoxLayout::kVertical, kMaterialMenuEdgeMargin, | 1548 new views::BoxLayout(views::BoxLayout::kVertical, 0, |
1525 views::kRelatedControlVerticalSpacing, | 1549 views::kRelatedControlVerticalSpacing, 0)); |
1526 views::kRelatedControlVerticalSpacing)); | |
1527 | 1550 |
1528 // Profile container for the profile photo and avatar/user name. | 1551 // Container for the profile photo and avatar/user name. |
1529 views::View* profile_container = new views::View(); | 1552 current_profile_card_ = |
| 1553 new BackgroundColorHoverButton(this, base::string16()); |
1530 | 1554 |
1531 // Profile picture, left-aligned. | 1555 // Profile picture, left-aligned. |
1532 current_profile_photo_ = new EditableProfilePhoto( | 1556 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( |
1533 this, avatar_item.icon, !is_guest, browser_->profile()); | 1557 this, avatar_item.icon, !is_guest, browser_->profile()); |
1534 | 1558 |
1535 // Profile name, left-aligned to the right of profile icon. | 1559 // Profile name, left-aligned to the right of profile icon. |
1536 bool editing_allowed = | 1560 views::Label* current_profile_name = new views::Label( |
1537 !is_guest && !browser_->profile()->IsLegacySupervised(); | 1561 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); |
1538 current_profile_name_ = new EditableProfileName( | 1562 current_profile_name->SetFontList( |
1539 this, profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()), | 1563 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
1540 editing_allowed); | 1564 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM)); |
1541 views::View* profile_name_container = new views::View(); | 1565 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1566 NonInteractiveContainer* profile_name_container = |
| 1567 new NonInteractiveContainer(); |
1542 int name_container_v_spacing = views::kRelatedControlSmallVerticalSpacing; | 1568 int name_container_v_spacing = views::kRelatedControlSmallVerticalSpacing; |
1543 if (!avatar_item.signed_in) | 1569 if (!avatar_item.signed_in || switches::IsEnableAccountConsistency()) |
1544 name_container_v_spacing += views::kRelatedControlVerticalSpacing; | 1570 name_container_v_spacing += views::kRelatedControlVerticalSpacing; |
1545 profile_name_container->SetLayoutManager(new views::BoxLayout( | 1571 profile_name_container->SetLayoutManager(new views::BoxLayout( |
1546 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0)); | 1572 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0)); |
1547 profile_name_container->AddChildView(current_profile_name_); | 1573 profile_name_container->AddChildView(current_profile_name); |
1548 | 1574 |
1549 const int between_child_spacing = | 1575 const int between_child_spacing = |
1550 kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing(); | 1576 kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing(); |
1551 profile_container->SetLayoutManager(new views::BoxLayout( | 1577 current_profile_card_->SetLayoutManager(new views::BoxLayout( |
1552 views::BoxLayout::kHorizontal, 0, | 1578 views::BoxLayout::kHorizontal, 0, |
1553 views::kRelatedControlSmallVerticalSpacing, between_child_spacing)); | 1579 views::kRelatedControlSmallVerticalSpacing, between_child_spacing)); |
1554 profile_container->AddChildView(current_profile_photo_); | 1580 current_profile_card_->AddChildView(current_profile_photo); |
1555 profile_container->AddChildView(profile_name_container); | 1581 current_profile_card_->AddChildView(profile_name_container); |
1556 view->AddChildView(profile_container); | 1582 current_profile_card_->SetMinSize(gfx::Size( |
| 1583 GetFixedMenuWidth(), current_profile_photo->GetPreferredSize().height() + |
| 1584 2 * views::kRelatedControlSmallVerticalSpacing)); |
| 1585 view->AddChildView(current_profile_card_); |
1557 | 1586 |
1558 if (is_guest) | 1587 if (is_guest) { |
| 1588 current_profile_card_->SetEnabled(false); |
1559 return view; | 1589 return view; |
| 1590 } |
1560 | 1591 |
1561 // The available links depend on the type of profile that is active. | 1592 // The available links depend on the type of profile that is active. |
1562 if (avatar_item.signed_in) { | 1593 if (avatar_item.signed_in) { |
1563 if (switches::IsEnableAccountConsistency()) { | 1594 if (switches::IsEnableAccountConsistency()) { |
1564 base::string16 link_title = l10n_util::GetStringUTF16( | 1595 base::string16 button_text = l10n_util::GetStringUTF16( |
1565 IsProfileChooser(view_mode_) | 1596 IsProfileChooser(view_mode_) |
1566 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON | 1597 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON |
1567 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | 1598 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
1568 manage_accounts_link_ = CreateLink(link_title, this); | 1599 manage_accounts_button_ = |
1569 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1600 new BackgroundColorHoverButton(this, button_text); |
1570 profile_name_container->AddChildView(manage_accounts_link_); | 1601 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1602 manage_accounts_button_->SetMinSize( |
| 1603 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); |
| 1604 view->AddChildView(manage_accounts_button_); |
1571 } else { | 1605 } else { |
1572 views::Label* email_label = new views::Label(avatar_item.username); | 1606 views::Label* email_label = new views::Label(avatar_item.username); |
1573 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); | 1607 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); |
1574 email_label->SetEnabled(false); | 1608 email_label->SetEnabled(false); |
1575 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1609 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
1576 profile_name_container->AddChildView(email_label); | 1610 profile_name_container->AddChildView(email_label); |
1577 } | 1611 } |
1578 return view; | 1612 return view; |
1579 } | 1613 } |
1580 | 1614 |
1581 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( | 1615 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( |
1582 browser_->profile()->GetOriginalProfile()); | 1616 browser_->profile()->GetOriginalProfile()); |
1583 if (signin_manager->IsSigninAllowed()) { | 1617 if (signin_manager->IsSigninAllowed()) { |
| 1618 views::View* extra_links_view = new views::View(); |
| 1619 views::BoxLayout* extra_links_layout = new views::BoxLayout( |
| 1620 views::BoxLayout::kVertical, kMaterialMenuEdgeMargin, |
| 1621 views::kRelatedControlVerticalSpacing, kMaterialMenuEdgeMargin); |
| 1622 extra_links_layout->set_cross_axis_alignment( |
| 1623 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 1624 extra_links_view->SetLayoutManager(extra_links_layout); |
1584 views::Label* promo = | 1625 views::Label* promo = |
1585 new views::Label(l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); | 1626 new views::Label(l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); |
1586 promo->SetMultiLine(true); | 1627 promo->SetMultiLine(true); |
1587 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1628 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
1588 view->AddChildView(promo); | 1629 extra_links_view->AddChildView(promo); |
1589 | 1630 |
1590 signin_current_profile_button_ = | 1631 signin_current_profile_button_ = |
1591 views::MdTextButton::CreateSecondaryUiBlueButton( | 1632 views::MdTextButton::CreateSecondaryUiBlueButton( |
1592 this, l10n_util::GetStringFUTF16( | 1633 this, l10n_util::GetStringFUTF16( |
1593 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 1634 IDS_SYNC_START_SYNC_BUTTON_LABEL, |
1594 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | 1635 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
1595 view->AddChildView(signin_current_profile_button_); | 1636 extra_links_view->AddChildView(signin_current_profile_button_); |
1596 content::RecordAction( | 1637 content::RecordAction( |
1597 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | 1638 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
1598 view->SetBorder(views::Border::CreateEmptyBorder( | 1639 extra_links_view->SetBorder(views::Border::CreateEmptyBorder( |
1599 0, 0, views::kRelatedControlVerticalSpacing, 0)); | 1640 0, 0, views::kRelatedControlSmallVerticalSpacing, 0)); |
| 1641 view->AddChildView(extra_links_view); |
1600 } | 1642 } |
1601 | 1643 |
1602 return view; | 1644 return view; |
1603 } | 1645 } |
1604 | 1646 |
1605 views::View* ProfileChooserView::CreateGuestProfileView() { | 1647 views::View* ProfileChooserView::CreateGuestProfileView() { |
1606 gfx::Image guest_icon = | 1648 gfx::Image guest_icon = |
1607 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1649 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
1608 profiles::GetPlaceholderAvatarIconResourceID()); | 1650 profiles::GetPlaceholderAvatarIconResourceID()); |
1609 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); | 1651 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2113 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2155 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2114 IncognitoModePrefs::DISABLED; | 2156 IncognitoModePrefs::DISABLED; |
2115 return incognito_available && !browser_->profile()->IsGuestSession(); | 2157 return incognito_available && !browser_->profile()->IsGuestSession(); |
2116 } | 2158 } |
2117 | 2159 |
2118 void ProfileChooserView::PostActionPerformed( | 2160 void ProfileChooserView::PostActionPerformed( |
2119 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2161 ProfileMetrics::ProfileDesktopMenu action_performed) { |
2120 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2162 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
2121 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2163 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
2122 } | 2164 } |
OLD | NEW |