Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might simply change the return type to bool.

Suggested change
return enabled;
return enabled != 0;

By the way cannot system_settings_set_value_bool be used instead of system_settings_get_value_int?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might simply change the return type to bool.

By the way cannot system_settings_set_value_bool be used instead of system_settings_get_value_int?

I had tried system_settings_set_value_bool, but met the parameter error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better than before. Thanks!

Thanks for your review. I have modified all of them.
Please check.

}

} // 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_
20 changes: 20 additions & 0 deletions shell/platform/tizen/flutter_tizen_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ bool FlutterTizenEngine::RunEngine(const char* entrypoint) {
SetWindowOrientation(0);
}

#ifndef __X64_SHELL__
accessibility_settings_ = std::make_unique<AccessibilitySettings>(this);
#endif

SetupLocales();

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

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 @@ -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"
Expand Down Expand Up @@ -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;

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

std::unique_ptr<AccessibilitySettings> accessibility_settings_;
#endif

// The event loop for the main thread that allows for delayed task execution.
Expand Down