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

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

Issue 2480813003: Reduce views::Border creation verbosity by promoting factory functions (Closed)
Patch Set: fix bad merge Created 4 years, 1 month 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
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 public: 188 public:
189 BackgroundColorHoverButton(views::ButtonListener* listener, 189 BackgroundColorHoverButton(views::ButtonListener* listener,
190 const base::string16& text) 190 const base::string16& text)
191 : views::LabelButton(listener, text) { 191 : views::LabelButton(listener, text) {
192 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu() 192 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu()
193 ? (kMaterialMenuEdgeMargin - 2) 193 ? (kMaterialMenuEdgeMargin - 2)
194 : views::kItemLabelSpacing); 194 : views::kItemLabelSpacing);
195 const int button_margin = switches::IsMaterialDesignUserMenu() 195 const int button_margin = switches::IsMaterialDesignUserMenu()
196 ? kMaterialMenuEdgeMargin 196 ? kMaterialMenuEdgeMargin
197 : views::kButtonHEdgeMarginNew; 197 : views::kButtonHEdgeMarginNew;
198 SetBorder( 198 SetBorder(views::CreateEmptyBorder(0, button_margin, 0, button_margin));
199 views::Border::CreateEmptyBorder(0, button_margin, 0, button_margin));
200 SetFocusForPlatform(); 199 SetFocusForPlatform();
201 set_request_focus_on_press(true); 200 set_request_focus_on_press(true);
202 201
203 if (switches::IsMaterialDesignUserMenu()) { 202 if (switches::IsMaterialDesignUserMenu()) {
204 label()->SetHandlesTooltips(false); 203 label()->SetHandlesTooltips(false);
205 } 204 }
206 } 205 }
207 206
208 BackgroundColorHoverButton(views::ButtonListener* listener, 207 BackgroundColorHoverButton(views::ButtonListener* listener,
209 const base::string16& text, 208 const base::string16& text,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 const gfx::Image& icon, 355 const gfx::Image& icon,
357 bool is_editing_allowed, 356 bool is_editing_allowed,
358 Profile* profile) 357 Profile* profile)
359 : views::LabelButton(listener, base::string16()), 358 : views::LabelButton(listener, base::string16()),
360 interactive_(!switches::IsMaterialDesignUserMenu()), 359 interactive_(!switches::IsMaterialDesignUserMenu()),
361 photo_overlay_(nullptr), 360 photo_overlay_(nullptr),
362 profile_(profile) { 361 profile_(profile) {
363 gfx::Image image = profiles::GetSizedAvatarIcon( 362 gfx::Image image = profiles::GetSizedAvatarIcon(
364 icon, true, icon_image_side(), icon_image_side()); 363 icon, true, icon_image_side(), icon_image_side());
365 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); 364 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia());
366 SetBorder(views::Border::NullBorder()); 365 SetBorder(views::NullBorder());
367 if (switches::IsMaterialDesignUserMenu()) { 366 if (switches::IsMaterialDesignUserMenu()) {
368 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(), 367 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(),
369 GetPreferredSize().height() + badge_spacing() + 368 GetPreferredSize().height() + badge_spacing() +
370 views::kRelatedControlSmallVerticalSpacing)); 369 views::kRelatedControlSmallVerticalSpacing));
371 } else { 370 } else {
372 SetSize(GetPreferredSize()); 371 SetSize(GetPreferredSize());
373 } 372 }
374 373
375 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) { 374 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) {
376 SetEnabled(false); 375 SetEnabled(false);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 520 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
522 521
523 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 522 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
524 const gfx::FontList& medium_font_list = 523 const gfx::FontList& medium_font_list =
525 rb->GetFontList(ui::ResourceBundle::MediumFont); 524 rb->GetFontList(ui::ResourceBundle::MediumFont);
526 const gfx::Insets textfield_border_insets = 525 const gfx::Insets textfield_border_insets =
527 views::Textfield().border()->GetInsets(); 526 views::Textfield().border()->GetInsets();
528 527
529 if (!is_editing_allowed) { 528 if (!is_editing_allowed) {
530 views::Label* name_label = new views::Label(text); 529 views::Label* name_label = new views::Label(text);
531 name_label->SetBorder( 530 name_label->SetBorder(views::CreateEmptyBorder(textfield_border_insets));
532 views::Border::CreateEmptyBorder(textfield_border_insets));
533 name_label->SetFontList(medium_font_list); 531 name_label->SetFontList(medium_font_list);
534 AddChildView(name_label); 532 AddChildView(name_label);
535 return; 533 return;
536 } 534 }
537 535
538 profile_name_textfield_ = new views::Textfield(); 536 profile_name_textfield_ = new views::Textfield();
539 // Textfield that overlaps the button. 537 // Textfield that overlaps the button.
540 profile_name_textfield_->set_controller(controller); 538 profile_name_textfield_->set_controller(controller);
541 profile_name_textfield_->SetFontList(medium_font_list); 539 profile_name_textfield_->SetFontList(medium_font_list);
542 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 540 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
(...skipping 13 matching lines...) Expand all
556 gfx::CreateVectorIcon( 554 gfx::CreateVectorIcon(
557 gfx::VectorIconId::MODE_EDIT, kIconSize, 555 gfx::VectorIconId::MODE_EDIT, kIconSize,
558 SkColorSetRGB(0x33, 0x33, 0x33))); 556 SkColorSetRGB(0x33, 0x33, 0x33)));
559 button_->SetImage(views::LabelButton::STATE_PRESSED, 557 button_->SetImage(views::LabelButton::STATE_PRESSED,
560 gfx::CreateVectorIcon( 558 gfx::CreateVectorIcon(
561 gfx::VectorIconId::MODE_EDIT, kIconSize, 559 gfx::VectorIconId::MODE_EDIT, kIconSize,
562 SkColorSetRGB(0x20, 0x20, 0x20))); 560 SkColorSetRGB(0x20, 0x20, 0x20)));
563 // We need to add a left padding as well as a small top/bottom padding 561 // We need to add a left padding as well as a small top/bottom padding
564 // to the text to account for the textfield's border. 562 // to the text to account for the textfield's border.
565 const int kIconTextLabelButtonSpacing = 5; 563 const int kIconTextLabelButtonSpacing = 5;
566 button_->SetBorder(views::Border::CreateEmptyBorder( 564 button_->SetBorder(views::CreateEmptyBorder(
567 textfield_border_insets + 565 textfield_border_insets +
568 gfx::Insets(0, kIconSize + kIconTextLabelButtonSpacing, 0, 0))); 566 gfx::Insets(0, kIconSize + kIconTextLabelButtonSpacing, 0, 0)));
569 AddChildView(button_); 567 AddChildView(button_);
570 } 568 }
571 569
572 views::Textfield* profile_name_textfield() { 570 views::Textfield* profile_name_textfield() {
573 return profile_name_textfield_; 571 return profile_name_textfield_;
574 } 572 }
575 573
576 // Hide the editable textfield to show the profile name button instead. 574 // Hide the editable textfield to show the profile name button instead.
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 // already initialized. 1551 // already initialized.
1554 DCHECK(button_out); 1552 DCHECK(button_out);
1555 // Adds a padding row between error title/content and the button. 1553 // Adds a padding row between error title/content and the button.
1556 SizedContainer* padding = 1554 SizedContainer* padding =
1557 new SizedContainer(gfx::Size(0, views::kRelatedControlVerticalSpacing)); 1555 new SizedContainer(gfx::Size(0, views::kRelatedControlVerticalSpacing));
1558 vertical_view->AddChildView(padding); 1556 vertical_view->AddChildView(padding);
1559 1557
1560 *button_out = views::MdTextButton::CreateSecondaryUiBlueButton( 1558 *button_out = views::MdTextButton::CreateSecondaryUiBlueButton(
1561 this, l10n_util::GetStringUTF16(button_string_id)); 1559 this, l10n_util::GetStringUTF16(button_string_id));
1562 vertical_view->AddChildView(*button_out); 1560 vertical_view->AddChildView(*button_out);
1563 view->SetBorder(views::Border::CreateEmptyBorder( 1561 view->SetBorder(views::CreateEmptyBorder(
1564 0, 0, views::kRelatedControlSmallVerticalSpacing, 0)); 1562 0, 0, views::kRelatedControlSmallVerticalSpacing, 0));
1565 } 1563 }
1566 1564
1567 view->AddChildView(vertical_view); 1565 view->AddChildView(vertical_view);
1568 return view; 1566 return view;
1569 } 1567 }
1570 1568
1571 views::View* ProfileChooserView::CreateCurrentProfileView( 1569 views::View* ProfileChooserView::CreateCurrentProfileView(
1572 const AvatarMenu::Item& avatar_item, 1570 const AvatarMenu::Item& avatar_item,
1573 bool is_guest) { 1571 bool is_guest) {
1574 views::View* view = new views::View(); 1572 views::View* view = new views::View();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL); 1624 auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL);
1627 auth_error_email_button_->SetImage( 1625 auth_error_email_button_->SetImage(
1628 views::LabelButton::STATE_NORMAL, 1626 views::LabelButton::STATE_NORMAL,
1629 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 18, 1627 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 18,
1630 gfx::kChromeIconGrey)); 1628 gfx::kChromeIconGrey));
1631 auth_error_email_button_->SetFocusForPlatform(); 1629 auth_error_email_button_->SetFocusForPlatform();
1632 auth_error_email_button_->set_request_focus_on_press(true); 1630 auth_error_email_button_->set_request_focus_on_press(true);
1633 gfx::Insets insets = 1631 gfx::Insets insets =
1634 views::LabelButtonAssetBorder::GetDefaultInsetsForStyle( 1632 views::LabelButtonAssetBorder::GetDefaultInsetsForStyle(
1635 views::Button::STYLE_TEXTBUTTON); 1633 views::Button::STYLE_TEXTBUTTON);
1636 auth_error_email_button_->SetBorder(views::Border::CreateEmptyBorder( 1634 auth_error_email_button_->SetBorder(views::CreateEmptyBorder(
1637 insets.top(), insets.left(), insets.bottom(), insets.right())); 1635 insets.top(), insets.left(), insets.bottom(), insets.right()));
1638 layout->AddView(auth_error_email_button_); 1636 layout->AddView(auth_error_email_button_);
1639 } else { 1637 } else {
1640 // Add a small padding between the email button and the profile name. 1638 // Add a small padding between the email button and the profile name.
1641 layout->StartRowWithPadding(1, 0, 0, 2); 1639 layout->StartRowWithPadding(1, 0, 0, 2);
1642 views::Label* email_label = new views::Label(avatar_item.username); 1640 views::Label* email_label = new views::Label(avatar_item.username);
1643 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); 1641 email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
1644 email_label->SetEnabled(false); 1642 email_label->SetEnabled(false);
1645 layout->AddView(email_label); 1643 layout->AddView(email_label);
1646 } 1644 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 extra_links_view->AddChildView(promo); 1769 extra_links_view->AddChildView(promo);
1772 1770
1773 signin_current_profile_button_ = 1771 signin_current_profile_button_ =
1774 views::MdTextButton::CreateSecondaryUiBlueButton( 1772 views::MdTextButton::CreateSecondaryUiBlueButton(
1775 this, l10n_util::GetStringFUTF16( 1773 this, l10n_util::GetStringFUTF16(
1776 IDS_SYNC_START_SYNC_BUTTON_LABEL, 1774 IDS_SYNC_START_SYNC_BUTTON_LABEL,
1777 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); 1775 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
1778 extra_links_view->AddChildView(signin_current_profile_button_); 1776 extra_links_view->AddChildView(signin_current_profile_button_);
1779 content::RecordAction( 1777 content::RecordAction(
1780 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); 1778 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
1781 extra_links_view->SetBorder(views::Border::CreateEmptyBorder( 1779 extra_links_view->SetBorder(views::CreateEmptyBorder(
1782 0, 0, views::kRelatedControlSmallVerticalSpacing, 0)); 1780 0, 0, views::kRelatedControlSmallVerticalSpacing, 0));
1783 view->AddChildView(extra_links_view); 1781 view->AddChildView(extra_links_view);
1784 } 1782 }
1785 1783
1786 return view; 1784 return view;
1787 } 1785 }
1788 1786
1789 views::View* ProfileChooserView::CreateGuestProfileView() { 1787 views::View* ProfileChooserView::CreateGuestProfileView() {
1790 gfx::Image guest_icon = 1788 gfx::Image guest_icon =
1791 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 1789 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 error_account_id == primary_account, GetFixedMenuWidth()); 2000 error_account_id == primary_account, GetFixedMenuWidth());
2003 for (size_t i = 0; i < accounts.size(); ++i) 2001 for (size_t i = 0; i < accounts.size(); ++i)
2004 CreateAccountButton(layout, accounts[i], false, 2002 CreateAccountButton(layout, accounts[i], false,
2005 error_account_id == accounts[i], GetFixedMenuWidth()); 2003 error_account_id == accounts[i], GetFixedMenuWidth());
2006 2004
2007 if (!profile->IsSupervised()) { 2005 if (!profile->IsSupervised()) {
2008 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 2006 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
2009 2007
2010 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( 2008 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16(
2011 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); 2009 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this);
2012 add_account_link_->SetBorder(views::Border::CreateEmptyBorder( 2010 add_account_link_->SetBorder(
2013 0, views::kButtonVEdgeMarginNew, 2011 views::CreateEmptyBorder(0, views::kButtonVEdgeMarginNew,
2014 views::kRelatedControlVerticalSpacing, 0)); 2012 views::kRelatedControlVerticalSpacing, 0));
2015 layout->StartRow(1, 0); 2013 layout->StartRow(1, 0);
2016 layout->AddView(add_account_link_); 2014 layout->AddView(add_account_link_);
2017 } 2015 }
2018 2016
2019 return view; 2017 return view;
2020 } 2018 }
2021 2019
2022 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, 2020 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout,
2023 const std::string& account_id, 2021 const std::string& account_id,
2024 bool is_primary_account, 2022 bool is_primary_account,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2303 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2306 IncognitoModePrefs::DISABLED; 2304 IncognitoModePrefs::DISABLED;
2307 return incognito_available && !browser_->profile()->IsGuestSession(); 2305 return incognito_available && !browser_->profile()->IsGuestSession();
2308 } 2306 }
2309 2307
2310 void ProfileChooserView::PostActionPerformed( 2308 void ProfileChooserView::PostActionPerformed(
2311 ProfileMetrics::ProfileDesktopMenu action_performed) { 2309 ProfileMetrics::ProfileDesktopMenu action_performed) {
2312 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 2310 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
2313 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 2311 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
2314 } 2312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698