20 @property(nonatomic, copy) NSString*
text;
26 @synthesize beginningOfDocument = _beginningOfDocument;
27 @synthesize endOfDocument = _endOfDocument;
32 @synthesize tokenizer = _tokenizer;
35 return self.text.length > 0;
38 - (NSString*)textInRange:(UITextRange*)range {
43 @"Expected a FlutterTextRange for range (got %@).", [range
class]);
45 NSAssert(textRange.location != NSNotFound,
@"Expected a valid text range.");
46 return [
self.text substringWithRange:textRange];
49 - (void)replaceRange:(UITextRange*)range withText:(NSString*)
text {
55 - (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)markedSelectedRange {
67 - (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
68 toPosition:(UITextPosition*)toPosition {
74 - (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
81 - (UITextPosition*)positionFromPosition:(UITextPosition*)position
82 inDirection:(UITextLayoutDirection)direction
83 offset:(NSInteger)offset {
90 - (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
97 - (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
104 - (UITextPosition*)positionWithinRange:(UITextRange*)range
105 farthestInDirection:(UITextLayoutDirection)direction {
112 - (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
113 inDirection:(UITextLayoutDirection)direction {
120 - (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
121 inDirection:(UITextStorageDirection)direction {
123 return UITextWritingDirectionNatural;
126 - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
127 forRange:(UITextRange*)range {
131 - (CGRect)firstRectForRange:(UITextRange*)range {
145 - (UITextPosition*)closestPositionToPoint:(CGPoint)point {
152 - (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
159 - (NSArray*)selectionRectsForRange:(UITextRange*)range {
166 - (UITextRange*)characterRangeAtPoint:(CGPoint)point {
173 - (void)insertText:(NSString*)
text {
179 - (void)deleteBackward {
191 - (instancetype)initWithBridge:(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge
193 self = [
super initWithBridge:bridge uid:uid];
202 #pragma mark - SemanticsObject overrides
204 - (void)setSemanticsNode:(
const flutter::SemanticsNode*)node {
205 [
super setSemanticsNode:node];
206 _inactive_text_input.
text = @(node->value.data());
208 if ([
self node].HasFlag(flutter::SemanticsFlags::kIsFocused)) {
209 textInput.backingTextInputAccessibilityObject =
self;
212 textInput.frame = CGRectMake(0.0, 0.0, 1.0, 1.0);
213 }
else if (textInput.backingTextInputAccessibilityObject ==
self) {
214 textInput.backingTextInputAccessibilityObject = nil;
218 #pragma mark - UIAccessibility overrides
228 - (UIView<UITextInput>*)textInputSurrogate {
229 if ([
self node].HasFlag(flutter::SemanticsFlags::kIsFocused)) {
230 return [
self bridge]->textInputView();
232 return _inactive_text_input;
236 - (UIView*)textInputView {
237 return [
self textInputSurrogate];
240 - (void)accessibilityElementDidBecomeFocused {
241 if (![
self isAccessibilityBridgeAlive]) {
244 [[
self textInputSurrogate] accessibilityElementDidBecomeFocused];
245 [
super accessibilityElementDidBecomeFocused];
248 - (void)accessibilityElementDidLoseFocus {
249 if (![
self isAccessibilityBridgeAlive]) {
252 [[
self textInputSurrogate] accessibilityElementDidLoseFocus];
253 [
super accessibilityElementDidLoseFocus];
256 - (BOOL)accessibilityElementIsFocused {
257 if (![
self isAccessibilityBridgeAlive]) {
260 return [
self node].HasFlag(flutter::SemanticsFlags::kIsFocused);
263 - (BOOL)accessibilityActivate {
264 if (![
self isAccessibilityBridgeAlive]) {
267 return [[
self textInputSurrogate] accessibilityActivate];
270 - (NSString*)accessibilityLabel {
271 if (![
self isAccessibilityBridgeAlive]) {
275 NSString* label = [
super accessibilityLabel];
279 return [
self textInputSurrogate].accessibilityLabel;
282 - (NSString*)accessibilityHint {
283 if (![
self isAccessibilityBridgeAlive]) {
286 NSString* hint = [
super accessibilityHint];
290 return [
self textInputSurrogate].accessibilityHint;
293 - (NSString*)accessibilityValue {
294 if (![
self isAccessibilityBridgeAlive]) {
297 NSString* value = [
super accessibilityValue];
301 return [
self textInputSurrogate].accessibilityValue;
304 - (UIAccessibilityTraits)accessibilityTraits {
305 if (![
self isAccessibilityBridgeAlive]) {
308 UIAccessibilityTraits results =
309 [
super accessibilityTraits] | [
self textInputSurrogate].accessibilityTraits;
316 #pragma mark - UITextInput overrides
318 - (NSString*)textInRange:(UITextRange*)range {
319 return [[
self textInputSurrogate] textInRange:range];
322 - (void)replaceRange:(UITextRange*)range withText:(NSString*)
text {
323 return [[
self textInputSurrogate] replaceRange:range withText:text];
326 - (BOOL)shouldChangeTextInRange:(UITextRange*)range replacementText:(NSString*)
text {
327 return [[
self textInputSurrogate] shouldChangeTextInRange:range replacementText:text];
331 return [[
self textInputSurrogate] selectedTextRange];
334 - (void)setSelectedTextRange:(UITextRange*)range {
335 [[
self textInputSurrogate] setSelectedTextRange:range];
339 return [[
self textInputSurrogate] markedTextRange];
343 return [[
self textInputSurrogate] markedTextStyle];
346 - (void)setMarkedTextStyle:(NSDictionary*)style {
347 [[
self textInputSurrogate] setMarkedTextStyle:style];
350 - (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)selectedRange {
351 [[
self textInputSurrogate] setMarkedText:markedText selectedRange:selectedRange];
355 [[
self textInputSurrogate] unmarkText];
358 - (UITextStorageDirection)selectionAffinity {
359 return [[
self textInputSurrogate] selectionAffinity];
362 - (UITextPosition*)beginningOfDocument {
363 return [[
self textInputSurrogate] beginningOfDocument];
366 - (UITextPosition*)endOfDocument {
367 return [[
self textInputSurrogate] endOfDocument];
371 return [[
self textInputSurrogate] inputDelegate];
374 - (void)setInputDelegate:(id<UITextInputDelegate>)delegate {
375 [[
self textInputSurrogate] setInputDelegate:delegate];
378 - (id<UITextInputTokenizer>)tokenizer {
379 return [[
self textInputSurrogate] tokenizer];
382 - (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
383 toPosition:(UITextPosition*)toPosition {
384 return [[
self textInputSurrogate] textRangeFromPosition:fromPosition toPosition:toPosition];
387 - (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
388 return [[
self textInputSurrogate] positionFromPosition:position offset:offset];
391 - (UITextPosition*)positionFromPosition:(UITextPosition*)position
392 inDirection:(UITextLayoutDirection)direction
393 offset:(NSInteger)offset {
394 return [[
self textInputSurrogate] positionFromPosition:position
395 inDirection:direction
399 - (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
400 return [[
self textInputSurrogate] comparePosition:position toPosition:other];
403 - (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
404 return [[
self textInputSurrogate] offsetFromPosition:from toPosition:toPosition];
407 - (UITextPosition*)positionWithinRange:(UITextRange*)range
408 farthestInDirection:(UITextLayoutDirection)direction {
409 return [[
self textInputSurrogate] positionWithinRange:range farthestInDirection:direction];
412 - (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
413 inDirection:(UITextLayoutDirection)direction {
414 return [[
self textInputSurrogate] characterRangeByExtendingPosition:position
415 inDirection:direction];
418 - (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
419 inDirection:(UITextStorageDirection)direction {
420 return [[
self textInputSurrogate] baseWritingDirectionForPosition:position inDirection:direction];
423 - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
424 forRange:(UITextRange*)range {
425 [[
self textInputSurrogate] setBaseWritingDirection:writingDirection forRange:range];
428 - (CGRect)firstRectForRange:(UITextRange*)range {
429 return [[
self textInputSurrogate] firstRectForRange:range];
433 return [[
self textInputSurrogate] caretRectForPosition:position];
436 - (UITextPosition*)closestPositionToPoint:(CGPoint)point {
437 return [[
self textInputSurrogate] closestPositionToPoint:point];
440 - (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
441 return [[
self textInputSurrogate] closestPositionToPoint:point withinRange:range];
444 - (NSArray*)selectionRectsForRange:(UITextRange*)range {
445 return [[
self textInputSurrogate] selectionRectsForRange:range];
448 - (UITextRange*)characterRangeAtPoint:(CGPoint)point {
449 return [[
self textInputSurrogate] characterRangeAtPoint:point];
452 - (void)insertText:(NSString*)
text {
453 [[
self textInputSurrogate] insertText:text];
456 - (void)deleteBackward {
457 [[
self textInputSurrogate] deleteBackward];
460 #pragma mark - UIKeyInput overrides
463 return [[
self textInputSurrogate] hasText];
466 #pragma mark - UIResponder overrides
468 - (void)cut:(
id)sender {
469 [[
self textInputSurrogate] cut:sender];
472 - (void)copy:(
id)sender {
473 [[
self textInputSurrogate] copy:sender];
476 - (void)paste:(
id)sender {
477 [[
self textInputSurrogate] paste:sender];
482 - (void)selectAll:(
id)sender {
483 [[
self textInputSurrogate] selectAll:sender];
486 - (void)
delete:(
id)sender {
487 [[
self textInputSurrogate] delete:sender];
490 - (BOOL)canPerformAction:(
SEL)action withSender:(id)sender {
491 return [[
self textInputSurrogate] canPerformAction:action withSender:sender];