Wiring for semantic actions copy, cut, paste (#14295)
* Roll engine to 6921873c71e700235c0f68f0359be2332f93c8bc
diff --git a/bin/internal/engine.version b/bin/internal/engine.version
index 8a709cb..944d85d 100644
--- a/bin/internal/engine.version
+++ b/bin/internal/engine.version
@@ -1 +1 @@
-7c34dfafc9acece1a9438f206bfbb0a9bedba3bf
+6921873c71e700235c0f68f0359be2332f93c8bc
diff --git a/packages/flutter/lib/src/rendering/custom_paint.dart b/packages/flutter/lib/src/rendering/custom_paint.dart
index 6c5bc6e..b66659c 100644
--- a/packages/flutter/lib/src/rendering/custom_paint.dart
+++ b/packages/flutter/lib/src/rendering/custom_paint.dart
@@ -859,6 +859,15 @@
if (properties.onDecrease != null) {
config.onDecrease = properties.onDecrease;
}
+ if (properties.onCopy != null) {
+ config.onCopy = properties.onCopy;
+ }
+ if (properties.onCut != null) {
+ config.onCut = properties.onCut;
+ }
+ if (properties.onPaste != null) {
+ config.onPaste = properties.onPaste;
+ }
if (properties.onMoveCursorForwardByCharacter != null) {
config.onMoveCursorForwardByCharacter = properties.onMoveCursorForwardByCharacter;
}
diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart
index ab16133..5e42bbb 100644
--- a/packages/flutter/lib/src/rendering/proxy_box.dart
+++ b/packages/flutter/lib/src/rendering/proxy_box.dart
@@ -3015,6 +3015,9 @@
VoidCallback onScrollDown,
VoidCallback onIncrease,
VoidCallback onDecrease,
+ VoidCallback onCopy,
+ VoidCallback onCut,
+ VoidCallback onPaste,
MoveCursorHandler onMoveCursorForwardByCharacter,
MoveCursorHandler onMoveCursorBackwardByCharacter,
SetSelectionHandler onSetSelection,
@@ -3039,6 +3042,9 @@
_onScrollDown = onScrollDown,
_onIncrease = onIncrease,
_onDecrease = onDecrease,
+ _onCopy = onCopy,
+ _onCut = onCut,
+ _onPaste = onPaste,
_onMoveCursorForwardByCharacter = onMoveCursorForwardByCharacter,
_onMoveCursorBackwardByCharacter = onMoveCursorBackwardByCharacter,
_onSetSelection = onSetSelection,
@@ -3365,6 +3371,58 @@
markNeedsSemanticsUpdate();
}
+ /// The handler for [SemanticsAction.copy].
+ ///
+ /// This is a request to copy the current selection to the clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ VoidCallback get onCopy => _onCopy;
+ VoidCallback _onCopy;
+ set onCopy(VoidCallback handler) {
+ if (_onCopy == handler)
+ return;
+ final bool hadValue = _onCopy != null;
+ _onCopy = handler;
+ if ((handler != null) != hadValue)
+ markNeedsSemanticsUpdate();
+ }
+
+ /// The handler for [SemanticsAction.cut].
+ ///
+ /// This is a request to cut the current selection and place it in the
+ /// clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ VoidCallback get onCut => _onCut;
+ VoidCallback _onCut;
+ set onCut(VoidCallback handler) {
+ if (_onCut == handler)
+ return;
+ final bool hadValue = _onCut != null;
+ _onCut = handler;
+ if ((handler != null) != hadValue)
+ markNeedsSemanticsUpdate();
+ }
+
+ /// The handler for [SemanticsAction.paste].
+ ///
+ /// This is a request to paste the current content of the clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ VoidCallback get onPaste => _onPaste;
+ VoidCallback _onPaste;
+ set onPaste(VoidCallback handler) {
+ if (_onPaste == handler)
+ return;
+ final bool hadValue = _onPaste != null;
+ _onPaste = handler;
+ if ((handler != null) != hadValue)
+ markNeedsSemanticsUpdate();
+ }
+
/// The handler for [SemanticsAction.onMoveCursorForwardByCharacter].
///
/// This handler is invoked when the user wants to move the cursor in a
@@ -3464,6 +3522,12 @@
config.onIncrease = _performIncrease;
if (onDecrease != null)
config.onDecrease = _performDecrease;
+ if (onCopy != null)
+ config.onCopy = _performCopy;
+ if (onCut != null)
+ config.onCut = _performCut;
+ if (onPaste != null)
+ config.onPaste = _performPaste;
if (onMoveCursorForwardByCharacter != null)
config.onMoveCursorForwardByCharacter = _performMoveCursorForwardByCharacter;
if (onMoveCursorBackwardByCharacter != null)
@@ -3512,6 +3576,21 @@
onDecrease();
}
+ void _performCopy() {
+ if (onCopy != null)
+ onCopy();
+ }
+
+ void _performCut() {
+ if (onCut != null)
+ onCut();
+ }
+
+ void _performPaste() {
+ if (onPaste != null)
+ onPaste();
+ }
+
void _performMoveCursorForwardByCharacter(bool extendSelection) {
if (onMoveCursorForwardByCharacter != null)
onMoveCursorForwardByCharacter(extendSelection);
diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart
index 652aa95..31c5d26 100644
--- a/packages/flutter/lib/src/semantics/semantics.dart
+++ b/packages/flutter/lib/src/semantics/semantics.dart
@@ -277,6 +277,9 @@
this.onScrollDown,
this.onIncrease,
this.onDecrease,
+ this.onCopy,
+ this.onCut,
+ this.onPaste,
this.onMoveCursorForwardByCharacter,
this.onMoveCursorBackwardByCharacter,
this.onSetSelection,
@@ -472,6 +475,31 @@
/// volume down button.
final VoidCallback onDecrease;
+ /// The handler for [SemanticsAction.copy].
+ ///
+ /// This is a request to copy the current selection to the clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ final VoidCallback onCopy;
+
+ /// The handler for [SemanticsAction.cut].
+ ///
+ /// This is a request to cut the current selection and place it in the
+ /// clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ final VoidCallback onCut;
+
+ /// The handler for [SemanticsAction.paste].
+ ///
+ /// This is a request to paste the current content of the clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ final VoidCallback onPaste;
+
/// The handler for [SemanticsAction.onMoveCursorForwardByCharacter].
///
/// This handler is invoked when the user wants to move the cursor in a
@@ -1618,6 +1646,46 @@
_onDecrease = value;
}
+ /// The handler for [SemanticsAction.copy].
+ ///
+ /// This is a request to copy the current selection to the clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ VoidCallback get onCopy => _onCopy;
+ VoidCallback _onCopy;
+ set onCopy(VoidCallback value) {
+ _addArgumentlessAction(SemanticsAction.copy, value);
+ _onCopy = value;
+ }
+
+ /// The handler for [SemanticsAction.cut].
+ ///
+ /// This is a request to cut the current selection and place it in the
+ /// clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ VoidCallback get onCut => _onCut;
+ VoidCallback _onCut;
+ set onCut(VoidCallback value) {
+ _addArgumentlessAction(SemanticsAction.cut, value);
+ _onCut = value;
+ }
+
+ /// The handler for [SemanticsAction.paste].
+ ///
+ /// This is a request to paste the current content of the clipboard.
+ ///
+ /// TalkBack users on Android can trigger this action from the local context
+ /// menu of a text field, for example.
+ VoidCallback get onPaste => _onPaste;
+ VoidCallback _onPaste;
+ set onPaste(VoidCallback value) {
+ _addArgumentlessAction(SemanticsAction.paste, value);
+ _onPaste = value;
+ }
+
/// The handler for [SemanticsAction.showOnScreen].
///
/// A request to fully show the semantics node on screen. For example, this
diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart
index 1a7bff7..bbacf10 100644
--- a/packages/flutter/lib/src/widgets/basic.dart
+++ b/packages/flutter/lib/src/widgets/basic.dart
@@ -4852,6 +4852,9 @@
VoidCallback onScrollDown,
VoidCallback onIncrease,
VoidCallback onDecrease,
+ VoidCallback onCopy,
+ VoidCallback onCut,
+ VoidCallback onPaste,
MoveCursorHandler onMoveCursorForwardByCharacter,
MoveCursorHandler onMoveCursorBackwardByCharacter,
SetSelectionHandler onSetSelection,
@@ -4879,6 +4882,9 @@
onScrollDown: onScrollDown,
onIncrease: onIncrease,
onDecrease: onDecrease,
+ onCopy: onCopy,
+ onCut: onCut,
+ onPaste: onPaste,
onMoveCursorForwardByCharacter: onMoveCursorForwardByCharacter,
onMoveCursorBackwardByCharacter: onMoveCursorBackwardByCharacter,
onSetSelection: onSetSelection,
@@ -4948,6 +4954,9 @@
onScrollDown: properties.onScrollDown,
onIncrease: properties.onIncrease,
onDecrease: properties.onDecrease,
+ onCopy: properties.onCopy,
+ onCut: properties.onCut,
+ onPaste: properties.onPaste,
onMoveCursorForwardByCharacter: properties.onMoveCursorForwardByCharacter,
onMoveCursorBackwardByCharacter: properties.onMoveCursorBackwardByCharacter,
onSetSelection: properties.onSetSelection,
@@ -4988,6 +4997,9 @@
..onScrollDown = properties.onScrollDown
..onIncrease = properties.onIncrease
..onDecrease = properties.onDecrease
+ ..onCopy = properties.onCopy
+ ..onCut = properties.onCut
+ ..onPaste = properties.onPaste
..onMoveCursorForwardByCharacter = properties.onMoveCursorForwardByCharacter
..onMoveCursorBackwardByCharacter = properties.onMoveCursorForwardByCharacter
..onSetSelection = properties.onSetSelection;
diff --git a/packages/flutter/test/widgets/semantics_test.dart b/packages/flutter/test/widgets/semantics_test.dart
index 7e42e49..b860e0c 100644
--- a/packages/flutter/test/widgets/semantics_test.dart
+++ b/packages/flutter/test/widgets/semantics_test.dart
@@ -392,6 +392,9 @@
onScrollDown: () => performedActions.add(SemanticsAction.scrollDown),
onIncrease: () => performedActions.add(SemanticsAction.increase),
onDecrease: () => performedActions.add(SemanticsAction.decrease),
+ onCopy: () => performedActions.add(SemanticsAction.copy),
+ onCut: () => performedActions.add(SemanticsAction.cut),
+ onPaste: () => performedActions.add(SemanticsAction.paste),
onMoveCursorForwardByCharacter: (bool _) => performedActions.add(SemanticsAction.moveCursorForwardByCharacter),
onMoveCursorBackwardByCharacter: (bool _) => performedActions.add(SemanticsAction.moveCursorBackwardByCharacter),
onSetSelection: (TextSelection _) => performedActions.add(SemanticsAction.setSelection),