Skip to content

Commit

Permalink
accessibility: add enable-high-contrast option.
Browse files Browse the repository at this point in the history
This change add "enable-high-contrast" command-line option to request that UI be rendered with darker colors.

Related issues sony#2, sony#168

Signed-off-by: Hidenori Matsubayashi <[email protected]>
  • Loading branch information
HidenoriMatsubayashi committed Aug 16, 2023
1 parent 36af86f commit c906b87
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FlutterEmbedderOptions {
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddWithoutValue("enable-high-contrast", "i",
"Request that UI be rendered with darker colors.",
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -86,6 +89,7 @@ class FlutterEmbedderOptions {
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");
enable_high_contrast_ = options_.Exist("enable-high-contrast");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
Expand Down Expand Up @@ -161,6 +165,9 @@ class FlutterEmbedderOptions {
double TextScaleFactor() const {
return text_scale_factor_;
}
bool EnableHighContrast() const {
return enable_high_contrast_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -189,6 +196,7 @@ class FlutterEmbedderOptions {
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_high_contrast_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-drm-eglstream-backend/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char** argv) {
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.enable_high_contrast = options.EnableHighContrast();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
8 changes: 8 additions & 0 deletions examples/flutter-drm-gbm-backend/flutter_embedder_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FlutterEmbedderOptions {
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddWithoutValue("enable-high-contrast", "i",
"Request that UI be rendered with darker colors.",
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -86,6 +89,7 @@ class FlutterEmbedderOptions {
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");
enable_high_contrast_ = options_.Exist("enable-high-contrast");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
Expand Down Expand Up @@ -161,6 +165,9 @@ class FlutterEmbedderOptions {
double TextScaleFactor() const {
return text_scale_factor_;
}
bool EnableHighContrast() const {
return enable_high_contrast_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -189,6 +196,7 @@ class FlutterEmbedderOptions {
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_high_contrast_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-drm-gbm-backend/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char** argv) {
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.enable_high_contrast = options.EnableHighContrast();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FlutterEmbedderOptions {
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddWithoutValue("enable-high-contrast", "i",
"Request that UI be rendered with darker colors.",
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -86,6 +89,7 @@ class FlutterEmbedderOptions {
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");
enable_high_contrast_ = options_.Exist("enable-high-contrast");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
Expand Down Expand Up @@ -161,6 +165,9 @@ class FlutterEmbedderOptions {
double TextScaleFactor() const {
return text_scale_factor_;
}
bool EnableHighContrast() const {
return enable_high_contrast_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -189,6 +196,7 @@ class FlutterEmbedderOptions {
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_high_contrast_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-external-texture-plugin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char** argv) {
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.enable_high_contrast = options.EnableHighContrast();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FlutterEmbedderOptions {
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddWithoutValue("enable-high-contrast", "i",
"Request that UI be rendered with darker colors.",
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -86,6 +89,7 @@ class FlutterEmbedderOptions {
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");
enable_high_contrast_ = options_.Exist("enable-high-contrast");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
Expand Down Expand Up @@ -161,6 +165,9 @@ class FlutterEmbedderOptions {
double TextScaleFactor() const {
return text_scale_factor_;
}
bool EnableHighContrast() const {
return enable_high_contrast_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -189,6 +196,7 @@ class FlutterEmbedderOptions {
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_high_contrast_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-video-player-plugin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char** argv) {
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.enable_high_contrast = options.EnableHighContrast();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
8 changes: 8 additions & 0 deletions examples/flutter-wayland-client/flutter_embedder_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FlutterEmbedderOptions {
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddWithoutValue("enable-high-contrast", "i",
"Request that UI be rendered with darker colors.",
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -86,6 +89,7 @@ class FlutterEmbedderOptions {
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");
enable_high_contrast_ = options_.Exist("enable-high-contrast");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
Expand Down Expand Up @@ -161,6 +165,9 @@ class FlutterEmbedderOptions {
double TextScaleFactor() const {
return text_scale_factor_;
}
bool EnableHighContrast() const {
return enable_high_contrast_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -189,6 +196,7 @@ class FlutterEmbedderOptions {
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_high_contrast_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-wayland-client/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char** argv) {
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.enable_high_contrast = options.EnableHighContrast();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
8 changes: 8 additions & 0 deletions examples/flutter-x11-client/flutter_embedder_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FlutterEmbedderOptions {
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddWithoutValue("enable-high-contrast", "i",
"Request that UI be rendered with darker colors.",
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -86,6 +89,7 @@ class FlutterEmbedderOptions {
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");
enable_high_contrast_ = options_.Exist("enable-high-contrast");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
Expand Down Expand Up @@ -161,6 +165,9 @@ class FlutterEmbedderOptions {
double TextScaleFactor() const {
return text_scale_factor_;
}
bool EnableHighContrast() const {
return enable_high_contrast_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -189,6 +196,7 @@ class FlutterEmbedderOptions {
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_high_contrast_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-x11-client/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char** argv) {
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.enable_high_contrast = options.EnableHighContrast();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
1 change: 1 addition & 0 deletions src/client_wrapper/flutter_view_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ FlutterViewController::FlutterViewController(
c_view_properties.use_window_decoration =
view_properties.use_window_decoration;
c_view_properties.text_scale_factor = view_properties.text_scale_factor;
c_view_properties.enable_high_contrast = view_properties.enable_high_contrast;
c_view_properties.force_scale_factor = view_properties.force_scale_factor;
c_view_properties.scale_factor = view_properties.scale_factor;
c_view_properties.enable_vsync = view_properties.enable_vsync;
Expand Down
3 changes: 3 additions & 0 deletions src/client_wrapper/include/flutter/flutter_view_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class FlutterViewController {
// Text scaling factor.
double text_scale_factor;

// Enable high contrast. Request that UI be rendered with darker colors.
bool enable_high_contrast;

// Force scale factor specified by command line argument
bool force_scale_factor;
double scale_factor;
Expand Down
3 changes: 2 additions & 1 deletion src/flutter/shell/platform/linux_embedded/flutter_elinux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(
}

const float text_scaling_factor = view_properties->text_scale_factor;
state->view->GetEngine()->SetSystemSettings(text_scaling_factor);
state->view->GetEngine()->SetSystemSettings(
text_scaling_factor, view_properties->enable_high_contrast);
}

// Must happen after engine is running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,10 @@ void FlutterELinuxEngine::ReloadSystemFonts() {
embedder_api_.ReloadSystemFonts(engine_);
}

void FlutterELinuxEngine::SetSystemSettings(float text_scaling_factor) {
void FlutterELinuxEngine::SetSystemSettings(float text_scaling_factor,
bool enable_high_contrast) {
view_->UpdateTextScaleFactor(text_scaling_factor);

// TODO: add theme initial value support.
view_->UpdateHighContrastEnabled(false);

view_->UpdateHighContrastEnabled(enable_high_contrast);
SendSystemLocales();
}

Expand Down Expand Up @@ -437,4 +435,9 @@ void FlutterELinuxEngine::OnVsync(uint64_t last_frame_time_nanos,
frame_target_time_nanos);
}

void FlutterELinuxEngine::UpdateAccessibilityFeatures(
FlutterAccessibilityFeature flags) {
embedder_api_.UpdateAccessibilityFeatures(engine_, flags);
}

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ class FlutterELinuxEngine {
bool IsImpellerEnabled() const { return enable_impeller_; }

// Sets system settings.
void SetSystemSettings(float text_scaling_factor);
void SetSystemSettings(float text_scaling_factor, bool enable_high_contrast);

// Updates accessibility, e.g. switch to high contrast mode
void UpdateAccessibilityFeatures(FlutterAccessibilityFeature flags);

private:
// Allows swapping out embedder_api_ calls in tests.
Expand Down
11 changes: 10 additions & 1 deletion src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,16 @@ std::pair<double, double> FlutterELinuxView::GetPointerRotation(double x_px,
}

void FlutterELinuxView::UpdateHighContrastEnabled(bool enabled) {
// TODO: add UpdateAccessibilityFeatures support
int flags = 0;
if (enabled) {
flags |=
FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast;
} else {
flags &=
~FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast;
}
engine_.get()->UpdateAccessibilityFeatures(
static_cast<FlutterAccessibilityFeature>(flags));
settings_handler_->UpdateHighContrastMode(enabled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ void SettingsPlugin::SendSettings() {
}

bool SettingsPlugin::GetAlwaysUse24HourFormat() {
// The current OS does not have 24 hour format factor.
return true;
return is_always_use_24hour_format_;
}

void SettingsPlugin::UpdateAlwaysUse24HourFormat(
bool is_always_use_24hour_format) {
is_always_use_24hour_format_ = is_always_use_24hour_format;
SendSettings();
}

float SettingsPlugin::GetTextScaleFactor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class SettingsPlugin {
// Sends settings (e.g., platform brightness) to the engine.
void SendSettings();

// Update the always use 24hour-format status of the system.
void UpdateAlwaysUse24HourFormat(bool is_always_use_24hour_format);

// Update the high contrast status of the system.
void UpdateHighContrastMode(bool is_high_contrast);

Expand All @@ -50,6 +53,7 @@ class SettingsPlugin {
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_;
WindowBindingHandler* delegate_;
bool is_high_contrast_ = false;
bool is_always_use_24hour_format_ = true;
float text_scaling_factor_ = 1.0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ typedef struct {
// Text scaling factor.
double text_scale_factor;

// Enable high contrast. Request that UI be rendered with darker colors.
bool enable_high_contrast;

// Force scale factor specified by command line argument
bool force_scale_factor;
double scale_factor;
Expand Down

0 comments on commit c906b87

Please sign in to comment.