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

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: fix win build 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
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_chooser_view.h ('k') | ui/views/controls/label.h » ('j') | 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"
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 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
194 profile_chooser_view_(profile_chooser_view),
195 #endif
196 title_(nullptr),
197 subtitle_(nullptr) {
191 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu() 198 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu()
192 ? (kMaterialMenuEdgeMargin - 2) 199 ? (kMaterialMenuEdgeMargin - 2)
193 : views::kItemLabelSpacing); 200 : views::kItemLabelSpacing);
194 const int button_margin = switches::IsMaterialDesignUserMenu() 201 const int button_margin = switches::IsMaterialDesignUserMenu()
195 ? kMaterialMenuEdgeMargin 202 ? kMaterialMenuEdgeMargin
196 : views::kButtonHEdgeMarginNew; 203 : views::kButtonHEdgeMarginNew;
197 SetBorder(views::CreateEmptyBorder(0, button_margin, 0, button_margin)); 204 SetBorder(views::CreateEmptyBorder(0, button_margin, 0, button_margin));
198 SetFocusForPlatform(); 205 SetFocusForPlatform();
199 206
200 if (switches::IsMaterialDesignUserMenu()) { 207 if (switches::IsMaterialDesignUserMenu()) {
201 label()->SetHandlesTooltips(false); 208 label()->SetHandlesTooltips(false);
202 } 209 }
203 } 210 }
204 211
205 BackgroundColorHoverButton(views::ButtonListener* listener, 212 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view,
206 const base::string16& text, 213 const base::string16& text,
207 const gfx::ImageSkia& icon) 214 const gfx::ImageSkia& icon)
208 : BackgroundColorHoverButton(listener, text) { 215 : BackgroundColorHoverButton(profile_chooser_view, text) {
209 SetMinSize(gfx::Size( 216 SetMinSize(gfx::Size(
210 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing)); 217 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing));
211 SetImage(STATE_NORMAL, icon); 218 SetImage(STATE_NORMAL, icon);
212 } 219 }
213 220
221 // Overrides the main label associated with this button. If unset,
222 // label() will be used instead. |label| should be drawn over this
223 // button, but it is not necessary that it be a child view.
224 void set_title(views::Label* label) { title_ = label; }
225
226 // Sets a secondary label associated with this button. |label|
227 // should be drawn over this button, but it is not necessary that it
228 // be a child view.
229 void set_subtitle(views::Label* label) { subtitle_ = label; }
230
214 ~BackgroundColorHoverButton() override {} 231 ~BackgroundColorHoverButton() override {}
215 232
216 private: 233 private:
217 // views::LabelButton: 234 // views::View:
218 void OnPaint(gfx::Canvas* canvas) override { 235 void OnNativeThemeChanged(const ui::NativeTheme* theme) override {
219 if ((state() == STATE_PRESSED) || 236 // The first time the theme changes, the state will not be hovered
220 (state() == STATE_HOVERED)) { 237 // or pressed and the colors will be initialized. It's okay to
221 canvas->DrawColor(profiles::kHoverColor); 238 // reset the colors when the theme changes and the button is NOT
239 // hovered or pressed because the labels will be in a normal state.
240 if (state() == STATE_HOVERED || state() == STATE_PRESSED)
241 return;
242
243 LabelButton::OnNativeThemeChanged(theme);
244 views::Label* title = title_ ? title_ : label();
245 normal_title_color_ = title->enabled_color();
246 if (subtitle_)
247 normal_subtitle_color_ = subtitle_->disabled_color();
248 }
249
250 // views::CustomButton:
251 void StateChanged(ButtonState old_state) override {
252 LabelButton::StateChanged(old_state);
253
254 views::Label* title = title_ ? title_ : label();
255
256 bool was_prelight =
257 old_state == STATE_HOVERED || old_state == STATE_PRESSED;
258 bool is_prelight = state() == STATE_HOVERED || state() == STATE_PRESSED;
259 if (was_prelight && !is_prelight) {
260 // The pointer is no longer over this button. Set the
261 // background and text colors back to their normal states.
262 set_background(nullptr);
263 title->SetEnabledColor(normal_title_color_);
264 if (subtitle_)
265 subtitle_->SetDisabledColor(normal_subtitle_color_);
266 } else if (!was_prelight && is_prelight) {
267 // The pointer moved over this button. Set the background and
268 // text colors back to their hovered states.
269 SkColor bg_color = profiles::kHoverColor;
270 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
271 if (ThemeServiceFactory::GetForProfile(
272 profile_chooser_view_->browser()->profile())
273 ->UsingSystemTheme()) {
274 // When using the system (GTK) theme, use the selected menuitem colors.
275 bg_color = GetNativeTheme()->GetSystemColor(
276 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
277 title->SetEnabledColor(GetNativeTheme()->GetSystemColor(
278 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
279 if (subtitle_) {
280 subtitle_->SetDisabledColor(GetNativeTheme()->GetSystemColor(
281 ui::NativeTheme::kColorId_MenuItemSubtitleColor));
282 }
283 }
284 #endif
285 set_background(views::Background::CreateSolidBackground(bg_color));
222 } 286 }
223 LabelButton::OnPaint(canvas);
224 } 287 }
225 288
289 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
290 ProfileChooserView* profile_chooser_view_;
291 #endif
292
293 views::Label* title_;
294 SkColor normal_title_color_;
295
296 views::Label* subtitle_;
297 SkColor normal_subtitle_color_;
298
226 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton); 299 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton);
227 }; 300 };
228 301
229 // SizedContainer ------------------------------------------------- 302 // SizedContainer -------------------------------------------------
230 303
231 // A simple container view that takes an explicit preferred size. 304 // A simple container view that takes an explicit preferred size.
232 class SizedContainer : public views::View { 305 class SizedContainer : public views::View {
233 public: 306 public:
234 explicit SizedContainer(const gfx::Size& preferred_size) 307 explicit SizedContainer(const gfx::Size& preferred_size)
235 : preferred_size_(preferred_size) {} 308 : preferred_size_(preferred_size) {}
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 1737
1665 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( 1738 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
1666 const AvatarMenu::Item& avatar_item, 1739 const AvatarMenu::Item& avatar_item,
1667 bool is_guest) { 1740 bool is_guest) {
1668 views::View* view = new views::View(); 1741 views::View* view = new views::View();
1669 view->SetLayoutManager( 1742 view->SetLayoutManager(
1670 new views::BoxLayout(views::BoxLayout::kVertical, 0, 1743 new views::BoxLayout(views::BoxLayout::kVertical, 0,
1671 views::kRelatedControlVerticalSpacing, 0)); 1744 views::kRelatedControlVerticalSpacing, 0));
1672 1745
1673 // Container for the profile photo and avatar/user name. 1746 // Container for the profile photo and avatar/user name.
1674 current_profile_card_ = 1747 BackgroundColorHoverButton* current_profile_card =
1675 new BackgroundColorHoverButton(this, base::string16()); 1748 new BackgroundColorHoverButton(this, base::string16());
1749 current_profile_card_ = current_profile_card;
1676 1750
1677 // Profile picture, left-aligned. 1751 // Profile picture, left-aligned.
1678 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( 1752 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto(
1679 this, avatar_item.icon, !is_guest, browser_->profile()); 1753 this, avatar_item.icon, !is_guest, browser_->profile());
1680 1754
1681 // Profile name, left-aligned to the right of profile icon. 1755 // Profile name, left-aligned to the right of profile icon.
1682 views::Label* current_profile_name = new views::Label( 1756 views::Label* current_profile_name = new views::Label(
1683 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); 1757 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()));
1758 current_profile_card->set_title(current_profile_name);
1684 current_profile_name->SetFontList( 1759 current_profile_name->SetFontList(
1685 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( 1760 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
1686 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM)); 1761 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM));
1687 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1762 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1688 NonInteractiveContainer* profile_name_container = 1763 NonInteractiveContainer* profile_name_container =
1689 new NonInteractiveContainer(); 1764 new NonInteractiveContainer();
1690 int name_container_v_spacing = 1765 int name_container_v_spacing =
1691 (current_profile_photo->GetPreferredSize().height() - 1766 (current_profile_photo->GetPreferredSize().height() -
1692 current_profile_name->GetPreferredSize().height()) / 2; 1767 current_profile_name->GetPreferredSize().height()) / 2;
1693 views::BoxLayout* profile_name_layout = new views::BoxLayout( 1768 views::BoxLayout* profile_name_layout = new views::BoxLayout(
(...skipping 29 matching lines...) Expand all
1723 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON 1798 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON
1724 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 1799 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1725 manage_accounts_button_ = 1800 manage_accounts_button_ =
1726 new BackgroundColorHoverButton(this, button_text); 1801 new BackgroundColorHoverButton(this, button_text);
1727 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1802 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1728 manage_accounts_button_->SetMinSize( 1803 manage_accounts_button_->SetMinSize(
1729 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); 1804 gfx::Size(GetFixedMenuWidth(), kButtonHeight));
1730 view->AddChildView(manage_accounts_button_); 1805 view->AddChildView(manage_accounts_button_);
1731 } else { 1806 } else {
1732 views::Label* email_label = new views::Label(avatar_item.username); 1807 views::Label* email_label = new views::Label(avatar_item.username);
1808 current_profile_card->set_subtitle(email_label);
1733 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); 1809 email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
1734 email_label->SetEnabled(false); 1810 email_label->SetEnabled(false);
1735 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1811 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1736 name_container_v_spacing = 1812 name_container_v_spacing =
1737 (current_profile_photo->GetPreferredSize().height() - 1813 (current_profile_photo->GetPreferredSize().height() -
1738 current_profile_name->GetPreferredSize().height() - 1814 current_profile_name->GetPreferredSize().height() -
1739 email_label->GetPreferredSize().height()) / 2; 1815 email_label->GetPreferredSize().height()) / 2;
1740 profile_name_layout->set_inside_border_insets( 1816 profile_name_layout->set_inside_border_insets(
1741 gfx::Insets(name_container_v_spacing, 0)); 1817 gfx::Insets(name_container_v_spacing, 0));
1742 profile_name_container->AddChildView(email_label); 1818 profile_name_container->AddChildView(email_label);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2380 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2305 IncognitoModePrefs::DISABLED; 2381 IncognitoModePrefs::DISABLED;
2306 return incognito_available && !browser_->profile()->IsGuestSession(); 2382 return incognito_available && !browser_->profile()->IsGuestSession();
2307 } 2383 }
2308 2384
2309 void ProfileChooserView::PostActionPerformed( 2385 void ProfileChooserView::PostActionPerformed(
2310 ProfileMetrics::ProfileDesktopMenu action_performed) { 2386 ProfileMetrics::ProfileDesktopMenu action_performed) {
2311 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 2387 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
2312 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 2388 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
2313 } 2389 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_chooser_view.h ('k') | ui/views/controls/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698