Add FlutterWindowsEngine::DispatchSemanticsAction (flutter/engine#29278)

Adds method for dispatching a semantics action received from the OS to
the matching node in Flutter's semantics tree.

Issue: https://github.com/flutter/flutter/issues/77838
This commit is contained in:
Chris Bracken
2021-10-20 23:33:19 -07:00
committed by GitHub
parent e8133209b9
commit 746ed52a12
3 changed files with 37 additions and 0 deletions

View File

@@ -444,4 +444,12 @@ bool FlutterWindowsEngine::MarkExternalTextureFrameAvailable(
engine_, texture_id) == kSuccess);
}
bool FlutterWindowsEngine::DispatchSemanticsAction(
uint64_t target,
FlutterSemanticsAction action,
const std::vector<uint8_t>& data) {
return (embedder_api_.DispatchSemanticsAction(
engine_, target, action, data.data(), data.size()) == kSuccess);
}
} // namespace flutter

View File

@@ -144,6 +144,11 @@ class FlutterWindowsEngine {
// given |texture_id|.
bool MarkExternalTextureFrameAvailable(int64_t texture_id);
// Dispatches a semantics action to the specified semantics node.
bool DispatchSemanticsAction(uint64_t id,
FlutterSemanticsAction action,
const std::vector<uint8_t>& data);
private:
// Allows swapping out embedder_api_ calls in tests.
friend class EngineModifier;

View File

@@ -231,5 +231,29 @@ TEST(FlutterWindowsEngine, SendPlatformMessageWithResponse) {
EXPECT_TRUE(send_message_called);
}
TEST(FlutterWindowsEngine, DispatchSemanticsAction) {
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
EngineModifier modifier(engine.get());
bool called = false;
std::string test_data = "Hello";
modifier.embedder_api().DispatchSemanticsAction = MOCK_ENGINE_PROC(
DispatchSemanticsAction,
([&called, &test_data](auto engine, auto target, auto action, auto data,
auto data_length) {
called = true;
EXPECT_EQ(target, 42);
EXPECT_EQ(action, kFlutterSemanticsActionDismiss);
EXPECT_EQ(memcmp(data, test_data.c_str(), test_data.size()), 0);
EXPECT_EQ(data_length, test_data.size());
return kSuccess;
}));
engine->DispatchSemanticsAction(
42, kFlutterSemanticsActionDismiss,
std::vector<uint8_t>(test_data.begin(), test_data.end()));
EXPECT_TRUE(called);
}
} // namespace testing
} // namespace flutter