From 45c49245b053a1e2023a7e14e56c262b5c056639 Mon Sep 17 00:00:00 2001 From: "zhouleon.lei" Date: Tue, 25 Jan 2022 17:02:08 +0800 Subject: [PATCH] Add high contrast --- shell/platform/tizen/BUILD.gn | 1 + .../platform/tizen/accessibility_settings.cc | 69 +++++++++++++++++++ shell/platform/tizen/accessibility_settings.h | 27 ++++++++ shell/platform/tizen/flutter_tizen_engine.cc | 20 ++++++ shell/platform/tizen/flutter_tizen_engine.h | 6 ++ 5 files changed, 123 insertions(+) create mode 100755 shell/platform/tizen/accessibility_settings.cc create mode 100755 shell/platform/tizen/accessibility_settings.h diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index d32185962fe2b..c288dfeb59880 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -154,6 +154,7 @@ template("embedder") { if (embedder_for_target) { sources += [ + "accessibility_settings.cc", "channels/app_control.cc", "channels/app_control_channel.cc", "channels/platform_channel_tizen.cc", diff --git a/shell/platform/tizen/accessibility_settings.cc b/shell/platform/tizen/accessibility_settings.cc new file mode 100755 index 0000000000000..1c55b3cb1df51 --- /dev/null +++ b/shell/platform/tizen/accessibility_settings.cc @@ -0,0 +1,69 @@ +// Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "accessibility_settings.h" + +#ifdef TV_PROFILE +#include +#endif + +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" +#include "flutter/shell/platform/tizen/logger.h" + +// SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST = 10059 has been +// defined in system_settings_keys.h only for TV profile. +#define SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST 10059 + +namespace flutter { + +AccessibilitySettings::AccessibilitySettings(FlutterTizenEngine* engine) + : engine_(engine) { +#ifdef TV_PROFILE + // Add listener for accessibility high contrast. + system_settings_set_changed_cb( + system_settings_key_e( + SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST), + [](system_settings_key_e key, void* user_data) -> void { + auto* self = reinterpret_cast(user_data); + self->OnHighContrastStateChanged(); + }, + this); + + // Set initialized value of accessibility high contrast. + if (engine_ != nullptr) { + engine_->EnableAccessibilityFeature(GetHighContrastValue()); + } +#endif +} + +AccessibilitySettings::~AccessibilitySettings() { +#ifdef TV_PROFILE + system_settings_unset_changed_cb(system_settings_key_e( + SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST)); +#endif +} + +void AccessibilitySettings::OnHighContrastStateChanged() { + if (engine_ != nullptr) { + engine_->EnableAccessibilityFeature(GetHighContrastValue()); + } +} + +bool AccessibilitySettings::GetHighContrastValue() { + int enabled = 0; +#ifdef TV_PROFILE + int ret = system_settings_get_value_int( + system_settings_key_e( + SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST), + &enabled); + if (ret != SYSTEM_SETTINGS_ERROR_NONE) { + FT_LOG(Error) + << "Failed to get value of accessibility high contrast. ERROR CODE = " + << ret; + } +#endif + return enabled; +} + +} // namespace flutter diff --git a/shell/platform/tizen/accessibility_settings.h b/shell/platform/tizen/accessibility_settings.h new file mode 100755 index 0000000000000..f93cc85a0f2d0 --- /dev/null +++ b/shell/platform/tizen/accessibility_settings.h @@ -0,0 +1,27 @@ +// Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EMBEDDER_ACCESSIBILITY_SETTINGS_H_ +#define EMBEDDER_ACCESSIBILITY_SETTINGS_H_ + +namespace flutter { + +class FlutterTizenEngine; + +class AccessibilitySettings { + public: + explicit AccessibilitySettings(FlutterTizenEngine* engine); + virtual ~AccessibilitySettings(); + + void OnHighContrastStateChanged(); + + private: + bool GetHighContrastValue(); + + FlutterTizenEngine* engine_; +}; + +} // namespace flutter + +#endif // EMBEDDER_ACCESSIBILITY_SETTINGS_H_ diff --git a/shell/platform/tizen/flutter_tizen_engine.cc b/shell/platform/tizen/flutter_tizen_engine.cc index edd9e823bdc39..aaa4891bbcf2e 100644 --- a/shell/platform/tizen/flutter_tizen_engine.cc +++ b/shell/platform/tizen/flutter_tizen_engine.cc @@ -273,6 +273,10 @@ bool FlutterTizenEngine::RunEngine(const char* entrypoint) { SetWindowOrientation(0); } +#ifndef __X64_SHELL__ + accessibility_settings_ = std::make_unique(this); +#endif + SetupLocales(); return true; @@ -476,6 +480,22 @@ bool FlutterTizenEngine::MarkExternalTextureFrameAvailable(int64_t texture_id) { engine_, texture_id) == kSuccess); } +// Set bold font when accessibility high contrast state is +// changed. +void FlutterTizenEngine::EnableAccessibilityFeature(bool bold_text) { + if (engine_ == nullptr) { + return; + } + + if (bold_text) { + embedder_api_.UpdateAccessibilityFeatures( + engine_, kFlutterAccessibilityFeatureBoldText); + } else { + embedder_api_.UpdateAccessibilityFeatures(engine_, + FlutterAccessibilityFeature(0)); + } +} + // The Flutter Engine calls out to this function when new platform messages // are available. diff --git a/shell/platform/tizen/flutter_tizen_engine.h b/shell/platform/tizen/flutter_tizen_engine.h index 4423053e0a831..4a25645f7752b 100644 --- a/shell/platform/tizen/flutter_tizen_engine.h +++ b/shell/platform/tizen/flutter_tizen_engine.h @@ -12,6 +12,7 @@ #include "flutter/shell/platform/common/incoming_message_dispatcher.h" #include "flutter/shell/platform/embedder/embedder.h" #ifndef __X64_SHELL__ +#include "flutter/shell/platform/tizen/accessibility_settings.h" #include "flutter/shell/platform/tizen/channels/app_control_channel.h" #endif #include "flutter/shell/platform/tizen/channels/key_event_channel.h" @@ -169,6 +170,9 @@ class FlutterTizenEngine : public TizenRenderer::Delegate { // given |texture_id|. bool MarkExternalTextureFrameAvailable(int64_t texture_id); + // Set bold font when accessibility high contrast state is changed. + void EnableAccessibilityFeature(bool bold_text); + private: friend class EngineModifier; @@ -251,6 +255,8 @@ class FlutterTizenEngine : public TizenRenderer::Delegate { #ifndef __X64_SHELL__ // A plugin that implements the Tizen window channel. std::unique_ptr window_channel_; + + std::unique_ptr accessibility_settings_; #endif // The event loop for the main thread that allows for delayed task execution.