Skip to content

Commit 8e796bd

Browse files
authored
[web] Librarify text editing files (flutter#27071)
1 parent 24ace61 commit 8e796bd

File tree

11 files changed

+227
-182
lines changed

11 files changed

+227
-182
lines changed

lib/web_ui/lib/src/engine.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ import '../ui.dart' as ui;
3535
import 'engine/alarm_clock.dart';
3636
export 'engine/alarm_clock.dart';
3737

38+
export 'engine/assets.dart';
39+
3840
import 'engine/browser_detection.dart';
3941
export 'engine/browser_detection.dart';
4042

43+
import 'engine/host_node.dart';
44+
export 'engine/host_node.dart';
45+
4146
import 'engine/html_image_codec.dart';
4247
export 'engine/html_image_codec.dart';
4348

@@ -146,7 +151,8 @@ export 'engine/shadow.dart';
146151
import 'engine/test_embedding.dart';
147152
export 'engine/test_embedding.dart';
148153

149-
import 'engine/text/layout_service.dart';
154+
export 'engine/text/font_collection.dart';
155+
150156
export 'engine/text/layout_service.dart';
151157

152158
export 'engine/text/line_break_properties.dart';
@@ -173,6 +179,14 @@ export 'engine/text/word_break_properties.dart';
173179

174180
export 'engine/text/word_breaker.dart';
175181

182+
export 'engine/text_editing/autofill_hint.dart';
183+
184+
export 'engine/text_editing/input_type.dart';
185+
186+
export 'engine/text_editing/text_capitalization.dart';
187+
188+
import 'engine/text_editing/text_editing.dart';
189+
export 'engine/text_editing/text_editing.dart';
176190

177191
import 'engine/util.dart';
178192
export 'engine/util.dart';
@@ -253,7 +267,6 @@ export 'engine/canvaskit/util.dart';
253267

254268
export 'engine/canvaskit/vertices.dart';
255269

256-
part 'engine/assets.dart';
257270
part 'engine/html/bitmap_canvas.dart';
258271
part 'engine/canvas_pool.dart';
259272
part 'engine/clipboard.dart';
@@ -263,7 +276,6 @@ part 'engine/dom_renderer.dart';
263276
part 'engine/engine_canvas.dart';
264277
part 'engine/font_change_util.dart';
265278
part 'engine/frame_reference.dart';
266-
part 'engine/host_node.dart';
267279
part 'engine/html/backdrop_filter.dart';
268280
part 'engine/html/canvas.dart';
269281
part 'engine/html/clip.dart';
@@ -301,11 +313,6 @@ part 'engine/semantics/semantics.dart';
301313
part 'engine/semantics/semantics_helper.dart';
302314
part 'engine/semantics/tappable.dart';
303315
part 'engine/semantics/text_field.dart';
304-
part 'engine/text/font_collection.dart';
305-
part 'engine/text_editing/autofill_hint.dart';
306-
part 'engine/text_editing/input_type.dart';
307-
part 'engine/text_editing/text_capitalization.dart';
308-
part 'engine/text_editing/text_editing.dart';
309316
part 'engine/window.dart';
310317

311318
// The mode the app is running in.

lib/web_ui/lib/src/engine/assets.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
part of engine;
5+
import 'dart:convert';
6+
import 'dart:html' as html;
7+
import 'dart:typed_data';
8+
9+
import 'text/font_collection.dart';
10+
import 'util.dart';
611

712
/// This class downloads assets over the network.
813
///
@@ -89,12 +94,12 @@ class WebOnlyMockAssetManager implements AssetManager {
8994
String defaultFontManifest = '''
9095
[
9196
{
92-
"family":"$_robotoFontFamily",
93-
"fonts":[{"asset":"$_robotoTestFontUrl"}]
97+
"family":"$robotoFontFamily",
98+
"fonts":[{"asset":"$robotoTestFontUrl"}]
9499
},
95100
{
96-
"family":"$_ahemFontFamily",
97-
"fonts":[{"asset":"$_ahemFontUrl"}]
101+
"family":"$ahemFontFamily",
102+
"fonts":[{"asset":"$ahemFontUrl"}]
98103
}
99104
]''';
100105

lib/web_ui/lib/src/engine/host_node.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
part of engine;
5+
import 'dart:html' as html;
6+
7+
import 'package:ui/src/engine.dart' show applyGlobalCssRulesToSheet;
8+
9+
import 'browser_detection.dart';
10+
import 'text_editing/text_editing.dart';
611

712
/// The interface required to host a flutter app in the DOM, and its tests.
813
///

lib/web_ui/lib/src/engine/platform_dispatcher.dart

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
332332

333333
if (assertionsEnabled && name == 'flutter/debug-echo') {
334334
// Echoes back the data unchanged. Used for testing purposes.
335-
_replyToPlatformMessage(callback, data);
335+
replyToPlatformMessage(callback, data);
336336
return;
337337
}
338338

@@ -357,7 +357,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
357357

358358
// Also respond in HTML mode. Otherwise, apps would have to detect
359359
// CanvasKit vs HTML before invoking this method.
360-
_replyToPlatformMessage(
360+
replyToPlatformMessage(
361361
callback, codec.encodeSuccessEnvelope([true]));
362362
break;
363363
}
@@ -366,10 +366,10 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
366366
case 'flutter/assets':
367367
final String url = utf8.decode(data!.buffer.asUint8List());
368368
ui.webOnlyAssetManager.load(url).then((ByteData assetData) {
369-
_replyToPlatformMessage(callback, assetData);
369+
replyToPlatformMessage(callback, assetData);
370370
}, onError: (dynamic error) {
371371
printWarning('Error while trying to load an asset: $error');
372-
_replyToPlatformMessage(callback, null);
372+
replyToPlatformMessage(callback, null);
373373
});
374374
return;
375375

@@ -385,15 +385,14 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
385385
.browserHistory
386386
.exit()
387387
.then((_) {
388-
_replyToPlatformMessage(
388+
replyToPlatformMessage(
389389
callback, codec.encodeSuccessEnvelope(true));
390390
});
391391
return;
392392
case 'HapticFeedback.vibrate':
393393
final String? type = decoded.arguments;
394394
domRenderer.vibrate(_getHapticFeedbackDuration(type));
395-
_replyToPlatformMessage(
396-
callback, codec.encodeSuccessEnvelope(true));
395+
replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
397396
return;
398397
case 'SystemChrome.setApplicationSwitcherDescription':
399398
final Map<String, dynamic> arguments = decoded.arguments;
@@ -402,20 +401,18 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
402401
final int primaryColor = arguments['primaryColor'] as int? ?? 0xFF000000;
403402
domRenderer.setTitle(label);
404403
domRenderer.setThemeColor(ui.Color(primaryColor));
405-
_replyToPlatformMessage(
406-
callback, codec.encodeSuccessEnvelope(true));
404+
replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
407405
return;
408406
case 'SystemChrome.setPreferredOrientations':
409407
final List<dynamic> arguments = decoded.arguments;
410408
domRenderer.setPreferredOrientation(arguments).then((bool success) {
411-
_replyToPlatformMessage(
409+
replyToPlatformMessage(
412410
callback, codec.encodeSuccessEnvelope(success));
413411
});
414412
return;
415413
case 'SystemSound.play':
416414
// There are no default system sounds on web.
417-
_replyToPlatformMessage(
418-
callback, codec.encodeSuccessEnvelope(true));
415+
replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
419416
return;
420417
case 'Clipboard.setData':
421418
ClipboardMessageHandler().setDataMethodCall(decoded, callback);
@@ -447,7 +444,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
447444

448445
case 'flutter/web_test_e2e':
449446
const MethodCodec codec = JSONMethodCodec();
450-
_replyToPlatformMessage(
447+
replyToPlatformMessage(
451448
callback,
452449
codec.encodeSuccessEnvelope(
453450
_handleWebTestEnd2EndMessage(codec, data)));
@@ -467,7 +464,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
467464
// In widget tests we want to bypass processing of platform messages.
468465
final StandardMessageCodec codec = StandardMessageCodec();
469466
accessibilityAnnouncements.handleMessage(codec, data);
470-
_replyToPlatformMessage(callback, codec.encodeMessage(true));
467+
replyToPlatformMessage(callback, codec.encodeMessage(true));
471468
return;
472469

473470
case 'flutter/navigation':
@@ -479,8 +476,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
479476
.then((bool handled) {
480477
if (handled) {
481478
const MethodCodec codec = JSONMethodCodec();
482-
_replyToPlatformMessage(
483-
callback, codec.encodeSuccessEnvelope(true));
479+
replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
484480
} else {
485481
callback?.call(null);
486482
}
@@ -501,7 +497,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
501497
// Passing [null] to [callback] indicates that the platform message isn't
502498
// implemented. Look at [MethodChannel.invokeMethod] to see how [null] is
503499
// handled.
504-
_replyToPlatformMessage(callback, null);
500+
replyToPlatformMessage(callback, null);
505501
}
506502

507503
int _getHapticFeedbackDuration(String? type) {
@@ -931,7 +927,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
931927
/// In Flutter, platform messages are exchanged between threads so the
932928
/// messages and responses have to be exchanged asynchronously. We simulate
933929
/// that by adding a zero-length delay to the reply.
934-
void _replyToPlatformMessage(
930+
void replyToPlatformMessage(
935931
ui.PlatformMessageResponseCallback? callback,
936932
ByteData? data,
937933
) {

lib/web_ui/lib/src/engine/semantics/text_field.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
4242
/// Current input configuration supplied by the "flutter/textinput" channel.
4343
InputConfiguration? inputConfig;
4444

45-
_OnChangeCallback? onChange;
46-
_OnActionCallback? onAction;
45+
OnChangeCallback? onChange;
46+
OnActionCallback? onAction;
4747

4848
/// The semantics implementation does not operate on DOM nodes, but only
4949
/// remembers the config and callbacks. This is because the DOM nodes are
5050
/// supplied in the semantics update and enabled by [activate].
5151
@override
5252
void enable(
5353
InputConfiguration inputConfig, {
54-
required _OnChangeCallback onChange,
55-
required _OnActionCallback onAction,
54+
required OnChangeCallback onChange,
55+
required OnActionCallback onAction,
5656
}) {
5757
this.inputConfig = inputConfig;
5858
this.onChange = onChange;
@@ -104,14 +104,14 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
104104
}
105105

106106
isEnabled = false;
107-
_style = null;
108-
_geometry = null;
107+
style = null;
108+
geometry = null;
109109

110-
for (int i = 0; i < _subscriptions.length; i++) {
111-
_subscriptions[i].cancel();
110+
for (int i = 0; i < subscriptions.length; i++) {
111+
subscriptions[i].cancel();
112112
}
113-
_subscriptions.clear();
114-
_lastEditingState = null;
113+
subscriptions.clear();
114+
lastEditingState = null;
115115

116116
// If the text element still has focus, remove focus from the editable
117117
// element to cause the on-screen keyboard, if any, to hide (e.g. on iOS,
@@ -126,26 +126,26 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
126126

127127
@override
128128
void addEventHandlers() {
129-
if (_inputConfiguration.autofillGroup != null) {
130-
_subscriptions
131-
.addAll(_inputConfiguration.autofillGroup!.addInputEventListeners());
129+
if (inputConfiguration.autofillGroup != null) {
130+
subscriptions
131+
.addAll(inputConfiguration.autofillGroup!.addInputEventListeners());
132132
}
133133

134134
// Subscribe to text and selection changes.
135-
_subscriptions.add(activeDomElement.onInput.listen(_handleChange));
136-
_subscriptions.add(activeDomElement.onKeyDown.listen(_maybeSendAction));
137-
_subscriptions.add(html.document.onSelectionChange.listen(_handleChange));
135+
subscriptions.add(activeDomElement.onInput.listen(handleChange));
136+
subscriptions.add(activeDomElement.onKeyDown.listen(maybeSendAction));
137+
subscriptions.add(html.document.onSelectionChange.listen(handleChange));
138138
preventDefaultForMouseEvents();
139139
}
140140

141141
@override
142142
void initializeTextEditing(InputConfiguration inputConfig,
143-
{_OnChangeCallback? onChange, _OnActionCallback? onAction}) {
143+
{OnChangeCallback? onChange, OnActionCallback? onAction}) {
144144
isEnabled = true;
145-
_inputConfiguration = inputConfig;
146-
_onChange = onChange;
147-
_onAction = onAction;
148-
_applyConfiguration(inputConfig);
145+
inputConfiguration = inputConfig;
146+
onChange = onChange;
147+
onAction = onAction;
148+
applyConfiguration(inputConfig);
149149
}
150150

151151
@override

lib/web_ui/lib/src/engine/text/font_collection.dart

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
part of engine;
6-
7-
const String _ahemFontFamily = 'Ahem';
8-
const String _ahemFontUrl = 'packages/ui/assets/ahem.ttf';
9-
const String _robotoFontFamily = 'Roboto';
10-
const String _robotoTestFontUrl = 'packages/ui/assets/Roboto-Regular.ttf';
5+
import 'dart:async';
6+
import 'dart:convert';
7+
import 'dart:html' as html;
8+
import 'dart:js_util' as js_util;
9+
import 'dart:typed_data';
10+
11+
import '../assets.dart';
12+
import '../browser_detection.dart';
13+
import '../util.dart';
14+
import 'measurement.dart';
15+
import 'layout_service.dart';
16+
17+
const String ahemFontFamily = 'Ahem';
18+
const String ahemFontUrl = 'packages/ui/assets/ahem.ttf';
19+
const String robotoFontFamily = 'Roboto';
20+
const String robotoTestFontUrl = 'packages/ui/assets/Roboto-Regular.ttf';
1121

1222
/// This class is responsible for registering and loading fonts.
1323
///
@@ -76,9 +86,9 @@ class FontCollection {
7686
void debugRegisterTestFonts() {
7787
_testFontManager = FontManager();
7888
_testFontManager!.registerAsset(
79-
_ahemFontFamily, 'url($_ahemFontUrl)', const <String, String>{});
80-
_testFontManager!.registerAsset(_robotoFontFamily,
81-
'url($_robotoTestFontUrl)', const <String, String>{});
89+
ahemFontFamily, 'url($ahemFontUrl)', const <String, String>{});
90+
_testFontManager!.registerAsset(robotoFontFamily,
91+
'url($robotoTestFontUrl)', const <String, String>{});
8292
}
8393

8494
/// Returns a [Future] that completes when the registered fonts are loaded

lib/web_ui/lib/src/engine/text_editing/autofill_hint.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
part of engine;
6-
75
/// Maps AutofillHints from the framework to the autofill hints that is used for
86
/// browsers.
97
/// See: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/autofill.dart

lib/web_ui/lib/src/engine/text_editing/input_type.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
part of engine;
5+
import 'dart:html' as html;
6+
7+
import '../browser_detection.dart';
68

79
/// Various types of inputs used in text fields.
810
///

lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
part of engine;
5+
import 'dart:html' as html;
6+
7+
import '../browser_detection.dart';
68

79
/// Controls the capitalization of the text.
810
///

0 commit comments

Comments
 (0)