Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1409)

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 1833383002: Correctly layout the profile name button, and disable the button listener for supervised user. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_(new RightAlignedIconLabelButton(this, text)),
393 profile_name_textfield_(new views::Textfield()) { 393 profile_name_textfield_(new views::Textfield()),
394 is_editing_allowed_(is_editing_allowed) {
395 SetLayoutManager(
396 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
Peter Kasting 2016/03/28 04:17:13 Nit: Add blank line below
Shu Chen 2016/03/28 07:33:30 Done.
394 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 397 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
395 const gfx::FontList& medium_font_list = 398 const gfx::FontList& medium_font_list =
396 rb->GetFontList(ui::ResourceBundle::MediumFont); 399 rb->GetFontList(ui::ResourceBundle::MediumFont);
397 button_->SetFontList(medium_font_list); 400 button_->SetFontList(medium_font_list);
398 AddChildView(button_); 401 AddChildView(button_);
399 402
400 if (!is_editing_allowed) { 403 if (!is_editing_allowed) {
Peter Kasting 2016/03/28 04:17:13 Nit: Use member, not param, name
Shu Chen 2016/03/28 07:33:30 Done.
401 button_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); 404 button_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0));
402 return; 405 return;
403 } 406 }
404 407
405 // Show an "edit" pencil icon when hovering over. In the default state, 408 // 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 409 // 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. 410 // the text doesn't jump around when the hovered icon appears.
408 // TODO(estade): revisit colors and press effect. 411 // TODO(estade): revisit colors and press effect.
409 const int kIconSize = 16; 412 const int kIconSize = 16;
410 button_->SetImage(views::LabelButton::STATE_NORMAL, 413 button_->SetImage(views::LabelButton::STATE_NORMAL,
(...skipping 11 matching lines...) Expand all
422 // padding to account for the textfield's border. 425 // padding to account for the textfield's border.
423 const int kIconTextLabelButtonSpacing = 5; 426 const int kIconTextLabelButtonSpacing = 5;
424 button_->SetBorder(views::Border::CreateEmptyBorder( 427 button_->SetBorder(views::Border::CreateEmptyBorder(
425 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); 428 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0));
426 429
427 // Textfield that overlaps the button. 430 // Textfield that overlaps the button.
428 profile_name_textfield_->set_controller(controller); 431 profile_name_textfield_->set_controller(controller);
429 profile_name_textfield_->SetFontList(medium_font_list); 432 profile_name_textfield_->SetFontList(medium_font_list);
430 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 433 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
431 profile_name_textfield_->SetVisible(false); 434 profile_name_textfield_->SetVisible(false);
432 435
Peter Kasting 2016/03/28 04:17:14 Nit: Remove this line
Shu Chen 2016/03/28 07:33:30 Done.
433 SetLayoutManager(
434 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
435 AddChildView(profile_name_textfield_); 436 AddChildView(profile_name_textfield_);
436 } 437 }
437 438
438 views::Textfield* profile_name_textfield() { 439 views::Textfield* profile_name_textfield() {
439 return profile_name_textfield_; 440 return profile_name_textfield_;
440 } 441 }
441 442
442 // Hide the editable textfield to show the profile name button instead. 443 // Hide the editable textfield to show the profile name button instead.
443 void ShowReadOnlyView() { 444 void ShowReadOnlyView() {
444 button_->SetVisible(true); 445 button_->SetVisible(true);
445 profile_name_textfield_->SetVisible(false); 446 profile_name_textfield_->SetVisible(false);
446 } 447 }
447 448
448 private: 449 private:
449 // views::ButtonListener: 450 // views::ButtonListener:
450 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 451 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
452 if (!is_editing_allowed_)
453 return;
451 button_->SetVisible(false); 454 button_->SetVisible(false);
452 profile_name_textfield_->SetVisible(true); 455 profile_name_textfield_->SetVisible(true);
453 profile_name_textfield_->SetText(button_->GetText()); 456 profile_name_textfield_->SetText(button_->GetText());
454 profile_name_textfield_->SelectAll(false); 457 profile_name_textfield_->SelectAll(false);
455 profile_name_textfield_->RequestFocus(); 458 profile_name_textfield_->RequestFocus();
456 // Re-layouts the view after swaping the controls. 459 // Re-layouts the view after swaping the controls.
457 Layout(); 460 Layout();
458 } 461 }
459 462
460 // views::LabelButton: 463 // views::LabelButton:
461 bool OnKeyReleased(const ui::KeyEvent& event) override { 464 bool OnKeyReleased(const ui::KeyEvent& event) override {
462 // Override CustomButton's implementation, which presses the button when 465 // 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 466 // 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. 467 // part of the new profile name typed in the textfield.
465 return false; 468 return false;
466 } 469 }
467 470
468 RightAlignedIconLabelButton* button_; 471 RightAlignedIconLabelButton* button_;
469 472
470 // Textfield that is shown when editing the profile name. Can be NULL if 473 // 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). 474 // the profile name isn't allowed to be edited (e.g. for guest profiles).
472 views::Textfield* profile_name_textfield_; 475 views::Textfield* profile_name_textfield_;
473 476
477 bool is_editing_allowed_;
Peter Kasting 2016/03/28 04:17:13 Hmm. Maybe instead of adding this, we should use
Shu Chen 2016/03/28 07:33:30 Done.
478
474 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); 479 DISALLOW_COPY_AND_ASSIGN(EditableProfileName);
475 }; 480 };
476 481
477 // A title card with one back button right aligned and one label center aligned. 482 // A title card with one back button right aligned and one label center aligned.
478 class TitleCard : public views::View { 483 class TitleCard : public views::View {
479 public: 484 public:
480 TitleCard(const base::string16& message, views::ButtonListener* listener, 485 TitleCard(const base::string16& message, views::ButtonListener* listener,
481 views::ImageButton** back_button) { 486 views::ImageButton** back_button) {
482 back_button_ = CreateBackButton(listener); 487 back_button_ = CreateBackButton(listener);
483 *back_button = back_button_; 488 *back_button = back_button_;
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1872 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1868 IncognitoModePrefs::DISABLED; 1873 IncognitoModePrefs::DISABLED;
1869 return incognito_available && !browser_->profile()->IsGuestSession(); 1874 return incognito_available && !browser_->profile()->IsGuestSession();
1870 } 1875 }
1871 1876
1872 void ProfileChooserView::PostActionPerformed( 1877 void ProfileChooserView::PostActionPerformed(
1873 ProfileMetrics::ProfileDesktopMenu action_performed) { 1878 ProfileMetrics::ProfileDesktopMenu action_performed) {
1874 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1879 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1875 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1880 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1876 } 1881 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698