Commit 97dbd9ea authored by Matt Perry's avatar Matt Perry Committed by GitHub

Rename RawInputLine to RawInput, and RenderEditableLine to RenderEdit… (#6401)

They support multiline text now.
parent 5bde9d28
...@@ -142,9 +142,9 @@ const Duration _kTransitionDuration = const Duration(milliseconds: 200); ...@@ -142,9 +142,9 @@ const Duration _kTransitionDuration = const Duration(milliseconds: 200);
const Curve _kTransitionCurve = Curves.fastOutSlowIn; const Curve _kTransitionCurve = Curves.fastOutSlowIn;
class _InputState extends State<Input> { class _InputState extends State<Input> {
GlobalKey<RawInputLineState> _rawInputLineKey = new GlobalKey<RawInputLineState>(); GlobalKey<RawInputState> _rawInputKey = new GlobalKey<RawInputState>();
GlobalKey get focusKey => config.key is GlobalKey ? config.key : _rawInputLineKey; GlobalKey get focusKey => config.key is GlobalKey ? config.key : _rawInputKey;
// Optional state to retain if we are inside a Form widget. // Optional state to retain if we are inside a Form widget.
_FormFieldData _formData; _FormFieldData _formData;
...@@ -251,8 +251,8 @@ class _InputState extends State<Input> { ...@@ -251,8 +251,8 @@ class _InputState extends State<Input> {
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: border, border: border,
), ),
child: new RawInputLine( child: new RawInput(
key: _rawInputLineKey, key: _rawInputKey,
value: value, value: value,
focusKey: focusKey, focusKey: focusKey,
style: textStyle, style: textStyle,
...@@ -305,7 +305,7 @@ class _InputState extends State<Input> { ...@@ -305,7 +305,7 @@ class _InputState extends State<Input> {
return new RepaintBoundary( return new RepaintBoundary(
child: new GestureDetector( child: new GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () => _rawInputLineKey.currentState?.requestKeyboard(), onTap: () => _rawInputKey.currentState?.requestKeyboard(),
child: new Padding( child: new Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0), padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: child child: child
......
...@@ -17,7 +17,7 @@ const double _kCaretWidth = 1.0; // pixels ...@@ -17,7 +17,7 @@ const double _kCaretWidth = 1.0; // pixels
final String _kZeroWidthSpace = new String.fromCharCode(0x200B); final String _kZeroWidthSpace = new String.fromCharCode(0x200B);
/// Called when the user changes the selection (including cursor location). /// Called when the user changes the selection (including cursor location).
typedef void SelectionChangedHandler(TextSelection selection, RenderEditableLine renderObject, bool longPress); typedef void SelectionChangedHandler(TextSelection selection, RenderEditable renderObject, bool longPress);
/// Represents a global screen coordinate of the point in a selection, and the /// Represents a global screen coordinate of the point in a selection, and the
/// text direction at that point. /// text direction at that point.
...@@ -36,12 +36,12 @@ class TextSelectionPoint { ...@@ -36,12 +36,12 @@ class TextSelectionPoint {
final TextDirection direction; final TextDirection direction;
} }
typedef Offset RenderEditableLinePaintOffsetNeededCallback(ViewportDimensions dimensions, Rect caretRect); typedef Offset RenderEditablePaintOffsetNeededCallback(ViewportDimensions dimensions, Rect caretRect);
/// A single line of editable text. /// A single line of editable text.
class RenderEditableLine extends RenderBox { class RenderEditable extends RenderBox {
/// Creates a render object for a single line of editable text. /// Creates a render object for a single line of editable text.
RenderEditableLine({ RenderEditable({
TextSpan text, TextSpan text,
Color cursorColor, Color cursorColor,
bool showCursor: false, bool showCursor: false,
...@@ -71,7 +71,7 @@ class RenderEditableLine extends RenderBox { ...@@ -71,7 +71,7 @@ class RenderEditableLine extends RenderBox {
SelectionChangedHandler onSelectionChanged; SelectionChangedHandler onSelectionChanged;
/// Called when the inner or outer dimensions of this render object change. /// Called when the inner or outer dimensions of this render object change.
RenderEditableLinePaintOffsetNeededCallback onPaintOffsetUpdateNeeded; RenderEditablePaintOffsetNeededCallback onPaintOffsetUpdateNeeded;
/// The text to display /// The text to display
TextSpan get text => _textPainter.text; TextSpan get text => _textPainter.text;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/rendering.dart' show RenderEditableLine, SelectionChangedHandler, RenderEditableLinePaintOffsetNeededCallback; import 'package:flutter/rendering.dart' show RenderEditable, SelectionChangedHandler, RenderEditablePaintOffsetNeededCallback;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:flutter_services/editing.dart' as mojom; import 'package:flutter_services/editing.dart' as mojom;
...@@ -158,11 +158,11 @@ class InputValue { ...@@ -158,11 +158,11 @@ class InputValue {
/// [Input], which provides focus management and material design. /// [Input], which provides focus management and material design.
// //
// TODO(mpcomplete): rename RawInput since it can span multiple lines. // TODO(mpcomplete): rename RawInput since it can span multiple lines.
class RawInputLine extends Scrollable { class RawInput extends Scrollable {
/// Creates a basic single-line input control. /// Creates a basic single-line input control.
/// ///
/// The [value] argument must not be null. /// The [value] argument must not be null.
RawInputLine({ RawInput({
Key key, Key key,
@required this.value, @required this.value,
this.focusKey, this.focusKey,
...@@ -235,11 +235,11 @@ class RawInputLine extends Scrollable { ...@@ -235,11 +235,11 @@ class RawInputLine extends Scrollable {
final ValueChanged<InputValue> onSubmitted; final ValueChanged<InputValue> onSubmitted;
@override @override
RawInputLineState createState() => new RawInputLineState(); RawInputState createState() => new RawInputState();
} }
/// State for a [RawInputLine]. /// State for a [RawInput].
class RawInputLineState extends ScrollableState<RawInputLine> { class RawInputState extends ScrollableState<RawInput> {
Timer _cursorTimer; Timer _cursorTimer;
bool _showCursor = false; bool _showCursor = false;
...@@ -264,7 +264,7 @@ class RawInputLineState extends ScrollableState<RawInputLine> { ...@@ -264,7 +264,7 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
} }
@override @override
void didUpdateConfig(RawInputLine oldConfig) { void didUpdateConfig(RawInput oldConfig) {
if (_keyboardClient.inputValue != config.value) { if (_keyboardClient.inputValue != config.value) {
_keyboardClient.inputValue = config.value; _keyboardClient.inputValue = config.value;
if (_isAttachedToKeyboard) if (_isAttachedToKeyboard)
...@@ -359,9 +359,9 @@ class RawInputLineState extends ScrollableState<RawInputLine> { ...@@ -359,9 +359,9 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
config.onSubmitted(_keyboardClient.inputValue); config.onSubmitted(_keyboardClient.inputValue);
} }
void _handleSelectionChanged(TextSelection selection, RenderEditableLine renderObject, bool longPress) { void _handleSelectionChanged(TextSelection selection, RenderEditable renderObject, bool longPress) {
// Note that this will show the keyboard for all selection changes on the // Note that this will show the keyboard for all selection changes on the
// EditableLineWidget, not just changes triggered by user gestures. // EditableWidget, not just changes triggered by user gestures.
requestKeyboard(); requestKeyboard();
InputValue newInput = new InputValue(text: _keyboardClient.inputValue.text, selection: selection); InputValue newInput = new InputValue(text: _keyboardClient.inputValue.text, selection: selection);
...@@ -463,7 +463,7 @@ class RawInputLineState extends ScrollableState<RawInputLine> { ...@@ -463,7 +463,7 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
} }
return new ClipRect( return new ClipRect(
child: new _EditableLineWidget( child: new _Editable(
value: _keyboardClient.inputValue, value: _keyboardClient.inputValue,
style: config.style, style: config.style,
cursorColor: config.cursorColor, cursorColor: config.cursorColor,
...@@ -480,8 +480,8 @@ class RawInputLineState extends ScrollableState<RawInputLine> { ...@@ -480,8 +480,8 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
} }
} }
class _EditableLineWidget extends LeafRenderObjectWidget { class _Editable extends LeafRenderObjectWidget {
_EditableLineWidget({ _Editable({
Key key, Key key,
this.value, this.value,
this.style, this.style,
...@@ -506,11 +506,11 @@ class _EditableLineWidget extends LeafRenderObjectWidget { ...@@ -506,11 +506,11 @@ class _EditableLineWidget extends LeafRenderObjectWidget {
final bool hideText; final bool hideText;
final SelectionChangedHandler onSelectionChanged; final SelectionChangedHandler onSelectionChanged;
final Offset paintOffset; final Offset paintOffset;
final RenderEditableLinePaintOffsetNeededCallback onPaintOffsetUpdateNeeded; final RenderEditablePaintOffsetNeededCallback onPaintOffsetUpdateNeeded;
@override @override
RenderEditableLine createRenderObject(BuildContext context) { RenderEditable createRenderObject(BuildContext context) {
return new RenderEditableLine( return new RenderEditable(
text: _styledTextSpan, text: _styledTextSpan,
cursorColor: cursorColor, cursorColor: cursorColor,
showCursor: showCursor, showCursor: showCursor,
...@@ -525,7 +525,7 @@ class _EditableLineWidget extends LeafRenderObjectWidget { ...@@ -525,7 +525,7 @@ class _EditableLineWidget extends LeafRenderObjectWidget {
} }
@override @override
void updateRenderObject(BuildContext context, RenderEditableLine renderObject) { void updateRenderObject(BuildContext context, RenderEditable renderObject) {
renderObject renderObject
..text = _styledTextSpan ..text = _styledTextSpan
..cursorColor = cursorColor ..cursorColor = cursorColor
......
...@@ -14,17 +14,17 @@ import 'framework.dart'; ...@@ -14,17 +14,17 @@ import 'framework.dart';
/// hardware buttons that are represented as keys. Typically used by games and /// hardware buttons that are represented as keys. Typically used by games and
/// other apps that use keyboards for purposes other than text entry. /// other apps that use keyboards for purposes other than text entry.
/// ///
/// For text entry, consider using a [RawInputLine], which integrates with /// For text entry, consider using a [RawInput], which integrates with
/// on-screen keyboards and input method editors (IMEs). /// on-screen keyboards and input method editors (IMEs).
/// ///
/// See also: /// See also:
/// ///
/// * [RawInputLine], which should be used instead of this widget for text /// * [RawInput], which should be used instead of this widget for text
/// entry. /// entry.
class RawKeyboardListener extends StatefulWidget { class RawKeyboardListener extends StatefulWidget {
/// Creates a widget that receives raw keyboard events. /// Creates a widget that receives raw keyboard events.
/// ///
/// For text entry, consider using a [RawInputLine], which integrates with /// For text entry, consider using a [RawInput], which integrates with
/// on-screen keyboards and input method editors (IMEs). /// on-screen keyboards and input method editors (IMEs).
RawKeyboardListener({ RawKeyboardListener({
Key key, Key key,
......
...@@ -109,7 +109,7 @@ class TextSelectionOverlay implements TextSelectionDelegate { ...@@ -109,7 +109,7 @@ class TextSelectionOverlay implements TextSelectionDelegate {
// TODO(mpcomplete): what if the renderObject is removed or replaced, or // TODO(mpcomplete): what if the renderObject is removed or replaced, or
// moves? Not sure what cases I need to handle, or how to handle them. // moves? Not sure what cases I need to handle, or how to handle them.
/// The editable line in which the selected text is being displayed. /// The editable line in which the selected text is being displayed.
final RenderEditableLine renderObject; final RenderEditable renderObject;
/// Called when the the selection changes. /// Called when the the selection changes.
/// ///
...@@ -301,7 +301,7 @@ class _TextSelectionHandleOverlay extends StatefulWidget { ...@@ -301,7 +301,7 @@ class _TextSelectionHandleOverlay extends StatefulWidget {
final TextSelection selection; final TextSelection selection;
final _TextSelectionHandlePosition position; final _TextSelectionHandlePosition position;
final RenderEditableLine renderObject; final RenderEditable renderObject;
final ValueChanged<TextSelection> onSelectionHandleChanged; final ValueChanged<TextSelection> onSelectionHandleChanged;
final VoidCallback onSelectionHandleTapped; final VoidCallback onSelectionHandleTapped;
final TextSelectionControls selectionControls; final TextSelectionControls selectionControls;
......
...@@ -190,7 +190,7 @@ void main() { ...@@ -190,7 +190,7 @@ void main() {
expect(mockKeyboard.currentState.text, equals(initialValue)); expect(mockKeyboard.currentState.text, equals(initialValue));
// initial value should also be visible in the raw input line // initial value should also be visible in the raw input line
RawInputLineState editableText = tester.state(find.byType(RawInputLine)); RawInputState editableText = tester.state(find.byType(RawInput));
expect(editableText.config.value.text, equals(initialValue)); expect(editableText.config.value.text, equals(initialValue));
// sanity check, make sure we can still edit the text and everything updates // sanity check, make sure we can still edit the text and everything updates
......
...@@ -73,27 +73,27 @@ void main() { ...@@ -73,27 +73,27 @@ void main() {
..composingExtent = testValue.length); ..composingExtent = testValue.length);
} }
// Returns the first RenderEditableLine. // Returns the first RenderEditable.
RenderEditableLine findRenderEditableLine(WidgetTester tester) { RenderEditable findRenderEditable(WidgetTester tester) {
RenderObject root = tester.renderObject(find.byType(RawInputLine)); RenderObject root = tester.renderObject(find.byType(RawInput));
expect(root, isNotNull); expect(root, isNotNull);
RenderEditableLine renderLine; RenderEditable renderEditable;
void recursiveFinder(RenderObject child) { void recursiveFinder(RenderObject child) {
if (child is RenderEditableLine) { if (child is RenderEditable) {
renderLine = child; renderEditable = child;
return; return;
} }
child.visitChildren(recursiveFinder); child.visitChildren(recursiveFinder);
} }
root.visitChildren(recursiveFinder); root.visitChildren(recursiveFinder);
expect(renderLine, isNotNull); expect(renderEditable, isNotNull);
return renderLine; return renderEditable;
} }
Point textOffsetToPosition(WidgetTester tester, int offset) { Point textOffsetToPosition(WidgetTester tester, int offset) {
RenderEditableLine renderLine = findRenderEditableLine(tester); RenderEditable renderEditable = findRenderEditable(tester);
List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection( List<TextSelectionPoint> endpoints = renderEditable.getEndpointsForSelection(
new TextSelection.collapsed(offset: offset)); new TextSelection.collapsed(offset: offset));
expect(endpoints.length, 1); expect(endpoints.length, 1);
return endpoints[0].point + new Offset(0.0, -2.0); return endpoints[0].point + new Offset(0.0, -2.0);
...@@ -157,7 +157,7 @@ void main() { ...@@ -157,7 +157,7 @@ void main() {
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
RawInputLineState editableText = tester.state(find.byType(RawInputLine)); RawInputState editableText = tester.state(find.byType(RawInput));
// Check that the cursor visibility toggles after each blink interval. // Check that the cursor visibility toggles after each blink interval.
Future<Null> checkCursorToggle() async { Future<Null> checkCursorToggle() async {
...@@ -296,8 +296,8 @@ void main() { ...@@ -296,8 +296,8 @@ void main() {
TextSelection selection = inputValue.selection; TextSelection selection = inputValue.selection;
RenderEditableLine renderLine = findRenderEditableLine(tester); RenderEditable renderEditable = findRenderEditable(tester);
List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection( List<TextSelectionPoint> endpoints = renderEditable.getEndpointsForSelection(
selection); selection);
expect(endpoints.length, 2); expect(endpoints.length, 2);
...@@ -363,8 +363,8 @@ void main() { ...@@ -363,8 +363,8 @@ void main() {
// Tap the selection handle to bring up the "paste / select all" menu. // Tap the selection handle to bring up the "paste / select all" menu.
await tester.tapAt(textOffsetToPosition(tester, testValue.indexOf('e'))); await tester.tapAt(textOffsetToPosition(tester, testValue.indexOf('e')));
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
RenderEditableLine renderLine = findRenderEditableLine(tester); RenderEditable renderEditable = findRenderEditable(tester);
List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection( List<TextSelectionPoint> endpoints = renderEditable.getEndpointsForSelection(
inputValue.selection); inputValue.selection);
await tester.tapAt(endpoints[0].point + new Offset(1.0, 1.0)); await tester.tapAt(endpoints[0].point + new Offset(1.0, 1.0));
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
...@@ -383,8 +383,8 @@ void main() { ...@@ -383,8 +383,8 @@ void main() {
// Tap again to bring back the menu. // Tap again to bring back the menu.
await tester.tapAt(textOffsetToPosition(tester, testValue.indexOf('e'))); await tester.tapAt(textOffsetToPosition(tester, testValue.indexOf('e')));
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
renderLine = findRenderEditableLine(tester); renderEditable = findRenderEditable(tester);
endpoints = renderLine.getEndpointsForSelection(inputValue.selection); endpoints = renderEditable.getEndpointsForSelection(inputValue.selection);
await tester.tapAt(endpoints[0].point + new Offset(1.0, 1.0)); await tester.tapAt(endpoints[0].point + new Offset(1.0, 1.0));
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
...@@ -427,8 +427,8 @@ void main() { ...@@ -427,8 +427,8 @@ void main() {
// Tap the selection handle to bring up the "paste / select all" menu. // Tap the selection handle to bring up the "paste / select all" menu.
await tester.tapAt(textOffsetToPosition(tester, testValue.indexOf('e'))); await tester.tapAt(textOffsetToPosition(tester, testValue.indexOf('e')));
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
RenderEditableLine renderLine = findRenderEditableLine(tester); RenderEditable renderEditable = findRenderEditable(tester);
List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection( List<TextSelectionPoint> endpoints = renderEditable.getEndpointsForSelection(
inputValue.selection); inputValue.selection);
await tester.tapAt(endpoints[0].point + new Offset(1.0, 1.0)); await tester.tapAt(endpoints[0].point + new Offset(1.0, 1.0));
await tester.pumpWidget(builder()); await tester.pumpWidget(builder());
...@@ -552,8 +552,8 @@ void main() { ...@@ -552,8 +552,8 @@ void main() {
expect(inputValue.selection.baseOffset, 76); expect(inputValue.selection.baseOffset, 76);
expect(inputValue.selection.extentOffset, 81); expect(inputValue.selection.extentOffset, 81);
RenderEditableLine renderLine = findRenderEditableLine(tester); RenderEditable renderEditable = findRenderEditable(tester);
List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection( List<TextSelectionPoint> endpoints = renderEditable.getEndpointsForSelection(
inputValue.selection); inputValue.selection);
expect(endpoints.length, 2); expect(endpoints.length, 2);
...@@ -656,8 +656,8 @@ void main() { ...@@ -656,8 +656,8 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pump(); await tester.pump();
RenderEditableLine renderLine = findRenderEditableLine(tester); RenderEditable renderEditable = findRenderEditable(tester);
List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection( List<TextSelectionPoint> endpoints = renderEditable.getEndpointsForSelection(
inputValue.selection); inputValue.selection);
expect(endpoints.length, 2); expect(endpoints.length, 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment