flutter_flutter/shell/platform/embedder/platform_view_embedder.cc
Chris Bracken abe9826a9d
Add accessibility semantics support to embedder (#7891)
Flutter's accessibility APIs consist of three main calls from the
embedder to the Dart application:

  1. FlutterEngineUpdateSemanticsEnabled: enables/disables semantics support.

  2. FlutterEngineUpdateAccessibilityFeatures: sets embedder-specific
     accessibility features.

  3. FlutterEngineDispatchSemanticsAction: dispatches an action (tap,
     long-press, scroll, etc.) to a semantics node.

and two main callbacks triggered by Dart code:

  1. FlutterUpdateSemanticsNodeCallback: notifies the embedder of
     updates to the properties of a given semantics node.

  2. FlutterUpdateSemanticsCustomActionCallback: notifies the embedder
     of updates to custom semantics actions registered in Dart code.

In the Flutter framework, when accessibility is first enabled, the
embedder will receive a stream of update callbacks notifying the
embedder of the full semantics tree. On further changes in the Dart
application, only updates will be sent.
2019-02-20 18:59:29 -08:00

84 lines
2.7 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/embedder/platform_view_embedder.h"
namespace shell {
PlatformViewEmbedder::PlatformViewEmbedder(
PlatformView::Delegate& delegate,
blink::TaskRunners task_runners,
EmbedderSurfaceGL::GLDispatchTable gl_dispatch_table,
bool fbo_reset_after_present,
PlatformDispatchTable platform_dispatch_table)
: PlatformView(delegate, std::move(task_runners)),
embedder_surface_(
std::make_unique<EmbedderSurfaceGL>(gl_dispatch_table,
fbo_reset_after_present)),
platform_dispatch_table_(platform_dispatch_table) {}
PlatformViewEmbedder::PlatformViewEmbedder(
PlatformView::Delegate& delegate,
blink::TaskRunners task_runners,
EmbedderSurfaceSoftware::SoftwareDispatchTable software_dispatch_table,
PlatformDispatchTable platform_dispatch_table)
: PlatformView(delegate, std::move(task_runners)),
embedder_surface_(
std::make_unique<EmbedderSurfaceSoftware>(software_dispatch_table)),
platform_dispatch_table_(platform_dispatch_table) {}
PlatformViewEmbedder::~PlatformViewEmbedder() = default;
void PlatformViewEmbedder::UpdateSemantics(
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {
if (platform_dispatch_table_.update_semantics_nodes_callback != nullptr) {
platform_dispatch_table_.update_semantics_nodes_callback(std::move(update));
}
if (platform_dispatch_table_.update_semantics_custom_actions_callback !=
nullptr) {
platform_dispatch_table_.update_semantics_custom_actions_callback(
std::move(actions));
}
}
void PlatformViewEmbedder::HandlePlatformMessage(
fml::RefPtr<blink::PlatformMessage> message) {
if (!message) {
return;
}
if (!message->response()) {
return;
}
if (platform_dispatch_table_.platform_message_response_callback == nullptr) {
message->response()->CompleteEmpty();
return;
}
platform_dispatch_table_.platform_message_response_callback(
std::move(message));
}
// |shell::PlatformView|
std::unique_ptr<Surface> PlatformViewEmbedder::CreateRenderingSurface() {
if (embedder_surface_ == nullptr) {
FML_LOG(ERROR) << "Embedder surface was null.";
return nullptr;
}
return embedder_surface_->CreateGPUSurface();
}
// |shell::PlatformView|
sk_sp<GrContext> PlatformViewEmbedder::CreateResourceContext() const {
if (embedder_surface_ == nullptr) {
FML_LOG(ERROR) << "Embedder surface was null.";
return nullptr;
}
return embedder_surface_->CreateResourceContext();
}
} // namespace shell