Commit 633a77ea authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Take the selected state of the tab into account for the text color.

Apply the tab selected state color into account in order to calculate the
proper contrast for the tab's text and icons.

Bug: 876794
Change-Id: Ie0db7e6eb5cd93c7b7d34098c88e9f06ff355d4d
Reviewed-on: https://chromium-review.googlesource.com/1188434
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585996}
parent 37e44dbf
...@@ -1065,6 +1065,10 @@ void Tab::FrameColorsChanged() { ...@@ -1065,6 +1065,10 @@ void Tab::FrameColorsChanged() {
SchedulePaint(); SchedulePaint();
} }
void Tab::SelectedStateChanged() {
OnButtonColorMaybeChanged();
}
bool Tab::IsSelected() const { bool Tab::IsSelected() const {
return controller_->IsTabSelected(this); return controller_->IsTabSelected(this);
} }
...@@ -1780,14 +1784,30 @@ void Tab::UpdateButtonIconColors(SkColor title_color) { ...@@ -1780,14 +1784,30 @@ void Tab::UpdateButtonIconColors(SkColor title_color) {
constexpr float kMinimumHoveredContrastRatio = 5.02f; constexpr float kMinimumHoveredContrastRatio = 5.02f;
constexpr float kMinimumPressedContrastRatio = 4.41f; constexpr float kMinimumPressedContrastRatio = 4.41f;
title_->SetEnabledColor(title_color); SkColor tab_bg_color = controller_->GetTabBackgroundColor(
const SkColor tab_bg_color = controller_->GetTabBackgroundColor(
IsActive() ? TAB_ACTIVE : TAB_INACTIVE, true); IsActive() ? TAB_ACTIVE : TAB_INACTIVE, true);
SkColor tab_title_color = title_color;
if (IsSelected() && !IsActive()) {
const SkColor tab_inactive_bg_color = tab_bg_color;
const SkColor tab_active_bg_color =
controller_->GetTabBackgroundColor(TAB_ACTIVE, true);
tab_bg_color = color_utils::AlphaBlend(
tab_active_bg_color, tab_bg_color,
gfx::ToRoundedInt(kSelectedTabOpacity * SK_AlphaOPAQUE));
const SkAlpha blend_alpha = color_utils::GetBlendValueWithMinimumContrast(
tab_bg_color, title_color, tab_inactive_bg_color,
kMinimumInactiveContrastRatio);
tab_title_color =
color_utils::AlphaBlend(title_color, tab_bg_color, blend_alpha);
}
title_->SetEnabledColor(tab_title_color);
const SkColor base_icon_color = const SkColor base_icon_color =
MD::GetMode() == ui::MaterialDesignController::MATERIAL_TOUCH_OPTIMIZED MD::GetMode() == ui::MaterialDesignController::MATERIAL_TOUCH_OPTIMIZED
? GetCloseTabButtonColor(views::Button::STATE_NORMAL) ? GetCloseTabButtonColor(views::Button::STATE_NORMAL)
: title_color; : tab_title_color;
const SkColor base_hovered_pressed_icon_color = const SkColor base_hovered_pressed_icon_color =
MD::IsNewerMaterialUi() ? base_icon_color : SK_ColorWHITE; MD::IsNewerMaterialUi() ? base_icon_color : SK_ColorWHITE;
const SkColor base_hovered_color = const SkColor base_hovered_color =
......
...@@ -139,6 +139,9 @@ class Tab : public gfx::AnimationDelegate, ...@@ -139,6 +139,9 @@ class Tab : public gfx::AnimationDelegate,
// Called when the frame state color changes. // Called when the frame state color changes.
void FrameColorsChanged(); void FrameColorsChanged();
// Called with the selected state changes.
void SelectedStateChanged();
// Returns true if the tab is selected. // Returns true if the tab is selected.
bool IsSelected() const; bool IsSelected() const;
......
...@@ -766,17 +766,24 @@ void TabStrip::SetSelection(const ui::ListSelectionModel& new_selection) { ...@@ -766,17 +766,24 @@ void TabStrip::SetSelection(const ui::ListSelectionModel& new_selection) {
new_selection.selected_indices(), selected_tabs_.selected_indices()); new_selection.selected_indices(), selected_tabs_.selected_indices());
// Fire accessibility events that reflect the changes to selection. // Fire accessibility events that reflect the changes to selection.
for (size_t i = 0; i < no_longer_selected.size(); ++i) { for (auto tab_index : no_longer_selected) {
tab_at(no_longer_selected[i]) tab_at(tab_index)->NotifyAccessibilityEvent(
->NotifyAccessibilityEvent(ax::mojom::Event::kSelectionRemove, true); ax::mojom::Event::kSelectionRemove, true);
} }
for (size_t i = 0; i < newly_selected.size(); ++i) { for (auto tab_index : newly_selected) {
tab_at(newly_selected[i]) tab_at(tab_index)->NotifyAccessibilityEvent(ax::mojom::Event::kSelectionAdd,
->NotifyAccessibilityEvent(ax::mojom::Event::kSelectionAdd, true); true);
} }
tab_at(new_selection.active()) tab_at(new_selection.active())
->NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true); ->NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true);
selected_tabs_ = new_selection; selected_tabs_ = new_selection;
// Notify all tabs whose selected state changed.
for (auto tab_index :
base::STLSetUnion<ui::ListSelectionModel::SelectedIndices>(
no_longer_selected, newly_selected)) {
tab_at(tab_index)->SelectedStateChanged();
}
} }
void TabStrip::SetTabNeedsAttention(int model_index, bool attention) { void TabStrip::SetTabNeedsAttention(int model_index, bool attention) {
......
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