diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 682114c7ed8e3..f2fc9a359e64c 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -100,6 +100,7 @@ template("embedder") { public = _public_headers sources = [ + "accessibility_settings.cc", "channels/app_control.cc", "channels/app_control_channel.cc", "channels/feedback_manager.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 8b91bfd9111e8..e8c3ad06c87f5 100644 --- a/shell/platform/tizen/flutter_tizen_engine.cc +++ b/shell/platform/tizen/flutter_tizen_engine.cc @@ -270,6 +270,8 @@ bool FlutterTizenEngine::RunEngine(const char* entrypoint) { SetWindowOrientation(0); } + accessibility_settings_ = std::make_unique(this); + SetupLocales(); return true; @@ -473,6 +475,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 74bb48a962f89..4f0a34f9e9206 100644 --- a/shell/platform/tizen/flutter_tizen_engine.h +++ b/shell/platform/tizen/flutter_tizen_engine.h @@ -11,6 +11,7 @@ #include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h" #include "flutter/shell/platform/common/incoming_message_dispatcher.h" #include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/shell/platform/tizen/accessibility_settings.h" #include "flutter/shell/platform/tizen/channels/app_control_channel.h" #include "flutter/shell/platform/tizen/channels/key_event_channel.h" #include "flutter/shell/platform/tizen/channels/lifecycle_channel.h" @@ -165,6 +166,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; @@ -245,6 +249,8 @@ class FlutterTizenEngine : public TizenRenderer::Delegate { // A plugin that implements the Tizen window channel. std::unique_ptr window_channel_; + std::unique_ptr accessibility_settings_; + // The event loop for the main thread that allows for delayed task execution. std::unique_ptr event_loop_;