5 #import <UIKit/UIKit.h>
15 @synthesize tokenizer = _tokenizer;
16 @synthesize beginningOfDocument = _beginningOfDocument;
17 @synthesize endOfDocument = _endOfDocument;
21 [_markedText release];
22 [_markedTextRange release];
23 [_selectedTextRange release];
24 [_markedTextStyle release];
29 return self.
text.length > 0;
32 - (NSString*)textInRange:(UITextRange*)range {
37 @"Expected a FlutterTextRange for range (got %@).", [range
class]);
39 NSAssert(textRange.location != NSNotFound,
@"Expected a valid text range.");
40 return [
self.text substringWithRange:textRange];
43 - (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
49 - (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)markedSelectedRange {
61 - (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
62 toPosition:(UITextPosition*)toPosition {
68 - (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
75 - (UITextPosition*)positionFromPosition:(UITextPosition*)position
76 inDirection:(UITextLayoutDirection)direction
77 offset:(NSInteger)offset {
84 - (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
91 - (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
98 - (UITextPosition*)positionWithinRange:(UITextRange*)range
99 farthestInDirection:(UITextLayoutDirection)direction {
106 - (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
107 inDirection:(UITextLayoutDirection)direction {
114 - (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
115 inDirection:(UITextStorageDirection)direction {
117 return UITextWritingDirectionNatural;
120 - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
121 forRange:(UITextRange*)range {
125 - (CGRect)firstRectForRange:(UITextRange*)range {
132 - (CGRect)caretRectForPosition:(UITextPosition*)position {
139 - (UITextPosition*)closestPositionToPoint:(CGPoint)point {
146 - (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
153 - (NSArray*)selectionRectsForRange:(UITextRange*)range {
160 - (UITextRange*)characterRangeAtPoint:(CGPoint)point {
167 - (void)insertText:(NSString*)text {
173 - (void)deleteBackward {
185 - (instancetype)initWithBridge:(fml::WeakPtr<
flutter::AccessibilityBridgeIos>)bridge
187 self = [
super initWithBridge:bridge uid:uid];
197 [_inactive_text_input release];
201 #pragma mark - SemanticsObject overrides
203 - (void)setSemanticsNode:(const
flutter::SemanticsNode*)node {
204 [
super setSemanticsNode:node];
205 _inactive_text_input.text = @(node->value.data());
207 if ([
self node].HasFlag(flutter::SemanticsFlags::kIsFocused)) {
208 textInput.backingTextInputAccessibilityObject =
self;
211 textInput.frame = CGRectMake(0.0, 0.0, 1.0, 1.0);
212 }
else if (textInput.backingTextInputAccessibilityObject ==
self) {
213 textInput.backingTextInputAccessibilityObject = nil;
217 #pragma mark - UIAccessibility overrides
227 - (UIView<UITextInput>*)textInputSurrogate {
228 if ([
self node].HasFlag(flutter::SemanticsFlags::kIsFocused)) {
229 return [
self bridge]->textInputView();
231 return _inactive_text_input;
235 - (UIView*)textInputView {
236 return [
self textInputSurrogate];
239 - (void)accessibilityElementDidBecomeFocused {
240 if (![
self isAccessibilityBridgeAlive]) {
243 [[
self textInputSurrogate] accessibilityElementDidBecomeFocused];
244 [
super accessibilityElementDidBecomeFocused];
247 - (void)accessibilityElementDidLoseFocus {
248 if (![
self isAccessibilityBridgeAlive]) {
251 [[
self textInputSurrogate] accessibilityElementDidLoseFocus];
252 [
super accessibilityElementDidLoseFocus];
255 - (BOOL)accessibilityElementIsFocused {
256 if (![
self isAccessibilityBridgeAlive]) {
259 return [
self node].HasFlag(flutter::SemanticsFlags::kIsFocused);
262 - (BOOL)accessibilityActivate {
263 if (![
self isAccessibilityBridgeAlive]) {
266 return [[
self textInputSurrogate] accessibilityActivate];
269 - (NSString*)accessibilityLabel {
270 if (![
self isAccessibilityBridgeAlive]) {
274 NSString* label = [
super accessibilityLabel];
278 return [
self textInputSurrogate].accessibilityLabel;
281 - (NSString*)accessibilityHint {
282 if (![
self isAccessibilityBridgeAlive]) {
285 NSString* hint = [
super accessibilityHint];
289 return [
self textInputSurrogate].accessibilityHint;
292 - (NSString*)accessibilityValue {
293 if (![
self isAccessibilityBridgeAlive]) {
296 NSString* value = [
super accessibilityValue];
300 return [
self textInputSurrogate].accessibilityValue;
303 - (UIAccessibilityTraits)accessibilityTraits {
304 if (![
self isAccessibilityBridgeAlive]) {
310 UIAccessibilityTraits results = [
super accessibilityTraits] |
311 [
self textInputSurrogate].accessibilityTraits |
312 UIAccessibilityTraitKeyboardKey;
319 #pragma mark - UITextInput overrides
321 - (NSString*)textInRange:(UITextRange*)range {
322 return [[
self textInputSurrogate] textInRange:range];
325 - (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
326 return [[
self textInputSurrogate] replaceRange:range withText:text];
329 - (BOOL)shouldChangeTextInRange:(UITextRange*)range replacementText:(NSString*)text {
330 return [[
self textInputSurrogate] shouldChangeTextInRange:range replacementText:text];
334 return [[
self textInputSurrogate] selectedTextRange];
337 - (void)setSelectedTextRange:(UITextRange*)range {
338 [[
self textInputSurrogate] setSelectedTextRange:range];
342 return [[
self textInputSurrogate] markedTextRange];
346 return [[
self textInputSurrogate] markedTextStyle];
349 - (void)setMarkedTextStyle:(NSDictionary*)style {
350 [[
self textInputSurrogate] setMarkedTextStyle:style];
353 - (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)selectedRange {
354 [[
self textInputSurrogate] setMarkedText:markedText selectedRange:selectedRange];
358 [[
self textInputSurrogate] unmarkText];
361 - (UITextStorageDirection)selectionAffinity {
362 return [[
self textInputSurrogate] selectionAffinity];
365 - (UITextPosition*)beginningOfDocument {
366 return [[
self textInputSurrogate] beginningOfDocument];
369 - (UITextPosition*)endOfDocument {
370 return [[
self textInputSurrogate] endOfDocument];
374 return [[
self textInputSurrogate] inputDelegate];
377 - (void)setInputDelegate:(
id<UITextInputDelegate>)delegate {
378 [[
self textInputSurrogate] setInputDelegate:delegate];
381 - (
id<UITextInputTokenizer>)tokenizer {
382 return [[
self textInputSurrogate] tokenizer];
385 - (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
386 toPosition:(UITextPosition*)toPosition {
387 return [[
self textInputSurrogate] textRangeFromPosition:fromPosition toPosition:toPosition];
390 - (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
391 return [[
self textInputSurrogate] positionFromPosition:position offset:offset];
394 - (UITextPosition*)positionFromPosition:(UITextPosition*)position
395 inDirection:(UITextLayoutDirection)direction
396 offset:(NSInteger)offset {
397 return [[
self textInputSurrogate] positionFromPosition:position
398 inDirection:direction
402 - (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
403 return [[
self textInputSurrogate] comparePosition:position toPosition:other];
406 - (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
407 return [[
self textInputSurrogate] offsetFromPosition:from toPosition:toPosition];
410 - (UITextPosition*)positionWithinRange:(UITextRange*)range
411 farthestInDirection:(UITextLayoutDirection)direction {
412 return [[
self textInputSurrogate] positionWithinRange:range farthestInDirection:direction];
415 - (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
416 inDirection:(UITextLayoutDirection)direction {
417 return [[
self textInputSurrogate] characterRangeByExtendingPosition:position
418 inDirection:direction];
421 - (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
422 inDirection:(UITextStorageDirection)direction {
423 return [[
self textInputSurrogate] baseWritingDirectionForPosition:position inDirection:direction];
426 - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
427 forRange:(UITextRange*)range {
428 [[
self textInputSurrogate] setBaseWritingDirection:writingDirection forRange:range];
431 - (CGRect)firstRectForRange:(UITextRange*)range {
432 return [[
self textInputSurrogate] firstRectForRange:range];
435 - (CGRect)caretRectForPosition:(UITextPosition*)position {
436 return [[
self textInputSurrogate] caretRectForPosition:position];
439 - (UITextPosition*)closestPositionToPoint:(CGPoint)point {
440 return [[
self textInputSurrogate] closestPositionToPoint:point];
443 - (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
444 return [[
self textInputSurrogate] closestPositionToPoint:point withinRange:range];
447 - (NSArray*)selectionRectsForRange:(UITextRange*)range {
448 return [[
self textInputSurrogate] selectionRectsForRange:range];
451 - (UITextRange*)characterRangeAtPoint:(CGPoint)point {
452 return [[
self textInputSurrogate] characterRangeAtPoint:point];
455 - (void)insertText:(NSString*)text {
456 [[
self textInputSurrogate] insertText:text];
459 - (void)deleteBackward {
460 [[
self textInputSurrogate] deleteBackward];
463 #pragma mark - UIKeyInput overrides
466 return [[
self textInputSurrogate] hasText];