Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a2957c57
Unverified
Commit
a2957c57
authored
Aug 30, 2019
by
Mouad Debbar
Committed by
GitHub
Aug 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upstream changes necessary for text editing in flutter web (#39344)
parent
bb1d139c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
370 additions
and
9 deletions
+370
-9
text_input.dart
packages/flutter/lib/src/services/text_input.dart
+55
-1
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+49
-2
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+266
-6
No files found.
packages/flutter/lib/src/services/text_input.dart
View file @
a2957c57
...
...
@@ -4,9 +4,17 @@
import
'dart:async'
;
import
'dart:io'
show
Platform
;
import
'dart:ui'
show
TextAffinity
,
hashValues
,
Offset
;
import
'dart:ui'
show
FontWeight
,
Offset
,
Size
,
TextAffinity
,
TextAlign
,
TextDirection
,
hashValues
;
import
'package:flutter/foundation.dart'
;
import
'package:vector_math/vector_math_64.dart'
show
Matrix4
;
import
'message_codec.dart'
;
import
'system_channels.dart'
;
...
...
@@ -660,6 +668,52 @@ class TextInputConnection {
);
}
/// Send the size and transform of the editable text to engine.
///
/// The values are sent as platform messages so they can be used on web for
/// example to correctly position and size the html input field.
///
/// 1. [editableBoxSize]: size of the render editable box.
///
/// 2. [transform]: a matrix that maps the local paint coordinate system
/// to the [PipelineOwner.rootNode].
void
setEditableSizeAndTransform
(
Size
editableBoxSize
,
Matrix4
transform
)
{
SystemChannels
.
textInput
.
invokeMethod
<
void
>(
'TextInput.setEditableSizeAndTransform'
,
<
String
,
dynamic
>{
'width'
:
editableBoxSize
.
width
,
'height'
:
editableBoxSize
.
height
,
'transform'
:
transform
.
storage
,
},
);
}
/// Send text styling information.
///
/// This information is used by the Flutter Web Engine to change the style
/// of the hidden native input's content. Hence, the content size will match
/// to the size of the editable widget's content.
void
setStyle
({
@required
String
fontFamily
,
@required
double
fontSize
,
@required
FontWeight
fontWeight
,
@required
TextDirection
textDirection
,
@required
TextAlign
textAlign
,
})
{
assert
(
attached
);
SystemChannels
.
textInput
.
invokeMethod
<
void
>(
'TextInput.setStyle'
,
<
String
,
dynamic
>{
'fontFamily'
:
fontFamily
,
'fontSize'
:
fontSize
,
'fontWeightIndex'
:
fontWeight
?.
index
,
'textAlignIndex'
:
textAlign
.
index
,
'textDirectionIndex'
:
textDirection
.
index
,
},
);
}
/// Stop interacting with the text input control.
///
/// After calling this method, the text input control might disappear if no
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
a2957c57
...
...
@@ -4,7 +4,7 @@
import
'dart:async'
;
import
'dart:math'
as
math
;
import
'dart:ui'
as
ui
;
import
'dart:ui'
as
ui
hide
TextStyle
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/painting.dart'
;
...
...
@@ -1095,6 +1095,16 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if
(
oldWidget
.
readOnly
&&
_hasFocus
)
_openInputConnection
();
}
if
(
widget
.
style
!=
oldWidget
.
style
)
{
final
TextStyle
style
=
widget
.
style
;
_textInputConnection
?.
setStyle
(
fontFamily:
style
.
fontFamily
,
fontSize:
style
.
fontSize
,
fontWeight:
style
.
fontWeight
,
textDirection:
_textDirection
,
textAlign:
widget
.
textAlign
,
);
}
}
@override
...
...
@@ -1335,7 +1345,19 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
textCapitalization:
widget
.
textCapitalization
,
keyboardAppearance:
widget
.
keyboardAppearance
,
),
)..
setEditingState
(
localValue
);
);
_updateSizeAndTransform
();
final
TextStyle
style
=
widget
.
style
;
_textInputConnection
..
setStyle
(
fontFamily:
style
.
fontFamily
,
fontSize:
style
.
fontSize
,
fontWeight:
style
.
fontWeight
,
textDirection:
_textDirection
,
textAlign:
widget
.
textAlign
,
)
..
setEditingState
(
localValue
);
}
_textInputConnection
.
show
();
}
...
...
@@ -1626,6 +1648,23 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
updateKeepAlive
();
}
Size
_lastSize
;
Matrix4
_lastTransform
;
void
_updateSizeAndTransform
()
{
if
(
_hasInputConnection
)
{
final
Size
size
=
renderEditable
.
size
;
final
Matrix4
transform
=
renderEditable
.
getTransformTo
(
null
);
if
(
size
!=
_lastSize
||
transform
!=
_lastTransform
)
{
_lastSize
=
size
;
_lastTransform
=
transform
;
_textInputConnection
.
setEditableSizeAndTransform
(
size
,
transform
);
}
SchedulerBinding
.
instance
.
addPostFrameCallback
((
Duration
_
)
=>
_updateSizeAndTransform
());
}
}
TextDirection
get
_textDirection
{
final
TextDirection
result
=
widget
.
textDirection
??
Directionality
.
of
(
context
);
assert
(
result
!=
null
,
'
$runtimeType
created without a textDirection and with no ambient Directionality.'
);
...
...
@@ -1659,6 +1698,14 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
/// Returns `false` if a toolbar couldn't be shown, such as when the toolbar
/// is already shown, or when no text selection currently exists.
bool
showToolbar
()
{
// Web is using native dom elements to enable clipboard functionality of the
// toolbar: copy, paste, select, cut. It might also provide additional
// functionality depending on the browser (such as translate). Due to this
// we should not show a Flutter toolbar for the editable text elements.
if
(
kIsWeb
)
{
return
false
;
}
if
(
_selectionOverlay
==
null
||
_selectionOverlay
.
toolbarIsVisible
)
{
return
false
;
}
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
a2957c57
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment