Commit b04cbd7e authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

mac: add high contrast theme

This change adds a high-contrast theme supplier (IncreasedContrastThemeSupplier)
and enables it on Mac when the system "Increase Contrast" setting is enabled,
or when --force-high-contrast is passed at startup. This theme maximizes
contrast between UI elements.

Bug: 831769
Change-Id: I6cbb1b67fd95372dd65501feab6639942f767019
Reviewed-on: https://chromium-review.googlesource.com/1142030Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576467}
parent 15b8ee56
......@@ -2936,6 +2936,8 @@ jumbo_split_static_library("browser") {
"themes/browser_theme_pack.h",
"themes/custom_theme_supplier.cc",
"themes/custom_theme_supplier.h",
"themes/increased_contrast_theme_supplier.cc",
"themes/increased_contrast_theme_supplier.h",
"themes/theme_properties.cc",
"themes/theme_service.cc",
"themes/theme_service.h",
......
......@@ -34,6 +34,7 @@ class CustomThemeSupplier
EXTENSION,
NATIVE_X11,
SUPERVISED_USER_THEME,
INCREASED_CONTRAST,
};
explicit CustomThemeSupplier(ThemeType type);
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/themes/increased_contrast_theme_supplier.h"
#include "chrome/browser/themes/theme_properties.h"
IncreasedContrastThemeSupplier::IncreasedContrastThemeSupplier()
: CustomThemeSupplier(INCREASED_CONTRAST) {}
IncreasedContrastThemeSupplier::~IncreasedContrastThemeSupplier() {}
// TODO(ellyjones): Follow up with a11y designers about these color choices.
bool IncreasedContrastThemeSupplier::GetColor(int id, SkColor* color) const {
switch (id) {
case ThemeProperties::COLOR_TAB_TEXT:
*color = SK_ColorBLACK;
return true;
case ThemeProperties::COLOR_BACKGROUND_TAB_TEXT:
*color = SK_ColorWHITE;
return true;
case ThemeProperties::COLOR_TOOLBAR:
*color = SK_ColorWHITE;
return true;
case ThemeProperties::COLOR_FRAME_INACTIVE:
*color = SK_ColorGRAY;
return true;
case ThemeProperties::COLOR_FRAME:
*color = SK_ColorDKGRAY;
return true;
case ThemeProperties::COLOR_FRAME_INCOGNITO:
*color = SK_ColorDKGRAY;
return true;
case ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR:
*color = SK_ColorLTGRAY;
return true;
case ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR:
*color = SK_ColorBLACK;
return true;
case ThemeProperties::COLOR_LOCATION_BAR_BORDER:
*color = SK_ColorBLACK;
return true;
}
return false;
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_THEMES_INCREASED_CONTRAST_THEME_SUPPLIER_H_
#define CHROME_BROWSER_THEMES_INCREASED_CONTRAST_THEME_SUPPLIER_H_
#include "chrome/browser/themes/custom_theme_supplier.h"
// A theme supplier that maximizes the contrast between UI elements and
// especially the visual prominence of key UI elements (omnibox, active vs
// inactive tab distinction).
class IncreasedContrastThemeSupplier : public CustomThemeSupplier {
public:
IncreasedContrastThemeSupplier();
bool GetColor(int id, SkColor* color) const override;
protected:
~IncreasedContrastThemeSupplier() override;
private:
DISALLOW_COPY_AND_ASSIGN(IncreasedContrastThemeSupplier);
};
#endif // CHROME_BROWSER_THEMES_INCREASED_CONTRAST_THEME_SUPPLIER_H_
......@@ -27,6 +27,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/browser_theme_pack.h"
#include "chrome/browser/themes/custom_theme_supplier.h"
#include "chrome/browser/themes/increased_contrast_theme_supplier.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/themes/theme_syncable_service.h"
......@@ -314,6 +315,11 @@ void ThemeService::UseDefaultTheme() {
SetSupervisedUserTheme();
return;
}
#endif
#if defined(OS_MACOSX)
// TODO(ellyjones): Expand ShouldIncreaseContrast() to non-Mac platforms.
if (original_theme_provider_.ShouldIncreaseContrast())
SetCustomDefaultTheme(new IncreasedContrastThemeSupplier);
#endif
ClearAllThemeData();
NotifyThemeChanged();
......
......@@ -118,9 +118,15 @@ namespace {
// Helper function to create a rounded rect background (no stroke).
std::unique_ptr<views::Background> CreateRoundRectBackground(SkColor bg_color,
float radius) {
std::unique_ptr<views::Background> background = CreateBackgroundFromPainter(
views::Painter::CreateSolidRoundRectPainter(bg_color, radius));
float radius,
SkColor fg_color) {
auto painter =
fg_color != SK_ColorTRANSPARENT
? views::Painter::CreateRoundRectWith1PxBorderPainter(
bg_color, fg_color, radius)
: views::Painter::CreateSolidRoundRectPainter(bg_color, radius);
std::unique_ptr<views::Background> background =
CreateBackgroundFromPainter(std::move(painter));
background->SetNativeControlColor(bg_color);
return background;
}
......@@ -789,8 +795,12 @@ void LocationBarView::RefreshBackground() {
if (is_popup_mode_) {
SetBackground(views::CreateSolidBackground(background_color));
} else if (IsRounded()) {
SetBackground(
CreateRoundRectBackground(background_color, GetBorderRadius()));
// High contrast schemes get a border stroke even on a rounded omnibox.
SkColor fg_color = GetNativeTheme()->UsesHighContrastColors()
? border_color
: SK_ColorTRANSPARENT;
SetBackground(CreateRoundRectBackground(background_color, GetBorderRadius(),
fg_color));
} else {
SetBackground(std::make_unique<BackgroundWith1PxBorder>(background_color,
border_color));
......
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