| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 382 |
| 383 // EditableProfileName ------------------------------------------------- | 383 // EditableProfileName ------------------------------------------------- |
| 384 | 384 |
| 385 // A custom text control that turns into a textfield for editing when clicked. | 385 // A custom text control that turns into a textfield for editing when clicked. |
| 386 class EditableProfileName : public views::View, | 386 class EditableProfileName : public views::View, |
| 387 public views::ButtonListener { | 387 public views::ButtonListener { |
| 388 public: | 388 public: |
| 389 EditableProfileName(views::TextfieldController* controller, | 389 EditableProfileName(views::TextfieldController* controller, |
| 390 const base::string16& text, | 390 const base::string16& text, |
| 391 bool is_editing_allowed) | 391 bool is_editing_allowed) |
| 392 : button_(new RightAlignedIconLabelButton(this, text)), | 392 : button_(nullptr), label_(nullptr), profile_name_textfield_(nullptr) { |
| 393 profile_name_textfield_(new views::Textfield()) { | 393 SetLayoutManager( |
| 394 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 395 |
| 394 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 396 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 395 const gfx::FontList& medium_font_list = | 397 const gfx::FontList& medium_font_list = |
| 396 rb->GetFontList(ui::ResourceBundle::MediumFont); | 398 rb->GetFontList(ui::ResourceBundle::MediumFont); |
| 397 button_->SetFontList(medium_font_list); | |
| 398 AddChildView(button_); | |
| 399 | 399 |
| 400 if (!is_editing_allowed) { | 400 if (!is_editing_allowed) { |
| 401 button_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); | 401 label_ = new views::Label(text); |
| 402 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); |
| 403 label_->SetFontList(medium_font_list); |
| 404 AddChildView(label_); |
| 402 return; | 405 return; |
| 403 } | 406 } |
| 404 | 407 |
| 408 button_ = new RightAlignedIconLabelButton(this, text); |
| 409 button_->SetFontList(medium_font_list); |
| 405 // Show an "edit" pencil icon when hovering over. In the default state, | 410 // Show an "edit" pencil icon when hovering over. In the default state, |
| 406 // we need to create an empty placeholder of the correct size, so that | 411 // we need to create an empty placeholder of the correct size, so that |
| 407 // the text doesn't jump around when the hovered icon appears. | 412 // the text doesn't jump around when the hovered icon appears. |
| 408 // TODO(estade): revisit colors and press effect. | 413 // TODO(estade): revisit colors and press effect. |
| 409 const int kIconSize = 16; | 414 const int kIconSize = 16; |
| 410 button_->SetImage(views::LabelButton::STATE_NORMAL, | 415 button_->SetImage(views::LabelButton::STATE_NORMAL, |
| 411 CreateSquarePlaceholderImage(kIconSize)); | 416 CreateSquarePlaceholderImage(kIconSize)); |
| 412 button_->SetImage(views::LabelButton::STATE_HOVERED, | 417 button_->SetImage(views::LabelButton::STATE_HOVERED, |
| 413 gfx::CreateVectorIcon( | 418 gfx::CreateVectorIcon( |
| 414 gfx::VectorIconId::MODE_EDIT, kIconSize, | 419 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 415 SkColorSetRGB(0x33, 0x33, 0x33))); | 420 SkColorSetRGB(0x33, 0x33, 0x33))); |
| 416 button_->SetImage(views::LabelButton::STATE_PRESSED, | 421 button_->SetImage(views::LabelButton::STATE_PRESSED, |
| 417 gfx::CreateVectorIcon( | 422 gfx::CreateVectorIcon( |
| 418 gfx::VectorIconId::MODE_EDIT, kIconSize, | 423 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 419 SkColorSetRGB(0x20, 0x20, 0x20))); | 424 SkColorSetRGB(0x20, 0x20, 0x20))); |
| 420 // To center the text, we need to offest it by the width of the icon we | 425 // To center the text, we need to offest it by the width of the icon we |
| 421 // are adding and its padding. We need to also add a small top/bottom | 426 // are adding and its padding. We need to also add a small top/bottom |
| 422 // padding to account for the textfield's border. | 427 // padding to account for the textfield's border. |
| 423 const int kIconTextLabelButtonSpacing = 5; | 428 const int kIconTextLabelButtonSpacing = 5; |
| 424 button_->SetBorder(views::Border::CreateEmptyBorder( | 429 button_->SetBorder(views::Border::CreateEmptyBorder( |
| 425 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); | 430 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); |
| 431 AddChildView(button_); |
| 426 | 432 |
| 433 profile_name_textfield_ = new views::Textfield(); |
| 427 // Textfield that overlaps the button. | 434 // Textfield that overlaps the button. |
| 428 profile_name_textfield_->set_controller(controller); | 435 profile_name_textfield_->set_controller(controller); |
| 429 profile_name_textfield_->SetFontList(medium_font_list); | 436 profile_name_textfield_->SetFontList(medium_font_list); |
| 430 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 437 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 431 profile_name_textfield_->SetVisible(false); | 438 profile_name_textfield_->SetVisible(false); |
| 432 | |
| 433 SetLayoutManager( | |
| 434 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 435 AddChildView(profile_name_textfield_); | 439 AddChildView(profile_name_textfield_); |
| 436 } | 440 } |
| 437 | 441 |
| 438 views::Textfield* profile_name_textfield() { | 442 views::Textfield* profile_name_textfield() { |
| 439 return profile_name_textfield_; | 443 return profile_name_textfield_; |
| 440 } | 444 } |
| 441 | 445 |
| 442 // Hide the editable textfield to show the profile name button instead. | 446 // Hide the editable textfield to show the profile name button instead. |
| 443 void ShowReadOnlyView() { | 447 void ShowReadOnlyView() { |
| 444 button_->SetVisible(true); | 448 button_->SetVisible(true); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 458 } | 462 } |
| 459 | 463 |
| 460 // views::LabelButton: | 464 // views::LabelButton: |
| 461 bool OnKeyReleased(const ui::KeyEvent& event) override { | 465 bool OnKeyReleased(const ui::KeyEvent& event) override { |
| 462 // Override CustomButton's implementation, which presses the button when | 466 // Override CustomButton's implementation, which presses the button when |
| 463 // you press space and clicks it when you release space, as the space can be | 467 // you press space and clicks it when you release space, as the space can be |
| 464 // part of the new profile name typed in the textfield. | 468 // part of the new profile name typed in the textfield. |
| 465 return false; | 469 return false; |
| 466 } | 470 } |
| 467 | 471 |
| 472 // The label button which shows the profile name, and can handle the event to |
| 473 // make it editable. Can be NULL if the profile name isn't allowed to be |
| 474 // edited. |
| 468 RightAlignedIconLabelButton* button_; | 475 RightAlignedIconLabelButton* button_; |
| 469 | 476 |
| 477 // The label which shows when the profile name cannot be edited (e.g. for |
| 478 // supervised user). Can be NULL if the profile name is allowed to be edited. |
| 479 views::Label* label_; |
| 480 |
| 470 // Textfield that is shown when editing the profile name. Can be NULL if | 481 // Textfield that is shown when editing the profile name. Can be NULL if |
| 471 // the profile name isn't allowed to be edited (e.g. for guest profiles). | 482 // the profile name isn't allowed to be edited (e.g. for guest profiles). |
| 472 views::Textfield* profile_name_textfield_; | 483 views::Textfield* profile_name_textfield_; |
| 473 | 484 |
| 474 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); | 485 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); |
| 475 }; | 486 }; |
| 476 | 487 |
| 477 // A title card with one back button right aligned and one label center aligned. | 488 // A title card with one back button right aligned and one label center aligned. |
| 478 class TitleCard : public views::View { | 489 class TitleCard : public views::View { |
| 479 public: | 490 public: |
| (...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 1878 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 1868 IncognitoModePrefs::DISABLED; | 1879 IncognitoModePrefs::DISABLED; |
| 1869 return incognito_available && !browser_->profile()->IsGuestSession(); | 1880 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 1870 } | 1881 } |
| 1871 | 1882 |
| 1872 void ProfileChooserView::PostActionPerformed( | 1883 void ProfileChooserView::PostActionPerformed( |
| 1873 ProfileMetrics::ProfileDesktopMenu action_performed) { | 1884 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 1874 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 1885 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 1875 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 1886 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 1876 } | 1887 } |
| OLD | NEW |