Skip to content

Commit

Permalink
Add parameters to SemanticActions; implement extend selection for a1…
Browse files Browse the repository at this point in the history
…1y (flutter#4444)
  • Loading branch information
goderbauer authored Dec 12, 2017
1 parent aaa758d commit 59c3a37
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 31 deletions.
5 changes: 3 additions & 2 deletions lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ void _dispatchPointerDataPacket(ByteData packet) {
_invoke1<PointerDataPacket>(window.onPointerDataPacket, window._onPointerDataPacketZone, _unpackPointerDataPacket(packet));
}

void _dispatchSemanticsAction(int id, int action) {
_invoke2<int, SemanticsAction>(
void _dispatchSemanticsAction(int id, int action, ByteData args) {
_invoke3<int, SemanticsAction, ByteData>(
window.onSemanticsAction,
window._onSemanticsActionZone,
id,
SemanticsAction.values[action],
args,
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef void FrameCallback(Duration duration);
typedef void PointerDataPacketCallback(PointerDataPacket packet);

/// Signature for [Window.onSemanticsAction].
typedef void SemanticsActionCallback(int id, SemanticsAction action);
typedef void SemanticsActionCallback(int id, SemanticsAction action, ByteData args);

/// Signature for responses to platform messages.
///
Expand Down Expand Up @@ -439,7 +439,7 @@ class Window {

/// The setting indicating whether time should always be shown in the 24-hour
/// format.
///
///
/// This option is used by [showTimePicker].
bool get alwaysUse24HourFormat => _alwaysUse24HourFormat;
bool _alwaysUse24HourFormat = false;
Expand Down
14 changes: 11 additions & 3 deletions lib/ui/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,22 @@ void Window::DispatchPointerDataPacket(const PointerDataPacket& packet) {
{data_handle});
}

void Window::DispatchSemanticsAction(int32_t id, SemanticsAction action) {
void Window::DispatchSemanticsAction(int32_t id,
SemanticsAction action,
std::vector<uint8_t> args) {
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))});
Dart_Handle args_handle = (args.empty()) ? Dart_Null() : ToByteData(args);

if (Dart_IsError(args_handle))
return;

DartInvokeField(
library_.value(), "_dispatchSemanticsAction",
{ToDart(id), ToDart(static_cast<int32_t>(action)), args_handle});
}

void Window::BeginFrame(fxl::TimePoint frameTime) {
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class Window {
void UpdateSemanticsEnabled(bool enabled);
void DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
void DispatchSemanticsAction(int32_t id, SemanticsAction action);
void DispatchSemanticsAction(int32_t id,
SemanticsAction action,
std::vector<uint8_t> args);
void BeginFrame(fxl::TimePoint frameTime);

void CompletePlatformMessageResponse(int response_id,
Expand Down
5 changes: 3 additions & 2 deletions runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ void RuntimeController::DispatchPointerDataPacket(
}

void RuntimeController::DispatchSemanticsAction(int32_t id,
SemanticsAction action) {
SemanticsAction action,
std::vector<uint8_t> args) {
TRACE_EVENT1("flutter", "RuntimeController::DispatchSemanticsAction", "mode",
"basic");
GetWindow()->DispatchSemanticsAction(id, action);
GetWindow()->DispatchSemanticsAction(id, action, std::move(args));
}

Window* RuntimeController::GetWindow() {
Expand Down
4 changes: 3 additions & 1 deletion runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class RuntimeController : public WindowClient, public IsolateClient {

void DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
void DispatchSemanticsAction(int32_t id, SemanticsAction action);
void DispatchSemanticsAction(int32_t id,
SemanticsAction action,
std::vector<uint8_t> args);

Dart_Port GetMainPort();
std::string GetIsolateName();
Expand Down
6 changes: 4 additions & 2 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,11 @@ void Engine::DispatchPointerDataPacket(const PointerDataPacket& packet) {
runtime_->DispatchPointerDataPacket(packet);
}

void Engine::DispatchSemanticsAction(int id, blink::SemanticsAction action) {
void Engine::DispatchSemanticsAction(int id,
blink::SemanticsAction action,
std::vector<uint8_t> args) {
if (runtime_)
runtime_->DispatchSemanticsAction(id, action);
runtime_->DispatchSemanticsAction(id, action, std::move(args));
}

void Engine::SetSemanticsEnabled(bool enabled) {
Expand Down
4 changes: 3 additions & 1 deletion shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class Engine : public blink::RuntimeDelegate {
void SetViewportMetrics(const blink::ViewportMetrics& metrics);
void DispatchPlatformMessage(fxl::RefPtr<blink::PlatformMessage> message);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
void DispatchSemanticsAction(int id, blink::SemanticsAction action);
void DispatchSemanticsAction(int id,
blink::SemanticsAction action,
std::vector<uint8_t> args);
void SetSemanticsEnabled(bool enabled);
void ScheduleFrame(bool regenerate_layer_tree = true) override;

Expand Down
7 changes: 4 additions & 3 deletions shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ void PlatformView::DispatchPlatformMessage(
}

void PlatformView::DispatchSemanticsAction(int32_t id,
blink::SemanticsAction action) {
blink::SemanticsAction action,
std::vector<uint8_t> args) {
blink::Threads::UI()->PostTask(
[ engine = engine_->GetWeakPtr(), id, action ] {
[ engine = engine_->GetWeakPtr(), id, action, args = std::move(args) ] {
if (engine) {
engine->DispatchSemanticsAction(
id, static_cast<blink::SemanticsAction>(action));
id, static_cast<blink::SemanticsAction>(action), std::move(args));
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion shell/common/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class PlatformView : public std::enable_shared_from_this<PlatformView> {
virtual void Attach() = 0;

void DispatchPlatformMessage(fxl::RefPtr<blink::PlatformMessage> message);
void DispatchSemanticsAction(int32_t id, blink::SemanticsAction action);
void DispatchSemanticsAction(int32_t id,
blink::SemanticsAction action,
std::vector<uint8_t> args);
void SetSemanticsEnabled(bool enabled);

void NotifyCreated(std::unique_ptr<Surface> surface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,16 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) {
boolean performCursorMoveAction(SemanticsObject object, int virtualViewId, Bundle arguments, boolean forward) {
final int granularity = arguments.getInt(
AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT);
// TODO(goderbauer): support extending selections.
// final boolean extendSelection = arguments.getBoolean(
// AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN);
final boolean extendSelection = arguments.getBoolean(
AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN);
switch (granularity) {
case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER: {
if (forward && object.hasAction(Action.MOVE_CURSOR_FORWARD_BY_CHARACTER)) {
mOwner.dispatchSemanticsAction(virtualViewId, Action.MOVE_CURSOR_FORWARD_BY_CHARACTER);
mOwner.dispatchSemanticsAction(virtualViewId, Action.MOVE_CURSOR_FORWARD_BY_CHARACTER, extendSelection);
return true;
}
if (!forward && object.hasAction(Action.MOVE_CURSOR_BACKWARD_BY_CHARACTER)) {
mOwner.dispatchSemanticsAction(virtualViewId, Action.MOVE_CURSOR_BACKWARD_BY_CHARACTER);
mOwner.dispatchSemanticsAction(virtualViewId, Action.MOVE_CURSOR_BACKWARD_BY_CHARACTER, extendSelection);
return true;
}
}
Expand Down
14 changes: 12 additions & 2 deletions shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ private static native void nativeDispatchPointerDataPacket(long nativePlatformVi
ByteBuffer buffer, int position);

private static native void nativeDispatchSemanticsAction(long nativePlatformViewAndroid, int id,
int action);
int action, ByteBuffer args, int argsPosition);

private static native void nativeSetSemanticsEnabled(long nativePlatformViewAndroid,
boolean enabled);
Expand Down Expand Up @@ -743,9 +743,19 @@ public void onFirstFrame() {
private TouchExplorationListener mTouchExplorationListener;

protected void dispatchSemanticsAction(int id, AccessibilityBridge.Action action) {
dispatchSemanticsAction(id, action, null);
}

protected void dispatchSemanticsAction(int id, AccessibilityBridge.Action action, Object args) {
if (!isAttached())
return;
nativeDispatchSemanticsAction(mNativeView.get(), id, action.value);
ByteBuffer encodedArgs = null;
int position = 0;
if (args != null) {
encodedArgs = StandardMessageCodec.INSTANCE.encodeMessage(args);
position = encodedArgs.position();
}
nativeDispatchSemanticsAction(mNativeView.get(), id, action.value, encodedArgs, position);
}

@Override
Expand Down
19 changes: 17 additions & 2 deletions shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,24 @@ void PlatformViewAndroid::HandlePlatformMessageEmptyResponse(int response_id) {
nullptr);
}

void PlatformViewAndroid::DispatchSemanticsAction(jint id, jint action) {
void PlatformViewAndroid::DispatchSemanticsAction(JNIEnv* env,
jint id,
jint action,
jobject args,
jint args_position) {
if (env->IsSameObject(args, NULL)) {
std::vector<uint8_t> args_vector;
PlatformView::DispatchSemanticsAction(
id, static_cast<blink::SemanticsAction>(action), args_vector);
return;
}

uint8_t* args_data = static_cast<uint8_t*>(env->GetDirectBufferAddress(args));
std::vector<uint8_t> args_vector =
std::vector<uint8_t>(args_data, args_data + args_position);

PlatformView::DispatchSemanticsAction(
id, static_cast<blink::SemanticsAction>(action));
id, static_cast<blink::SemanticsAction>(action), std::move(args_vector));
}

void PlatformViewAndroid::SetSemanticsEnabled(jboolean enabled) {
Expand Down
6 changes: 5 additions & 1 deletion shell/platform/android/platform_view_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class PlatformViewAndroid : public PlatformView {
void InvokePlatformMessageEmptyResponseCallback(JNIEnv* env,
jint response_id);

void DispatchSemanticsAction(jint id, jint action);
void DispatchSemanticsAction(JNIEnv* env,
jint id,
jint action,
jobject args,
jint args_position);

void SetSemanticsEnabled(jboolean enabled);

Expand Down
9 changes: 6 additions & 3 deletions shell/platform/android/platform_view_android_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ static void DispatchSemanticsAction(JNIEnv* env,
jobject jcaller,
jlong platform_view,
jint id,
jint action) {
return PLATFORM_VIEW->DispatchSemanticsAction(id, action);
jint action,
jobject args,
jint args_position) {
return PLATFORM_VIEW->DispatchSemanticsAction(env, id, action, args,
args_position);
}

static void SetSemanticsEnabled(JNIEnv* env,
Expand Down Expand Up @@ -413,7 +416,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
},
{
.name = "nativeDispatchSemanticsAction",
.signature = "(JII)V",
.signature = "(JIILjava/nio/ByteBuffer;I)V",
.fnPtr = reinterpret_cast<void*>(&shell::DispatchSemanticsAction),
},
{
Expand Down

0 comments on commit 59c3a37

Please sign in to comment.