Revert rollback of "add assistiveTechnologyEnabled to window" (flutter/engine#5750)

This commit is contained in:
Jonah Williams
2018-07-16 09:04:20 -07:00
committed by GitHub
parent c7124e6dfa
commit c8516387e2
18 changed files with 272 additions and 161 deletions

View File

@@ -70,6 +70,11 @@ void _updateSemanticsEnabled(bool enabled) {
_invoke(window.onSemanticsEnabledChanged, window._onSemanticsEnabledChangedZone);
}
void _updateAssistiveTechnologyEnabled(bool enabled) {
window._assistiveTechnologyEnabled = enabled;
_invoke(window.onAssistiveTechnologyEnabled, window._onAssistiveTechnologyEnabledZone);
}
void _dispatchPlatformMessage(String name, ByteData data, int responseId) {
if (window.onPlatformMessage != null) {
_invoke3<String, ByteData, PlatformMessageResponseCallback>(

View File

@@ -649,6 +649,31 @@ class Window {
_onSemanticsEnabledChangedZone = Zone.current;
}
/// Whether the user is using assitive technologies to interact with the
/// application.
///
/// This includes screen readers such as TalkBack on Android and VoiceOVer
/// on iOS, as well as hardware switches, and more.
///
/// The [onAssistiveTechnologyEnabled] callback is called whenever this value
/// changes.
bool get assistiveTechnologyEnabled => _assistiveTechnologyEnabled;
bool _assistiveTechnologyEnabled = false;
/// A callback that is invoked when the value of [assistiveTechnologyEnabled]
/// changes.
///
/// The framework invokes this callback in the same zone in which the callback
/// was set.
VoidCallback get onAssistiveTechnologyEnabled => _onAssistiveTechnologyEnabled;
VoidCallback _onAssistiveTechnologyEnabled;
Zone _onAssistiveTechnologyEnabledZone;
set onAssistiveTechnologyEnabled(VoidCallback callback) {
_onAssistiveTechnologyEnabled = callback;
_onAssistiveTechnologyEnabledZone = Zone.current;
}
/// A callback that is invoked whenever the user requests an action to be
/// performed.
///

View File

@@ -146,21 +146,20 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) {
if (!dart_state)
return;
tonic::DartState::Scope scope(dart_state);
DartInvokeField(
library_.value(), "_updateWindowMetrics",
{
ToDart(metrics.device_pixel_ratio),
ToDart(metrics.physical_width),
ToDart(metrics.physical_height),
ToDart(metrics.physical_padding_top),
ToDart(metrics.physical_padding_right),
ToDart(metrics.physical_padding_bottom),
ToDart(metrics.physical_padding_left),
ToDart(metrics.physical_view_inset_top),
ToDart(metrics.physical_view_inset_right),
ToDart(metrics.physical_view_inset_bottom),
ToDart(metrics.physical_view_inset_left),
});
DartInvokeField(library_.value(), "_updateWindowMetrics",
{
ToDart(metrics.device_pixel_ratio),
ToDart(metrics.physical_width),
ToDart(metrics.physical_height),
ToDart(metrics.physical_padding_top),
ToDart(metrics.physical_padding_right),
ToDart(metrics.physical_padding_bottom),
ToDart(metrics.physical_padding_left),
ToDart(metrics.physical_view_inset_top),
ToDart(metrics.physical_view_inset_right),
ToDart(metrics.physical_view_inset_bottom),
ToDart(metrics.physical_view_inset_left),
});
}
void Window::UpdateLocale(const std::string& language_code,
@@ -199,6 +198,16 @@ void Window::UpdateSemanticsEnabled(bool enabled) {
{ToDart(enabled)});
}
void Window::UpdateAssistiveTechnologyEnabled(bool enabled) {
tonic::DartState* dart_state = library_.dart_state().get();
if (!dart_state)
return;
tonic::DartState::Scope scope(dart_state);
DartInvokeField(library_.value(), "_updateAssistiveTechnologyEnabled",
{ToDart(enabled)});
}
void Window::DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message) {
tonic::DartState* dart_state = library_.dart_state().get();
if (!dart_state)

View File

@@ -54,6 +54,7 @@ class Window final {
const std::string& country_code);
void UpdateUserSettingsData(const std::string& data);
void UpdateSemanticsEnabled(bool enabled);
void UpdateAssistiveTechnologyEnabled(bool enabled);
void DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
void DispatchSemanticsAction(int32_t id,

View File

@@ -19,6 +19,7 @@ dart:ui,::,_getScheduleMicrotaskClosure
dart:ui,::,_setupHooks
dart:ui,::,_updateLocale
dart:ui,::,_updateSemanticsEnabled
dart:ui,::,_updateAssistiveTechnologyEnabled
dart:ui,::,_updateUserSettingsData
dart:ui,::,_updateWindowMetrics
dart:ui,_ImageInfo,get:width

View File

@@ -122,7 +122,9 @@ std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
bool RuntimeController::FlushRuntimeStateToIsolate() {
return SetViewportMetrics(window_data_.viewport_metrics) &&
SetLocale(window_data_.language_code, window_data_.country_code) &&
SetSemanticsEnabled(window_data_.semantics_enabled);
SetSemanticsEnabled(window_data_.semantics_enabled) &&
SetAssistiveTechnologyEnabled(
window_data_.assistive_technology_enabled);
}
bool RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) {
@@ -170,6 +172,17 @@ bool RuntimeController::SetSemanticsEnabled(bool enabled) {
return false;
}
bool RuntimeController::SetAssistiveTechnologyEnabled(bool enabled) {
window_data_.assistive_technology_enabled = enabled;
if (auto window = GetWindowIfAvailable()) {
window->UpdateAssistiveTechnologyEnabled(
window_data_.assistive_technology_enabled);
return true;
}
return false;
}
bool RuntimeController::BeginFrame(fxl::TimePoint frame_time) {
if (auto window = GetWindowIfAvailable()) {
window->BeginFrame(frame_time);

View File

@@ -9,8 +9,8 @@
#include "flutter/common/task_runners.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/text/font_collection.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/runtime/dart_vm.h"
@@ -47,6 +47,8 @@ class RuntimeController final : public WindowClient {
bool SetSemanticsEnabled(bool enabled);
bool SetAssistiveTechnologyEnabled(bool enabled);
bool BeginFrame(fxl::TimePoint frame_time);
bool NotifyIdle(int64_t deadline);
@@ -80,6 +82,7 @@ class RuntimeController final : public WindowClient {
std::string country_code;
std::string user_settings_data = "{}";
bool semantics_enabled = false;
bool assistive_technology_enabled = false;
};
RuntimeDelegate& client_;

View File

@@ -339,6 +339,10 @@ void Engine::SetSemanticsEnabled(bool enabled) {
runtime_controller_->SetSemanticsEnabled(enabled);
}
void Engine::SetAssistiveTechnologyEnabled(bool enabled) {
runtime_controller_->SetAssistiveTechnologyEnabled(enabled);
}
void Engine::StopAnimator() {
animator_->Stop();
}
@@ -374,7 +378,8 @@ void Engine::Render(std::unique_ptr<flow::LayerTree> layer_tree) {
void Engine::UpdateSemantics(blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {
delegate_.OnEngineUpdateSemantics(*this, std::move(update), std::move(actions));
delegate_.OnEngineUpdateSemantics(*this, std::move(update),
std::move(actions));
}
void Engine::HandlePlatformMessage(

View File

@@ -10,8 +10,8 @@
#include "flutter/assets/asset_manager.h"
#include "flutter/common/task_runners.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "flutter/lib/ui/text/font_collection.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
@@ -99,6 +99,8 @@ class Engine final : public blink::RuntimeDelegate {
void SetSemanticsEnabled(bool enabled);
void SetAssistiveTechnologyEnabled(bool enabled);
void ScheduleFrame(bool regenerate_layer_tree = true) override;
// |blink::RuntimeDelegate|
@@ -125,8 +127,9 @@ class Engine final : public blink::RuntimeDelegate {
void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
// |blink::RuntimeDelegate|
void UpdateSemantics(blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) override;
void UpdateSemantics(
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) override;
// |blink::RuntimeDelegate|
void HandlePlatformMessage(

View File

@@ -52,6 +52,10 @@ void PlatformView::SetSemanticsEnabled(bool enabled) {
delegate_.OnPlatformViewSetSemanticsEnabled(*this, enabled);
}
void PlatformView::SetAssistiveTechnologyEnabled(bool enabled) {
delegate_.OnPlatformViewSetAssistiveTechnologyEnabled(*this, enabled);
}
void PlatformView::SetViewportMetrics(const blink::ViewportMetrics& metrics) {
delegate_.OnPlatformViewSetViewportMetrics(*this, metrics);
}
@@ -74,8 +78,9 @@ fml::WeakPtr<PlatformView> PlatformView::GetWeakPtr() const {
return weak_factory_.GetWeakPtr();
}
void PlatformView::UpdateSemantics(blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {}
void PlatformView::UpdateSemantics(
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {}
void PlatformView::HandlePlatformMessage(
fxl::RefPtr<blink::PlatformMessage> message) {

View File

@@ -10,8 +10,8 @@
#include "flutter/common/task_runners.h"
#include "flutter/flow/texture.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
@@ -58,6 +58,10 @@ class PlatformView {
virtual void OnPlatformViewSetSemanticsEnabled(const PlatformView& view,
bool enabled) = 0;
virtual void OnPlatformViewSetAssistiveTechnologyEnabled(
const PlatformView& view,
bool enabled) = 0;
virtual void OnPlatformViewRegisterTexture(
const PlatformView& view,
std::shared_ptr<flow::Texture> texture) = 0;
@@ -84,6 +88,8 @@ class PlatformView {
virtual void SetSemanticsEnabled(bool enabled);
virtual void SetAssistiveTechnologyEnabled(bool enabled);
void SetViewportMetrics(const blink::ViewportMetrics& metrics);
void NotifyCreated();

View File

@@ -205,8 +205,7 @@ static void PerformInitializationTasks(const blink::Settings& settings) {
});
}
std::unique_ptr<Shell> Shell::Create(
std::unique_ptr<Shell> Shell::Create(
blink::TaskRunners task_runners,
blink::Settings settings,
Shell::CreateCallback<PlatformView> on_create_platform_view,
@@ -574,6 +573,21 @@ void Shell::OnPlatformViewSetSemanticsEnabled(const PlatformView& view,
});
}
void Shell::OnPlatformViewSetAssistiveTechnologyEnabled(
const PlatformView& view,
bool enabled) {
FXL_DCHECK(is_setup_);
FXL_DCHECK(&view == platform_view_.get());
FXL_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
task_runners_.GetUITaskRunner()->PostTask(
[engine = engine_->GetWeakPtr(), enabled] {
if (engine) {
engine->SetAssistiveTechnologyEnabled(enabled);
}
});
}
// |shell::PlatformView::Delegate|
void Shell::OnPlatformViewRegisterTexture(
const PlatformView& view,
@@ -706,14 +720,16 @@ void Shell::OnAnimatorDrawLastLayerTree(const Animator& animator) {
}
// |shell::Engine::Delegate|
void Shell::OnEngineUpdateSemantics(const Engine& engine,
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {
void Shell::OnEngineUpdateSemantics(
const Engine& engine,
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {
FXL_DCHECK(is_setup_);
FXL_DCHECK(task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread());
task_runners_.GetPlatformTaskRunner()->PostTask(
[view = platform_view_->GetWeakPtr(), update = std::move(update), actions = std::move(actions)] {
[view = platform_view_->GetWeakPtr(), update = std::move(update),
actions = std::move(actions)] {
if (view) {
view->UpdateSemantics(std::move(update), std::move(actions));
}

View File

@@ -14,8 +14,8 @@
#include "flutter/fml/memory/thread_checker.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/thread.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/runtime/service_protocol.h"
#include "flutter/shell/common/animator.h"
@@ -149,6 +149,10 @@ class Shell final : public PlatformView::Delegate,
void OnPlatformViewSetSemanticsEnabled(const PlatformView& view,
bool enabled) override;
// |shell::PlatformView::Delegate|
void OnPlatformViewSetAssistiveTechnologyEnabled(const PlatformView& view,
bool enabled) override;
// |shell::PlatformView::Delegate|
void OnPlatformViewRegisterTexture(
const PlatformView& view,
@@ -183,9 +187,10 @@ class Shell final : public PlatformView::Delegate,
void OnAnimatorDrawLastLayerTree(const Animator& animator) override;
// |shell::Engine::Delegate|
void OnEngineUpdateSemantics(const Engine& engine,
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) override;
void OnEngineUpdateSemantics(
const Engine& engine,
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) override;
// |shell::Engine::Delegate|
void OnEngineHandlePlatformMessage(

View File

@@ -41,9 +41,9 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* An Android view containing a Flutter app.
*/
public class FlutterView extends SurfaceView
implements BinaryMessenger, TextureRegistry, AccessibilityManager.AccessibilityStateChangeListener {
public class FlutterView
extends SurfaceView implements BinaryMessenger, TextureRegistry,
AccessibilityManager.AccessibilityStateChangeListener {
/**
* Interface for those objects that maintain and expose a reference to a
* {@code FlutterView} (such as a full-screen Flutter activity).
@@ -129,7 +129,7 @@ public class FlutterView extends SurfaceView
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true);
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
&& typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
&& typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
color = typedValue.data;
}
// TODO(abarth): Consider letting the developer override this color.
@@ -156,29 +156,29 @@ public class FlutterView extends SurfaceView
};
getHolder().addCallback(mSurfaceCallback);
mAccessibilityManager = (AccessibilityManager) getContext()
.getSystemService(Context.ACCESSIBILITY_SERVICE);
mAccessibilityManager =
(AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
mActivityLifecycleListeners = new ArrayList<>();
mFirstFrameListeners = new ArrayList<>();
// Configure the platform plugins and flutter channels.
mFlutterLocalizationChannel = new MethodChannel(this, "flutter/localization",
JSONMethodCodec.INSTANCE);
mFlutterNavigationChannel = new MethodChannel(this, "flutter/navigation",
JSONMethodCodec.INSTANCE);
mFlutterKeyEventChannel = new BasicMessageChannel<>(this, "flutter/keyevent",
JSONMessageCodec.INSTANCE);
mFlutterLifecycleChannel = new BasicMessageChannel<>(this, "flutter/lifecycle",
StringCodec.INSTANCE);
mFlutterSystemChannel = new BasicMessageChannel<>(this, "flutter/system",
JSONMessageCodec.INSTANCE);
mFlutterSettingsChannel = new BasicMessageChannel<>(this, "flutter/settings",
JSONMessageCodec.INSTANCE);
mFlutterLocalizationChannel =
new MethodChannel(this, "flutter/localization", JSONMethodCodec.INSTANCE);
mFlutterNavigationChannel =
new MethodChannel(this, "flutter/navigation", JSONMethodCodec.INSTANCE);
mFlutterKeyEventChannel =
new BasicMessageChannel<>(this, "flutter/keyevent", JSONMessageCodec.INSTANCE);
mFlutterLifecycleChannel =
new BasicMessageChannel<>(this, "flutter/lifecycle", StringCodec.INSTANCE);
mFlutterSystemChannel =
new BasicMessageChannel<>(this, "flutter/system", JSONMessageCodec.INSTANCE);
mFlutterSettingsChannel =
new BasicMessageChannel<>(this, "flutter/settings", JSONMessageCodec.INSTANCE);
PlatformPlugin platformPlugin = new PlatformPlugin(activity);
MethodChannel flutterPlatformChannel = new MethodChannel(this,
"flutter/platform", JSONMethodCodec.INSTANCE);
MethodChannel flutterPlatformChannel =
new MethodChannel(this, "flutter/platform", JSONMethodCodec.INSTANCE);
flutterPlatformChannel.setMethodCallHandler(platformPlugin);
addActivityLifecycleListener(platformPlugin);
mImm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -310,15 +310,15 @@ public class FlutterView extends SurfaceView
}
private void setUserSettings() {
Map<String, Object> message = new HashMap<>();
message.put("textScaleFactor", getResources().getConfiguration().fontScale);
message.put("alwaysUse24HourFormat", DateFormat.is24HourFormat(getContext()));
mFlutterSettingsChannel.send(message);
Map<String, Object> message = new HashMap<>();
message.put("textScaleFactor", getResources().getConfiguration().fontScale);
message.put("alwaysUse24HourFormat", DateFormat.is24HourFormat(getContext()));
mFlutterSettingsChannel.send(message);
}
private void setLocale(Locale locale) {
mFlutterLocalizationChannel.invokeMethod("setLocale",
Arrays.asList(locale.getLanguage(), locale.getCountry()));
mFlutterLocalizationChannel.invokeMethod(
"setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry()));
}
@Override
@@ -333,8 +333,7 @@ public class FlutterView extends SurfaceView
}
public FlutterNativeView detach() {
if (!isAttached())
return null;
if (!isAttached()) return null;
if (mDiscoveryReceiver != null) {
getContext().unregisterReceiver(mDiscoveryReceiver);
}
@@ -347,8 +346,7 @@ public class FlutterView extends SurfaceView
}
public void destroy() {
if (!isAttached())
return;
if (!isAttached()) return;
if (mDiscoveryReceiver != null) {
getContext().unregisterReceiver(mDiscoveryReceiver);
@@ -425,8 +423,7 @@ public class FlutterView extends SurfaceView
}
}
private void addPointerForIndex(MotionEvent event, int pointerIndex,
ByteBuffer packet) {
private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer packet) {
int pointerChange = getPointerChangeForAction(event.getActionMasked());
if (pointerChange == -1) {
return;
@@ -463,8 +460,8 @@ public class FlutterView extends SurfaceView
packet.putDouble(1.0); // pressure_max
if (pointerKind == kPointerDeviceKindStylus) {
packet
.putDouble(event.getAxisValue(MotionEvent.AXIS_DISTANCE, pointerIndex)); // distance
packet.putDouble(
event.getAxisValue(MotionEvent.AXIS_DISTANCE, pointerIndex)); // distance
packet.putDouble(0.0); // distance_max
} else {
packet.putDouble(0.0); // distance
@@ -478,7 +475,7 @@ public class FlutterView extends SurfaceView
packet.putDouble(0.0); // radius_max
packet.putDouble(
event.getAxisValue(MotionEvent.AXIS_ORIENTATION, pointerIndex)); // orientation
event.getAxisValue(MotionEvent.AXIS_ORIENTATION, pointerIndex)); // orientation
if (pointerKind == kPointerDeviceKindStylus) {
packet.putDouble(event.getAxisValue(MotionEvent.AXIS_TILT, pointerIndex)); // tilt
@@ -508,17 +505,16 @@ public class FlutterView extends SurfaceView
int pointerCount = event.getPointerCount();
ByteBuffer packet = ByteBuffer
.allocateDirect(pointerCount * kPointerDataFieldCount * kBytePerField);
ByteBuffer packet =
ByteBuffer.allocateDirect(pointerCount * kPointerDataFieldCount * kBytePerField);
packet.order(ByteOrder.LITTLE_ENDIAN);
int maskedAction = event.getActionMasked();
// ACTION_UP, ACTION_POINTER_UP, ACTION_DOWN, and ACTION_POINTER_DOWN
// only apply to a single pointer, other events apply to all pointers.
if (maskedAction == MotionEvent.ACTION_UP
|| maskedAction == MotionEvent.ACTION_POINTER_UP
|| maskedAction == MotionEvent.ACTION_DOWN
|| maskedAction == MotionEvent.ACTION_POINTER_DOWN) {
if (maskedAction == MotionEvent.ACTION_UP || maskedAction == MotionEvent.ACTION_POINTER_UP
|| maskedAction == MotionEvent.ACTION_DOWN
|| maskedAction == MotionEvent.ACTION_POINTER_DOWN) {
addPointerForIndex(event, event.getActionIndex(), packet);
} else {
// ACTION_MOVE may not actually mean all pointers have moved
@@ -600,16 +596,14 @@ public class FlutterView extends SurfaceView
}
void assertAttached() {
if (!isAttached())
throw new AssertionError("Platform view is not attached");
if (!isAttached()) throw new AssertionError("Platform view is not attached");
}
private void preRun() {
resetAccessibilityTree();
}
private void postRun() {
}
private void postRun() {}
public void runFromBundle(String bundlePath, String snapshotOverride) {
runFromBundle(bundlePath, snapshotOverride, "main", false);
@@ -619,7 +613,8 @@ public class FlutterView extends SurfaceView
runFromBundle(bundlePath, snapshotOverride, entrypoint, false);
}
public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) {
public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint,
boolean reuseRuntimeController) {
assertAttached();
preRun();
mNativeView.runFromBundle(bundlePath, snapshotOverride, entrypoint, reuseRuntimeController);
@@ -636,68 +631,57 @@ public class FlutterView extends SurfaceView
return nativeGetBitmap(mNativeView.get());
}
private static native void nativeSurfaceCreated(long nativePlatformViewAndroid,
Surface surface,
int backgroundColor);
private static native void nativeSurfaceCreated(
long nativePlatformViewAndroid, Surface surface, int backgroundColor);
private static native void nativeSurfaceChanged(long nativePlatformViewAndroid,
int width,
int height);
private static native void nativeSurfaceChanged(
long nativePlatformViewAndroid, int width, int height);
private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid);
private static native void nativeSetViewportMetrics(long nativePlatformViewAndroid,
float devicePixelRatio,
int physicalWidth,
int physicalHeight,
int physicalPaddingTop,
int physicalPaddingRight,
int physicalPaddingBottom,
int physicalPaddingLeft,
int physicalViewInsetTop,
int physicalViewInsetRight,
int physicalViewInsetBottom,
int physicalViewInsetLeft);
float devicePixelRatio, int physicalWidth, int physicalHeight, int physicalPaddingTop,
int physicalPaddingRight, int physicalPaddingBottom, int physicalPaddingLeft,
int physicalViewInsetTop, int physicalViewInsetRight, int physicalViewInsetBottom,
int physicalViewInsetLeft);
private static native Bitmap nativeGetBitmap(long nativePlatformViewAndroid);
private static native void nativeDispatchPointerDataPacket(long nativePlatformViewAndroid,
ByteBuffer buffer, int position);
private static native void nativeDispatchPointerDataPacket(
long nativePlatformViewAndroid, ByteBuffer buffer, int position);
private static native void nativeDispatchSemanticsAction(long nativePlatformViewAndroid, int id,
int action, ByteBuffer args, int argsPosition);
private static native void nativeDispatchSemanticsAction(
long nativePlatformViewAndroid, int id, int action, ByteBuffer args, int argsPosition);
private static native void nativeSetSemanticsEnabled(long nativePlatformViewAndroid,
boolean enabled);
private static native void nativeSetSemanticsEnabled(
long nativePlatformViewAndroid, boolean enabled);
private static native void nativeSetAssistiveTechnologyEnabled(
long nativePlatformViewAndroid, boolean enabled);
private static native boolean nativeGetIsSoftwareRenderingEnabled();
private static native void nativeRegisterTexture(long nativePlatformViewAndroid, long textureId, SurfaceTexture surfaceTexture);
private static native void nativeRegisterTexture(
long nativePlatformViewAndroid, long textureId, SurfaceTexture surfaceTexture);
private static native void nativeMarkTextureFrameAvailable(long nativePlatformViewAndroid, long textureId);
private static native void nativeMarkTextureFrameAvailable(
long nativePlatformViewAndroid, long textureId);
private static native void nativeUnregisterTexture(long nativePlatformViewAndroid, long textureId);
private static native void nativeUnregisterTexture(
long nativePlatformViewAndroid, long textureId);
private void updateViewportMetrics() {
if (!isAttached())
return;
nativeSetViewportMetrics(mNativeView.get(),
mMetrics.devicePixelRatio,
mMetrics.physicalWidth,
mMetrics.physicalHeight,
mMetrics.physicalPaddingTop,
mMetrics.physicalPaddingRight,
mMetrics.physicalPaddingBottom,
mMetrics.physicalPaddingLeft,
mMetrics.physicalViewInsetTop,
mMetrics.physicalViewInsetRight,
mMetrics.physicalViewInsetBottom,
mMetrics.physicalViewInsetLeft);
if (!isAttached()) return;
nativeSetViewportMetrics(mNativeView.get(), mMetrics.devicePixelRatio,
mMetrics.physicalWidth, mMetrics.physicalHeight, mMetrics.physicalPaddingTop,
mMetrics.physicalPaddingRight, mMetrics.physicalPaddingBottom,
mMetrics.physicalPaddingLeft, mMetrics.physicalViewInsetTop,
mMetrics.physicalViewInsetRight, mMetrics.physicalViewInsetBottom,
mMetrics.physicalViewInsetLeft);
WindowManager wm = (WindowManager) getContext()
.getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
float fps = wm.getDefaultDisplay().getRefreshRate();
VsyncWaiter.refreshPeriodNanos = (long)(1000000000.0 / fps);
VsyncWaiter.refreshPeriodNanos = (long) (1000000000.0 / fps);
}
// Called by native to update the semantics/accessibility tree.
@@ -743,8 +727,7 @@ public class FlutterView extends SurfaceView
}
protected void dispatchSemanticsAction(int id, AccessibilityBridge.Action action, Object args) {
if (!isAttached())
return;
if (!isAttached()) return;
ByteBuffer encodedArgs = null;
int position = 0;
if (args != null) {
@@ -777,8 +760,8 @@ public class FlutterView extends SurfaceView
super.onDetachedFromWindow();
mAccessibilityManager.removeAccessibilityStateChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mAccessibilityManager
.removeTouchExplorationStateChangeListener(mTouchExplorationListener);
mAccessibilityManager.removeTouchExplorationStateChangeListener(
mTouchExplorationListener);
}
}
@@ -805,18 +788,19 @@ public class FlutterView extends SurfaceView
}
class TouchExplorationListener
implements AccessibilityManager.TouchExplorationStateChangeListener {
implements AccessibilityManager.TouchExplorationStateChangeListener {
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
if (enabled) {
mTouchExplorationEnabled = true;
ensureAccessibilityEnabled();
nativeSetAssistiveTechnologyEnabled(mNativeView.get(), true);
} else {
mTouchExplorationEnabled = false;
if (mAccessibilityNodeProvider != null) {
mAccessibilityNodeProvider.handleTouchExplorationExit();
}
nativeSetAssistiveTechnologyEnabled(mNativeView.get(), false);
}
resetWillNotDraw();
}
@@ -824,17 +808,16 @@ public class FlutterView extends SurfaceView
@Override
public AccessibilityNodeProvider getAccessibilityNodeProvider() {
if (mAccessibilityEnabled)
return mAccessibilityNodeProvider;
// TODO(goderbauer): when a11y is off this should return a one-off snapshot of the a11y tree.
if (mAccessibilityEnabled) return mAccessibilityNodeProvider;
// TODO(goderbauer): when a11y is off this should return a one-off snapshot of the a11y
// tree.
return null;
}
private AccessibilityBridge mAccessibilityNodeProvider;
void ensureAccessibilityEnabled() {
if (!isAttached())
return;
if (!isAttached()) return;
mAccessibilityEnabled = true;
if (mAccessibilityNodeProvider == null) {
mAccessibilityNodeProvider = new AccessibilityBridge(this);
@@ -853,8 +836,8 @@ public class FlutterView extends SurfaceView
if (!mTouchExplorationEnabled) {
return false;
}
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER ||
event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER
|| event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
mAccessibilityNodeProvider.handleTouchExploration(event.getX(), event.getY());
} else if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT) {
mAccessibilityNodeProvider.handleTouchExplorationExit();
@@ -892,7 +875,6 @@ public class FlutterView extends SurfaceView
* and the tool scrapes the log lines for the data.
*/
private class DiscoveryReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
URI observatoryUri = URI.create(FlutterNativeView.getObservatoryUri());
@@ -900,7 +882,8 @@ public class FlutterView extends SurfaceView
try {
discover.put("id", getContext().getPackageName());
discover.put("observatoryPort", observatoryUri.getPort());
Log.i(TAG, "DISCOVER: " + discover); // The tool looks for this data. See android_device.dart.
Log.i(TAG, "DISCOVER: " + discover); // The tool looks for this data. See
// android_device.dart.
} catch (JSONException e) {
}
}
@@ -909,16 +892,14 @@ public class FlutterView extends SurfaceView
/**
* Listener will be called on the Android UI thread once when Flutter renders the first frame.
*/
public interface FirstFrameListener {
void onFirstFrame();
}
public interface FirstFrameListener { void onFirstFrame(); }
@Override
public TextureRegistry.SurfaceTextureEntry createSurfaceTexture() {
final SurfaceTexture surfaceTexture = new SurfaceTexture(0);
surfaceTexture.detachFromGLContext();
final SurfaceTextureRegistryEntry entry = new SurfaceTextureRegistryEntry(
nextTextureId.getAndIncrement(), surfaceTexture);
final SurfaceTextureRegistryEntry entry =
new SurfaceTextureRegistryEntry(nextTextureId.getAndIncrement(), surfaceTexture);
nativeRegisterTexture(mNativeView.get(), entry.id(), surfaceTexture);
return entry;
}
@@ -931,17 +912,19 @@ public class FlutterView extends SurfaceView
SurfaceTextureRegistryEntry(long id, SurfaceTexture surfaceTexture) {
this.id = id;
this.surfaceTexture = surfaceTexture;
this.surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
@Override
public void onFrameAvailable(SurfaceTexture texture) {
nativeMarkTextureFrameAvailable(mNativeView.get(), SurfaceTextureRegistryEntry.this.id);
}
});
this.surfaceTexture.setOnFrameAvailableListener(
new SurfaceTexture.OnFrameAvailableListener() {
@Override
public void onFrameAvailable(SurfaceTexture texture) {
nativeMarkTextureFrameAvailable(
mNativeView.get(), SurfaceTextureRegistryEntry.this.id);
}
});
}
@Override
public SurfaceTexture surfaceTexture() {
return surfaceTexture;
return surfaceTexture;
}
@Override

View File

@@ -85,7 +85,8 @@ void FlutterViewUpdateCustomAccessibilityActions(JNIEnv* env,
jobject obj,
jobject buffer,
jobjectArray strings) {
env->CallVoidMethod(obj, g_update_custom_accessibility_actions_method, buffer, strings);
env->CallVoidMethod(obj, g_update_custom_accessibility_actions_method, buffer,
strings);
FXL_CHECK(CheckException(env));
}
@@ -429,6 +430,14 @@ static void SetSemanticsEnabled(JNIEnv* env,
ANDROID_SHELL_HOLDER->GetPlatformView()->SetSemanticsEnabled(enabled);
}
static void SetAssistiveTechnologyEnabled(JNIEnv* env,
jobject jcaller,
jlong shell_holder,
jboolean enabled) {
ANDROID_SHELL_HOLDER->GetPlatformView()->SetAssistiveTechnologyEnabled(
enabled);
}
static jboolean GetIsSoftwareRendering(JNIEnv* env, jobject jcaller) {
return FlutterMain::Get().GetSettings().enable_software_rendering;
}
@@ -600,6 +609,12 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.signature = "(JZ)V",
.fnPtr = reinterpret_cast<void*>(&shell::SetSemanticsEnabled),
},
{
.name = "nativeSetAssistiveTechnologyEnabled",
.signature = "(JZ)V",
.fnPtr =
reinterpret_cast<void*>(&shell::SetAssistiveTechnologyEnabled),
},
{
.name = "nativeGetIsSoftwareRenderingEnabled",
.signature = "()Z",
@@ -657,9 +672,9 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return false;
}
g_update_custom_accessibility_actions_method =
env->GetMethodID(g_flutter_native_view_class->obj(), "updateCustomAccessibilityActions",
"(Ljava/nio/ByteBuffer;[Ljava/lang/String;)V");
g_update_custom_accessibility_actions_method = env->GetMethodID(
g_flutter_native_view_class->obj(), "updateCustomAccessibilityActions",
"(Ljava/nio/ByteBuffer;[Ljava/lang/String;)V");
if (g_update_custom_accessibility_actions_method == nullptr) {
return false;

View File

@@ -792,16 +792,18 @@ static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* to
#pragma mark - Accessibility
- (void)onAccessibilityStatusChanged:(NSNotification*)notification {
auto platformView = _shell->GetPlatformView();
#if TARGET_OS_SIMULATOR
// There doesn't appear to be any way to determine whether the accessibility
// inspector is enabled on the simulator. We conservatively always turn on the
// accessibility bridge in the simulator.
bool enabled = true;
// accessibility bridge in the simulator, but never assistive technology.
platformView->SetSemanticsEnabled(true);
platformView->SetAssistiveTechnologyEnabled(false);
#else
bool enabled = UIAccessibilityIsVoiceOverRunning() || UIAccessibilityIsSwitchControlRunning() ||
UIAccessibilityIsSpeakScreenEnabled();
bool enabled = UIAccessibilityIsVoiceOverRunning() || UIAccessibilityIsSwitchControlRunning();
platformView->SetSemanticsEnabled(enabled || UIAccessibilityIsSpeakScreenEnabled());
platformView->SetAssistiveTechnologyEnabled(enabled);
#endif
_shell->GetPlatformView()->SetSemanticsEnabled(enabled);
}
#pragma mark - Memory Notifications

View File

@@ -57,10 +57,13 @@ class PlatformViewIOS final : public HeadlessPlatformViewIOS {
// |shell::PlatformView|
void SetSemanticsEnabled(bool enabled) override;
// |shell::PlatformView|
void SetAssistiveTechnologyEnabled(bool enabled) override;
// |shell::PlatformView|
void UpdateSemantics(blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) override;
void UpdateSemantics(
blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) override;
// |shell::PlatformView|
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;

View File

@@ -67,6 +67,17 @@ void PlatformViewIOS::SetSemanticsEnabled(bool enabled) {
PlatformView::SetSemanticsEnabled(enabled);
}
// |shell:PlatformView|
void PlatformViewIOS::SetAssistiveTechnologyEnabled(bool enabled) {
if (enabled && !accessibility_bridge_) {
accessibility_bridge_ = std::make_unique<AccessibilityBridge>(owner_view_, this);
}
// Note: since the accessibility bridge is needed for both semantics and
// assistive technologies, but you cannot have the latter without the
// former, we only destroy the bridge in SetSemanticsEnabled and not here.
PlatformView::SetAssistiveTechnologyEnabled(enabled);
}
// |shell::PlatformView|
void PlatformViewIOS::UpdateSemantics(blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {