forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add high contrast accessibility support for TV (#237)
- Loading branch information
1 parent
eeee17d
commit dba8fff
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters