Skip to content

Commit

Permalink
Add high contrast accessibility support for TV (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouleonlei authored and swift-kim committed Mar 4, 2022
1 parent eeee17d commit dba8fff
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
69 changes: 69 additions & 0 deletions shell/platform/tizen/accessibility_settings.cc
Original file line number Diff line number Diff line change
@@ -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 <system/system_settings.h>
#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<AccessibilitySettings*>(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
27 changes: 27 additions & 0 deletions shell/platform/tizen/accessibility_settings.h
Original file line number Diff line number Diff line change
@@ -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_
18 changes: 18 additions & 0 deletions shell/platform/tizen/flutter_tizen_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ bool FlutterTizenEngine::RunEngine(const char* entrypoint) {
SetWindowOrientation(0);
}

accessibility_settings_ = std::make_unique<AccessibilitySettings>(this);

SetupLocales();

return true;
Expand Down Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions shell/platform/tizen/flutter_tizen_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -245,6 +249,8 @@ class FlutterTizenEngine : public TizenRenderer::Delegate {
// A plugin that implements the Tizen window channel.
std::unique_ptr<WindowChannel> window_channel_;

std::unique_ptr<AccessibilitySettings> accessibility_settings_;

// The event loop for the main thread that allows for delayed task execution.
std::unique_ptr<TizenPlatformEventLoop> event_loop_;

Expand Down

0 comments on commit dba8fff

Please sign in to comment.