Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a mechanism for announce events to be forwarded to a11y. #23499

Merged
merged 1 commit into from
Jan 25, 2021
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/fuchsia/flutter/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ template("runner_sources") {
"//flutter/lib/ui",
"//flutter/runtime",
"//flutter/shell/common",
"//flutter/shell/platform/common/cpp/client_wrapper:client_wrapper",
]
flutter_deps = [
":fuchsia_gpu_configuration",
Expand Down
9 changes: 9 additions & 0 deletions shell/platform/fuchsia/flutter/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ fuchsia::accessibility::semantics::Node AccessibilityBridge::GetRootNodeUpdate(
return root_fuchsia_node;
}

void AccessibilityBridge::RequestAnnounce(const std::string message) {
fuchsia::accessibility::semantics::SemanticEvent semantic_event;
fuchsia::accessibility::semantics::AnnounceEvent announce_event;
announce_event.set_message(message);
semantic_event.set_announce(std::move(announce_event));

tree_ptr_->SendSemanticEvent(std::move(semantic_event), []() {});
}

void AccessibilityBridge::UpdateScreenRects() {
std::unordered_set<int32_t> visited_nodes;
UpdateScreenRects(kRootNodeId, SkM44{}, &visited_nodes);
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/fuchsia/flutter/accessibility_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class AccessibilityBridge
void AddSemanticsNodeUpdate(const flutter::SemanticsNodeUpdates update,
float view_pixel_ratio);

// Requests a message announcement from the accessibility TTS system.
void RequestAnnounce(const std::string message);

// Notifies the bridge of a 'hover move' touch exploration event.
zx_status_t OnHoverMove(double x, double y);

Expand Down
10 changes: 10 additions & 0 deletions shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ TEST_F(AccessibilityBridgeTest, EnableDisable) {
EXPECT_TRUE(accessibility_delegate_.enabled());
}

TEST_F(AccessibilityBridgeTest, RequestAnnounce) {
accessibility_bridge_->RequestAnnounce("message");
RunLoopUntilIdle();

auto& last_events = semantics_manager_.GetLastEvents();
ASSERT_EQ(last_events.size(), 1u);
ASSERT_TRUE(last_events[0].is_announce());
EXPECT_EQ(last_events[0].announce().message(), "message");
}

TEST_F(AccessibilityBridgeTest, UpdatesNodeRoles) {
flutter::SemanticsNodeUpdates updates;

Expand Down
13 changes: 13 additions & 0 deletions shell/platform/fuchsia/flutter/flutter_runner_fakes.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ class MockSemanticsManager
commit_count_++;
}

void SendSemanticEvent(
fuchsia::accessibility::semantics::SemanticEvent semantic_event,
SendSemanticEventCallback callback) override {
last_events_.emplace_back(std::move(semantic_event));
callback();
}

std::vector<fuchsia::accessibility::semantics::SemanticEvent>&
GetLastEvents() {
return last_events_;
}

private:
bool has_view_ref_ = false;
fidl::BindingSet<SemanticsManager> bindings_;
Expand All @@ -102,6 +114,7 @@ class MockSemanticsManager
bool delete_overflowed_;
std::vector<uint32_t> last_deleted_node_ids_;
int commit_count_;
std::vector<fuchsia::accessibility::semantics::SemanticEvent> last_events_;
};

} // namespace flutter_runner_test
Expand Down
21 changes: 21 additions & 0 deletions shell/platform/fuchsia/flutter/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "flutter/fml/logging.h"
#include "flutter/lib/ui/window/pointer_data.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/encodable_value.h"
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h"
#include "third_party/rapidjson/include/rapidjson/document.h"
#include "third_party/rapidjson/include/rapidjson/stringbuffer.h"
#include "third_party/rapidjson/include/rapidjson/writer.h"
Expand Down Expand Up @@ -658,6 +660,25 @@ void PlatformView::UpdateSemantics(
void PlatformView::HandleAccessibilityChannelPlatformMessage(
fml::RefPtr<flutter::PlatformMessage> message) {
FML_DCHECK(message->channel() == kAccessibilityChannel);

const flutter::StandardMessageCodec& standard_message_codec =
flutter::StandardMessageCodec::GetInstance(nullptr);
std::unique_ptr<flutter::EncodableValue> decoded =
standard_message_codec.DecodeMessage(message->data());

flutter::EncodableMap map = std::get<flutter::EncodableMap>(*decoded);
std::string type =
std::get<std::string>(map.at(flutter::EncodableValue("type")));
if (type == "announce") {
flutter::EncodableMap data_map = std::get<flutter::EncodableMap>(
map.at(flutter::EncodableValue("data")));
std::string text =
std::get<std::string>(data_map.at(flutter::EncodableValue("message")));

accessibility_bridge_->RequestAnnounce(text);
}

message->response()->CompleteEmpty();
}

// Channel handler for kFlutterPlatformChannel
Expand Down