Skip to content

Commit dba8fff

Browse files
zhouleonleiswift-kim
authored andcommitted
Add high contrast accessibility support for TV (#237)
1 parent eeee17d commit dba8fff

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

shell/platform/tizen/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ template("embedder") {
100100
public = _public_headers
101101

102102
sources = [
103+
"accessibility_settings.cc",
103104
"channels/app_control.cc",
104105
"channels/app_control_channel.cc",
105106
"channels/feedback_manager.cc",
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "accessibility_settings.h"
6+
7+
#ifdef TV_PROFILE
8+
#include <system/system_settings.h>
9+
#endif
10+
11+
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
12+
#include "flutter/shell/platform/tizen/logger.h"
13+
14+
// SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST = 10059 has been
15+
// defined in system_settings_keys.h only for TV profile.
16+
#define SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST 10059
17+
18+
namespace flutter {
19+
20+
AccessibilitySettings::AccessibilitySettings(FlutterTizenEngine* engine)
21+
: engine_(engine) {
22+
#ifdef TV_PROFILE
23+
// Add listener for accessibility high contrast.
24+
system_settings_set_changed_cb(
25+
system_settings_key_e(
26+
SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST),
27+
[](system_settings_key_e key, void* user_data) -> void {
28+
auto* self = reinterpret_cast<AccessibilitySettings*>(user_data);
29+
self->OnHighContrastStateChanged();
30+
},
31+
this);
32+
33+
// Set initialized value of accessibility high contrast.
34+
if (engine_ != nullptr) {
35+
engine_->EnableAccessibilityFeature(GetHighContrastValue());
36+
}
37+
#endif
38+
}
39+
40+
AccessibilitySettings::~AccessibilitySettings() {
41+
#ifdef TV_PROFILE
42+
system_settings_unset_changed_cb(system_settings_key_e(
43+
SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST));
44+
#endif
45+
}
46+
47+
void AccessibilitySettings::OnHighContrastStateChanged() {
48+
if (engine_ != nullptr) {
49+
engine_->EnableAccessibilityFeature(GetHighContrastValue());
50+
}
51+
}
52+
53+
bool AccessibilitySettings::GetHighContrastValue() {
54+
int enabled = 0;
55+
#ifdef TV_PROFILE
56+
int ret = system_settings_get_value_int(
57+
system_settings_key_e(
58+
SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST),
59+
&enabled);
60+
if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
61+
FT_LOG(Error)
62+
<< "Failed to get value of accessibility high contrast. ERROR CODE = "
63+
<< ret;
64+
}
65+
#endif
66+
return enabled;
67+
}
68+
69+
} // namespace flutter
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef EMBEDDER_ACCESSIBILITY_SETTINGS_H_
6+
#define EMBEDDER_ACCESSIBILITY_SETTINGS_H_
7+
8+
namespace flutter {
9+
10+
class FlutterTizenEngine;
11+
12+
class AccessibilitySettings {
13+
public:
14+
explicit AccessibilitySettings(FlutterTizenEngine* engine);
15+
virtual ~AccessibilitySettings();
16+
17+
void OnHighContrastStateChanged();
18+
19+
private:
20+
bool GetHighContrastValue();
21+
22+
FlutterTizenEngine* engine_;
23+
};
24+
25+
} // namespace flutter
26+
27+
#endif // EMBEDDER_ACCESSIBILITY_SETTINGS_H_

shell/platform/tizen/flutter_tizen_engine.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ bool FlutterTizenEngine::RunEngine(const char* entrypoint) {
270270
SetWindowOrientation(0);
271271
}
272272

273+
accessibility_settings_ = std::make_unique<AccessibilitySettings>(this);
274+
273275
SetupLocales();
274276

275277
return true;
@@ -473,6 +475,22 @@ bool FlutterTizenEngine::MarkExternalTextureFrameAvailable(int64_t texture_id) {
473475
engine_, texture_id) == kSuccess);
474476
}
475477

478+
// Set bold font when accessibility high contrast state is
479+
// changed.
480+
void FlutterTizenEngine::EnableAccessibilityFeature(bool bold_text) {
481+
if (engine_ == nullptr) {
482+
return;
483+
}
484+
485+
if (bold_text) {
486+
embedder_api_.UpdateAccessibilityFeatures(
487+
engine_, kFlutterAccessibilityFeatureBoldText);
488+
} else {
489+
embedder_api_.UpdateAccessibilityFeatures(engine_,
490+
FlutterAccessibilityFeature(0));
491+
}
492+
}
493+
476494
// The Flutter Engine calls out to this function when new platform messages
477495
// are available.
478496

shell/platform/tizen/flutter_tizen_engine.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
1212
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
1313
#include "flutter/shell/platform/embedder/embedder.h"
14+
#include "flutter/shell/platform/tizen/accessibility_settings.h"
1415
#include "flutter/shell/platform/tizen/channels/app_control_channel.h"
1516
#include "flutter/shell/platform/tizen/channels/key_event_channel.h"
1617
#include "flutter/shell/platform/tizen/channels/lifecycle_channel.h"
@@ -165,6 +166,9 @@ class FlutterTizenEngine : public TizenRenderer::Delegate {
165166
// given |texture_id|.
166167
bool MarkExternalTextureFrameAvailable(int64_t texture_id);
167168

169+
// Set bold font when accessibility high contrast state is changed.
170+
void EnableAccessibilityFeature(bool bold_text);
171+
168172
private:
169173
friend class EngineModifier;
170174

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

252+
std::unique_ptr<AccessibilitySettings> accessibility_settings_;
253+
248254
// The event loop for the main thread that allows for delayed task execution.
249255
std::unique_ptr<TizenPlatformEventLoop> event_loop_;
250256

0 commit comments

Comments
 (0)