diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart index 054b16e6be8..3a4c1a4cbc3 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart @@ -29,10 +29,23 @@ enum BrowserEngine { /// Lazily initialized current browser engine. BrowserEngine _browserEngine; +/// Override the value of [browserEngine]. +/// +/// Setting this to `null` lets [browserEngine] detect the browser that the +/// app is running on. +/// +/// This is intended to be used for testing and debugging only. +BrowserEngine debugBrowserEngineOverride; + /// Returns the [BrowserEngine] used by the current browser. /// /// This is used to implement browser-specific behavior. -BrowserEngine get browserEngine => _browserEngine ??= _detectBrowserEngine(); +BrowserEngine get browserEngine { + if (debugBrowserEngineOverride != null) { + return debugBrowserEngineOverride; + } + return _browserEngine ??= _detectBrowserEngine(); +} BrowserEngine _detectBrowserEngine() { final String vendor = html.window.navigator.vendor; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart index 47c0ff7a099..d7620c2f625 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart @@ -66,7 +66,7 @@ abstract class EngineInputType { html.HtmlElement createDomElement() => html.InputElement(); /// Given a [domElement], set attributes that are specific to this input type. - void configureDomElement(html.HtmlElement domElement) { + void configureInputMode(html.HtmlElement domElement) { if (inputmodeAttribute == null) { return; } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart index edba66651a5..9c99621b78d 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart @@ -12,16 +12,6 @@ const int _kReturnKeyCode = 13; void _emptyCallback(dynamic _) {} -/// Indicates whether virtual keyboard shifts the location of input element. -/// -/// Value decided using the operating system and the browser engine. -/// -/// In iOS, the virtual keyboard might shifts the screen up to make input -/// visible depending on the location of the focused input element. -bool get _doesKeyboardShiftInput => - browserEngine == BrowserEngine.webkit && - operatingSystem == OperatingSystem.iOs; - /// These style attributes are constant throughout the life time of an input /// element. /// @@ -222,37 +212,78 @@ class InputConfiguration { typedef _OnChangeCallback = void Function(EditingState editingState); typedef _OnActionCallback = void Function(String inputAction); -/// Wraps the DOM element used to provide text editing capabilities. +/// Interface defining the template for text editing strategies. /// -/// The backing DOM element could be one of: +/// The algorithms will be picked in the runtime depending on the concrete +/// class implementing the interface. +/// +/// These algorithms is expected to differ by operating system and/or browser. +abstract class TextEditingStrategy { + void initializeTextEditing( + InputConfiguration inputConfig, { + @required _OnChangeCallback onChange, + @required _OnActionCallback onAction, + }); + + /// Place the DOM element to its initial position. + /// + /// It will be located exactly in the same place with the editable widgets, + /// however it's contents and cursor will be invisible. + /// + /// Users can interact with the element and use the functionalities of the + /// right-click menu. Such as copy,paste, cut, select, translate... + void initializeElementPosition(); + + /// Register event listeners to the DOM element. + /// + /// These event listener will be removed in [disable]. + void addEventHandlers(); + + /// Update the element's position. + /// + /// The position will be updated everytime Flutter Framework sends + /// 'TextInput.setEditableSizeAndTransform' message. + void updateElementPosition(_GeometricInfo geometricInfo); + + /// Set editing state of the element. + /// + /// This includes text and selection relelated states. The editing state will + /// be updated everytime Flutter Framework sends 'TextInput.setEditingState' + /// message. + void setEditingState(EditingState editingState); + + /// Set style to the native DOM element used for text editing. + void updateElementStyle(_EditingStyle style); + + /// Disables the element so it's no longer used for text editing. + /// + /// Calling [disable] also removes any registered event listeners. + void disable(); +} + +/// Class implementing the default editing strategies for text editing. +/// +/// This class uses a DOM element to provide text editing capabilities. +/// +/// The backing DOM element could be one of: /// /// 1. ``. /// 2. `