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

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

Issue 2624683002: Linux UI: Fix profile chooser button background color (Closed)
Patch Set: Rewrite Created 3 years, 10 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
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"
11 #include "chrome/browser/lifetime/application_lifetime.h" 11 #include "chrome/browser/lifetime/application_lifetime.h"
12 #include "chrome/browser/prefs/incognito_mode_prefs.h" 12 #include "chrome/browser/prefs/incognito_mode_prefs.h"
13 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 13 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/profiles/profile_metrics.h" 15 #include "chrome/browser/profiles/profile_metrics.h"
16 #include "chrome/browser/profiles/profile_window.h" 16 #include "chrome/browser/profiles/profile_window.h"
17 #include "chrome/browser/profiles/profiles_state.h" 17 #include "chrome/browser/profiles/profiles_state.h"
18 #include "chrome/browser/signin/chrome_signin_helper.h" 18 #include "chrome/browser/signin/chrome_signin_helper.h"
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
20 #include "chrome/browser/signin/signin_error_controller_factory.h" 20 #include "chrome/browser/signin/signin_error_controller_factory.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/signin/signin_promo.h" 22 #include "chrome/browser/signin/signin_promo.h"
23 #include "chrome/browser/signin/signin_ui_util.h" 23 #include "chrome/browser/signin/signin_ui_util.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/sync/sync_ui_util.h" 25 #include "chrome/browser/sync/sync_ui_util.h"
26 #include "chrome/browser/themes/theme_service.h"
27 #include "chrome/browser/themes/theme_service_factory.h"
26 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h" 29 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_dialogs.h" 30 #include "chrome/browser/ui/browser_dialogs.h"
29 #include "chrome/browser/ui/browser_list.h" 31 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/chrome_pages.h" 32 #include "chrome/browser/ui/chrome_pages.h"
31 #include "chrome/browser/ui/profile_chooser_constants.h" 33 #include "chrome/browser/ui/profile_chooser_constants.h"
32 #include "chrome/browser/ui/singleton_tabs.h" 34 #include "chrome/browser/ui/singleton_tabs.h"
33 #include "chrome/browser/ui/user_manager.h" 35 #include "chrome/browser/ui/user_manager.h"
34 #include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views .h" 36 #include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views .h"
35 #include "chrome/browser/ui/views/profiles/user_manager_view.h" 37 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 rb->GetImageSkiaNamed(IDR_BACK_D)); 180 rb->GetImageSkiaNamed(IDR_BACK_D));
179 back_button->SetFocusForPlatform(); 181 back_button->SetFocusForPlatform();
180 return back_button; 182 return back_button;
181 } 183 }
182 184
183 // BackgroundColorHoverButton ------------------------------------------------- 185 // BackgroundColorHoverButton -------------------------------------------------
184 186
185 // A custom button that allows for setting a background color when hovered over. 187 // A custom button that allows for setting a background color when hovered over.
186 class BackgroundColorHoverButton : public views::LabelButton { 188 class BackgroundColorHoverButton : public views::LabelButton {
187 public: 189 public:
188 BackgroundColorHoverButton(views::ButtonListener* listener, 190 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view,
189 const base::string16& text) 191 const base::string16& text)
190 : views::LabelButton(listener, text) { 192 : views::LabelButton(profile_chooser_view, text),
193 profile_chooser_view_(profile_chooser_view),
194 state_(views::Button::STATE_NORMAL),
195 title_(nullptr),
196 normal_title_color_(SK_ColorRED),
197 subtitle_(nullptr),
198 normal_subtitle_color_(SK_ColorRED) {
191 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu() 199 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu()
192 ? (kMaterialMenuEdgeMargin - 2) 200 ? (kMaterialMenuEdgeMargin - 2)
193 : views::kItemLabelSpacing); 201 : views::kItemLabelSpacing);
194 const int button_margin = switches::IsMaterialDesignUserMenu() 202 const int button_margin = switches::IsMaterialDesignUserMenu()
195 ? kMaterialMenuEdgeMargin 203 ? kMaterialMenuEdgeMargin
196 : views::kButtonHEdgeMarginNew; 204 : views::kButtonHEdgeMarginNew;
197 SetBorder(views::CreateEmptyBorder(0, button_margin, 0, button_margin)); 205 SetBorder(views::CreateEmptyBorder(0, button_margin, 0, button_margin));
198 SetFocusForPlatform(); 206 SetFocusForPlatform();
199 207
200 if (switches::IsMaterialDesignUserMenu()) { 208 if (switches::IsMaterialDesignUserMenu()) {
201 label()->SetHandlesTooltips(false); 209 label()->SetHandlesTooltips(false);
202 } 210 }
203 } 211 }
204 212
205 BackgroundColorHoverButton(views::ButtonListener* listener, 213 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view,
206 const base::string16& text, 214 const base::string16& text,
207 const gfx::ImageSkia& icon) 215 const gfx::ImageSkia& icon)
208 : BackgroundColorHoverButton(listener, text) { 216 : BackgroundColorHoverButton(profile_chooser_view, text) {
209 SetMinSize(gfx::Size( 217 SetMinSize(gfx::Size(
210 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing)); 218 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing));
211 SetImage(STATE_NORMAL, icon); 219 SetImage(STATE_NORMAL, icon);
212 } 220 }
213 221
222 void set_title(views::Label* label) { title_ = label; }
sky 2017/02/06 22:56:41 Document what title and subtitle are for. At first
Tom (Use chromium acct) 2017/02/07 00:45:24 Done.
223
224 void set_subtitle(views::Label* label) { subtitle_ = label; }
225
214 ~BackgroundColorHoverButton() override {} 226 ~BackgroundColorHoverButton() override {}
215 227
216 private: 228 private:
217 // views::LabelButton: 229 ProfileChooserView* profile_chooser_view_;
sky 2017/02/06 22:56:40 functions then members.
Tom (Use chromium acct) 2017/02/07 00:45:24 Done.
218 void OnPaint(gfx::Canvas* canvas) override { 230
219 if ((state() == STATE_PRESSED) || 231 ButtonState state_;
220 (state() == STATE_HOVERED)) { 232
221 canvas->DrawColor(profiles::kHoverColor); 233 views::Label* title_;
234 SkColor normal_title_color_;
235
236 views::Label* subtitle_;
237 SkColor normal_subtitle_color_;
238
239 // views::CustomButton:
240 void StateChanged() override {
241 LabelButton::StateChanged();
242
243 views::Label* title = title_ ? title_ : label();
244
245 bool was_prelight = state_ == STATE_HOVERED || state_ == STATE_PRESSED;
246 bool is_prelight = state() == STATE_HOVERED || state() == STATE_PRESSED;
247 if (was_prelight && !is_prelight) {
sky 2017/02/06 22:56:40 This code is fairly complex and warrants a descrip
Tom (Use chromium acct) 2017/02/07 00:45:24 Done.
248 set_background(nullptr);
249 title->SetEnabledColor(normal_title_color_);
250 if (subtitle_)
251 subtitle_->SetDisabledColor(normal_subtitle_color_);
252 } else if (!was_prelight && is_prelight) {
253 SkColor bg_color = profiles::kHoverColor;
254 normal_title_color_ = title->enabled_color();
sky 2017/02/06 22:56:40 Do you have to keep caching the colors? Can you as
Tom (Use chromium acct) 2017/02/07 00:45:24 Done.
255 if (subtitle_)
256 normal_subtitle_color_ = subtitle_->disabled_color();
257 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
258 if (ThemeServiceFactory::GetForProfile(
259 profile_chooser_view_->browser()->profile())
260 ->UsingSystemTheme()) {
261 // When using the system (GTK) theme, use the selected menuitem colors.
262 bg_color = GetNativeTheme()->GetSystemColor(
263 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
264 title->SetEnabledColor(GetNativeTheme()->GetSystemColor(
265 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
266 if (subtitle_) {
267 subtitle_->SetDisabledColor(GetNativeTheme()->GetSystemColor(
268 ui::NativeTheme::kColorId_MenuItemSubtitleColor));
269 }
270 }
271 #endif
272 set_background(views::Background::CreateSolidBackground(bg_color));
222 } 273 }
223 LabelButton::OnPaint(canvas); 274
275 state_ = state();
sky 2017/02/06 22:56:41 You shouldn't have to cache the old state. StateCh
Tom (Use chromium acct) 2017/02/07 00:45:24 Done.
224 } 276 }
225 277
226 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton); 278 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton);
227 }; 279 };
228 280
229 // SizedContainer ------------------------------------------------- 281 // SizedContainer -------------------------------------------------
230 282
231 // A simple container view that takes an explicit preferred size. 283 // A simple container view that takes an explicit preferred size.
232 class SizedContainer : public views::View { 284 class SizedContainer : public views::View {
233 public: 285 public:
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 1716
1665 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( 1717 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
1666 const AvatarMenu::Item& avatar_item, 1718 const AvatarMenu::Item& avatar_item,
1667 bool is_guest) { 1719 bool is_guest) {
1668 views::View* view = new views::View(); 1720 views::View* view = new views::View();
1669 view->SetLayoutManager( 1721 view->SetLayoutManager(
1670 new views::BoxLayout(views::BoxLayout::kVertical, 0, 1722 new views::BoxLayout(views::BoxLayout::kVertical, 0,
1671 views::kRelatedControlVerticalSpacing, 0)); 1723 views::kRelatedControlVerticalSpacing, 0));
1672 1724
1673 // Container for the profile photo and avatar/user name. 1725 // Container for the profile photo and avatar/user name.
1674 current_profile_card_ = 1726 BackgroundColorHoverButton* current_profile_card =
1675 new BackgroundColorHoverButton(this, base::string16()); 1727 new BackgroundColorHoverButton(this, base::string16());
1728 current_profile_card_ = current_profile_card;
1676 1729
1677 // Profile picture, left-aligned. 1730 // Profile picture, left-aligned.
1678 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( 1731 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto(
1679 this, avatar_item.icon, !is_guest, browser_->profile()); 1732 this, avatar_item.icon, !is_guest, browser_->profile());
1680 1733
1681 // Profile name, left-aligned to the right of profile icon. 1734 // Profile name, left-aligned to the right of profile icon.
1682 views::Label* current_profile_name = new views::Label( 1735 views::Label* current_profile_name = new views::Label(
1683 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); 1736 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()));
1737 current_profile_card->set_title(current_profile_name);
1684 current_profile_name->SetFontList( 1738 current_profile_name->SetFontList(
1685 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( 1739 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
1686 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM)); 1740 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM));
1687 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1741 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1688 NonInteractiveContainer* profile_name_container = 1742 NonInteractiveContainer* profile_name_container =
1689 new NonInteractiveContainer(); 1743 new NonInteractiveContainer();
1690 int name_container_v_spacing = 1744 int name_container_v_spacing =
1691 (current_profile_photo->GetPreferredSize().height() - 1745 (current_profile_photo->GetPreferredSize().height() -
1692 current_profile_name->GetPreferredSize().height()) / 2; 1746 current_profile_name->GetPreferredSize().height()) / 2;
1693 views::BoxLayout* profile_name_layout = new views::BoxLayout( 1747 views::BoxLayout* profile_name_layout = new views::BoxLayout(
(...skipping 29 matching lines...) Expand all
1723 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON 1777 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON
1724 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 1778 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1725 manage_accounts_button_ = 1779 manage_accounts_button_ =
1726 new BackgroundColorHoverButton(this, button_text); 1780 new BackgroundColorHoverButton(this, button_text);
1727 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1781 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1728 manage_accounts_button_->SetMinSize( 1782 manage_accounts_button_->SetMinSize(
1729 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); 1783 gfx::Size(GetFixedMenuWidth(), kButtonHeight));
1730 view->AddChildView(manage_accounts_button_); 1784 view->AddChildView(manage_accounts_button_);
1731 } else { 1785 } else {
1732 views::Label* email_label = new views::Label(avatar_item.username); 1786 views::Label* email_label = new views::Label(avatar_item.username);
1787 current_profile_card->set_subtitle(email_label);
1733 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); 1788 email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
1734 email_label->SetEnabled(false); 1789 email_label->SetEnabled(false);
1735 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1790 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1736 name_container_v_spacing = 1791 name_container_v_spacing =
1737 (current_profile_photo->GetPreferredSize().height() - 1792 (current_profile_photo->GetPreferredSize().height() -
1738 current_profile_name->GetPreferredSize().height() - 1793 current_profile_name->GetPreferredSize().height() -
1739 email_label->GetPreferredSize().height()) / 2; 1794 email_label->GetPreferredSize().height()) / 2;
1740 profile_name_layout->set_inside_border_insets( 1795 profile_name_layout->set_inside_border_insets(
1741 gfx::Insets(name_container_v_spacing, 0)); 1796 gfx::Insets(name_container_v_spacing, 0));
1742 profile_name_container->AddChildView(email_label); 1797 profile_name_container->AddChildView(email_label);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2359 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2305 IncognitoModePrefs::DISABLED; 2360 IncognitoModePrefs::DISABLED;
2306 return incognito_available && !browser_->profile()->IsGuestSession(); 2361 return incognito_available && !browser_->profile()->IsGuestSession();
2307 } 2362 }
2308 2363
2309 void ProfileChooserView::PostActionPerformed( 2364 void ProfileChooserView::PostActionPerformed(
2310 ProfileMetrics::ProfileDesktopMenu action_performed) { 2365 ProfileMetrics::ProfileDesktopMenu action_performed) {
2311 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 2366 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
2312 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 2367 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
2313 } 2368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698