Expose SemanticsUpdate and SemanticsUpdateBuilder (flutter/engine#3098)

This patch prepares us to switch sending semantics information over mojom to
using dart:ui directly. Currently the recorded information is dropped on the
floor, but that will improve in future patches.
This commit is contained in:
Adam Barth
2016-10-05 12:22:03 -07:00
committed by GitHub
parent 6b35710136
commit 649b958d19
21 changed files with 634 additions and 12 deletions

View File

@@ -44,6 +44,12 @@ source_set("ui") {
"painting/rrect.h",
"painting/shader.cc",
"painting/shader.h",
"semantics/semantics_node.cc",
"semantics/semantics_node.h",
"semantics/semantics_update_builder.cc",
"semantics/semantics_update_builder.h",
"semantics/semantics_update.cc",
"semantics/semantics_update.h",
"text/paragraph_builder.cc",
"text/paragraph_builder.h",
"text/paragraph.cc",

View File

@@ -12,6 +12,7 @@ dart_ui_files = [
"//flutter/lib/ui/natives.dart",
"//flutter/lib/ui/painting.dart",
"//flutter/lib/ui/pointer.dart",
"//flutter/lib/ui/semantics.dart",
"//flutter/lib/ui/text.dart",
"//flutter/lib/ui/ui.dart",
"//flutter/lib/ui/window.dart",

View File

@@ -26,6 +26,12 @@ void _updateLocale(String languageCode, String countryCode) {
window.onLocaleChanged();
}
void _updateSemanticsEnabled(bool enabled) {
window._semanticsEnabled = enabled;
if (window.onSemanticsEnabledChanged != null)
window.onSemanticsEnabledChanged();
}
void _pushRoute(String route) {
assert(window._defaultRouteName == null);
window._defaultRouteName = route;
@@ -43,6 +49,11 @@ void _dispatchPointerDataPacket(ByteData packet) {
window.onPointerDataPacket(_unpackPointerDataPacket(packet));
}
void _dispatchSemanticsAction(int id, int action) {
if (window.onSemanticsAction != null)
window.onSemanticsAction(id, SemanticsAction.values[action]);
}
void _beginFrame(int microseconds) {
if (window.onBeginFrame != null)
window.onBeginFrame(new Duration(microseconds: microseconds));

View File

@@ -0,0 +1,251 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of dart_ui;
/// The possible actions that can be conveyed from the operating system
/// accessibility APIs to a semantics node.
class SemanticsAction {
static const int _kTapIndex = 1 << 0;
static const int _kLongPressIndex = 1 << 1;
static const int _kScrollLeftIndex = 1 << 2;
static const int _kScrollRightIndex = 1 << 3;
static const int _kScrollUpIndex = 1 << 4;
static const int _kScrollDownIndex = 1 << 5;
static const int _kIncreaseIndex = 1 << 6;
static const int _kDecreaseIndex = 1 << 7;
const SemanticsAction._(this.index);
/// The numerical value for this action.
///
/// Each action has one bit set in this bit field.
final int index;
/// The equivalent of a user briefly tapping the screen with the finger
/// without moving it.
static const SemanticsAction tap = const SemanticsAction._(_kTapIndex);
/// The equivalent of a user pressing and holding the screen with the finger
/// for a few seconds without moving it.
static const SemanticsAction longPress = const SemanticsAction._(_kLongPressIndex);
/// The equivalent of a user moving their finger across the screen from right
/// to left.
///
/// This action should be recognized by controls that are horizontally
/// scrollable.
static const SemanticsAction scrollLeft = const SemanticsAction._(_kScrollLeftIndex);
/// The equivalent of a user moving their finger across the screen from left
/// to right.
///
/// This action should be recognized by controls that are horizontally
/// scrollable.
static const SemanticsAction scrollRight = const SemanticsAction._(_kScrollRightIndex);
/// The equivalent of a user moving their finger across the screen from
/// bottom to top.
///
/// This action should be recognized by controls that are vertically
/// scrollable.
static const SemanticsAction scrollUp = const SemanticsAction._(_kScrollUpIndex);
/// The equivalent of a user moving their finger across the screen from top
/// to bottom.
///
/// This action should be recognized by controls that are vertically
/// scrollable.
static const SemanticsAction scrollDown = const SemanticsAction._(_kScrollDownIndex);
/// A request to increase the value represented by the semantics node.
///
/// For example, this action might be recognized by a slider control.
static const SemanticsAction increase = const SemanticsAction._(_kIncreaseIndex);
/// A request to decrease the value represented by the semantics node.
///
/// For example, this action might be recognized by a slider control.
static const SemanticsAction decrease = const SemanticsAction._(_kDecreaseIndex);
/// The possible semantics actions.
///
/// The map's key is the [index] of the action and the value is the action
/// itself.
static final Map<int, SemanticsAction> values = const <int, SemanticsAction>{
_kTapIndex: tap,
_kLongPressIndex: longPress,
_kScrollLeftIndex: scrollLeft,
_kScrollRightIndex: scrollRight,
_kScrollUpIndex: scrollUp,
_kScrollDownIndex: scrollDown,
_kIncreaseIndex: increase,
_kDecreaseIndex: decrease,
};
@override
String toString() {
switch (index) {
case _kTapIndex:
return 'SemanticsAction.tap';
case _kLongPressIndex:
return 'SemanticsAction.longPress';
case _kScrollLeftIndex:
return 'SemanticsAction.scrollLeft';
case _kScrollRightIndex:
return 'SemanticsAction.scrollRight';
case _kScrollUpIndex:
return 'SemanticsAction.scrollUp';
case _kScrollDownIndex:
return 'SemanticsAction.scrollDown';
case _kIncreaseIndex:
return 'SemanticsAction.increase';
case _kDecreaseIndex:
return 'SemanticsAction.decrease';
}
return null;
}
}
/// A Boolean value that can be associated with a semantics node.
class SemanticsFlags {
static const int _kHasCheckedStateIndex = 1 << 0;
static const int _kIsCheckedIndex = 1 << 1;
const SemanticsFlags._(this.index);
/// The numerical value for this flag.
///
/// Each flag has one bit set in this bit field.
final int index;
/// The semantics node has the quality of either being "checked" or "unchecked".
///
/// For example, a checkbox or a radio button widget has checked state.
static const SemanticsFlags hasCheckedState = const SemanticsFlags._(_kHasCheckedStateIndex);
/// Whether a semantics node that [hasCheckedState] is checked.
///
/// If true, the semantics node is "checked". If false, the semantics node is
/// "unchecked".
///
/// For example, if a checkbox has a visible checkmark, [isChecked] is true.
static const SemanticsFlags isChecked = const SemanticsFlags._(_kIsCheckedIndex);
/// The possible semantics flags.
///
/// The map's key is the [index] of the flag and the value is the flag itself.
static final Map<int, SemanticsFlags> values = const <int, SemanticsFlags>{
_kHasCheckedStateIndex: hasCheckedState,
_kIsCheckedIndex: isChecked,
};
@override
String toString() {
switch (index) {
case _kHasCheckedStateIndex:
return 'SemanticsFlags.hasCheckedState';
case _kIsCheckedIndex:
return 'SemanticsFlags.isChecked';
}
return null;
}
}
/// An object that creates [SemanticsUpdate] objects.
///
/// Once created, the [SemanticsUpdate] objects can be passed to
/// [Window.updateSemantics] to update the semantics conveyed to the user.
class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
/// Creates an empty [SemanticsUpdateBuilder] object.
SemanticsUpdateBuilder() { _constructor(); }
void _constructor() native "SemanticsUpdateBuilder_constructor";
/// Update the information associated with the node with the given `id`.
///
/// The semantics nodes form a tree, with the root of the tree always having
/// an id of zero. The `children` are the ids of the nodes that are immediate
/// children of this node. The system retains the nodes that are currently
/// reachable from the root. A given update need not contain information for
/// nodes that do not change in the update. If a node is not reachable from
/// the root after an update, the node will be discarded from the tree.
///
/// The `flags` are a bit field of [SemanticsFlags] that apply to this node.
///
/// The `actions` are a bit field of [SemanticsActions] that can be undertaken
/// by this node. If the user wishes to undertake one of these actions on this
/// node, the [Window.onSemanticsAction] will be called with `id` and one of
/// the possible [SemanticsActions]. Because the semantics tree is maintained
/// asynchronously, the [Window.onSemanticsAction] callback might be called
/// with an action that is no longer possible.
///
/// The `label` is a string that describes this node.
///
/// The `rect` is the region occupied by this node in its own coordinate
/// system.
///
/// The `transform` is a matrix that maps this node's coodinate system into
/// its parent's coordate system.
void updateNode({
int id,
int flags,
int actions,
Rect rect,
String label,
Float64List transform,
Int32List children
}) {
if (transform.length != 16)
throw new ArgumentError("[transform] must have 16 entries.");
_updateNode(id,
flags,
actions,
rect.left,
rect.top,
rect.right,
rect.bottom,
label,
transform,
children);
}
void _updateNode(
int id,
int flags,
int actions,
double left,
double top,
double right,
double bottom,
String label,
Float64List transform,
Int32List children
) native "SemanticsUpdateBuilder_updateNode";
/// Creates a [SemanticsUpdate] object that encapsulates the updates recorded
/// by this object.
///
/// The returned object can be passed to [Window.updateSemantics] to actually
/// update the semantics retained by the system.
SemanticsUpdate build() native "SemanticsUpdateBuilder_build";
}
/// An opaque object representing a batch of semantics updates.
///
/// To create a SemanticsUpdate object, use a [SemanticsUpdateBuilder].
///
/// Semantics updates can be applied to the system's retained semantics tree
/// using the [Window.updateSemantics] method.
class SemanticsUpdate extends NativeFieldWrapperClass2 {
/// Creates an uninitialized SemanticsUpdate object.
///
/// Calling the SemanticsUpdate constructor directly will not create a useable
/// object. To create a SemanticsUpdate object, use a [SemanticsUpdateBuilder].
SemanticsUpdate(); // (this constructor is here just so we can document it)
/// Releases the resources used by this semantics update.
///
/// After calling this function, the semantics update is cannot be used
/// further.
void dispose() native "SemanticsUpdateBuilder_dispose";
}

View File

@@ -0,0 +1,15 @@
// Copyright 2016 The Chromium 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/lib/ui/semantics/semantics_node.h"
#include <string.h>
namespace blink {
SemanticsNode::SemanticsNode() = default;
SemanticsNode::~SemanticsNode() = default;
} // namespace blink

View File

@@ -0,0 +1,51 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_
#define FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_
#include <stdint.h>
#include <string>
#include <vector>
#include "third_party/skia/include/core/SkMatrix44.h"
#include "third_party/skia/include/core/SkRect.h"
namespace blink {
// Must match the SemanticsAction enum in semantics.dart.
enum class SemanticsAction : int32_t {
kTap = 1 << 0,
kLongPress = 1 << 1,
kScrollLeft = 1 << 2,
kScrollRight = 1 << 3,
kScrollUp = 1 << 4,
kScrollDown = 1 << 5,
kIncrease = 1 << 6,
kDecrease = 1 << 7,
};
// Must match the SemanticsFlags enum in semantics.dart.
enum class SemanticsFlags : int32_t {
kHasCheckedState = 1 << 0,
kIsChecked = 1 << 1,
};
struct SemanticsNode {
SemanticsNode();
~SemanticsNode();
int32_t id = 0;
int32_t flags = 0;
int32_t actions = 0;
std::string label;
SkRect rect = SkRect::MakeEmpty();
SkMatrix44 transform = SkMatrix44(SkMatrix44::kIdentity_Constructor);
std::vector<int32_t> children;
};
} // namespace blink
#endif // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_

View File

@@ -0,0 +1,41 @@
// Copyright 2016 The Chromium 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/lib/ui/semantics/semantics_update_builder.h"
#include <memory>
#include "flutter/lib/ui/painting/matrix.h"
#include "lib/tonic/converter/dart_converter.h"
#include "lib/tonic/dart_args.h"
#include "lib/tonic/dart_binding_macros.h"
#include "lib/tonic/dart_library_natives.h"
namespace blink {
IMPLEMENT_WRAPPERTYPEINFO(ui, SemanticsUpdate);
#define FOR_EACH_BINDING(V) V(SemanticsUpdate, dispose)
DART_BIND_ALL(SemanticsUpdate, FOR_EACH_BINDING)
ftl::RefPtr<SemanticsUpdate> SemanticsUpdate::create(
std::vector<SemanticsNode> nodes) {
return ftl::MakeRefCounted<SemanticsUpdate>(std::move(nodes));
}
SemanticsUpdate::SemanticsUpdate(std::vector<SemanticsNode> nodes)
: nodes_(std::move(nodes)) {}
SemanticsUpdate::~SemanticsUpdate() = default;
std::vector<SemanticsNode> SemanticsUpdate::takeNodes() {
return std::move(nodes_);
}
void SemanticsUpdate::dispose() {
ClearDartWrapper();
}
} // namespace blink

View File

@@ -0,0 +1,42 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_UPDATE_H_
#define FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_UPDATE_H_
#include <vector>
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "lib/tonic/dart_wrappable.h"
namespace tonic {
class DartLibraryNatives;
} // namespace tonic
namespace blink {
class SemanticsUpdate : public ftl::RefCountedThreadSafe<SemanticsUpdate>,
public tonic::DartWrappable {
DEFINE_WRAPPERTYPEINFO();
FRIEND_MAKE_REF_COUNTED(SemanticsUpdate);
public:
~SemanticsUpdate() override;
static ftl::RefPtr<SemanticsUpdate> create(std::vector<SemanticsNode> nodes);
std::vector<SemanticsNode> takeNodes();
void dispose();
static void RegisterNatives(tonic::DartLibraryNatives* natives);
private:
explicit SemanticsUpdate(std::vector<SemanticsNode> nodes);
std::vector<SemanticsNode> nodes_;
};
} // namespace blink
#endif // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_UPDATE_H_

View File

@@ -0,0 +1,63 @@
// Copyright 2016 The Chromium 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/lib/ui/semantics/semantics_update_builder.h"
#include "lib/tonic/converter/dart_converter.h"
#include "lib/tonic/dart_args.h"
#include "lib/tonic/dart_binding_macros.h"
#include "lib/tonic/dart_library_natives.h"
namespace blink {
static void SemanticsUpdateBuilder_constructor(Dart_NativeArguments args) {
DartCallConstructor(&SemanticsUpdateBuilder::create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, SemanticsUpdateBuilder);
#define FOR_EACH_BINDING(V) \
V(SemanticsUpdateBuilder, updateNode) \
V(SemanticsUpdateBuilder, build)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void SemanticsUpdateBuilder::RegisterNatives(
tonic::DartLibraryNatives* natives) {
natives->Register({{"SemanticsUpdateBuilder_constructor",
SemanticsUpdateBuilder_constructor, 1, true},
FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
}
SemanticsUpdateBuilder::SemanticsUpdateBuilder() = default;
SemanticsUpdateBuilder::~SemanticsUpdateBuilder() = default;
void SemanticsUpdateBuilder::updateNode(int id,
int flags,
int actions,
double left,
double top,
double right,
double bottom,
std::string label,
const tonic::Float64List& transform,
const tonic::Int32List& children) {
SemanticsNode node;
node.id = id;
node.flags = flags;
node.actions = actions;
node.rect = SkRect::MakeLTRB(left, top, right, bottom);
node.label = label;
node.transform.setColMajord(transform.data());
node.children = std::vector<int32_t>(
children.data(), children.data() + children.num_elements());
nodes_.push_back(node);
}
ftl::RefPtr<SemanticsUpdate> SemanticsUpdateBuilder::build() {
return SemanticsUpdate::create(std::move(nodes_));
}
} // namespace blink

View File

@@ -0,0 +1,51 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_UPDATE_BUILDER_H_
#define FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_UPDATE_BUILDER_H_
#include "flutter/lib/ui/semantics/semantics_update.h"
#include "lib/tonic/dart_wrappable.h"
#include "lib/tonic/typed_data/float64_list.h"
#include "lib/tonic/typed_data/int32_list.h"
namespace blink {
class SemanticsUpdateBuilder
: public ftl::RefCountedThreadSafe<SemanticsUpdateBuilder>,
public tonic::DartWrappable {
DEFINE_WRAPPERTYPEINFO();
FRIEND_MAKE_REF_COUNTED(SemanticsUpdateBuilder);
public:
static ftl::RefPtr<SemanticsUpdateBuilder> create() {
return ftl::MakeRefCounted<SemanticsUpdateBuilder>();
}
~SemanticsUpdateBuilder() override;
void updateNode(int id,
int flags,
int actions,
double left,
double top,
double right,
double bottom,
std::string label,
const tonic::Float64List& transform,
const tonic::Int32List& children);
ftl::RefPtr<SemanticsUpdate> build();
static void RegisterNatives(tonic::DartLibraryNatives* natives);
private:
explicit SemanticsUpdateBuilder();
std::vector<SemanticsNode> nodes_;
};
} // namespace blink
#endif // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_UPDATE_BUILDER_H_

View File

@@ -31,5 +31,6 @@ part 'mojo_services.dart';
part 'natives.dart';
part 'painting.dart';
part 'pointer.dart';
part 'semantics.dart';
part 'text.dart';
part 'window.dart';

View File

@@ -13,6 +13,9 @@ typedef void FrameCallback(Duration duration);
/// Signature for [Window.onPointerDataPacket].
typedef void PointerDataPacketCallback(PointerDataPacket packet);
/// Signature for [Window.onSemanticsAction].
typedef void SemanticsActionCallback(int id, SemanticsAction action);
/// Signature for [Window.onAppLifecycleStateChanged].
typedef void AppLifecycleStateCallback(AppLifecycleState state);
@@ -124,9 +127,12 @@ class Window {
/// [physicalSize], or [padding] values change.
VoidCallback onMetricsChanged;
/// The system-reported locale. This establishes the language and formatting
/// conventions that application should, if possible, use to render their user
/// interface.
/// The system-reported locale.
///
/// This establishes the language and formatting conventions that application
/// should, if possible, use to render their user interface.
///
/// The [onLocaleChanged] callback is called whenever this value changes.
Locale get locale => _locale;
Locale _locale;
@@ -179,6 +185,33 @@ class Window {
/// you can then obtain a [Scene] object, which you can display to
/// the user via this [render] function.
void render(Scene scene) native "Window_render";
/// Whether the user has requested that [updateSemantics] be called when
/// the semantic contents of window changes.
///
/// The [onSemanticsEnabledChanged] callback is called whenever this value
/// changes.
bool get semanticsEnabled => _semanticsEnabled;
bool _semanticsEnabled = false;
/// A callback that is invoked when the value of [semanticsEnabled] changes.
VoidCallback onSemanticsEnabledChanged;
/// A callback that is invoked whenever the user requests an action to be
/// performed.
///
/// This callback is used when the user expresses the action they wish to
/// perform based on the semantics supplied by [updateSemantics].
SemanticsActionCallback onSemanticsAction;
/// Change the retained semantics data about this window.
///
/// If [semanticsEnabled] is true, the user has requested that this funciton
/// be called whenever the semantic content of this window changes.
///
/// In either case, this function disposes the given update, which means the
/// semantics update cannot be used further.
void updateSemantics(SemanticsUpdate update) native "Window_updateSemantics";
}
/// The [Window] singleton. This object exposes the size of the display, the

View File

@@ -77,6 +77,16 @@ void Window::UpdateLocale(const std::string& language_code,
});
}
void Window::UpdateSemanticsEnabled(bool enabled) {
tonic::DartState* dart_state = library_.dart_state().get();
if (!dart_state)
return;
tonic::DartState::Scope scope(dart_state);
DartInvokeField(library_.value(), "_updateSemanticsEnabled",
{ToDart(enabled)});
}
void Window::PushRoute(const std::string& route) {
tonic::DartState* dart_state = library_.dart_state().get();
if (!dart_state)
@@ -121,6 +131,16 @@ void Window::DispatchPointerDataPacket(const PointerDataPacket& packet) {
{data_handle});
}
void Window::DispatchSemanticsAction(int32_t id, SemanticsAction action) {
tonic::DartState* dart_state = library_.dart_state().get();
if (!dart_state)
return;
tonic::DartState::Scope scope(dart_state);
DartInvokeField(library_.value(), "_dispatchSemanticsAction",
{ToDart(id), ToDart(static_cast<int32_t>(action))});
}
void Window::BeginFrame(ftl::TimePoint frameTime) {
tonic::DartState* dart_state = library_.dart_state().get();
if (!dart_state)

View File

@@ -5,6 +5,7 @@
#ifndef FLUTTER_LIB_UI_WINDOW_WINDOW_H_
#define FLUTTER_LIB_UI_WINDOW_WINDOW_H_
#include "flutter/lib/ui/semantics/semantics_update.h"
#include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/services/engine/sky_engine.mojom.h"
#include "flutter/services/pointer/pointer.mojom.h"
@@ -22,6 +23,7 @@ class WindowClient {
public:
virtual void ScheduleFrame() = 0;
virtual void Render(Scene* scene) = 0;
virtual void UpdateSemantics(SemanticsUpdate* update) = 0;
protected:
virtual ~WindowClient();
@@ -38,7 +40,9 @@ class Window {
void UpdateWindowMetrics(const sky::ViewportMetricsPtr& metrics);
void UpdateLocale(const std::string& language_code,
const std::string& country_code);
void UpdateSemanticsEnabled(bool enabled);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
void DispatchSemanticsAction(int32_t id, SemanticsAction action);
void BeginFrame(ftl::TimePoint frameTime);
void PushRoute(const std::string& route);

View File

@@ -4,6 +4,7 @@ dart:isolate,::,_startMainIsolate
dart:mojo.internal,MojoHandleWatcher,mojoControlHandle
dart:ui,::,_beginFrame
dart:ui,::,_dispatchPointerDataPacket
dart:ui,::,_dispatchSemanticsAction
dart:ui,::,_getGetBaseURLClosure
dart:ui,::,_getMainClosure
dart:ui,::,_getPrintClosure
@@ -13,6 +14,7 @@ dart:ui,::,_popRoute
dart:ui,::,_pushRoute
dart:ui,::,_setupHooks
dart:ui,::,_updateLocale
dart:ui,::,_updateSemanticsEnabled
dart:ui,::,_updateWindowMetrics
dart:ui,Canvas,Canvas.
dart:ui,Color,Color.
@@ -26,6 +28,8 @@ dart:ui,PictureRecorder,PictureRecorder.
dart:ui,Rect,Rect.fromLTRB
dart:ui,Scene,Scene.
dart:ui,SceneBuilder,SceneBuilder.
dart:ui,SemanticsUpdate,SemanticsUpdate.
dart:ui,SemanticsUpdateBuilder,SemanticsUpdateBuilder.
dart:ui,Shader,Shader.
dart:ui,TextBox,TextBox._
dart:vmservice_sky,::,main

View File

@@ -64,6 +64,13 @@ void RuntimeController::SetLocale(const std::string& language_code,
GetWindow()->UpdateLocale(language_code_, country_code_);
}
void RuntimeController::SetSemanticsEnabled(bool enabled) {
if (semantics_enabled_ == enabled)
return;
semantics_enabled_ = enabled;
GetWindow()->UpdateSemanticsEnabled(enabled);
}
void RuntimeController::PushRoute(const std::string& route) {
GetWindow()->PushRoute(route);
}
@@ -76,12 +83,18 @@ void RuntimeController::BeginFrame(ftl::TimePoint frame_time) {
GetWindow()->BeginFrame(frame_time);
}
void RuntimeController::HandlePointerDataPacket(
void RuntimeController::DispatchPointerDataPacket(
const PointerDataPacket& packet) {
TRACE_EVENT0("input", "RuntimeController::HandlePointerDataPacket");
TRACE_EVENT0("flutter", "RuntimeController::DispatchPointerDataPacket");
GetWindow()->DispatchPointerDataPacket(packet);
}
void RuntimeController::DispatchSemanticsAction(int32_t id,
SemanticsAction action) {
TRACE_EVENT0("flutter", "RuntimeController::DispatchSemanticsAction");
GetWindow()->DispatchSemanticsAction(id, action);
}
Window* RuntimeController::GetWindow() {
return dart_controller_->dart_state()->window();
}
@@ -94,6 +107,11 @@ void RuntimeController::Render(Scene* scene) {
client_->Render(scene->takeLayerTree());
}
void RuntimeController::UpdateSemantics(SemanticsUpdate* update) {
if (semantics_enabled_)
client_->UpdateSemantics(update->takeNodes());
}
void RuntimeController::DidCreateSecondaryIsolate(Dart_Isolate isolate) {
client_->DidCreateSecondaryIsolate(isolate);
}

View File

@@ -34,12 +34,14 @@ class RuntimeController : public WindowClient, public IsolateClient {
void SetViewportMetrics(const sky::ViewportMetricsPtr& metrics);
void SetLocale(const std::string& language_code,
const std::string& country_code);
void SetSemanticsEnabled(bool enabled);
void PushRoute(const std::string& route);
void PopRoute();
void BeginFrame(ftl::TimePoint frame_time);
void HandlePointerDataPacket(const PointerDataPacket& packet);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
void DispatchSemanticsAction(int32_t id, SemanticsAction action);
void OnAppLifecycleStateChanged(sky::AppLifecycleState state);
@@ -54,6 +56,7 @@ class RuntimeController : public WindowClient, public IsolateClient {
void ScheduleFrame() override;
void Render(Scene* scene) override;
void UpdateSemantics(SemanticsUpdate* update) override;
void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;
@@ -61,6 +64,7 @@ class RuntimeController : public WindowClient, public IsolateClient {
sky::ViewportMetricsPtr viewport_metrics_;
std::string language_code_;
std::string country_code_;
bool semantics_enabled_ = false;
std::unique_ptr<DartController> dart_controller_;
FTL_DISALLOW_COPY_AND_ASSIGN(RuntimeController);

View File

@@ -6,9 +6,11 @@
#define FLUTTER_RUNTIME_RUNTIME_DELEGATE_H_
#include <memory>
#include <vector>
#include "dart/runtime/include/dart_api.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
namespace blink {
@@ -16,6 +18,7 @@ class RuntimeDelegate {
public:
virtual void ScheduleFrame() = 0;
virtual void Render(std::unique_ptr<flow::LayerTree> layer_tree) = 0;
virtual void UpdateSemantics(std::vector<SemanticsNode> update) = 0;
virtual void DidCreateMainIsolate(Dart_Isolate isolate);
virtual void DidCreateSecondaryIsolate(Dart_Isolate isolate);

View File

@@ -185,10 +185,10 @@ void Engine::OnLocaleChanged(const mojo::String& language_code,
runtime_->SetLocale(language_code_, country_code_);
}
void Engine::HandlePointerDataPacket(const PointerDataPacket& packet) {
TRACE_EVENT0("flutter", "Engine::HandlePointerDataPacket");
void Engine::DispatchPointerDataPacket(const PointerDataPacket& packet) {
TRACE_EVENT0("flutter", "Engine::DispatchPointerDataPacket");
if (runtime_)
runtime_->HandlePointerDataPacket(packet);
runtime_->DispatchPointerDataPacket(packet);
}
// TODO(abarth): Remove pointer::PointerPacketPtr and route PointerDataPacket
@@ -222,7 +222,7 @@ void Engine::OnPointerPacket(pointer::PointerPacketPtr packetPtr) {
pointer_data.tilt = pointer->tilt;
packet.SetPointerData(i, pointer_data);
}
runtime_->HandlePointerDataPacket(packet);
runtime_->DispatchPointerDataPacket(packet);
}
}
@@ -400,4 +400,6 @@ void Engine::Render(std::unique_ptr<flow::LayerTree> layer_tree) {
animator_->Render(std::move(layer_tree));
}
void Engine::UpdateSemantics(std::vector<blink::SemanticsNode> update) {}
} // namespace shell

View File

@@ -49,7 +49,7 @@ class Engine : public UIDelegate,
std::string GetUIIsolateName();
void HandlePointerDataPacket(const PointerDataPacket& packet);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
private:
// UIDelegate implementation:
@@ -80,6 +80,7 @@ class Engine : public UIDelegate,
// RuntimeDelegate methods:
void ScheduleFrame() override;
void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
void DidCreateMainIsolate(Dart_Isolate isolate) override;
void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;

View File

@@ -436,7 +436,7 @@ void PlatformViewAndroid::DispatchPointerDataPacket(JNIEnv* env,
packet = std::make_unique<PointerDataPacket>(data, position)
] {
if (engine.get())
engine->HandlePointerDataPacket(*packet);
engine->DispatchPointerDataPacket(*packet);
}));
}