Commit dc2407bc authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Fix Sync promo background not responding to theme changes

R=pkasting
BUG=914974

Change-Id: I55b5a93b9e217ec0bc5a81f5246db5efbc568b64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073272
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744759}
parent 0c7dc288
......@@ -100,16 +100,6 @@ int CountBrowsersFor(Profile* profile) {
return browser_count;
}
SkColor GetSyncErrorBackgroundColor(bool sync_paused) {
constexpr int kAlpha = 16;
ui::NativeTheme::ColorId base_color_id =
sync_paused ? ui::NativeTheme::kColorId_ProminentButtonColor
: ui::NativeTheme::kColorId_AlertSeverityHigh;
SkColor base_color =
ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor(base_color_id);
return SkColorSetA(base_color, kAlpha);
}
bool IsSyncPaused(Profile* profile) {
int unused;
return sync_ui_util::GetMessagesForAvatarSyncError(
......@@ -463,6 +453,7 @@ void ProfileMenuView::BuildSyncInfo() {
GetSyncIcon(),
/*description=*/base::string16(),
l10n_util::GetStringUTF16(IDS_PROFILES_OPEN_SYNC_SETTINGS_BUTTON),
SyncInfoContainerBackgroundState::kNoError,
base::BindRepeating(&ProfileMenuView::OnSyncSettingsButtonClicked,
base::Unretained(this)));
} else {
......@@ -481,9 +472,10 @@ void ProfileMenuView::BuildSyncInfo() {
SetSyncInfo(
GetSyncIcon(), l10n_util::GetStringUTF16(description_string_id),
l10n_util::GetStringUTF16(button_string_id),
sync_paused ? SyncInfoContainerBackgroundState::kPaused
: SyncInfoContainerBackgroundState::kError,
base::BindRepeating(&ProfileMenuView::OnSyncErrorButtonClicked,
base::Unretained(this), error));
SetSyncInfoBackgroundColor(GetSyncErrorBackgroundColor(sync_paused));
}
return;
}
......@@ -500,19 +492,17 @@ void ProfileMenuView::BuildSyncInfo() {
GetSyncIcon(),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_NOT_SYNCING_TITLE),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON),
SyncInfoContainerBackgroundState::kNoPrimaryAccount,
base::BindRepeating(&ProfileMenuView::OnSigninAccountButtonClicked,
base::Unretained(this), account_info.value()));
} else {
SetSyncInfo(/*icon=*/gfx::ImageSkia(),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SYNC_PROMO),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON),
SyncInfoContainerBackgroundState::kNoPrimaryAccount,
base::BindRepeating(&ProfileMenuView::OnSigninButtonClicked,
base::Unretained(this)));
}
SetSyncInfoBackgroundColor(
ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor(
ui::NativeTheme::kColorId_HighlightedMenuItemBackgroundColor));
}
void ProfileMenuView::BuildFeatureButtons() {
......
......@@ -312,10 +312,12 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::ImageSkia& image,
}
}
void ProfileMenuViewBase::SetSyncInfo(const gfx::ImageSkia& icon,
const base::string16& description,
const base::string16& clickable_text,
base::RepeatingClosure action) {
void ProfileMenuViewBase::SetSyncInfo(
const gfx::ImageSkia& icon,
const base::string16& description,
const base::string16& clickable_text,
SyncInfoContainerBackgroundState sync_background_state,
base::RepeatingClosure action) {
constexpr int kIconSize = 16;
const int kDescriptionIconSpacing =
ChromeLayoutProvider::Get()->GetDistanceMetric(
......@@ -325,6 +327,9 @@ void ProfileMenuViewBase::SetSyncInfo(const gfx::ImageSkia& icon,
const int kBorderCornerRadius =
views::LayoutProvider::Get()->GetCornerRadiusMetric(views::EMPHASIS_HIGH);
sync_background_state_ = sync_background_state;
UpdateSyncInfoContainerBackground();
sync_info_container_->RemoveAllChildViews(/*delete_children=*/true);
sync_info_container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(), kInsidePadding));
......@@ -375,12 +380,6 @@ void ProfileMenuViewBase::SetSyncInfo(const gfx::ImageSkia& icon,
RegisterClickAction(button, std::move(action));
}
void ProfileMenuViewBase::SetSyncInfoBackgroundColor(SkColor bg_color) {
sync_info_container_->SetBackground(views::CreateRoundedRectBackground(
bg_color, views::LayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_HIGH)));
}
void ProfileMenuViewBase::AddShortcutFeatureButton(
const gfx::ImageSkia& icon,
const base::string16& text,
......@@ -547,6 +546,7 @@ void ProfileMenuViewBase::OnThemeChanged() {
views::BubbleDialogDelegateView::OnThemeChanged();
SetBackground(views::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DialogBackground)));
UpdateSyncInfoContainerBackground();
}
bool ProfileMenuViewBase::HandleContextMenu(
......@@ -671,6 +671,29 @@ void ProfileMenuViewBase::RegisterClickAction(views::View* clickable_view,
click_actions_[clickable_view] = std::move(action);
}
void ProfileMenuViewBase::UpdateSyncInfoContainerBackground() {
ui::NativeTheme::ColorId bg_color;
SkAlpha alpha = 16;
switch (sync_background_state_) {
case SyncInfoContainerBackgroundState::kNoError:
sync_info_container_->SetBackground(nullptr);
return;
case SyncInfoContainerBackgroundState::kPaused:
bg_color = ui::NativeTheme::kColorId_ProminentButtonColor;
break;
case SyncInfoContainerBackgroundState::kError:
bg_color = ui::NativeTheme::kColorId_AlertSeverityHigh;
break;
case SyncInfoContainerBackgroundState::kNoPrimaryAccount:
bg_color = ui::NativeTheme::kColorId_HighlightedMenuItemBackgroundColor;
alpha = SK_AlphaOPAQUE;
}
sync_info_container_->SetBackground(views::CreateRoundedRectBackground(
SkColorSetA(GetNativeTheme()->GetSystemColor(bg_color), alpha),
views::LayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_HIGH)));
}
void ProfileMenuViewBase::FocusButtonOnKeyboardOpen() {
if (first_profile_button_)
first_profile_button_->RequestFocus();
......
......@@ -62,6 +62,13 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
kMaxValue = kEditProfileButton,
};
enum class SyncInfoContainerBackgroundState {
kNoError,
kPaused,
kError,
kNoPrimaryAccount,
};
// Shows the bubble if one is not already showing. This allows us to easily
// make a button toggle the bubble on and off when clicked: we unconditionally
// call this function when the button is clicked and if the bubble isn't
......@@ -96,8 +103,8 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
void SetSyncInfo(const gfx::ImageSkia& icon,
const base::string16& description,
const base::string16& clickable_text,
SyncInfoContainerBackgroundState background_state,
base::RepeatingClosure action);
void SetSyncInfoBackgroundColor(SkColor bg_color);
void AddShortcutFeatureButton(const gfx::ImageSkia& icon,
const base::string16& text,
base::RepeatingClosure action);
......@@ -173,6 +180,8 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
void RegisterClickAction(views::View* clickable_view,
base::RepeatingClosure action);
void UpdateSyncInfoContainerBackground();
Browser* const browser_;
views::Button* const anchor_button_;
......@@ -197,6 +206,9 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
CloseBubbleOnTabActivationHelper close_bubble_helper_;
SyncInfoContainerBackgroundState sync_background_state_ =
SyncInfoContainerBackgroundState::kNoError;
DISALLOW_COPY_AND_ASSIGN(ProfileMenuViewBase);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment