iOS a11y text entry (~70% of it) (flutter/engine#4575)
* implement iOS text field editing in a11y mode * address Chinmay's comments * replace node in child list when changing type
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "third_party/skia/include/core/SkMatrix44.h"
|
||||
@@ -70,6 +71,12 @@ struct SemanticsNode {
|
||||
std::vector<int32_t> children;
|
||||
};
|
||||
|
||||
// Contains semantic nodes that need to be updated.
|
||||
//
|
||||
// The keys in the map are stable node IDd, and the values contain
|
||||
// semantic information for the node corresponding to the ID.
|
||||
using SemanticsNodeUpdates = std::unordered_map<int32_t, SemanticsNode>;
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_
|
||||
|
||||
@@ -21,16 +21,16 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, SemanticsUpdate);
|
||||
DART_BIND_ALL(SemanticsUpdate, FOR_EACH_BINDING)
|
||||
|
||||
fxl::RefPtr<SemanticsUpdate> SemanticsUpdate::create(
|
||||
std::vector<SemanticsNode> nodes) {
|
||||
SemanticsNodeUpdates nodes) {
|
||||
return fxl::MakeRefCounted<SemanticsUpdate>(std::move(nodes));
|
||||
}
|
||||
|
||||
SemanticsUpdate::SemanticsUpdate(std::vector<SemanticsNode> nodes)
|
||||
SemanticsUpdate::SemanticsUpdate(SemanticsNodeUpdates nodes)
|
||||
: nodes_(std::move(nodes)) {}
|
||||
|
||||
SemanticsUpdate::~SemanticsUpdate() = default;
|
||||
|
||||
std::vector<SemanticsNode> SemanticsUpdate::takeNodes() {
|
||||
SemanticsNodeUpdates SemanticsUpdate::takeNodes() {
|
||||
return std::move(nodes_);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#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"
|
||||
|
||||
@@ -23,18 +21,18 @@ class SemanticsUpdate : public fxl::RefCountedThreadSafe<SemanticsUpdate>,
|
||||
|
||||
public:
|
||||
~SemanticsUpdate() override;
|
||||
static fxl::RefPtr<SemanticsUpdate> create(std::vector<SemanticsNode> nodes);
|
||||
static fxl::RefPtr<SemanticsUpdate> create(SemanticsNodeUpdates nodes);
|
||||
|
||||
std::vector<SemanticsNode> takeNodes();
|
||||
SemanticsNodeUpdates takeNodes();
|
||||
|
||||
void dispose();
|
||||
|
||||
static void RegisterNatives(tonic::DartLibraryNatives* natives);
|
||||
|
||||
private:
|
||||
explicit SemanticsUpdate(std::vector<SemanticsNode> nodes);
|
||||
explicit SemanticsUpdate(SemanticsNodeUpdates nodes);
|
||||
|
||||
std::vector<SemanticsNode> nodes_;
|
||||
SemanticsNodeUpdates nodes_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@@ -69,7 +69,7 @@ void SemanticsUpdateBuilder::updateNode(int id,
|
||||
node.transform.setColMajord(transform.data());
|
||||
node.children = std::vector<int32_t>(
|
||||
children.data(), children.data() + children.num_elements());
|
||||
nodes_.push_back(node);
|
||||
nodes_[id] = node;
|
||||
}
|
||||
|
||||
fxl::RefPtr<SemanticsUpdate> SemanticsUpdateBuilder::build() {
|
||||
|
||||
@@ -51,7 +51,7 @@ class SemanticsUpdateBuilder
|
||||
private:
|
||||
explicit SemanticsUpdateBuilder();
|
||||
|
||||
std::vector<SemanticsNode> nodes_;
|
||||
SemanticsNodeUpdates nodes_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@@ -20,7 +20,7 @@ class RuntimeDelegate {
|
||||
virtual std::string DefaultRouteName() = 0;
|
||||
virtual void ScheduleFrame(bool regenerate_layer_tree = true) = 0;
|
||||
virtual void Render(std::unique_ptr<flow::LayerTree> layer_tree) = 0;
|
||||
virtual void UpdateSemantics(std::vector<SemanticsNode> update) = 0;
|
||||
virtual void UpdateSemantics(blink::SemanticsNodeUpdates update) = 0;
|
||||
virtual void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) = 0;
|
||||
|
||||
virtual void DidCreateMainIsolate(Dart_Isolate isolate);
|
||||
|
||||
@@ -662,7 +662,7 @@ void Engine::Render(std::unique_ptr<flow::LayerTree> layer_tree) {
|
||||
animator_->Render(std::move(layer_tree));
|
||||
}
|
||||
|
||||
void Engine::UpdateSemantics(std::vector<blink::SemanticsNode> update) {
|
||||
void Engine::UpdateSemantics(blink::SemanticsNodeUpdates update) {
|
||||
blink::Threads::Platform()->PostTask(fxl::MakeCopyable([
|
||||
platform_view = platform_view_.lock(), update = std::move(update)
|
||||
]() mutable {
|
||||
|
||||
@@ -85,7 +85,7 @@ class Engine : public blink::RuntimeDelegate {
|
||||
// RuntimeDelegate methods:
|
||||
std::string DefaultRouteName() override;
|
||||
void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
|
||||
void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
|
||||
void UpdateSemantics(blink::SemanticsNodeUpdates update) override;
|
||||
void HandlePlatformMessage(
|
||||
fxl::RefPtr<blink::PlatformMessage> message) override;
|
||||
void DidCreateMainIsolate(Dart_Isolate isolate) override;
|
||||
|
||||
@@ -130,7 +130,7 @@ VsyncWaiter* PlatformView::GetVsyncWaiter() {
|
||||
return vsync_waiter_.get();
|
||||
}
|
||||
|
||||
void PlatformView::UpdateSemantics(std::vector<blink::SemanticsNode> update) {}
|
||||
void PlatformView::UpdateSemantics(blink::SemanticsNodeUpdates update) {}
|
||||
|
||||
void PlatformView::HandlePlatformMessage(
|
||||
fxl::RefPtr<blink::PlatformMessage> message) {
|
||||
|
||||
@@ -60,7 +60,7 @@ class PlatformView : public std::enable_shared_from_this<PlatformView> {
|
||||
|
||||
virtual bool ResourceContextMakeCurrent() = 0;
|
||||
|
||||
virtual void UpdateSemantics(std::vector<blink::SemanticsNode> update);
|
||||
virtual void UpdateSemantics(blink::SemanticsNodeUpdates update);
|
||||
virtual void HandlePlatformMessage(
|
||||
fxl::RefPtr<blink::PlatformMessage> message);
|
||||
|
||||
|
||||
@@ -460,7 +460,7 @@ bool PlatformViewAndroid::ResourceContextMakeCurrent() {
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::UpdateSemantics(
|
||||
std::vector<blink::SemanticsNode> update) {
|
||||
blink::SemanticsNodeUpdates update) {
|
||||
constexpr size_t kBytesPerNode = 33 * sizeof(int32_t);
|
||||
constexpr size_t kBytesPerChild = sizeof(int32_t);
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class PlatformViewAndroid : public PlatformView {
|
||||
|
||||
bool ResourceContextMakeCurrent() override;
|
||||
|
||||
void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
|
||||
void UpdateSemantics(blink::SemanticsNodeUpdates update) override;
|
||||
|
||||
void HandlePlatformMessage(
|
||||
fxl::RefPtr<blink::PlatformMessage> message) override;
|
||||
|
||||
@@ -55,6 +55,8 @@ shared_library("create_flutter_framework_dylib") {
|
||||
"framework/Source/FlutterViewController.mm",
|
||||
"framework/Source/accessibility_bridge.h",
|
||||
"framework/Source/accessibility_bridge.mm",
|
||||
"framework/Source/accessibility_text_entry.h",
|
||||
"framework/Source/accessibility_text_entry.mm",
|
||||
"framework/Source/flutter_main_ios.h",
|
||||
"framework/Source/flutter_main_ios.mm",
|
||||
"framework/Source/flutter_touch_mapper.h",
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#ifndef SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
|
||||
#define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterChannels.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
|
||||
|
||||
@@ -13,6 +15,33 @@
|
||||
@property(nonatomic, assign) id<FlutterTextInputDelegate> textInputDelegate;
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
|
||||
|
||||
/**
|
||||
* The `UITextInput` implementation used to control text entry.
|
||||
*
|
||||
* This is used by `AccessibilityBridge` to forward interactions with iOS'
|
||||
* accessibility system.
|
||||
*/
|
||||
- (UIView<UITextInput>*)textInputView;
|
||||
|
||||
@end
|
||||
|
||||
/** An indexed position in the buffer of a Flutter text editing widget. */
|
||||
@interface FlutterTextPosition : UITextPosition
|
||||
|
||||
@property(nonatomic, readonly) NSUInteger index;
|
||||
|
||||
+ (instancetype)positionWithIndex:(NSUInteger)index;
|
||||
- (instancetype)initWithIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
||||
|
||||
/** A range of text in the buffer of a Flutter text editing widget. */
|
||||
@interface FlutterTextRange : UITextRange<NSCopying>
|
||||
|
||||
@property(nonatomic, readonly) NSRange range;
|
||||
|
||||
+ (instancetype)rangeWithNSRange:(NSRange)range;
|
||||
|
||||
@end
|
||||
|
||||
#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
|
||||
|
||||
@@ -41,16 +41,6 @@ static UITextAutocapitalizationType ToUITextAutocapitalizationType(NSString* inp
|
||||
|
||||
#pragma mark - FlutterTextPosition
|
||||
|
||||
/** An indexed position in the buffer of a Flutter text editing widget. */
|
||||
@interface FlutterTextPosition : UITextPosition
|
||||
|
||||
@property(nonatomic, readonly) NSUInteger index;
|
||||
|
||||
+ (instancetype)positionWithIndex:(NSUInteger)index;
|
||||
- (instancetype)initWithIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FlutterTextPosition
|
||||
|
||||
+ (instancetype)positionWithIndex:(NSUInteger)index {
|
||||
@@ -69,15 +59,6 @@ static UITextAutocapitalizationType ToUITextAutocapitalizationType(NSString* inp
|
||||
|
||||
#pragma mark - FlutterTextRange
|
||||
|
||||
/** A range of text in the buffer of a Flutter text editing widget. */
|
||||
@interface FlutterTextRange : UITextRange<NSCopying>
|
||||
|
||||
@property(nonatomic, readonly) NSRange range;
|
||||
|
||||
+ (instancetype)rangeWithNSRange:(NSRange)range;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FlutterTextRange
|
||||
|
||||
+ (instancetype)rangeWithNSRange:(NSRange)range {
|
||||
@@ -536,8 +517,28 @@ static UITextAutocapitalizationType ToUITextAutocapitalizationType(NSString* inp
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Hides `FlutterTextInputView` from iOS accessibility system so it
|
||||
* does not show up twice, once where it is in the `UIView` hierarchy,
|
||||
* and a second time as part of the `SemanticsObject` hierarchy.
|
||||
*/
|
||||
@interface FlutterTextInputViewAccessibilityHider : UIView {
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation FlutterTextInputViewAccessibilityHider {
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityElementsHidden {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation FlutterTextInputPlugin {
|
||||
FlutterTextInputView* _view;
|
||||
FlutterTextInputViewAccessibilityHider* _inputHider;
|
||||
}
|
||||
|
||||
@synthesize textInputDelegate = _textInputDelegate;
|
||||
@@ -547,6 +548,7 @@ static UITextAutocapitalizationType ToUITextAutocapitalizationType(NSString* inp
|
||||
|
||||
if (self) {
|
||||
_view = [[FlutterTextInputView alloc] init];
|
||||
_inputHider = [[FlutterTextInputViewAccessibilityHider alloc] init];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -555,10 +557,15 @@ static UITextAutocapitalizationType ToUITextAutocapitalizationType(NSString* inp
|
||||
- (void)dealloc {
|
||||
[self hideTextInput];
|
||||
[_view release];
|
||||
[_inputHider release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (UIView<UITextInput>*)textInputView {
|
||||
return _view;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||
NSString* method = call.method;
|
||||
id args = call.arguments;
|
||||
@@ -587,13 +594,15 @@ static UITextAutocapitalizationType ToUITextAutocapitalizationType(NSString* inp
|
||||
@"The application must have a key window since the keyboard client "
|
||||
@"must be part of the responder chain to function");
|
||||
_view.textInputDelegate = _textInputDelegate;
|
||||
[[UIApplication sharedApplication].keyWindow addSubview:_view];
|
||||
[_inputHider addSubview:_view];
|
||||
[[UIApplication sharedApplication].keyWindow addSubview:_inputHider];
|
||||
[_view becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (void)hideTextInput {
|
||||
[_view resignFirstResponder];
|
||||
[_view removeFromSuperview];
|
||||
[_inputHider removeFromSuperview];
|
||||
}
|
||||
|
||||
- (void)setTextInputClient:(int)client withConfiguration:(NSDictionary*)configuration {
|
||||
|
||||
@@ -197,6 +197,7 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
|
||||
[_textInputChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
||||
[_textInputPlugin.get() handleMethodCall:call result:result];
|
||||
}];
|
||||
_platformView->SetTextInputPlugin(_textInputPlugin);
|
||||
|
||||
[self setupNotificationCenterObservers];
|
||||
}
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
||||
#include "flutter/lib/ui/semantics/semantics_node.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterChannels.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "third_party/skia/include/core/SkMatrix44.h"
|
||||
@@ -22,6 +25,9 @@ namespace shell {
|
||||
class AccessibilityBridge;
|
||||
} // namespace shell
|
||||
|
||||
/**
|
||||
* A node in the iOS semantics tree.
|
||||
*/
|
||||
@interface SemanticsObject : NSObject
|
||||
|
||||
/**
|
||||
@@ -35,12 +41,57 @@ class AccessibilityBridge;
|
||||
*/
|
||||
@property(nonatomic, strong) SemanticsObject* parent;
|
||||
|
||||
/**
|
||||
* The accessibility bridge that this semantics object is attached to. This
|
||||
* object may use the bridge to access contextual application information.
|
||||
*/
|
||||
@property(nonatomic, readonly) shell::AccessibilityBridge* bridge;
|
||||
|
||||
/**
|
||||
* The semantics node used to produce this semantics object.
|
||||
*/
|
||||
@property(nonatomic, readonly) blink::SemanticsNode node;
|
||||
|
||||
/**
|
||||
* Updates this semantics object using data from the `node` argument.
|
||||
*/
|
||||
- (void)setSemanticsNode:(const blink::SemanticsNode*)node NS_REQUIRES_SUPER;
|
||||
|
||||
/**
|
||||
* Whether this semantics object has child semantics objects.
|
||||
*/
|
||||
@property(nonatomic, readonly) BOOL hasChildren;
|
||||
|
||||
/**
|
||||
* Direct children of this semantics object. Each child's `parent` property must
|
||||
* be equal to this object.
|
||||
*/
|
||||
@property(nonatomic, readonly) std::vector<SemanticsObject*>* children;
|
||||
|
||||
- (BOOL)nodeWillCauseLayoutChange:(const blink::SemanticsNode*)node;
|
||||
|
||||
#pragma mark - Designated initializers
|
||||
|
||||
- (instancetype)init __attribute__((unavailable("Use initWithBridge instead")));
|
||||
- (instancetype)initWithBridge:(shell::AccessibilityBridge*)bridge
|
||||
uid:(int32_t)uid NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* The default implementation of `SemanticsObject` for most accessibility elements
|
||||
* in the iOS accessibility tree.
|
||||
*
|
||||
* Use this implementation for nodes that do not need to be expressed via UIKit-specific
|
||||
* protocols (it only implements NSObject).
|
||||
*
|
||||
* See also:
|
||||
* * TextInputSemanticsObject, which implements `UITextInput` protocol to expose
|
||||
* editable text widgets to a11y.
|
||||
*/
|
||||
@interface FlutterSemanticsObject : SemanticsObject
|
||||
@end
|
||||
|
||||
namespace shell {
|
||||
class PlatformViewIOS;
|
||||
|
||||
@@ -49,13 +100,14 @@ class AccessibilityBridge final {
|
||||
AccessibilityBridge(UIView* view, PlatformViewIOS* platform_view);
|
||||
~AccessibilityBridge();
|
||||
|
||||
void UpdateSemantics(std::vector<blink::SemanticsNode> nodes);
|
||||
void UpdateSemantics(blink::SemanticsNodeUpdates nodes);
|
||||
void DispatchSemanticsAction(int32_t id, blink::SemanticsAction action);
|
||||
UIView<UITextInput>* textInputView();
|
||||
|
||||
UIView* view() const { return view_; }
|
||||
|
||||
private:
|
||||
SemanticsObject* GetOrCreateObject(int32_t id);
|
||||
SemanticsObject* GetOrCreateObject(int32_t id, blink::SemanticsNodeUpdates& updates);
|
||||
void VisitObjectsRecursivelyAndRemove(SemanticsObject* object,
|
||||
NSMutableArray<NSNumber*>* doomed_uids);
|
||||
void ReleaseObjects(std::unordered_map<int, SemanticsObject*>& objects);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -93,10 +94,8 @@ bool GeometryComparator(SemanticsObject* a, SemanticsObject* b) {
|
||||
@end
|
||||
|
||||
@implementation SemanticsObject {
|
||||
shell::AccessibilityBridge* _bridge;
|
||||
blink::SemanticsNode _node;
|
||||
std::vector<SemanticsObject*> _children;
|
||||
SemanticsObjectContainer* _container;
|
||||
std::vector<SemanticsObject*> _children;
|
||||
}
|
||||
|
||||
#pragma mark - Override base class designated initializers
|
||||
@@ -123,6 +122,14 @@ bool GeometryComparator(SemanticsObject* a, SemanticsObject* b) {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
_bridge = nullptr;
|
||||
_children.clear();
|
||||
[_parent release];
|
||||
[_container release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark - Semantic object methods
|
||||
|
||||
- (void)setSemanticsNode:(const blink::SemanticsNode*)node {
|
||||
@@ -132,8 +139,8 @@ bool GeometryComparator(SemanticsObject* a, SemanticsObject* b) {
|
||||
/**
|
||||
* Whether calling `setSemanticsNode:` with `node` would cause a layout change.
|
||||
*/
|
||||
- (BOOL)willCauseLayoutChange:(const blink::SemanticsNode*)node {
|
||||
return _node.rect != node->rect || _node.transform != node->transform;
|
||||
- (BOOL)nodeWillCauseLayoutChange:(const blink::SemanticsNode*)node {
|
||||
return [self node].rect != node->rect || [self node].transform != node->transform;
|
||||
}
|
||||
|
||||
- (std::vector<SemanticsObject*>*)children {
|
||||
@@ -144,71 +151,43 @@ bool GeometryComparator(SemanticsObject* a, SemanticsObject* b) {
|
||||
return _children.size() != 0;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
_bridge = nullptr;
|
||||
_children.clear();
|
||||
[_parent release];
|
||||
if (_container != nil)
|
||||
[_container release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark - UIAccessibility overrides
|
||||
|
||||
- (BOOL)isAccessibilityElement {
|
||||
// Note: hit detection will only apply to elements that report
|
||||
// -isAccessibilityElement of YES. The framework will continue scanning the
|
||||
// entire element tree looking for such a hit.
|
||||
return _node.flags != 0 || !_node.label.empty() || !_node.value.empty() || !_node.hint.empty() ||
|
||||
(_node.actions & ~blink::kScrollableSemanticsActions) != 0;
|
||||
return [self node].flags != 0 || ![self node].label.empty() || ![self node].value.empty() ||
|
||||
![self node].hint.empty() ||
|
||||
([self node].actions & ~blink::kScrollableSemanticsActions) != 0;
|
||||
}
|
||||
|
||||
- (NSString*)accessibilityLabel {
|
||||
if (_node.label.empty())
|
||||
if ([self node].label.empty())
|
||||
return nil;
|
||||
return @(_node.label.data());
|
||||
return @([self node].label.data());
|
||||
}
|
||||
|
||||
- (NSString*)accessibilityHint {
|
||||
if (_node.hint.empty())
|
||||
if ([self node].hint.empty())
|
||||
return nil;
|
||||
return @(_node.hint.data());
|
||||
return @([self node].hint.data());
|
||||
}
|
||||
|
||||
- (NSString*)accessibilityValue {
|
||||
if (_node.value.empty())
|
||||
if ([self node].value.empty())
|
||||
return nil;
|
||||
return @(_node.value.data());
|
||||
}
|
||||
|
||||
- (UIAccessibilityTraits)accessibilityTraits {
|
||||
UIAccessibilityTraits traits = UIAccessibilityTraitNone;
|
||||
if (_node.HasAction(blink::SemanticsAction::kIncrease) ||
|
||||
_node.HasAction(blink::SemanticsAction::kDecrease)) {
|
||||
traits |= UIAccessibilityTraitAdjustable;
|
||||
}
|
||||
if (_node.HasFlag(blink::SemanticsFlags::kIsSelected) ||
|
||||
_node.HasFlag(blink::SemanticsFlags::kIsChecked)) {
|
||||
traits |= UIAccessibilityTraitSelected;
|
||||
}
|
||||
if (_node.HasFlag(blink::SemanticsFlags::kIsButton)) {
|
||||
traits |= UIAccessibilityTraitButton;
|
||||
}
|
||||
if (_node.HasFlag(blink::SemanticsFlags::kHasEnabledState) &&
|
||||
!_node.HasFlag(blink::SemanticsFlags::kIsEnabled)) {
|
||||
traits |= UIAccessibilityTraitNotEnabled;
|
||||
}
|
||||
return traits;
|
||||
return @([self node].value.data());
|
||||
}
|
||||
|
||||
- (CGRect)accessibilityFrame {
|
||||
SkMatrix44 globalTransform = _node.transform;
|
||||
for (SemanticsObject* parent = _parent; parent; parent = parent.parent) {
|
||||
globalTransform = parent->_node.transform * globalTransform;
|
||||
SkMatrix44 globalTransform = [self node].transform;
|
||||
for (SemanticsObject* parent = [self parent]; parent; parent = parent.parent) {
|
||||
globalTransform = parent.node.transform * globalTransform;
|
||||
}
|
||||
|
||||
SkPoint quad[4];
|
||||
_node.rect.toQuad(quad);
|
||||
[self node].rect.toQuad(quad);
|
||||
for (auto& point : quad) {
|
||||
SkScalar vector[4] = {point.x(), point.y(), 0, 1};
|
||||
globalTransform.mapScalars(vector);
|
||||
@@ -220,57 +199,101 @@ bool GeometryComparator(SemanticsObject* a, SemanticsObject* b) {
|
||||
// `rect` is in the physical pixel coordinate system. iOS expects the accessibility frame in
|
||||
// the logical pixel coordinate system. Therefore, we divide by the `scale` (pixel ratio) to
|
||||
// convert.
|
||||
CGFloat scale = [[_bridge->view() window] screen].scale;
|
||||
CGFloat scale = [[[self bridge] -> view() window] screen].scale;
|
||||
auto result =
|
||||
CGRectMake(rect.x() / scale, rect.y() / scale, rect.width() / scale, rect.height() / scale);
|
||||
return UIAccessibilityConvertFrameToScreenCoordinates(result, _bridge->view());
|
||||
return UIAccessibilityConvertFrameToScreenCoordinates(result, [self bridge] -> view());
|
||||
}
|
||||
|
||||
#pragma mark - UIAccessibilityElement protocol
|
||||
|
||||
- (id)accessibilityContainer {
|
||||
if ([self hasChildren] || _uid == kRootNodeId) {
|
||||
if ([self hasChildren] || [self uid] == kRootNodeId) {
|
||||
if (_container == nil)
|
||||
_container = [[SemanticsObjectContainer alloc] initWithSemanticsObject:self bridge:_bridge];
|
||||
_container =
|
||||
[[SemanticsObjectContainer alloc] initWithSemanticsObject:self bridge:[self bridge]];
|
||||
return _container;
|
||||
}
|
||||
NSAssert(_parent != nil, @"Illegal access to non-existent parent of root semantics node");
|
||||
return [_parent accessibilityContainer];
|
||||
NSAssert([self parent] != nil, @"Illegal access to non-existent parent of root semantics node");
|
||||
return [[self parent] accessibilityContainer];
|
||||
}
|
||||
|
||||
#pragma mark - UIAccessibilityAction overrides
|
||||
|
||||
- (BOOL)accessibilityActivate {
|
||||
if (!_node.HasAction(blink::SemanticsAction::kTap))
|
||||
if (![self node].HasAction(blink::SemanticsAction::kTap))
|
||||
return NO;
|
||||
_bridge->DispatchSemanticsAction(_uid, blink::SemanticsAction::kTap);
|
||||
[self bridge] -> DispatchSemanticsAction([self uid], blink::SemanticsAction::kTap);
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)accessibilityIncrement {
|
||||
if (_node.HasAction(blink::SemanticsAction::kIncrease)) {
|
||||
_node.value = _node.increasedValue;
|
||||
_bridge->DispatchSemanticsAction(_uid, blink::SemanticsAction::kIncrease);
|
||||
if ([self node].HasAction(blink::SemanticsAction::kIncrease)) {
|
||||
[self node].value = [self node].increasedValue;
|
||||
[self bridge] -> DispatchSemanticsAction([self uid], blink::SemanticsAction::kIncrease);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)accessibilityDecrement {
|
||||
if (_node.HasAction(blink::SemanticsAction::kDecrease)) {
|
||||
_node.value = _node.decreasedValue;
|
||||
_bridge->DispatchSemanticsAction(_uid, blink::SemanticsAction::kDecrease);
|
||||
if ([self node].HasAction(blink::SemanticsAction::kDecrease)) {
|
||||
[self node].value = [self node].decreasedValue;
|
||||
[self bridge] -> DispatchSemanticsAction([self uid], blink::SemanticsAction::kDecrease);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction {
|
||||
blink::SemanticsAction action = GetSemanticsActionForScrollDirection(direction);
|
||||
if (!_node.HasAction(action))
|
||||
if (![self node].HasAction(action))
|
||||
return NO;
|
||||
_bridge->DispatchSemanticsAction(_uid, action);
|
||||
[self bridge] -> DispatchSemanticsAction([self uid], action);
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation FlutterSemanticsObject {
|
||||
}
|
||||
|
||||
#pragma mark - Override base class designated initializers
|
||||
|
||||
// Method declared as unavailable in the interface
|
||||
- (instancetype)init {
|
||||
[self release];
|
||||
[super doesNotRecognizeSelector:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - Designated initializers
|
||||
|
||||
- (instancetype)initWithBridge:(shell::AccessibilityBridge*)bridge uid:(int32_t)uid {
|
||||
self = [super initWithBridge:bridge uid:uid];
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - UIAccessibility overrides
|
||||
|
||||
- (UIAccessibilityTraits)accessibilityTraits {
|
||||
UIAccessibilityTraits traits = UIAccessibilityTraitNone;
|
||||
if ([self node].HasAction(blink::SemanticsAction::kIncrease) ||
|
||||
[self node].HasAction(blink::SemanticsAction::kDecrease)) {
|
||||
traits |= UIAccessibilityTraitAdjustable;
|
||||
}
|
||||
if ([self node].HasFlag(blink::SemanticsFlags::kIsSelected) ||
|
||||
[self node].HasFlag(blink::SemanticsFlags::kIsChecked)) {
|
||||
traits |= UIAccessibilityTraitSelected;
|
||||
}
|
||||
if ([self node].HasFlag(blink::SemanticsFlags::kIsButton)) {
|
||||
traits |= UIAccessibilityTraitButton;
|
||||
}
|
||||
if ([self node].HasFlag(blink::SemanticsFlags::kHasEnabledState) &&
|
||||
![self node].HasFlag(blink::SemanticsFlags::kIsEnabled)) {
|
||||
traits |= UIAccessibilityTraitNotEnabled;
|
||||
}
|
||||
return traits;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SemanticsObjectContainer {
|
||||
SemanticsObject* _semanticsObject;
|
||||
shell::AccessibilityBridge* _bridge;
|
||||
@@ -372,21 +395,26 @@ AccessibilityBridge::~AccessibilityBridge() {
|
||||
[accessibility_channel_.get() setMessageHandler:nil];
|
||||
}
|
||||
|
||||
void AccessibilityBridge::UpdateSemantics(std::vector<blink::SemanticsNode> nodes) {
|
||||
UIView<UITextInput>* AccessibilityBridge::textInputView() {
|
||||
return [platform_view_->text_input_plugin() textInputView];
|
||||
}
|
||||
|
||||
void AccessibilityBridge::UpdateSemantics(blink::SemanticsNodeUpdates nodes) {
|
||||
// Children are received in paint order (inverse hit testing order). We need to bring them into
|
||||
// traversal order (top left to bottom right, with hit testing order as tie breaker).
|
||||
NSMutableSet<SemanticsObject*>* childOrdersToUpdate = [[[NSMutableSet alloc] init] autorelease];
|
||||
BOOL layoutChanged = NO;
|
||||
|
||||
for (const blink::SemanticsNode& node : nodes) {
|
||||
SemanticsObject* object = GetOrCreateObject(node.id);
|
||||
layoutChanged = layoutChanged || [object willCauseLayoutChange:&node];
|
||||
for (const auto& entry : nodes) {
|
||||
const blink::SemanticsNode& node = entry.second;
|
||||
SemanticsObject* object = GetOrCreateObject(node.id, nodes);
|
||||
layoutChanged = layoutChanged || [object nodeWillCauseLayoutChange:&node];
|
||||
[object setSemanticsNode:&node];
|
||||
const size_t childrenCount = node.children.size();
|
||||
auto& children = *[object children];
|
||||
children.resize(childrenCount);
|
||||
for (size_t i = 0; i < childrenCount; ++i) {
|
||||
SemanticsObject* child = GetOrCreateObject(node.children[i]);
|
||||
SemanticsObject* child = GetOrCreateObject(node.children[i], nodes);
|
||||
child.parent = object;
|
||||
// Reverting to get hit testing order (as tie breaker for sorting below).
|
||||
children[childrenCount - i - 1] = child;
|
||||
@@ -431,11 +459,45 @@ void AccessibilityBridge::DispatchSemanticsAction(int32_t uid, blink::SemanticsA
|
||||
platform_view_->DispatchSemanticsAction(uid, action, args);
|
||||
}
|
||||
|
||||
SemanticsObject* AccessibilityBridge::GetOrCreateObject(int32_t uid) {
|
||||
SemanticsObject* AccessibilityBridge::GetOrCreateObject(int32_t uid,
|
||||
blink::SemanticsNodeUpdates& updates) {
|
||||
SemanticsObject* object = objects_.get()[@(uid)];
|
||||
if (!object) {
|
||||
object = [[[SemanticsObject alloc] initWithBridge:this uid:uid] autorelease];
|
||||
// New node case: simply create a new SemanticsObject.
|
||||
blink::SemanticsNode node = updates[uid];
|
||||
if (node.HasFlag(blink::SemanticsFlags::kIsTextField)) {
|
||||
// Text fields are backed by objects that implement UITextInput.
|
||||
object = [[[TextInputSemanticsObject alloc] initWithBridge:this uid:uid] autorelease];
|
||||
} else {
|
||||
object = [[[FlutterSemanticsObject alloc] initWithBridge:this uid:uid] autorelease];
|
||||
}
|
||||
|
||||
objects_.get()[@(uid)] = object;
|
||||
} else {
|
||||
// Existing node case
|
||||
auto nodeEntry = updates.find(object.node.id);
|
||||
if (nodeEntry != updates.end()) {
|
||||
// There's an update for this node
|
||||
blink::SemanticsNode node = nodeEntry->second;
|
||||
BOOL isTextField = node.HasFlag(blink::SemanticsFlags::kIsTextField);
|
||||
BOOL wasTextField = object.node.HasFlag(blink::SemanticsFlags::kIsTextField);
|
||||
if (wasTextField != isTextField) {
|
||||
// The node changed its type from text field to something else, or vice versa. In this
|
||||
// case, we cannot reuse the existing SemanticsObject implementation. Instead, we replace
|
||||
// it with a new instance.
|
||||
auto positionInChildlist =
|
||||
std::find(object.parent.children->begin(), object.parent.children->end(), object);
|
||||
[objects_ removeObjectForKey:@(node.id)];
|
||||
if (isTextField) {
|
||||
// Text fields are backed by objects that implement UITextInput.
|
||||
object = [[[TextInputSemanticsObject alloc] initWithBridge:this uid:uid] autorelease];
|
||||
} else {
|
||||
object = [[[FlutterSemanticsObject alloc] initWithBridge:this uid:uid] autorelease];
|
||||
}
|
||||
*positionInChildlist = object;
|
||||
objects_.get()[@(node.id)] = object;
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2018 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 SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_TEXT_ENTRY_H_
|
||||
#define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_TEXT_ENTRY_H_
|
||||
|
||||
/**
|
||||
* An implementation of `UITextInput` used for text fields that do not currently
|
||||
* have input focus.
|
||||
*
|
||||
* This class is used by `TextInputSemanticsObject`.
|
||||
*/
|
||||
@interface FlutterInactiveTextInput : UIView<UITextInput>
|
||||
|
||||
@property(nonatomic, copy) NSString* text;
|
||||
@property(nonatomic, readonly) NSMutableString* markedText;
|
||||
@property(readwrite, copy) UITextRange* selectedTextRange;
|
||||
@property(nonatomic, strong) UITextRange* markedTextRange;
|
||||
@property(nonatomic, copy) NSDictionary* markedTextStyle;
|
||||
@property(nonatomic, assign) id<UITextInputDelegate> inputDelegate;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* An implementation of `SemanticsObject` specialized for expressing text
|
||||
* fields.
|
||||
*
|
||||
* Delegates to `FlutterTextInputView` when the object corresponds to a text
|
||||
* field that currently owns input focus. Delegates to
|
||||
* `FlutterInactiveTextInput` otherwise.
|
||||
*/
|
||||
@interface TextInputSemanticsObject : SemanticsObject<UITextInput>
|
||||
@end
|
||||
|
||||
#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_ACCESSIBILITY_TEXT_ENTRY_H_
|
||||
@@ -0,0 +1,409 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h"
|
||||
|
||||
@implementation FlutterInactiveTextInput {
|
||||
}
|
||||
|
||||
@synthesize tokenizer = _tokenizer;
|
||||
@synthesize beginningOfDocument = _beginningOfDocument;
|
||||
@synthesize endOfDocument = _endOfDocument;
|
||||
|
||||
- (instancetype)init {
|
||||
return [super init];
|
||||
}
|
||||
|
||||
- (BOOL)hasText {
|
||||
return self.text.length > 0;
|
||||
}
|
||||
|
||||
- (NSString*)textInRange:(UITextRange*)range {
|
||||
NSRange textRange = ((FlutterTextRange*)range).range;
|
||||
return [self.text substringWithRange:textRange];
|
||||
}
|
||||
|
||||
- (NSString*)accessibilityLabel {
|
||||
return self.text;
|
||||
}
|
||||
|
||||
- (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
}
|
||||
|
||||
- (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)markedSelectedRange {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
}
|
||||
|
||||
- (void)unmarkText {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
}
|
||||
|
||||
- (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
|
||||
toPosition:(UITextPosition*)toPosition {
|
||||
NSUInteger fromIndex = ((FlutterTextPosition*)fromPosition).index;
|
||||
NSUInteger toIndex = ((FlutterTextPosition*)toPosition).index;
|
||||
return [FlutterTextRange rangeWithNSRange:NSMakeRange(fromIndex, toIndex - fromIndex)];
|
||||
}
|
||||
|
||||
- (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (UITextPosition*)positionFromPosition:(UITextPosition*)position
|
||||
inDirection:(UITextLayoutDirection)direction
|
||||
offset:(NSInteger)offset {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return NSOrderedSame;
|
||||
}
|
||||
|
||||
- (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (UITextPosition*)positionWithinRange:(UITextRange*)range
|
||||
farthestInDirection:(UITextLayoutDirection)direction {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
|
||||
inDirection:(UITextLayoutDirection)direction {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
|
||||
inDirection:(UITextStorageDirection)direction {
|
||||
// Not editable. Does not apply.
|
||||
return UITextWritingDirectionNatural;
|
||||
}
|
||||
|
||||
- (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
|
||||
forRange:(UITextRange*)range {
|
||||
// Not editable. Does not apply.
|
||||
}
|
||||
|
||||
- (CGRect)firstRectForRange:(UITextRange*)range {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return CGRectZero;
|
||||
}
|
||||
|
||||
- (CGRect)caretRectForPosition:(UITextPosition*)position {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return CGRectZero;
|
||||
}
|
||||
|
||||
- (UITextPosition*)closestPositionToPoint:(CGPoint)point {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray*)selectionRectsForRange:(UITextRange*)range {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return @[];
|
||||
}
|
||||
|
||||
- (UITextRange*)characterRangeAtPoint:(CGPoint)point {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)insertText:(NSString*)text {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
}
|
||||
|
||||
- (void)deleteBackward {
|
||||
// This method is required but not called by accessibility API for
|
||||
// features we are using it for. It may need to be implemented if
|
||||
// requirements change.
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TextInputSemanticsObject {
|
||||
FlutterInactiveTextInput* _inactive_text_input;
|
||||
}
|
||||
|
||||
- (instancetype)initWithBridge:(shell::AccessibilityBridge*)bridge uid:(int32_t)uid {
|
||||
self = [super initWithBridge:bridge uid:uid];
|
||||
|
||||
if (self) {
|
||||
_inactive_text_input = [[FlutterInactiveTextInput alloc] init];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_inactive_text_input release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark - SemanticsObject overrides
|
||||
|
||||
- (void)setSemanticsNode:(const blink::SemanticsNode*)node {
|
||||
[super setSemanticsNode:node];
|
||||
_inactive_text_input.text = @(node->value.data());
|
||||
if ([self node].HasFlag(blink::SemanticsFlags::kIsFocused)) {
|
||||
// The text input view must have a non-trivial size for the accessibility
|
||||
// system to send text editing events.
|
||||
[self bridge]->textInputView().frame = CGRectMake(0.0, 0.0, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UIAccessibility overrides
|
||||
|
||||
/**
|
||||
* The UITextInput whose accessibility properties we present to UIKit as
|
||||
* substitutes for Flutter's text field properties.
|
||||
*
|
||||
* When the field is currently focused (i.e. it is being edited), we use
|
||||
* the FlutterTextInputView used by FlutterTextInputPlugin. Otherwise,
|
||||
* we use an FlutterInactiveTextInput.
|
||||
*/
|
||||
- (UIView<UITextInput>*)textInputSurrogate {
|
||||
if ([self node].HasFlag(blink::SemanticsFlags::kIsFocused)) {
|
||||
return [self bridge]->textInputView();
|
||||
} else {
|
||||
return _inactive_text_input;
|
||||
}
|
||||
}
|
||||
|
||||
- (UIView*)textInputView {
|
||||
return [self textInputSurrogate];
|
||||
}
|
||||
|
||||
- (void)accessibilityElementDidBecomeFocused {
|
||||
[[self textInputSurrogate] accessibilityElementDidBecomeFocused];
|
||||
}
|
||||
|
||||
- (void)accessibilityElementDidLoseFocus {
|
||||
[[self textInputSurrogate] accessibilityElementDidLoseFocus];
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityElementIsFocused {
|
||||
return [self node].HasFlag(blink::SemanticsFlags::kIsFocused);
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityActivate {
|
||||
return [[self textInputSurrogate] accessibilityActivate];
|
||||
}
|
||||
|
||||
- (NSString*)accessibilityLabel {
|
||||
return [self textInputSurrogate].accessibilityLabel;
|
||||
}
|
||||
|
||||
- (NSString*)accessibilityHint {
|
||||
return [self textInputSurrogate].accessibilityHint;
|
||||
}
|
||||
|
||||
- (NSString*)accessibilityValue {
|
||||
return [self textInputSurrogate].accessibilityValue;
|
||||
}
|
||||
|
||||
- (UIAccessibilityTraits)accessibilityTraits {
|
||||
// Adding UIAccessibilityTraitKeyboardKey to the trait list so that iOS treats it like
|
||||
// a keyboard entry control, thus adding support for text editing features, such as
|
||||
// pinch to select text, and up/down fling to move cursor.
|
||||
return [self textInputSurrogate].accessibilityTraits | UIAccessibilityTraitKeyboardKey;
|
||||
}
|
||||
|
||||
#pragma mark - UITextInput overrides
|
||||
|
||||
- (NSString*)textInRange:(UITextRange*)range {
|
||||
return [[self textInputSurrogate] textInRange:range];
|
||||
}
|
||||
|
||||
- (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
|
||||
return [[self textInputSurrogate] replaceRange:range withText:text];
|
||||
}
|
||||
|
||||
- (BOOL)shouldChangeTextInRange:(UITextRange*)range replacementText:(NSString*)text {
|
||||
return [[self textInputSurrogate] shouldChangeTextInRange:range replacementText:text];
|
||||
}
|
||||
|
||||
- (UITextRange*)selectedTextRange {
|
||||
return [[self textInputSurrogate] selectedTextRange];
|
||||
}
|
||||
|
||||
- (void)setSelectedTextRange:(UITextRange*)range {
|
||||
[[self textInputSurrogate] setSelectedTextRange:range];
|
||||
}
|
||||
|
||||
- (UITextRange*)markedTextRange {
|
||||
return [[self textInputSurrogate] markedTextRange];
|
||||
}
|
||||
|
||||
- (NSDictionary*)markedTextStyle {
|
||||
return [[self textInputSurrogate] markedTextStyle];
|
||||
}
|
||||
|
||||
- (void)setMarkedTextStyle:(NSDictionary*)style {
|
||||
[[self textInputSurrogate] setMarkedTextStyle:style];
|
||||
}
|
||||
|
||||
- (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)selectedRange {
|
||||
[[self textInputSurrogate] setMarkedText:markedText selectedRange:selectedRange];
|
||||
}
|
||||
|
||||
- (void)unmarkText {
|
||||
[[self textInputSurrogate] unmarkText];
|
||||
}
|
||||
|
||||
- (UITextStorageDirection)selectionAffinity {
|
||||
return [[self textInputSurrogate] selectionAffinity];
|
||||
}
|
||||
|
||||
- (UITextPosition*)beginningOfDocument {
|
||||
return [[self textInputSurrogate] beginningOfDocument];
|
||||
}
|
||||
|
||||
- (UITextPosition*)endOfDocument {
|
||||
return [[self textInputSurrogate] endOfDocument];
|
||||
}
|
||||
|
||||
- (id<UITextInputDelegate>)inputDelegate {
|
||||
return [[self textInputSurrogate] inputDelegate];
|
||||
}
|
||||
|
||||
- (void)setInputDelegate:(id<UITextInputDelegate>)delegate {
|
||||
[[self textInputSurrogate] setInputDelegate:delegate];
|
||||
}
|
||||
|
||||
- (id<UITextInputTokenizer>)tokenizer {
|
||||
return [[self textInputSurrogate] tokenizer];
|
||||
}
|
||||
|
||||
- (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
|
||||
toPosition:(UITextPosition*)toPosition {
|
||||
return [[self textInputSurrogate] textRangeFromPosition:fromPosition toPosition:toPosition];
|
||||
}
|
||||
|
||||
- (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
|
||||
return [[self textInputSurrogate] positionFromPosition:position offset:offset];
|
||||
}
|
||||
|
||||
- (UITextPosition*)positionFromPosition:(UITextPosition*)position
|
||||
inDirection:(UITextLayoutDirection)direction
|
||||
offset:(NSInteger)offset {
|
||||
return
|
||||
[[self textInputSurrogate] positionFromPosition:position inDirection:direction offset:offset];
|
||||
}
|
||||
|
||||
- (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
|
||||
return [[self textInputSurrogate] comparePosition:position toPosition:other];
|
||||
}
|
||||
|
||||
- (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
|
||||
return [[self textInputSurrogate] offsetFromPosition:from toPosition:toPosition];
|
||||
}
|
||||
|
||||
- (UITextPosition*)positionWithinRange:(UITextRange*)range
|
||||
farthestInDirection:(UITextLayoutDirection)direction {
|
||||
return [[self textInputSurrogate] positionWithinRange:range farthestInDirection:direction];
|
||||
}
|
||||
|
||||
- (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
|
||||
inDirection:(UITextLayoutDirection)direction {
|
||||
return
|
||||
[[self textInputSurrogate] characterRangeByExtendingPosition:position inDirection:direction];
|
||||
}
|
||||
|
||||
- (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
|
||||
inDirection:(UITextStorageDirection)direction {
|
||||
return [[self textInputSurrogate] baseWritingDirectionForPosition:position inDirection:direction];
|
||||
}
|
||||
|
||||
- (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
|
||||
forRange:(UITextRange*)range {
|
||||
[[self textInputSurrogate] setBaseWritingDirection:writingDirection forRange:range];
|
||||
}
|
||||
|
||||
- (CGRect)firstRectForRange:(UITextRange*)range {
|
||||
return [[self textInputSurrogate] firstRectForRange:range];
|
||||
}
|
||||
|
||||
- (CGRect)caretRectForPosition:(UITextPosition*)position {
|
||||
return [[self textInputSurrogate] caretRectForPosition:position];
|
||||
}
|
||||
|
||||
- (UITextPosition*)closestPositionToPoint:(CGPoint)point {
|
||||
return [[self textInputSurrogate] closestPositionToPoint:point];
|
||||
}
|
||||
|
||||
- (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
|
||||
return [[self textInputSurrogate] closestPositionToPoint:point withinRange:range];
|
||||
}
|
||||
|
||||
- (NSArray*)selectionRectsForRange:(UITextRange*)range {
|
||||
return [[self textInputSurrogate] selectionRectsForRange:range];
|
||||
}
|
||||
|
||||
- (UITextRange*)characterRangeAtPoint:(CGPoint)point {
|
||||
return [[self textInputSurrogate] characterRangeAtPoint:point];
|
||||
}
|
||||
|
||||
- (void)insertText:(NSString*)text {
|
||||
[[self textInputSurrogate] insertText:text];
|
||||
}
|
||||
|
||||
- (void)deleteBackward {
|
||||
[[self textInputSurrogate] deleteBackward];
|
||||
}
|
||||
|
||||
#pragma mark - UIKeyInput overrides
|
||||
|
||||
- (BOOL)hasText {
|
||||
return [[self textInputSurrogate] hasText];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "flutter/fml/memory/weak_ptr.h"
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterTexture.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.h"
|
||||
#include "flutter/shell/platform/darwin/ios/ios_surface.h"
|
||||
@@ -53,7 +54,7 @@ class PlatformViewIOS : public PlatformView {
|
||||
|
||||
void RegisterExternalTexture(int64_t id, NSObject<FlutterTexture>* texture);
|
||||
|
||||
void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
|
||||
void UpdateSemantics(blink::SemanticsNodeUpdates update) override;
|
||||
|
||||
void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
@@ -61,6 +62,23 @@ class PlatformViewIOS : public PlatformView {
|
||||
|
||||
void SetAssetBundlePath(const std::string& assets_directory) override;
|
||||
|
||||
/**
|
||||
* Exposes the `FlutterTextInputPlugin` singleton for the
|
||||
* `AccessibilityBridge` to be able to interact with the text entry system.
|
||||
*/
|
||||
fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin() {
|
||||
return text_input_plugin_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `FlutterTextInputPlugin` singleton returned by
|
||||
* `text_input_plugin`.
|
||||
*/
|
||||
void SetTextInputPlugin(
|
||||
fml::scoped_nsprotocol<FlutterTextInputPlugin*> textInputPlugin) {
|
||||
text_input_plugin_ = textInputPlugin;
|
||||
}
|
||||
|
||||
NSObject<FlutterBinaryMessenger>* binary_messenger() const {
|
||||
return binary_messenger_;
|
||||
}
|
||||
@@ -72,6 +90,7 @@ class PlatformViewIOS : public PlatformView {
|
||||
fxl::Closure firstFrameCallback_;
|
||||
fml::WeakPtrFactory<PlatformViewIOS> weak_factory_;
|
||||
NSObject<FlutterBinaryMessenger>* binary_messenger_;
|
||||
fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin_;
|
||||
|
||||
void SetupAndLoadFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
|
||||
@@ -99,7 +99,7 @@ bool PlatformViewIOS::ResourceContextMakeCurrent() {
|
||||
return ios_surface_ != nullptr ? ios_surface_->ResourceContextMakeCurrent() : false;
|
||||
}
|
||||
|
||||
void PlatformViewIOS::UpdateSemantics(std::vector<blink::SemanticsNode> update) {
|
||||
void PlatformViewIOS::UpdateSemantics(blink::SemanticsNodeUpdates update) {
|
||||
if (accessibility_bridge_)
|
||||
accessibility_bridge_->UpdateSemantics(std::move(update));
|
||||
}
|
||||
|
||||
@@ -2,60 +2,52 @@
|
||||
# See http://pub.dartlang.org/doc/glossary.html#lockfile
|
||||
packages:
|
||||
archive:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: archive
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.33"
|
||||
args:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: args
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.7"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.14.5"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: convert
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
crypto:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: crypto
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2+1"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.1"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.5"
|
||||
sdks:
|
||||
dart: ">=1.21.0 <=2.0.0-dev.16.0"
|
||||
dart: ">=1.21.0 <2.0.0"
|
||||
|
||||
Reference in New Issue
Block a user