зеркало из https://github.com/mozilla/gecko-dev.git
e51cdb3ca3
This patch tries to implement Blink-compat white-space normalizer for `HTMLEditor`. It's difficult to list up our traditional white-space normalization rules because `WSRunObject` touches white space sequence only when there is not acceptable case, e.g., an ASCII white-spaces will be adjacent to another one, and replaces only unacceptable white-space only. Therefore, whether white-space sequence may start with either an ASCII white-space or an NBSP. On the other hand, Blink and WebKit makes white-space sequence always starts with an NBSP or an ASCII white-space (unfortunately, they behave differently!). So, for web-compat, we should simulate Blink's behavior because either behavior is reasonable but Blink have more market share. This patch simply adds new white-space normalization path for the new one, and it's switchable with a pref, and still disabled by default. The other reason why we should do this is, our traditional white-space normalizer touches the DOM a lot of times per edit action, and the timing is both before and after touches the DOM tree. Therefore, it's difficult to compute actual deleting range for `InputEvent.getTargetRanges()` and touching a lot of times causes running mutation event listeners a lot and creates a lot of transaction class instances. So, new one have a lot of merits: 1. Improve web-compat 2. Improve the peformance 3. Improve the security 4. Improve the footprint (but this is now worse then traditional one) 5. Simplify the implementation The new normalizer is mostly implemented with only 3 `HTMLEditor` methods. One is `HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces()`. This is semi-public method for the edit action handlers. This takes a range with 2 `EditorDOMPoinInText` to delete the range simply. This also replaces surrounding white-space sequence if necessary. For inserting text case, this method also handles only white-space normalization when it's called with collapsed range, i.e., same `EditorDOMPointInText`. This tries to use `RepaceTextWithTransaction()` as far as possible to reduce creation cost of transaction classes and the footprint. Another one is `HTMLEditor::ExtendRangeToDeleteWithNormalizingWhiteSpaces()`. This tries to extend the given range to normalize surrounding white-spaces. This is currently not optimized for footprint because this may include white-spaces which do not need to be replaced. This optimization should be done before shipping, but for now, enabling `InputEvent.getTargetRanges()` in Nightly channel is more important. So that it should be done in a follow-up bug. The other is `HTMLEditor::GenerateWhitepaceSequence()`. This creates normalized white-space sequence with surrounding character information. For keeping this method simple as far as possible, we shouldn't optimize the range of generation even in follow-ups. Finally, the white-space sequence is not tested in mochitests, so that we can enable this new normalizer when we run mochitests under `editor/libeditor/tests`. However, WPT has some tests. We should keep them running with current normalizer for checking regression. Instead, we should enable the pref only for the new WPT added by the previous patch. Depends on D78655 Differential Revision: https://phabricator.services.mozilla.com/D78656 |
||
---|---|---|
.. | ||
composer | ||
libeditor | ||
reftests | ||
spellchecker | ||
txmgr | ||
AsyncSpellCheckTestHelper.jsm | ||
moz.build | ||
nsIDocumentStateListener.idl | ||
nsIEditActionListener.idl | ||
nsIEditor.idl | ||
nsIEditorMailSupport.idl | ||
nsIEditorObserver.idl | ||
nsIEditorSpellCheck.idl | ||
nsIHTMLAbsPosEditor.idl | ||
nsIHTMLEditor.idl | ||
nsIHTMLInlineTableEditor.idl | ||
nsIHTMLObjectResizer.idl | ||
nsITableEditor.idl |