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

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: uses views::Label for supervised user. 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 15 matching lines...) Expand all
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
468 RightAlignedIconLabelButton* button_; 472 RightAlignedIconLabelButton* button_;
469 473
474 views::Label* label_;
Peter Kasting 2016/03/29 02:30:41 Nit: I suggest giving these members comments notin
Shu Chen 2016/03/29 04:39:56 Done.
475
470 // Textfield that is shown when editing the profile name. Can be NULL if 476 // 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). 477 // the profile name isn't allowed to be edited (e.g. for guest profiles).
472 views::Textfield* profile_name_textfield_; 478 views::Textfield* profile_name_textfield_;
473 479
474 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); 480 DISALLOW_COPY_AND_ASSIGN(EditableProfileName);
475 }; 481 };
476 482
477 // A title card with one back button right aligned and one label center aligned. 483 // A title card with one back button right aligned and one label center aligned.
478 class TitleCard : public views::View { 484 class TitleCard : public views::View {
479 public: 485 public:
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1873 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1868 IncognitoModePrefs::DISABLED; 1874 IncognitoModePrefs::DISABLED;
1869 return incognito_available && !browser_->profile()->IsGuestSession(); 1875 return incognito_available && !browser_->profile()->IsGuestSession();
1870 } 1876 }
1871 1877
1872 void ProfileChooserView::PostActionPerformed( 1878 void ProfileChooserView::PostActionPerformed(
1873 ProfileMetrics::ProfileDesktopMenu action_performed) { 1879 ProfileMetrics::ProfileDesktopMenu action_performed) {
1874 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1880 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1875 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1881 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1876 } 1882 }
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