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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/profiles/profile_chooser_view.cc
diff --git a/chrome/browser/ui/views/profiles/profile_chooser_view.cc b/chrome/browser/ui/views/profiles/profile_chooser_view.cc
index 4cb0ca6cf201d885d0c5d6d9755ad8245dc36ddc..a2cab62517c2b9ec77653d17f87c60feafdaddf3 100644
--- a/chrome/browser/ui/views/profiles/profile_chooser_view.cc
+++ b/chrome/browser/ui/views/profiles/profile_chooser_view.cc
@@ -23,6 +23,8 @@
#include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/sync_ui_util.h"
+#include "chrome/browser/themes/theme_service.h"
+#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
@@ -185,9 +187,15 @@ views::ImageButton* CreateBackButton(views::ButtonListener* listener) {
// A custom button that allows for setting a background color when hovered over.
class BackgroundColorHoverButton : public views::LabelButton {
public:
- BackgroundColorHoverButton(views::ButtonListener* listener,
+ BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view,
const base::string16& text)
- : views::LabelButton(listener, text) {
+ : views::LabelButton(profile_chooser_view, text),
+ profile_chooser_view_(profile_chooser_view),
+ state_(views::Button::STATE_NORMAL),
+ title_(nullptr),
+ normal_title_color_(SK_ColorRED),
+ subtitle_(nullptr),
+ normal_subtitle_color_(SK_ColorRED) {
SetImageLabelSpacing(switches::IsMaterialDesignUserMenu()
? (kMaterialMenuEdgeMargin - 2)
: views::kItemLabelSpacing);
@@ -202,25 +210,69 @@ class BackgroundColorHoverButton : public views::LabelButton {
}
}
- BackgroundColorHoverButton(views::ButtonListener* listener,
+ BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view,
const base::string16& text,
const gfx::ImageSkia& icon)
- : BackgroundColorHoverButton(listener, text) {
+ : BackgroundColorHoverButton(profile_chooser_view, text) {
SetMinSize(gfx::Size(
icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing));
SetImage(STATE_NORMAL, icon);
}
+ 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.
+
+ void set_subtitle(views::Label* label) { subtitle_ = label; }
+
~BackgroundColorHoverButton() override {}
private:
- // views::LabelButton:
- void OnPaint(gfx::Canvas* canvas) override {
- if ((state() == STATE_PRESSED) ||
- (state() == STATE_HOVERED)) {
- canvas->DrawColor(profiles::kHoverColor);
+ 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.
+
+ ButtonState state_;
+
+ views::Label* title_;
+ SkColor normal_title_color_;
+
+ views::Label* subtitle_;
+ SkColor normal_subtitle_color_;
+
+ // views::CustomButton:
+ void StateChanged() override {
+ LabelButton::StateChanged();
+
+ views::Label* title = title_ ? title_ : label();
+
+ bool was_prelight = state_ == STATE_HOVERED || state_ == STATE_PRESSED;
+ bool is_prelight = state() == STATE_HOVERED || state() == STATE_PRESSED;
+ 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.
+ set_background(nullptr);
+ title->SetEnabledColor(normal_title_color_);
+ if (subtitle_)
+ subtitle_->SetDisabledColor(normal_subtitle_color_);
+ } else if (!was_prelight && is_prelight) {
+ SkColor bg_color = profiles::kHoverColor;
+ 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.
+ if (subtitle_)
+ normal_subtitle_color_ = subtitle_->disabled_color();
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+ if (ThemeServiceFactory::GetForProfile(
+ profile_chooser_view_->browser()->profile())
+ ->UsingSystemTheme()) {
+ // When using the system (GTK) theme, use the selected menuitem colors.
+ bg_color = GetNativeTheme()->GetSystemColor(
+ ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
+ title->SetEnabledColor(GetNativeTheme()->GetSystemColor(
+ ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
+ if (subtitle_) {
+ subtitle_->SetDisabledColor(GetNativeTheme()->GetSystemColor(
+ ui::NativeTheme::kColorId_MenuItemSubtitleColor));
+ }
+ }
+#endif
+ set_background(views::Background::CreateSolidBackground(bg_color));
}
- LabelButton::OnPaint(canvas);
+
+ 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.
}
DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton);
@@ -1671,8 +1723,9 @@ views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
views::kRelatedControlVerticalSpacing, 0));
// Container for the profile photo and avatar/user name.
- current_profile_card_ =
+ BackgroundColorHoverButton* current_profile_card =
new BackgroundColorHoverButton(this, base::string16());
+ current_profile_card_ = current_profile_card;
// Profile picture, left-aligned.
EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto(
@@ -1681,6 +1734,7 @@ views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
// Profile name, left-aligned to the right of profile icon.
views::Label* current_profile_name = new views::Label(
profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()));
+ current_profile_card->set_title(current_profile_name);
current_profile_name->SetFontList(
ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM));
@@ -1730,6 +1784,7 @@ views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
view->AddChildView(manage_accounts_button_);
} else {
views::Label* email_label = new views::Label(avatar_item.username);
+ current_profile_card->set_subtitle(email_label);
email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
email_label->SetEnabled(false);
email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);

Powered by Google App Engine
This is Rietveld 408576698