Skip to content

Commit

Permalink
(#871) The dark mode implementation has been fixed. Settings should n…
Browse files Browse the repository at this point in the history
…ow be applied to the renderer process via the dark-mode-settings switch, which also needs the corresponding WebContentsForceDark feature to be enabled. This required the introduction of a hack in feature_list to enable the feature when the switch is present, avoiding the need for the user to use two separate flags to enable and use the feature. Furthermore, several options were duplicates with different labels. Now each option is unique, with the ability to have CIELAB/HSL/RGB-based forced darkening, both with and without selective image modification, as opposed to having duplicates of the CIELAB options.
  • Loading branch information
win32ss committed Oct 18, 2024
1 parent 9140148 commit 837ff97
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 65 deletions.
4 changes: 3 additions & 1 deletion base/feature_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <tuple>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/debug/crash_logging.h"
Expand Down Expand Up @@ -725,7 +726,8 @@ void FeatureList::FinalizeInitialization() {

bool FeatureList::IsFeatureEnabled(const Feature& feature) const {
OverrideState overridden_state = GetOverrideState(feature);

if(!strcmp(feature.name, "WebContentsForceDark") && base::CommandLine::ForCurrentProcess()->HasSwitch("dark-mode-settings"))
return true;
// If marked as OVERRIDE_USE_DEFAULT, simply return the default state below.
if (overridden_state != OVERRIDE_USE_DEFAULT)
return overridden_state == OVERRIDE_ENABLE_FEATURE;
Expand Down
81 changes: 18 additions & 63 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -840,66 +840,23 @@ const FeatureEntry::FeatureVariation kAccessibilityPageZoomVariations[] = {
#endif // BUILDFLAG(IS_ANDROID)

#if !BUILDFLAG(IS_CHROMEOS_ASH)
const FeatureEntry::FeatureParam kForceDark_SimpleHsl[] = {
{"inversion_method", "hsl_based"},
{"image_behavior", "none"},
{"foreground_lightness_threshold", "150"},
{"background_lightness_threshold", "205"}};

const FeatureEntry::FeatureParam kForceDark_SimpleCielab[] = {
{"inversion_method", "cielab_based"},
{"image_behavior", "none"},
{"foreground_lightness_threshold", "150"},
{"background_lightness_threshold", "205"}};

const FeatureEntry::FeatureParam kForceDark_SimpleRgb[] = {
{"inversion_method", "rgb_based"},
{"image_behavior", "none"},
{"foreground_lightness_threshold", "150"},
{"background_lightness_threshold", "205"}};

// Keep in sync with the kForceDark_SelectiveImageInversion
// in aw_feature_entries.cc if you tweak these parameters.
const FeatureEntry::FeatureParam kForceDark_SelectiveImageInversion[] = {
{"inversion_method", "cielab_based"},
{"image_behavior", "selective"},
{"foreground_lightness_threshold", "150"},
{"background_lightness_threshold", "205"}};

const FeatureEntry::FeatureParam kForceDark_SelectiveElementInversion[] = {
{"inversion_method", "cielab_based"},
{"image_behavior", "none"},
{"foreground_lightness_threshold", "150"},
{"background_lightness_threshold", "205"}};

const FeatureEntry::FeatureParam kForceDark_SelectiveGeneralInversion[] = {
{"inversion_method", "cielab_based"},
{"image_behavior", "selective"},
{"foreground_lightness_threshold", "150"},
{"background_lightness_threshold", "205"}};

const FeatureEntry::FeatureParam kForceDark_TransparencyAndNumColors[] = {
{"classifier_policy", "transparency_and_num_colors"}};

const FeatureEntry::FeatureVariation kForceDarkVariations[] = {
{"with simple HSL-based inversion", kForceDark_SimpleHsl,
std::size(kForceDark_SimpleHsl), nullptr},
{"with simple CIELAB-based inversion", kForceDark_SimpleCielab,
std::size(kForceDark_SimpleCielab), nullptr},
{"with simple RGB-based inversion", kForceDark_SimpleRgb,
std::size(kForceDark_SimpleRgb), nullptr},
{"with selective image inversion", kForceDark_SelectiveImageInversion,
std::size(kForceDark_SelectiveImageInversion), nullptr},
{"with selective inversion of non-image elements",
kForceDark_SelectiveElementInversion,
std::size(kForceDark_SelectiveElementInversion), nullptr},
{"with selective inversion of everything",
kForceDark_SelectiveGeneralInversion,
std::size(kForceDark_SelectiveGeneralInversion), nullptr},
const FeatureEntry::Choice kDarkModeSettings[] = {
{"Disabled", "", ""},
{"with simple HSL-based inversion", "dark-mode-settings",
"InversionAlgorithm=2,ImagePolicy=1,ForegroundBrightnessThreshold=150,BackgroundBrightnessThreshold=205"},
{"with simple CIELAB-based inversion", "dark-mode-settings",
"InversionAlgorithm=3,ImagePolicy=1,ForegroundBrightnessThreshold=150,BackgroundBrightnessThreshold=205"},
{"with simple RGB-based inversion", "dark-mode-settings",
"InversionAlgorithm=1,ImagePolicy=1,ForegroundBrightnessThreshold=150,BackgroundBrightnessThreshold=205"},
{"with selective CIELAB-based image inversion", "dark-mode-settings",
"InversionAlgorithm=3,ImagePolicy=2,ForegroundBrightnessThreshold=150,BackgroundBrightnessThreshold=205"},
{"with selective RGB-based image inversion", "dark-mode-settings",
"InversionAlgorithm=1,ImagePolicy=2,ForegroundBrightnessThreshold=150,BackgroundBrightnessThreshold=205"},
{"with selective HSL-based image inversion", "dark-mode-settings",
"InversionAlgorithm=2,ImagePolicy=2,ForegroundBrightnessThreshold=150,BackgroundBrightnessThreshold=205"},
{"with selective image inversion based on transparency and number of "
"colors",
kForceDark_TransparencyAndNumColors,
std::size(kForceDark_TransparencyAndNumColors), nullptr}};
"colors", "dark-mode-settings",
"InversionAlgorithm=2,ImagePolicy=2,ForegroundBrightnessThreshold=150,BackgroundBrightnessThreshold=205,ImageClassifierPolicy=1"}};
#endif // !BUILDFLAG(IS_CHROMEOS)

const FeatureEntry::FeatureParam
Expand Down Expand Up @@ -5428,16 +5385,14 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kRefreshFeedOnRestartDescription, kOsAndroid,
FEATURE_VALUE_TYPE(feed::kRefreshFeedOnRestart)},
#endif // BUILDFLAG(IS_ANDROID)
{"enable-force-dark", flag_descriptions::kAutoWebContentsDarkModeName,
{"dark-mode-settings", flag_descriptions::kAutoWebContentsDarkModeName,
flag_descriptions::kAutoWebContentsDarkModeDescription, kOsAll,
#if BUILDFLAG(IS_CHROMEOS_ASH)
// TODO(crbug.com/40651782): Investigate crash reports and
// re-enable variations for ChromeOS.
FEATURE_VALUE_TYPE(blink::features::kForceWebContentsDarkMode)},
#else
FEATURE_WITH_PARAMS_VALUE_TYPE(blink::features::kForceWebContentsDarkMode,
kForceDarkVariations,
"ForceDarkVariations")},
MULTI_VALUE_TYPE(kDarkModeSettings)},
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if BUILDFLAG(IS_ANDROID)
{"enable-accessibility-include-long-click-action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace {
const constexpr DarkModeInversionAlgorithm kDefaultDarkModeInversionAlgorithm =
DarkModeInversionAlgorithm::kInvertLightnessLAB;
const constexpr DarkModeImagePolicy kDefaultDarkModeImagePolicy =
DarkModeImagePolicy::kFilterNone;
DarkModeImagePolicy::kFilterSmart;
const constexpr DarkModeImageClassifierPolicy
kDefaultDarkModeImageClassifierPolicy =
DarkModeImageClassifierPolicy::kNumColorsWithMlFallback;
Expand Down

0 comments on commit 837ff97

Please sign in to comment.