Граф коммитов

7162 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano 8eb9f61b5e Bug 1627175 - part 24: Make `EditorBase::FindNode` and `EditorBase::Get*NodeInternal()` take an `EnumSet` instead of multiple `bool` arguments r=m_kato
Before moving them from `EditorBase`, they should take only one option argument
whose type is an `EnumSet` class.

Note that I wanted to name each option for optional behavior, but
`FindAnyDataNode` requires to revert the its meaning  (I.e., only with this
patch, `true` should be set an option).  Therefore, the following patch renames
it.

Differential Revision: https://phabricator.services.mozilla.com/D113228
2021-04-27 11:17:38 +00:00
Masayuki Nakano dc502df61b Bug 1703561 - Make `HTMLEditor` not allow to modify content nodes in `<select>` element r=m_kato
Like the other browsers, we shouldn't allow to user modify content in
`<select>` element.  Note that this case won't occur with moving caret
with input devices.  This occurs only with Selection API.

FYI: Chrome deletes `<select>` element if children of it are selected,
but it's odd behavior since user don't see where is selected visually
and may cause unexpected data loss (i.e., deleting `<select>` element).

Perhaps, we should investigate the behavior in other replaced elements
like `<textarea>` etc in follow up bugs.

Depends on D112513

Differential Revision: https://phabricator.services.mozilla.com/D112517
2021-04-20 12:07:15 +00:00
Masayuki Nakano d39859eba7 Bug 1627175 - part 23: Move `HTMLEditor::IsEmptyNode()` into `HTMLEditUtils` with making it take `EnumSet` instead of `bool` arguments r=m_kato
It's hard to understand each caller of `HTMLEditor::IsEmptyNode()` tries to
check with multiple `bool` arguments.  Therefore, they should be replaced
with an `EnumSet`.

Note that only the first argument is reverted the meaning.  Therefore, if
it's omitted or `false`, `EmptyCheckOption::TreatSingleBRElementAsVisible`
is specified explicitly.  Otherwise, i.e., `true`, nothing should be
specified.

Differential Revision: https://phabricator.services.mozilla.com/D112513
2021-04-20 12:02:17 +00:00
Masayuki Nakano 1ce7f565ac Bug 1627175 - part 22: Get rid of `HTMLEditor::IsEmptyTextNode()` r=m_kato
It returns true only when it's a text node, but the text is empty.
However, `HTMLEditUtils::IsVisibleTextNode()` is used in
`HTMLEditor::IsEmptyNodeImpl()`.  So, we replace it with directly using
`HTMLEditUtils::IsVisibleTextNode()`.

Depends on D112511

Differential Revision: https://phabricator.services.mozilla.com/D112512
2021-04-20 02:00:15 +00:00
Masayuki Nakano 96ee002082 Bug 1627175 - part 21: Move `HTMLEditor::IsInVisibleTextFrames()` to `HTMLEditUtils` r=m_kato
Depends on D112510

Differential Revision: https://phabricator.services.mozilla.com/D112511
2021-04-20 00:41:25 +00:00
Masayuki Nakano fd48bf5244 Bug 1627175 - part 20: Move `HTMLEditor::IsEmptyTextNode()` to `HTMLEditUtils` r=m_kato
Now, it does not depend on `HTMLEditor`.  So, we can move it into the
`HTMLEditUtils`.

Depends on D112509

Differential Revision: https://phabricator.services.mozilla.com/D112510
2021-04-20 00:41:24 +00:00
Masayuki Nakano 91572af027 Bug 1705598 - part 8: Make `WSRunScanner::AutoInclusiveAncestorBlockElementsJoiner()` take editing host instead of `HTMLEditor` r=m_kato
Depends on D112508

Differential Revision: https://phabricator.services.mozilla.com/D112509
2021-04-19 23:25:47 +00:00
Masayuki Nakano 16c03a3b47 Bug 1705598 - part 7: Make `WSRunScanner::GetRangeContainingInvisibleWhiteSpacesAtRangeBoundaries()` take editing host instead of `HTMLEditor` r=m_kato
Depends on D112507

Differential Revision: https://phabricator.services.mozilla.com/D112508
2021-04-19 23:25:47 +00:00
Masayuki Nakano 7c39f920b9 Bug 1705598 - part 6: Make `WSRunScanner::GetRangesForDeletingAtomicContent()` take editing host instead of `HTMLEditor` r=m_kato
Depends on D112506

Differential Revision: https://phabricator.services.mozilla.com/D112507
2021-04-19 23:25:46 +00:00
Masayuki Nakano 73372428c9 Bug 1705598 - part 5: Make `WSRunScanner::GetRangeInTextNodesToForwardDeleteFrom()` and `WSRunScanner::GetRangeInTextNodesToBackspaceFrom()` take editing host instead of `HTMLEditor` r=m_kato
Depends on D112505

Differential Revision: https://phabricator.services.mozilla.com/D112506
2021-04-19 23:25:46 +00:00
Masayuki Nakano dd0159dcf3 Bug 1705598 - part 4: Make `WSRunScanner::ScanNextVisibleNodeOrBlockBoundary()` and `WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary()` take editing host instead of `HTMLEditor` r=m_kato
Depends on D112504

Differential Revision: https://phabricator.services.mozilla.com/D112505
2021-04-19 23:25:46 +00:00
Masayuki Nakano 265f751419 Bug 1705598 - part 3: Make `WSRunScanner::GetPreviousEditableCharPoint()` and `WSRunScanner::GetInclusiveNextEditableCharPoint()` take editing host instead of `HTMLEditor` r=m_kato
Depends on D112503

Differential Revision: https://phabricator.services.mozilla.com/D112504
2021-04-19 23:25:45 +00:00
Masayuki Nakano a7b87b61b1 Bug 1705598 - part 2: Make the constructor of `WSRunScanner` take editing host instead of `HTMLEditor` r=m_kato
I think that it's no matter to make `WSRunScanner` work without editing host.
Therefore, this patch make it take pointer of `Element` rather than reference.

Depends on D112502

Differential Revision: https://phabricator.services.mozilla.com/D112503
2021-04-19 23:25:45 +00:00
Masayuki Nakano 9227d30f9b Bug 1705598 - part 1: Get rid of `WSRunScanner::mHTMLEditor` r=m_kato
It's not referred by anybody.

Differential Revision: https://phabricator.services.mozilla.com/D112502
2021-04-19 23:25:45 +00:00
Masayuki Nakano d8194cbbea Bug 1704381 - part 3: Add automated test r=m_kato
Depends on D111580

Differential Revision: https://phabricator.services.mozilla.com/D111581
2021-04-13 05:54:49 +00:00
Masayuki Nakano 1d08839089 Bug 1704381 - part 2: Make `AutoEditActionDataSetter` not store whether editor is destroyed after handling its edit action r=m_kato
Currently, its `mEditorWasDestroyed` is set to true even while `input` event
is being dispatched, i.e., even when it finished everything for the edit action.
However, the flag should be only for blocking unexpected cause which is caused
by mutation event listeners or something other unexpected event listeners
which shouldn't be run while editor is handling an edit action.

Therefore, this patch makes it store "handled" state which is marked before
notifying editor observers and dispatching `input` event and the flag won't
be set to true after it's marked as "handled".

Depends on D111579

Differential Revision: https://phabricator.services.mozilla.com/D111580
2021-04-13 05:54:49 +00:00
Masayuki Nakano 518cbe163b Bug 1704381 - part 1: Make `EditorBase::Init` set edit action to `EditAction::eInitializing` r=m_kato
I forgot to do this in `EditorBase::Init`. Therefore, it fails at synchronous
reinitializing during an edit action.

Differential Revision: https://phabricator.services.mozilla.com/D111579
2021-04-13 05:54:49 +00:00
Masayuki Nakano 762db8b745 Bug 1691051 - Make edit action data which is being handled manage whether the editor was temporarily destroyed or not r=m_kato
The editing session is temporarily disabled when opening a document.  Then,
when the document is closed, the editing session is restored with same
`HTMLEditor` instance.  Therefore, initializing editor may occur during
an edit action is being handled.

Probably, this must not be used in normal webapps since mutation events are
used rarely.  So, I think that for avoiding further complicated things, we
should make editor won't accept new edit action handling after original
editing session ended.

This patch renames `AutoEditActionDataSetter::CanHandle()` to
`IsDataAvailable()` since it just checks whether the important resource is
available or not.  And makes new `CanHandle()` return `false` for
non-initializing edit actions if editing session has ended.

Differential Revision: https://phabricator.services.mozilla.com/D111241
2021-04-09 06:59:54 +00:00
Masayuki Nakano 46da3502b3 Bug 1699866 - Make `HTMLEditor::SplitAncestorStyledInlineElementsAt` return "not handled" if there is no splitable element at given point r=m_kato
When given point is **in** a void element, e.g., this can be when JS inserts
nodes into a void element like `<meta>`,
`HTMLEditor::SplitNodeDeepWithTransaction` may return "not handled" state.
So, it's possible case, we shouldn't assert the case.

This patch adds both WPT and crashtests because I couldn't reproduce it
with WPT's simpler API use.

Differential Revision: https://phabricator.services.mozilla.com/D111231
2021-04-09 02:34:23 +00:00
Masayuki Nakano 74d01e2a81 Bug 1701348 - Make `TextEditor::Init()` and `HTMLEditor::Init()` stop using `EditAction::eNotEditing` r=m_kato
Currently, they set `EditAction::eNotEditing` even though they may create a
paddning `<br>` element.  If there is already handling edit action, setting
`eNotEditing` makes inherit the parent edit action.
https://searchfox.org/mozilla-central/rev/be413c29deeb86be6cdac22445e0d0b035cb9e04/editor/libeditor/EditorBase.cpp#5150-5159

However, in the reported case, `FlushPendingNotificationsIfToHandleDeletionWithFrameSelection()`
is called for computing target ranges at `forwarddelete` command handling.
In this case, `EditAction::eDeleteSelection` or something is set as parent
edit action.
https://searchfox.org/mozilla-central/rev/be413c29deeb86be6cdac22445e0d0b035cb9e04/editor/libeditor/EditorBase.cpp#3638-3660
But at this moment, `beforeinput` event hasn't been dispatched.  Then,
initializing code inherits this state and trying to insert a padding `<br>`
element without `beforeinput` event.  Then, we hit the assertion.

For solving this issue, `Init` methods should set edit action to "initializing"
and it should be marked as not requiring `beforeinput` event.

Differential Revision: https://phabricator.services.mozilla.com/D111191
2021-04-08 08:51:41 +00:00
Masayuki Nakano 0175ca9bc4 Bug 1649639 - Add WPT and remove unnecessary `MOZ_ASSERT` of `HTMLEditor::ClearStyleAt` r=m_kato
When the method detects the style coming from a parent block, the `MOZ_ASSERT`
checks whether the current mode is "style with CSS" or not because currently,
`HTMLEditor` does not use `<span>` with CSS when the mode is not "style with
CSS".  However, fixing it requires bigger patch, and the change does not match
with the bug's summary.  So, I just remove the `MOZ_ASSERT`, add WPT and filed
bug 1649639 for the root issue.

Differential Revision: https://phabricator.services.mozilla.com/D111067
2021-04-08 07:49:53 +00:00
Masayuki Nakano 4bd57eadd1 Bug 1703144 - Get rid of `MOZ_KnownLive` for `EditorBase::SelectionRefPtr()` r=m_kato
The lifetime of it is guaranteed by `AutoEditActionDataSetter` which grabs
`Selection` until it's destroyed, and it's a stack only class and created
at first step of all public method calls.  Therefore, we can mark it as
`MOZ_KNOWN_LIVE` and we can change it returning reference of `Selection`
instead of reference of `RefPtr<Selection>`.

Differential Revision: https://phabricator.services.mozilla.com/D110896
2021-04-08 01:31:54 +00:00
Masayuki Nakano e1298d770d Bug 1697876 - part 2: Make `EditorBase::EndPlaceholderTransaction()` release placeholder transaction and related stuff before dispatching `input` event r=m_kato
Currently, it dispatches `input` event with holding `mPlaceholderTransaction`
and `mPlaceholerBatch` as 1.  If `input` event listener sets value in XUL
document, the setting value transaction will break the existing placeholder
transaction.  Then, only the last one will be undone, and it causes inserting
new padding `br` element with transaction and clears redo history.

This patch makes it forget them before dispatching `input` event.

Note that I tried to create automated test for this, but I cannot reproduce
this with simple testcase.  I guess something other things also required to
reproduce this bug.

Differential Revision: https://phabricator.services.mozilla.com/D110715
2021-04-05 11:35:49 +00:00
Masayuki Nakano 119be8e287 Bug 1697876 - part 1: Add logging code to transaction classes for making easier to debug r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D110714
2021-04-05 11:35:48 +00:00
Masayuki Nakano cbb83f40f6 Bug 1655988 - Fix assertion in `WhiteSpaceVisibilityKeeper::MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange()` r=m_kato
This is a bug of the assertion.

When there is 2 text nodes are adjacent, one ends with a visible character and
the other starts with a white-space, and the deleting range ends at end of the
first one, `GetReplaceRangeDataAtEndOfDeletionRange()` returns a range starting
with the start of the second one since it does not need to touch the first one.
Therefore, the white-space range start may be after the deleting range end.

This patch adds new condition to the `MOZ_ASSERT_IF`, and test this specific
case with new `MOZ_ASSERT_IF`.

Differential Revision: https://phabricator.services.mozilla.com/D110068
2021-03-30 06:09:23 +00:00
Masayuki Nakano d68f6fc838 Bug 1220696 - part 6: Support `insertLineBreak` and `insertParagraphSeparator` commands in `<textarea>` r=smaug
Those command handlers just check whether the given editor is an `HTMLEditor`
or not.  Therefore, we should make them check whether the given editor is
a single line editor or not instead.

Differential Revision: https://phabricator.services.mozilla.com/D108572
2021-03-24 01:55:09 +00:00
Masayuki Nakano fad3ed3447 Bug 1220696 - part 5: Support "contentReadOnly" and "getHTML" commands in `<input>` and `<textarea>` r=smaug
Although these commands supported supported only by Gecko, we shouldn't stop
supporting them unless we know the usage in the wild.  Therefore, this patch
adds the handling code for `TextEditor` too.

Differential Revision: https://phabricator.services.mozilla.com/D108571
2021-03-24 01:55:09 +00:00
Masayuki Nakano f956ee81ea Bug 1220696 - part 3: Make `AutoEditorCommandTarget` consider command handling editor with command and focused `TextEditor` or `HTMLEditor` r=smaug
For making `execCommand` and related methods with `<input>` and `<textarea>`
even if they are in `contenteditable` and focused, command should be handled
in active editor (focused editor if in foreground window and tab).

However, some commands should be handled by `HTMLEditor` even if an `TextEditor`
has focus.  Therefore, this patch adds new enum class which have 3 state into
`InternalCommandData` and makes `AutoEditorCommandTarget` consider it with the
enum class.

Note that the new failures about `contentReadOnly` command will be fixed by
a following patch.

Differential Revision: https://phabricator.services.mozilla.com/D108569
2021-03-24 01:55:08 +00:00
Butkovits Atila 3361c11f7d Backed out 7 changesets (bug 1220696) for causing build bustages. CLOSED TREE
Backed out changeset 1ad2d5c0f253 (bug 1220696)
Backed out changeset 5e2f62a11d95 (bug 1220696)
Backed out changeset 07012ed7a30e (bug 1220696)
Backed out changeset a4e90de9355d (bug 1220696)
Backed out changeset 63ec6c3d05fd (bug 1220696)
Backed out changeset f165f45f8e1a (bug 1220696)
Backed out changeset ade95bf58db4 (bug 1220696)
2021-03-24 01:34:56 +02:00
Masayuki Nakano 9892a73421 Bug 1220696 - part 6: Support `insertLineBreak` and `insertParagraphSeparator` commands in `<textarea>` r=smaug
Those command handlers just check whether the given editor is an `HTMLEditor`
or not.  Therefore, we should make them check whether the given editor is
a single line editor or not instead.

Differential Revision: https://phabricator.services.mozilla.com/D108572
2021-03-23 19:29:23 +00:00
Masayuki Nakano 843cdb6b35 Bug 1220696 - part 5: Support "contentReadOnly" and "getHTML" commands in `<input>` and `<textarea>` r=smaug
Although these commands supported supported only by Gecko, we shouldn't stop
supporting them unless we know the usage in the wild.  Therefore, this patch
adds the handling code for `TextEditor` too.

Differential Revision: https://phabricator.services.mozilla.com/D108571
2021-03-23 19:29:23 +00:00
Masayuki Nakano fc94975380 Bug 1220696 - part 3: Make `AutoEditorCommandTarget` consider command handling editor with command and focused `TextEditor` or `HTMLEditor` r=smaug
For making `execCommand` and related methods with `<input>` and `<textarea>`
even if they are in `contenteditable` and focused, command should be handled
in active editor (focused editor if in foreground window and tab).

However, some commands should be handled by `HTMLEditor` even if an `TextEditor`
has focus.  Therefore, this patch adds new enum class which have 3 state into
`InternalCommandData` and makes `AutoEditorCommandTarget` consider it with the
enum class.

Note that the new failures about `contentReadOnly` command will be fixed by
a following patch.

Differential Revision: https://phabricator.services.mozilla.com/D108569
2021-03-23 19:29:22 +00:00
Jonathan Kew 0bf4eb7c5d Bug 1698734 - Don't create an EventListenerManager just to check for existing listeners. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D108612
2021-03-16 12:49:44 +00:00
Makoto Kato 605d5484aa Bug 1692052 - Don't notify IMEContext of widget when IMEStateManger doesn't manage this content. r=masayuki
This test case doesn't generate body element and isn't general case. Actually
since we don't manage current IME focus on IMEStateManager, we shouldn't notify
IMEContext of widget.

Differential Revision: https://phabricator.services.mozilla.com/D108366
2021-03-15 09:31:58 +00:00
Jonathan Kew a9143c6051 Bug 1692673 - Update tests for new Cut/Copy command-enabling behavior. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107481
2021-03-12 16:34:42 +00:00
Jonathan Kew 4fec409fa9 Bug 1692673 - Avoid enabling Cut/Copy menu commands in text editor context when there's no selection, unless a listener is present. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107480
2021-03-12 16:34:42 +00:00
Brindusan Cristian b073741c99 Backed out 3 changesets (bug 1692673) for bc failures in browser_contextmenu_input.js. CLOSED TREE
Backed out changeset 6060fa16bc3e (bug 1692673)
Backed out changeset 0f6717c26ae3 (bug 1692673)
Backed out changeset 8148b9e5dfba (bug 1692673)
2021-03-12 16:07:49 +02:00
Jonathan Kew 5eda87fe7b Bug 1692673 - Update tests for new Cut/Copy command-enabling behavior. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107481
2021-03-12 12:04:08 +00:00
Jonathan Kew 91adcd2694 Bug 1692673 - Avoid enabling Cut/Copy menu commands in text editor context when there's no selection, unless a listener is present. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107480
2021-03-12 12:04:07 +00:00
Csoregi Natalia 46c0e3eebc Backed out 2 changesets (bug 1692673) for failures on browser_contextmenu.js. CLOSED TREE
Backed out changeset dd24e610d956 (bug 1692673)
Backed out changeset b88ab8c6dd39 (bug 1692673)
2021-03-11 23:27:31 +02:00
Jonathan Kew ba5722b476 Bug 1692673 - Update tests for new Cut/Copy command-enabling behavior. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107481
2021-03-11 16:16:34 +00:00
Jonathan Kew e3ad8e8158 Bug 1692673 - Avoid enabling Cut/Copy menu commands in text editor context when there's no selection, unless a listener is present. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107480
2021-03-11 16:16:33 +00:00
Butkovits Atila 479d6f893c Backed out 2 changesets (bug 1692673) for causing build bustages on EditorBase.cpp. CLOSED TREE
Backed out changeset 988b919adc5c (bug 1692673)
Backed out changeset 5b1ba8dbfc8a (bug 1692673)
2021-03-11 12:43:24 +02:00
Jonathan Kew ba23557a7e Bug 1692673 - Update tests for new Cut/Copy command-enabling behavior. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107481
2021-03-11 10:27:04 +00:00
Jonathan Kew 24a5b45445 Bug 1692673 - Avoid enabling Cut/Copy menu commands in text editor context when there's no selection, unless a listener is present. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107480
2021-03-11 10:27:04 +00:00
Masayuki Nakano 18e444a223 Bug 1697249 - Stop creating `<span>` element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element).  Then, unlink the new link element (i.e.,
clearing the "link style").  At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.

On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.

Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded.  And then,
when preparing for inserting text, this patch makes it pass to the utility
method.

For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.

Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 07:19:33 +00:00
Jonathan Kew ceb44d34d6 Bug 1664730 - Disable async font fallback when running mochitests, to avoid unpredictable extra reflows that can disrupt event-/timing-sensitive tests. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D107284
2021-03-10 12:26:52 +00:00
Masayuki Nakano 468bffc558 Bug 1429523 - Make IMEContentObserver ignore character data change notifications of invisible data nodes r=smaug
E.g., comment node is an invisible data node, and it's not handled by
`HTMLEditor` nor `ContentEventHandler`.  Therefore, `IMEContentObserver`
should ignore invisible data nodes, which are not derived from `dom::Text`.

Differential Revision: https://phabricator.services.mozilla.com/D107590
2021-03-09 23:57:56 +00:00
Masayuki Nakano eec5dff65e Bug 1655539 - Add crash test (the bug itself is fixed by the patch for bug 1677566) r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D107589
2021-03-09 23:57:55 +00:00
Masayuki Nakano 7af10cee55 Bug 1677566 - part 3: Ignore non-deletable ranges in `HTMLEditor::HandleDeleteSelection()` r=m_kato
For making delete handlers simpler, and set better target ranges to the
corresponding `beforeinput` event, we should ignore non-editable ranges
before handling deletion.

This patch makes editor stop handling deleteion when a range crosses editing
host boundaries.  In this case, Gecko has done nothing, but fired
`beforeinput` event.  Note that Blink deletes editable contents in the range
**until** it meets first non-editable content, but I don't think this is
a good behavior because it makes things complicated.  Therefore, I filed
a spec issue: https://github.com/w3c/editing/issues/283

On the other hand, this behavior change causes different behavior in
https://searchfox.org/mozilla-central/source/editor/libeditor/crashtests/1345015.html

It tries to insert paragraph into `<html>` element, but our editor currently
does not support it.  Therefore, it hits `MOZ_ASSERT`.  Therefore, this patch
added a new check into `HTMLEditor::InsertParagraphSeparatorAsSubAction()`.

Differential Revision: https://phabricator.services.mozilla.com/D107588
2021-03-09 23:57:54 +00:00
Masayuki Nakano 1229430221 Bug 1677566 - part 2: Make `HTMLEditUtils` treat a found non-editable element as a leaf node even if it has children r=m_kato
Blink treats each non-editable node as an atomic object.  E.g., deleting or
forward-deleting from next to a non-editable element, it deletes only one
non-editable element.

Unfortunately, our layout treat adjacent non-editable nodes as a node.
Therefore, the adding WPTs do not work, but they are not new regression of
this patch.

Differential Revision: https://phabricator.services.mozilla.com/D107587
2021-03-09 23:57:54 +00:00
Masayuki Nakano e659ab60ed Bug 1677566 - part 1: `WSRunScanner::TextFragmentData` stop handling non-editable content r=m_kato
It does not make sense `WSRunScanner` handles invisible white-spaces in
non-editable elements.  Therefore, this patch makes it stop handling in the
cases.

Note that this change causes new fail of some WPTs.  That will be fixed by
the following patch.

Differential Revision: https://phabricator.services.mozilla.com/D107586
2021-03-09 23:57:54 +00:00
Emilio Cobos Álvarez 0a34cbc059 Bug 1695650 - Consider selection editable even if the anchor is the empty <br> element. r=masayuki
Otherwise we disable the context menu commands which seems bad. This also
matches the HTML editor.

Differential Revision: https://phabricator.services.mozilla.com/D107513
2021-03-09 01:32:47 +00:00
Emilio Cobos Álvarez 942ec256fe Bug 1695650 - Clean up some checks in EditorUtils. r=masayuki
No behavior change. We were already returning false for HTML editor +
non-editable so we can simplify it a bit.

Depends on D107511

Differential Revision: https://phabricator.services.mozilla.com/D107512
2021-03-09 00:24:27 +00:00
Emilio Cobos Álvarez 60aae1e6b6 Bug 1695650 - Avoid to warn always. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D107511
2021-03-09 00:24:27 +00:00
Kagami Sascha Rosylight e9a7261412 Bug 1360715 - Part 3: Remove remaining cross-context instanceof from tests r=edgar
Differential Revision: https://phabricator.services.mozilla.com/D106663
2021-03-04 22:03:58 +00:00
Brindusan Cristian b926d96be6 Backed out 3 changesets (bug 1360715) for mochitest failures at test_WebCrypto.html. CLOSED TREE
Backed out changeset b4a14c42313d (bug 1360715)
Backed out changeset 0e4b1b65fcbe (bug 1360715)
Backed out changeset fb8b9841d82b (bug 1360715)
2021-03-04 21:15:16 +02:00
Kagami Sascha Rosylight 7bec866ac5 Bug 1360715 - Part 3: Remove remaining cross-context instanceof from tests r=edgar
Differential Revision: https://phabricator.services.mozilla.com/D106663
2021-03-04 15:05:27 +00:00
Masayuki Nakano 3b20d0d64b Bug 1655508 - Add crashtest (the bug itself was fixed by bug 1517028) r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D106873
2021-03-02 06:38:38 +00:00
Masayuki Nakano 5e6dccb510 Bug 1517028 - Make `HTMLEditor::SplitNodeDeepWithTransaction` not try to split non-splittable node and `HTMLEditor::HandleInsertParagraphInHeadingElement` check its result r=m_kato
There are 2 bugs.  One is that `SplitNodeDeepWithTransaction` tries to split
comment node, but it fails.  The other is, the failure result is not checked
by `HandleInsertParagraphInHeadingElement`.  Therefore, the original head
element's previous node may not be a heading element.

Depends on D106591

Differential Revision: https://phabricator.services.mozilla.com/D106620
2021-03-02 00:51:05 +00:00
Makoto Kato b1cd4c6075 Bug 1675779 - Update browserscope for contenteditable=false case. r=masayuki
browserscope is no longer maintained, so contenteditable=false case is
incorrect now. So I would like to update this tests for non editable case.

Differential Revision: https://phabricator.services.mozilla.com/D96299
2021-02-22 10:18:49 +00:00
Makoto Kato 6d173e8282 Bug 1675779 - HandleDeleteAtomicContent should handle non-editable text node. r=masayuki
Since `WSScanResult` can return non-editable/non-removable text node,
`HandleDeleteAtomicContent` is called with non editable text node, then it cannot
remove atomic content.

This fix doesn't follow other block case such as added newer test.

Differential Revision: https://phabricator.services.mozilla.com/D96298
2021-02-22 10:18:48 +00:00
Kagami Sascha Rosylight 717d5d2aa5 Bug 1671768 - Part 4: Use MOZ_CAN_RUN_SCRIPT for Selection::RemoveAllRanges r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D103780
2021-02-03 21:52:48 +00:00
Kagami Sascha Rosylight 0ea5caf27e Bug 1671768 - Part 3: Use MOZ_CAN_RUN_SCRIPT for Selection::SelectAllChildren r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D103779
2021-02-03 21:52:22 +00:00
Masayuki Nakano ef60f67cc9 Bug 1103374 - Add simple automoated test for arrow key navigation in vertical editable content r=jfkthame
Now, we can write a test for the situation with synthesized key events.

Differential Revision: https://phabricator.services.mozilla.com/D102882
2021-02-02 03:05:01 +00:00
Masayuki Nakano a25988774a Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed.  For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification.  However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.

Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.

Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 03:29:31 +00:00
Masayuki Nakano 9b750e79a1 Bug 1685491 - part 2: Fix all new oranges caused by the previous patch r=smaug
Applying default edit action for some shortcut keys on Linux and macOS
causes some oranges.  The new failure reasons are:
* The keyboard events are consumed in the bubbling phase of the system
group if editor has focus (`EditorEventListener` or `TextInputListener`
does it).
* No key combinations are mapped to per-word move or select on macOS.
* Home/End keys on macOS do not change selection.

Therefore, this adjusts each failure case for the new behavior.

Differential Revision: https://phabricator.services.mozilla.com/D102878
2021-02-02 03:02:53 +00:00
Tom Schuster d0d823f729 Bug 1689827 - Remove length parameter from JS callers of setTransferData. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D103555
2021-02-01 12:05:12 +00:00
Emilio Cobos Álvarez b9b4fc2acc Bug 1689871 - Ensure non-native resizers are loaded in test_bug629172.html r=masayuki
The issue is that the test was depending on the native resizers (or on a
previous test having loaded the non-native ones).

The first snapshot will not have resizers (because we just started the
load of the SVG) and thus following snapshots would fail.

Wait for the load event and pre-show the ltr textarea, so that the
resizer is known loaded.

This doesn't happen without the non-native theme because that uses
native resizers which don't depend on the image load.

Differential Revision: https://phabricator.services.mozilla.com/D103591
2021-02-01 02:36:41 +00:00
Masayuki Nakano 1a7d5b3f13 Bug 1664969 - Disable async font list initialization under editor/libeditor/tests r=m_kato,jfkthame
According to the debug log and result on tryserver, the frequency of this
test failure becomes higher is caused by bug 1676966.  When global reflow
is kicked during dragging the grabber, the implicit capture is released
forcibly.  Fortunately, editor behavior shouldn't depend on font list
loading system, so, disabling the feature until fixing bug 1688430 is fine.

Differential Revision: https://phabricator.services.mozilla.com/D102889
2021-01-25 10:19:12 +00:00
Henri Sivonen e9ebba30d8 Bug 1682950 - Skip test_sanitizer_on_paste.html in headless mode. r=saschanaz
Differential Revision: https://phabricator.services.mozilla.com/D101338
2021-01-13 11:30:50 +00:00
Masayuki Nakano 8907ec27b0 Bug 1357365 - part 7: Make `TypeInState::OnSelectionChange` stop keeping link style for new inserting content after content around a link edge is deleted r=m_kato
This is same behavior as the other browsers.  When selection is collapsed to
a edge of a link after deletion, we should stop applying link style to new
inserted content.

Differential Revision: https://phabricator.services.mozilla.com/D101006
2021-01-13 01:56:05 +00:00
Masayuki Nakano 900311e687 Bug 1357365 - part 6: Make `TypeInState::OnSelectionChange()` stop keeping link style when selection is not collapsed and the range is not entirely in a link r=m_kato
When selection is not collapsed and is across link element boundary, we can
assume that user does not try to modify the link text because the other
browsers behave so.  Therefore, we should take the same behavior in this case.

Note that all the new failures of `editing/run/inserttext.html` are passed
only on Gecko.  So, it should be updated in another bug.

Differential Revision: https://phabricator.services.mozilla.com/D101005
2021-01-13 01:55:48 +00:00
Masayuki Nakano 269faceec3 Bug 1357365 - part 5: Make `TypeInState::OnSelectionChange` stop keeping link style for new inserting content when selection is changed by JS r=m_kato,edgar
This is the most important situation.  If selection is collapsed to a edge of a
link, the other browsers does not insert new content into the link.  So, from
the point of view of web developers, this cause should work exactly same as
the other browsers.

Note that the new failures in `editing/run/inserttext.html` are passed only
on Gecko.  So, the test should be updated after fixing this bug.

Differential Revision: https://phabricator.services.mozilla.com/D101004
2021-01-13 01:55:40 +00:00
Masayuki Nakano b12d5c9e83 Bug 1357365 - part 4: Make `TypeInState` stop keeping link style when selection change command is performed, but it didn't change selection r=m_kato,edgar
When caret is not moved but selection change command is fired, it means that
the caret is already set to start or end of editing host.  In this case, we
should stop keeping link style for new inserting content because otherwise,
user cannot exit from the first or last link with arrow keys.

Differential Revision: https://phabricator.services.mozilla.com/D101003
2021-01-13 01:55:32 +00:00
Masayuki Nakano 201d289381 Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.

However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.

Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style.  This helps advanced users who are familiar with keyboard navigatin
in editor.

Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.

Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too.  But a following patch will add a new
reason to notify selection listeners of caused by JS.  So, the problem
will be fixed by the following patch.

Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 01:55:29 +00:00
Masayuki Nakano 4b218fc374 Bug 1357365 - part 2: Make `TypeInState::OnSelectionChange()` stop inserting new content into the link if clicked outside it r=m_kato
When mouse button is clicked outside a link element but caret is positioned
start or end of the link, our traditional behavior keeps inserting new content
into the link.  But this is different from the other browsers, and it does
not make sense to treat such selection change is intended to keep typing in
the link element.

Therefore, this patch makes `TypeInState::OnSelectionChange()` handle
selection change reason is `mousedown` and `mouseup` cases.  However,
it cannot know whether the event was fired in the parent link element or
not.  Therefore, this patch makes `HTMLEditorEventListener` notifies
`TypeInState` of mouse events via `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D101001
2021-01-13 01:55:27 +00:00
Masayuki Nakano 0028b2127b Bug 1357365 - part 1: Rename `HTMLEditor::OnMouseDown()`, `HTMLEditor::OnMouseUp()` and `HTMLEditor::OnMouseMove()` r=m_kato
They were designed for object resizer and grabber to move absolutely positioned
element.  Therefore, they should have better name to explain what they do.
Then, we can create event listener methods for generic cases.

Differential Revision: https://phabricator.services.mozilla.com/D100999
2021-01-13 01:54:17 +00:00
Masayuki Nakano aca200577d Bug 1357365 - part 0-1: Make `test_typing_at_edge_of_anchor.html` test both on `contenteditable` and `designMode` r=m_kato
Currently, the test checks the result only in `contenteditable`, but I'd be
better to do same tests in `designMode` editor too.

Additionally, for detecting regressions of the following patches, it should
check the result of 2nd typing too because inserting text into end of a link
element may cause unlink it.

Differential Revision: https://phabricator.services.mozilla.com/D100997
2021-01-13 01:53:46 +00:00
Daniel Holbert ac4480af11 Bug 1685231: Fix the typo "ot" in various code-comments (to "to", "of", or "not"). r=mccr8
DONTBUILD because this is a comment-only change and hence doesn't affect
behavior at all.

I ran across this typo in nsPageFrame.cpp, and figured I might as well grep for
it and fix it more comprehensively. And while I'm at it, I also fixed some
neighboring instances of a duplicated word around a linebreak, in
nsXMLContentSerializer.h.

Differential Revision: https://phabricator.services.mozilla.com/D100852
2021-01-06 04:54:51 +00:00
Andi-Bogdan Postelnicu b6b336c821 Bug 1683534 - Make `editor` buildable outside of `unified-build` environment. r=sg
Differential Revision: https://phabricator.services.mozilla.com/D100206
2021-01-04 14:18:50 +00:00
Masayuki Nakano 5599ddec3c Bug 1683226 - part 3: Get rid of pathes for handling plugin from `IMEStateManager`, `IMEContentObserver` and `ContentEventHandler` r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D100102
2020-12-21 05:52:49 +00:00
Masayuki Nakano d27602eee6 Bug 1683226 - part 1: Make `IMEState::Enabled` an enum class r=m_kato,geckoview-reviewers
Before deleting `IMEState::Enabled::PLUGIN`, let's make it an enum class
for making the change safer.  Almost all of this change is done by
"replace" of VSCode.

Differential Revision: https://phabricator.services.mozilla.com/D100100
2020-12-21 05:52:03 +00:00
Emilio Cobos Álvarez 039592f4d8 Bug 1682003 - Avoid UTF-8 -> UTF-16 conversion during CSSOM serialization. r=heycam
This lifts a bunch of string conversions higher up the stack, but allows
us to make the servo code use utf-8 unconditionally, and seemed faster
in my benchmarking (see comment 0).

It should also make a bunch of attribute setters faster too (like
setting .cssText), now that we use UTF8String for them (we couldn't
because we couldn't specify different string types for the getter and
setters).

Differential Revision: https://phabricator.services.mozilla.com/D99590
2020-12-17 14:04:35 +00:00
Henri Sivonen 97959884fc Bug 1666300 test - Test SVG style sanitization on paste. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D93634
2020-11-18 17:18:56 +00:00
Emilio Cobos Álvarez b1964fa19a Bug 1682006 - Don't call Truncate() on the return string in GetPropertyValue. r=xidorn
Turns out this causes a bit of overhead when appending to an AutoString,
because Truncate() calls SetToEmptyBuffer(), which makes it go from
inline-string to buffer string, and next time we append we need to turn
the string from a buffer-based string to an inline string again, which
is some minor, but measurable, work, while profiling some
micro-benchmarks.

Probably we should make Truncate() a no-op for a zero-length string, but
I'll send that separately.

Differential Revision: https://phabricator.services.mozilla.com/D99493
2020-12-12 12:06:06 +00:00
Kagami Sascha Rosylight 8aba7414f7 Bug 1680167 - Part 6: Use RefPtr for nsFocusManager in editor r=masayuki
Depends on D98628

Differential Revision: https://phabricator.services.mozilla.com/D98629
2020-12-03 21:35:20 +00:00
Simon Giesecke dd80614fa0 Bug 1678062 - Remove unnecessary includes. r=andi
Differential Revision: https://phabricator.services.mozilla.com/D97467

Depends on D96561
2020-11-23 16:12:02 +00:00
Simon Giesecke f15895390e Bug 1673931 - Avoid including Element.h from header files.
Differential Revision: https://phabricator.services.mozilla.com/D96535

Depends on D96534
2020-11-23 16:08:40 +00:00
Simon Giesecke 071c7c035f Bug 1676356 - Avoid including PresShell.h from header files. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D96534

Depends on D95184
2020-11-23 16:08:23 +00:00
Simon Giesecke 5bfbb2a572 Bug 1673931 - Avoid including Document.h from header files. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D95046

Depends on D95045
2020-11-23 16:07:43 +00:00
Simon Giesecke 971b645fe3 Bug 1660470 - Add missing include directives/forward declarations. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D87865
2020-11-23 16:21:38 +00:00
Kagami Sascha Rosylight 7db6203754 Bug 1678361 - Return gracely when GetDataTransfer fails r=masayuki
DragEvent::GetDataTransfer() is fallible when memory allocation fails as it lazily constructs DataTransfer. This tries failing gracely when that happens.

Differential Revision: https://phabricator.services.mozilla.com/D97663
2020-11-20 06:04:43 +00:00
Mirko Brodesser 2bd707b236 Bug 1669963: factor some constants and functions for testing the clipboard out. r=ahal
They'll be used by other tests too.

Differential Revision: https://phabricator.services.mozilla.com/D97329
2020-11-17 20:28:48 +00:00
Masayuki Nakano 1edcd70cdd Bug 1676295 - Add WPT to test deleting in/around/across list items r=smaug
There are not enough tests comparing delete operation result and result of
`getTargetRanges()` when selection is in/around/across list item elements.
This patch creates a utility method to make the test body not need to use
Selection API for making simpler tests.

The expected behavior is based on Blink and WebKit unless their behavior is
buggy because their behavior is more reasonable than Gecko's in most cases.

Note that the removing tests are covered by the new tests.

Differential Revision: https://phabricator.services.mozilla.com/D96800
2020-11-14 10:30:31 +00:00
Masayuki Nakano 00b602a0f0 Bug 1627673 - Do null-check the result of `DragEvent::GetDataTransfer()` in `EditorEventListener`` r=smaug
I guess that `DataTransfer::HasType()` is inlined in the opt builds and
actually crashed in `EditorEventListener::DragEventHasSupportingData()`
at accessing `aDragEvent->GetDataTransfer()` result without null-check
because `DataTransfer::mItems` is set to `nullptr` only by the cycle
collector, but it does not make sense to think that it occurs the STR
in bug 1627673 comment 3.

Therefore, this patch adds null-checks in
`EditorEventListener::DragEventHasSupportingData()`.

I have no idea how to test this with automated tests.

Differential Revision: https://phabricator.services.mozilla.com/D96310
2020-11-09 23:39:10 +00:00
Masayuki Nakano c6d7f7e4f8 Bug 1605741 - Make all callers of `HTMLEditor::InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary()` check whether there is a caret or not r=m_kato
`InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary()` checks whether
a line containing `aPointToInsert` requires invisible `<br>` element.
Therefore, `aPointToInsert` must be set and valid.  However, all selection
ranges may be removed by somebody when modifying the DOM tree before that.

Therefore, this patch makes all callers of it check whether they succeeded
to retrieve caret position or not.

Differential Revision: https://phabricator.services.mozilla.com/D96280
2020-11-09 03:01:16 +00:00
Masayuki Nakano 6109e35d9e Bug 1579934 - Make `WhiteSpaceVisibilityKeeper::MergeFirstLineOf*()` stop handling their job if calling `DeleteInvisibleASCIIWhiteSpace()` makes the descendant block position changed r=m_kato
They join first line of a descendant block element into the line at the other
block contains the descendant block.  First of all of their jobs, they call
`DeleteInvisibleASCIIWhiteSpace()` to clean up unnecessary whitespaces at
the other block.  At this time, the point which tells whether the descendant
element is contained in the other block may become invalid if script runs
and it causes changing the DOM tree.  Therefore, they should check the
given point is still valid after calling `DeleteInvisibleASCIIWhiteSpace()`
because `AutoTrackDOMPoint` requires valid point.

Differential Revision: https://phabricator.services.mozilla.com/D95987
2020-11-06 06:38:49 +00:00
Masayuki Nakano 994715338f Bug 1578916 - Add reported testcase to crashtests (the crash was fixed by bug 1627175) r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D95983
2020-11-06 04:07:28 +00:00
Andrew Halberstadt 331bc892dd Bug 1675319 - [manifestparser] Properly support multiline skip-if statements, r=jmaher,extension-reviewers,zombie
This supports one manifestparser expression per line in the 'skip-if',
'fail-if' and 'run-if' keys. As a side effect the:

    skip-if = foo ||
        bar

syntax is no longer supported. Instead it can be:

    skip-if =
        foo  # bug 123
        bar  # bug 456

Differential Revision: https://phabricator.services.mozilla.com/D95927
2020-11-05 19:55:08 +00:00
tobar2018 eb66350c76 Bug 1674609 - HTMLEditorDeleteHandler.cpp: redundant continue statement at the end of loop statement. r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D95669
2020-11-03 22:58:01 +00:00
Masayuki Nakano ec06061862 Bug 1581246 - Add reported testcase as a crashtest (the crash was fixed by bug 1666556) r=m_kato
This does not require recursive call of `execCommand` so that this does not
set the pref.

Depends on D95268

Differential Revision: https://phabricator.services.mozilla.com/D95269
2020-10-30 12:03:59 +00:00
Masayuki Nakano 10b3906382 Bug 1666556 - Make `HTMLEditor` stop accepting focus event when a text control which is an editing host gets focus r=m_kato
`HTMLEditor` ignores input events when a text control element in an editing
host has focus.
https://searchfox.org/mozilla-central/rev/d866b96d74ec2a63f09ee418f048d23f4fd379a2/editor/libeditor/HTMLEditor.cpp#6322

However, focus event does not check it and modifies ancestor limiter of
`Selection` for the document.  And even in this case, public methods for
handling some edit actions are open for `execCommand` requests.  Then,
edit action handlers may set selection outside the elements, but new focus
event to update the selection ancestor limiter will be handled later.
Therefore, until getting next focus event, `HTMLEditor` does not work as
expected since `Selection::*InLimiter()` APIs refuse to change selection.

Ideally, we should make `nsFocusManager` notifies editor of focus change
synchronously, but I cannot fix it quickly because it needs to touch security
sensitive area.  Therefore, this patch makes `HTMLEditor` do not set
ancestor limiter when a text control in any editing host gets focus.

Additionally, this patch makes
`HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::HandleDeleteAtOtherBlockBoundary`
stop handling leaf node deletion if it cannot change caret position.

Differential Revision: https://phabricator.services.mozilla.com/D95268
2020-10-30 13:45:48 +00:00
Masayuki Nakano 1fe9274aa4 Bug 1663725 - Add reported test as a crashtest (the crash bug itself was fixed by bug 1663601) r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D95127
2020-10-30 04:18:36 +00:00
Masayuki Nakano 9b606cfb10 Bug 1624005 - Make `WSScanResult` have error state and make the scan methods of `WSRunScanner` use it when it fails to initialize `TextFragmentData` r=m_kato
The test runs `execCommand("insertHorizontalRule")` when the document node
has no children.  In this case, `TextFragmentData` fails to initialize itself.
In this case, our editor cannot do anything.  Therefore, returning error
in this case must be better.

This patch makes all callers of the scan methods handle the error case unless
the caller cannot return error.

Comparing with Blink, perhaps, we should insert `<html>` and `<body>` element
in this case first and keep doing the requested operation in the future.
Currently, doing it may cause another complicated issue with mutation event
listeners.

Differential Revision: https://phabricator.services.mozilla.com/D95126
2020-10-30 07:33:39 +00:00
Masayuki Nakano e58b93b3d9 Bug 1613521 - Make `NeedsToDispatchBeforeInputEvent()` return false if the edit action requires a clipboard event and it's not dispatched yet r=m_kato
The reason of hitting the assertion is, a clipboard event listener nests
another edit action, initializing the editor, runs, and tries to create an
anonymous `<br>` element with transaction, but it checks whether `beforeinput`
event has already been dispatched or not with the parent edit action data.

For fixing it, this patch adds a flag to edit action data to indicate whether
a clipboard event has already been dispatched or not.  If it's already been
dispatched, it's **okay** to modify the DOM tree.  Ideally, we should put off
modifying the DOM tree after dispatching `beforeinput` event, but this case
does not notify web apps anything so that this patch should be fine.

Although this patch adds a crash test which is attached by the reporter,
it's not reproducible with current editor code because we stopped modifying
native anonymous nodes with transaction, but it depends on the behavior.
Still this assertion hits in `test_clipboard_noeditor.html` intermittently,
but I don't have idea how to reproduce this permanently.  Therefore, this
patch does not contain a test to check to regression actually.

Differential Revision: https://phabricator.services.mozilla.com/D95115
2020-10-30 07:21:40 +00:00
Makoto Kato 85f53704b2 Bug 1673816 - DeleteNodeWithTransaction should allow non-editable node which parent is editable. r=masayuki
Actually, `DeleteNodeWithTransaction` cannot remove non-editable node. But
we should allow it which parent node is ediatble.

Differential Revision: https://phabricator.services.mozilla.com/D94937
2020-10-30 01:38:41 +00:00
Masayuki Nakano 9d40c25ea2 Bug 1673790 - Split `editor/libeditor/HTMLEditSubActionHandler.cpp` r=m_kato
It's too big (+15k lines) and there are 2 groups which does not depend on the
others.  One is getting current state for `Document.queryCommandState` etc.
This is copied to `HTMLEditorState.cpp`.  And the other is delete handlers.
This is copied to `HTMLEditorDeleteHandler.cpp`.

Differential Revision: https://phabricator.services.mozilla.com/D94934
2020-10-28 13:08:34 +00:00
Masayuki Nakano 21fd55f3a4 Bug 1663793 - part 7: Make `runTest()` automatically handle editor value check in the case canceling `beforeinput` r=m_kato
When `beforeinput` event is canceled, the editor content shouldn't be modified.
Therefore, `runTest()` can handle it with caching initial value before
running the test body.

Additionally, this patch makes every test ensure that target editor has focus.
So, finally, each test is now isolated completely.  Developers can run only
a test with commenting out the other tests.

Depends on D94520

Differential Revision: https://phabricator.services.mozilla.com/D94521
2020-10-27 09:10:05 +00:00
Masayuki Nakano 58a805938e Bug 1663793 - part 6: Encapsulate all variables interacting with event listeners into a function r=m_kato
This patch makes all test functions call `runTest()` and it adds event listeners
only while running the function.  Therefore, this makes each test function do:
* initializing for running test
* running test with `runTest` and specifying expected data

Depends on D94519

Differential Revision: https://phabricator.services.mozilla.com/D94520
2020-10-27 08:08:51 +00:00
Masayuki Nakano 4302a60fd8 Bug 1663793 - part 5: Create a common method to check editor content, beforeinput event and input event r=m_kato
Depends on D94518

Differential Revision: https://phabricator.services.mozilla.com/D94519
2020-10-27 04:34:36 +00:00
Masayuki Nakano b6a756a7b5 Bug 1663793 - part 4: Make all test functions take an object for consistency r=m_kato
This allows the following patches will make all functions use batch function
to test with a framework.

Depends on D94517

Differential Revision: https://phabricator.services.mozilla.com/D94518
2020-10-27 03:49:42 +00:00
Masayuki Nakano 8b035a3c62 Bug 1663793 - part 3: Use same function to check canceling "beforeinput" and not canceling it r=m_kato
So, this removes functions named as `*_and_canceling_beforeinput` and
makes corresponding function take an object which has `action` and
`cancelBeforeInput` to reduce dependency on wider scope variables.

Depends on D94516

Differential Revision: https://phabricator.services.mozilla.com/D94517
2020-10-27 01:48:34 +00:00
Masayuki Nakano 50d3d995a4 Bug 1663793 - part 2: Split each chunk into IIFE r=m_kato
Although, still there are dependencies between the functions, this allows
stack has meaningful name where a failure occurs.

Depends on D94515

Differential Revision: https://phabricator.services.mozilla.com/D94516
2020-10-26 13:01:36 +00:00
Masayuki Nakano 3cd4b0ed5d Bug 1663793 - part 1: Make sure description of `ok()`, `is()`, etc. have its own line r=m_kato
Indent level of the tests will be increased.  Therefore, all descriptions
should be in their own lines.

Note that this and following patches rewrite almost all lines in the test
files again and again.  Therefore, it's hard to rebase and existing bugs
will be fixed when I was writing each patch.  So, I'd like reviewers just
put inline comment which should be fixed before landing.  Then, I'll add
a patch to fix them.

Differential Revision: https://phabricator.services.mozilla.com/D94515
2020-10-26 09:11:41 +00:00
Masayuki Nakano 03ae5e76db Bug 1669479 - part 2: Make `HTMLEditor::ComputeTargetRanges()` handle table cell selection mode with new utilities r=m_kato
So, the root cause of this assertion hit was, I forgot to add this path
when I implement the methods to compute target ranges.  Although the other
browsers don't support multiple selection ranges, this patch adds WPTs
for the cases.

Depends on D94241

Differential Revision: https://phabricator.services.mozilla.com/D94242
2020-10-26 09:10:29 +00:00
Masayuki Nakano 7f22e0e96a Bug 1671556 - part 14: Get rid of `HTMLEditor::GetFirstSelectedTableCellElement()`, `HTMLEditor::GetNextSelectedTableCellElement()` and `HTMLEditor::mSelectedCellIndex` r=m_kato
Depends on D94240

Differential Revision: https://phabricator.services.mozilla.com/D94241
2020-10-26 05:53:58 +00:00
Ricky Stewart 02a7b4ebdf Bug 1654103: Standardize on Black for Python code in `mozilla-central`.
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat.

5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-26 18:34:53 +00:00
Masayuki Nakano 632bea14d4 Bug 1671556 - part 13: Make `HTMLEditor::GetFirstSelectedCellInTable()` stop using `CellAndIndexes` which uses `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
The method is tested by `test_nsITableEditor_getFirstSelectedCellInTable.html`.

And now, nobody uses `CellAndIndexes` so that this patch removes it.

Depends on D94239

Differential Revision: https://phabricator.services.mozilla.com/D94240
2020-10-26 05:53:26 +00:00
Masayuki Nakano 624be44b8c Bug 1671556 - part 12: Make `HTMLEditor::GetSelectedOrParentTableElement()` stop using `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_getSelectedOrParentTableElement.html`.

Depends on D94238

Differential Revision: https://phabricator.services.mozilla.com/D94239
2020-10-26 05:24:12 +00:00
Masayuki Nakano 8a7dfed0fd Bug 1671556 - part 11: Make `HTMLEditor::GetSelectedCellsType()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Depends on D94236

Differential Revision: https://phabricator.services.mozilla.com/D94238
2020-10-26 05:06:59 +00:00
Masayuki Nakano 7a6b5b722c Bug 1671556 - part 10: Make `HTMLEditor::JoinTableCells()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Unfortunately, there is no automated tests for `nsITableEditor.joinTableCells()`
and it'll take a couple of days to write its testcase because of too big
method.  And it's not so important for Firefox (although it's used in
comm-central).  Therefore, this patch skips to check it.

Note that `CellAndIndexes` uses `HTMLEditor::GetFirstSelectedTableCellElement()`
to retrieve first selected cell element and then, it retrieves its indexes.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#4090,4098,4109
Therefore, this patch makes it stop using this simple structure too.

Depends on D94235

Differential Revision: https://phabricator.services.mozilla.com/D94236
2020-10-26 05:04:51 +00:00
Edgar Chen 0c7b507968 Bug 1653457 - Enable editor/libeditor/tests/test_bug1151186.html on fission and cross-origin; r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D94677
2020-10-24 23:25:27 +00:00
Masayuki Nakano 379413947b Bug 1671556 - part 9: Make `HTMLEditor::DeleteSelectedTableRowsWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_deleteTableRow.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94235
2020-10-24 04:14:03 +00:00
Masayuki Nakano c159d456cd Bug 1671556 - part 8: Make `HTMLEditor::DeleteSelectedTableColumnWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_deleteTableColumn.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94234
2020-10-24 04:13:55 +00:00
Masayuki Nakano c3e66c2cd1 Bug 1671556 - part 7: Make `HTMLEditor::DeleteTableCellContentsWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_deleteTableCellContents.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94233
2020-10-24 04:13:43 +00:00
Masayuki Nakano b757a23d31 Bug 1671556 - part 6: Make `HTMLEditor::DeleteTableCellWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This method is tested by `test_nsITableEditor_deleteTableCell.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94232
2020-10-24 04:13:30 +00:00
Masayuki Nakano d8a219bbef Bug 1671556 - part 5: Make `HTMLEditor::HandleDeleteSelection()` stop using `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D94231
2020-10-24 04:13:17 +00:00
Masayuki Nakano 055932a8ee Bug 1671556 - part 4: Make `HTMLEditor::HTMLWithContextInserter::Run()` stop using `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
Although it's not tested yet, but I have no idea how to test it.
https://coverage.moz.tools/#revision=latest&path=editor%2Flibeditor%2FHTMLEditorDataTransfer.cpp&view=file&line=545

Differential Revision: https://phabricator.services.mozilla.com/D94230
2020-10-24 04:13:04 +00:00
Masayuki Nakano 8165ffcad7 Bug 1671556 - part 3: Make `HTMLEditor::SetHTMLBackgroundColorWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D94229
2020-10-24 04:12:51 +00:00
Masayuki Nakano d57d81d139 Bug 1671556 - part 2: Replace `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` with `nsITableEditor.getSelectedCells()` r=m_kato
`nsITableEditor.getFirstSelectedCell()` and
`nsITableEditor.getNextSelectedCell()` use `HTMLEditor::mSelectedCellIndex`
via their internal methods.  That makes these API unstable if mutation happens
between the calls.  Therefore, it's really simpler and stabler that there is
an API to return selected table cell elements once.

Therefore this patch creates new API, `nsITableEditor.getSelectedCells()`,
which returns array of selected table cell elements.  And it stops taking
inconsistent behavior of the old API:
1. Even if there is no selection. it does not throw an exception.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#3956-3961
2. Even if it meets selection range in a text node (i.e.,
`nsRange::GetChildAtStartOffset()` returns `nullptr`), this just ignores the
range.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#4041-4047

The following patches will remove their internal methods too.

Differential Revision: https://phabricator.services.mozilla.com/D94228
2020-10-24 04:12:38 +00:00
Masayuki Nakano f450442d99 Bug 1671556 - part 1: Make `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` stop returning selected range with out argument r=m_kato
These APIs are used only in comm-central (not in BlueGriffon) and nobody
refers the out argument which is selected range of the cell selection.
Therefore, we should drop them to make the APIs simpler.

Differential Revision: https://phabricator.services.mozilla.com/D94226
2020-10-24 04:12:15 +00:00
Masayuki Nakano 4482ff7eab Bug 1669479 - part 1: Make `WSRunScanner::TextFragmentData::GetNonCollapsedRangeInTexts()` stop searching text node when given range is collapsed r=m_kato
This is a simple mistake.  If the given range is collapsed, scanning text node
to before/after from collapsed range may create reversed range.

Differential Revision: https://phabricator.services.mozilla.com/D94225
2020-10-24 04:11:56 +00:00
Bogdan Tara da1098d4aa Backed out 10 changesets (bug 1654103, bug 1672023, bug 1518999) for PanZoomControllerTest.touchEventForResult gv-junit failures CLOSED TREE
Backed out changeset ff3fb0b4a512 (bug 1672023)
Backed out changeset e7834b600201 (bug 1654103)
Backed out changeset 807893ca8069 (bug 1518999)
Backed out changeset 13e6b92440e9 (bug 1518999)
Backed out changeset 8b2ac5a6c98a (bug 1518999)
Backed out changeset 575748295752 (bug 1518999)
Backed out changeset 65f07ce7b39b (bug 1518999)
Backed out changeset 4bb80556158d (bug 1518999)
Backed out changeset 8ac8461d7bd7 (bug 1518999)
Backed out changeset e8ba13ee17f5 (bug 1518999)
2020-10-24 03:36:18 +03:00
Ricky Stewart c0cea3b0fa Bug 1654103: Standardize on Black for Python code in `mozilla-central`. r=remote-protocol-reviewers,marionette-reviewers,webdriver-reviewers,perftest-reviewers,devtools-backward-compat-reviewers,jgilbert,preferences-reviewers,sylvestre,maja_zf,webcompat-reviewers,denschub,ntim,whimboo,sparky
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat.

5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-23 20:40:42 +00:00
Henri Sivonen 4362f51641 Bug 1666300 part 2 - Parse into an inert document. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D93478
2020-10-23 12:48:52 +00:00
Mihai Alexandru Michis f0df85d472 Backed out 4 changesets (bug 1671556, bug 1669479) for causing bustages in HTMLEditUtils.h
CLOSED TREE

Backed out changeset 17405d242d1b (bug 1671556)
Backed out changeset fe3735c5aac9 (bug 1671556)
Backed out changeset 585df60d18f9 (bug 1671556)
Backed out changeset e94d989b8cb4 (bug 1669479)
2020-10-23 15:10:04 +03:00
Masayuki Nakano e3ee32aed5 Bug 1671556 - part 3: Make `HTMLEditor::SetHTMLBackgroundColorWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D94229
2020-10-23 10:51:20 +00:00
Masayuki Nakano d115dc42a4 Bug 1671556 - part 2: Replace `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` with `nsITableEditor.getSelectedCells()` r=m_kato
`nsITableEditor.getFirstSelectedCell()` and
`nsITableEditor.getNextSelectedCell()` use `HTMLEditor::mSelectedCellIndex`
via their internal methods.  That makes these API unstable if mutation happens
between the calls.  Therefore, it's really simpler and stabler that there is
an API to return selected table cell elements once.

Therefore this patch creates new API, `nsITableEditor.getSelectedCells()`,
which returns array of selected table cell elements.  And it stops taking
inconsistent behavior of the old API:
1. Even if there is no selection. it does not throw an exception.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#3956-3961
2. Even if it meets selection range in a text node (i.e.,
`nsRange::GetChildAtStartOffset()` returns `nullptr`), this just ignores the
range.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#4041-4047

The following patches will remove their internal methods too.

Differential Revision: https://phabricator.services.mozilla.com/D94228
2020-10-23 10:51:13 +00:00
Masayuki Nakano 0b038d0a0b Bug 1671556 - part 1: Make `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` stop returning selected range with out argument r=m_kato
These APIs are used only in comm-central (not in BlueGriffon) and nobody
refers the out argument which is selected range of the cell selection.
Therefore, we should drop them to make the APIs simpler.

Differential Revision: https://phabricator.services.mozilla.com/D94226
2020-10-23 10:51:08 +00:00
Masayuki Nakano fdd3d5b1af Bug 1669479 - part 1: Make `WSRunScanner::TextFragmentData::GetNonCollapsedRangeInTexts()` stop searching text node when given range is collapsed r=m_kato
This is a simple mistake.  If the given range is collapsed, scanning text node
to before/after from collapsed range may create reversed range.

Differential Revision: https://phabricator.services.mozilla.com/D94225
2020-10-23 10:51:05 +00:00
Razvan Maries b4044e05f9 Backed out 3 changesets (bug 1666300, bug 1667113) for perma failures on browser_parsable_css.js. CLOSED TREE
Backed out changeset 29c5257d0a06 (bug 1667113)
Backed out changeset 0f0fc78ad521 (bug 1666300)
Backed out changeset 9b0c50269ef7 (bug 1666300)
2020-10-22 14:04:15 +03:00
Henri Sivonen 8439bf4064 Bug 1666300 part 2 - Parse into an inert document. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D93478
2020-10-19 13:42:31 +00:00
Dorel Luca 1ff59cb7a3 Backed out changeset 7558c8821a07 (bug 1654103) for multiple failures. CLOSED TREE 2020-10-22 03:51:06 +03:00
Ricky Stewart 50762dacab Bug 1654103: Standardize on Black for Python code in `mozilla-central`. r=remote-protocol-reviewers,marionette-reviewers,webdriver-reviewers,perftest-reviewers,devtools-backward-compat-reviewers,jgilbert,preferences-reviewers,sylvestre,maja_zf,webcompat-reviewers,denschub,ntim,whimboo,sparky
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-21 21:27:27 +00:00
Masayuki Nakano 04027a5656 Bug 1607131 - Make `beforeinput` event for `MozEditableElement.setUserInput()` not cancelable by default r=smaug
Blink and WebKit do not fire `beforeinput` event when user uses build-in
password manager and autocomplete.  But the `inputType` value for this case,
`"insertReplacementText"` is defined as cancelable in the spec, and it's
actually cancelable when it's fired for correcting a word with built-in
spellchecker of them.

For making only our users' autocomplete and password manager not blocked by
web apps, we should make them not cancelable by default, but I think that we
should keep dispatching such non-cancelable `beforeinput` for conforming to
the standard unless we'd get a web-compat report for this.

Differential Revision: https://phabricator.services.mozilla.com/D93206
2020-10-20 00:13:43 +00:00
Kagami Sascha Rosylight 2c5fb988f2 Bug 1615296 - Part 2: Fix MOZ_CAN_RUN_SCRIPT warnings in editor module r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D93599
2020-10-15 19:12:44 +00:00
Masayuki Nakano 049c973fbf Bug 1671197 - Make `HTMLEditor::SelectAllInternal()` select all children of `<body>` element if computed selection root is an ancestor of the `<body>` element r=m_kato
In strictly speaking, we should shrink selection ranges at very first time
of edit action handling.  However, we support multiple selection ranges and
it makes the check cost really expensive, and the code would be really
complicated since ranges cannot be overlapped.  I.e., changing one range
could affect some of the others.

Therefore, this patch changes `HTMLEditor::SelectAllInternal()` instead.
If computed selection root is an ancestor of `<body>` element in HTML document,
it use the `<body>` element instead.

Note that, in HTML document, there should be only one `<body>` element and
only its content should be editable at least for now.  (Note that in XHTML
document, no `<body>` is allowed, multiple `<body>` elements allowed.)

Differential Revision: https://phabricator.services.mozilla.com/D93712
2020-10-16 09:38:56 +00:00
Masayuki Nakano 053daa2052 Bug 1627924 - Make `HTMLEditor::HideGrabberInternal()` reset dragging state r=emilio
When the grabber to move absolutely positioned element is disabled,
`HTMLEditor::HideGrabberInternal()` is called to delete it.  However,
it does not reset dragging state.  Therefore, `mousemove` event listener
will try to handle drag even after the grabber is removed.

This patch makes `HideGrabberInternal()` reset the dragging state to
make the event listener stop handling the drag action.

However, I hit a buggy assertion in `EventStateManager`.  It tries to
set active state to parent of the grabber (in this case, absolutely positioned
element).  However, editable element in `contenteditable` cannot have
active state.  Therefore, `leaf` becomes `nullptr`, but `newleaf` is the
absolutely positioned element.  Therefore, this patch adds this condition
into the `MOZ_ASSERT`.

Differential Revision: https://phabricator.services.mozilla.com/D93632
2020-10-16 02:34:15 +00:00
Magnus Melin 53d4e1215b Bug 1649005 - fix crash when rewrapping an empty message via mozilla::HTMLEditor::InsertTextWithQuotationsInternal. r=masayuki
If empty input, aStringToInsert.First() will crash at https://searchfox.org/mozilla-central/rev/c2e3ac11be4837718c2604e58085fbc8252b69dd/xpcom/string/nsTSubstring.cpp#968

Needed to adjust whether rewrap needs beforeinput handling:
NeedsBeforeInputEventHandling would return false, because rewrap was set not to need that
https://searchfox.org/mozilla-central/rev/803b368879fa332e8e2c1840bf1ec164f7ed2c32/editor/libeditor/EditorBase.h#1152
.. so EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent would assert

rewrap also needs to be allowed for MayEditActionDeleteSelection (not to assert)

Differential Revision: https://phabricator.services.mozilla.com/D93167
2020-10-14 12:55:00 +00:00
Razvan Maries 5d8ff793a4 Backed out changeset c7cca3c4602b (bug 1649005) for perma failures on EditorBase.cpp. CLOSED TREE 2020-10-12 14:55:29 +03:00
Magnus Melin 336b9a62fd Bug 1649005 - fix crash when rewrapping an empty message via mozilla::HTMLEditor::InsertTextWithQuotationsInternal. r=masayuki
If empty input, aStringToInsert.First() will crash at https://searchfox.org/mozilla-central/rev/c2e3ac11be4837718c2604e58085fbc8252b69dd/xpcom/string/nsTSubstring.cpp#968

Differential Revision: https://phabricator.services.mozilla.com/D93167
2020-10-12 11:11:55 +00:00
Masayuki Nakano 498c3f96b9 Bug 1668134 - part 3: Add telemetry probes to collect how percentage of `HTMLEditor` is or is not handled with `beforeinput` event listeners r=smaug data-review=tdsmith
Unfortunately, there is no official way to detect whether browser supports
or not `beforeinput` event in the wild because Chromium does not support
`onbeforeinput` event handler attribute.  On the other hand, we're the
last browser vendor which does not support `beforeinput` event, and we
make `InputEvent.getTargetRanges()` enabled only when `beforeinput` event
because it returns meaningful value only when the event type is `beforeinput`.
So, web apps can detect `beforeinput` event support with checking type of
or existence of it instead.  However, in our experience, it's guessed what
a lot of web apps check whether "Firefox" or not to consider whether it
can use `beforeinput` events.  If so, we need to announce shipping
`beforeinput` event and the way to feature detection before actually shipping
it.  Otherwise, we wouldn't get enough feedback from testers.

First of all for shipping `beforeinput` events, we should collect how much
web apps which use `HTMLEditor` use `beforeinput` event when it's enabled,
and how much web apps use mutation events or mutation observer instead of
`beforeinput` events even when it's enabled.

Honestly, I'd like to collect URLs which don't use `beforeinput` event, but
use mutation events or mutation observer.  But it's really sensitive data
so that I believe that we shouldn't collect it.

Differential Revision: https://phabricator.services.mozilla.com/D92548
2020-10-09 23:54:19 +00:00
Masayuki Nakano 0f46ae6a8e Bug 1668134 - part 2: Make `nsPIDOMWindowInner` have an API to know whether a node is (was) in the window has been observed by web apps with a mutation observer r=smaug
There is similar API in `Document`, but they indicate whether a node has been
observed by any mutation receiver, not only by `MutationObserver` of JS.
However, I'd like to know the percentage of web apps which use
`MutationObserver`, but not use `beforeinput` events.  Therefore, this patch
adds similar API into `nsPIDOMWindowInner` as same as `beforeinput` and
ignores `MutationObserver`s which are created by chrome script and addons.

Differential Revision: https://phabricator.services.mozilla.com/D92547
2020-10-08 02:25:35 +00:00
Masayuki Nakano 8c5fa85517 Bug 1668134 - part 1: Make `nsPIDOMWindowInner` have an API to know whether the window or its descendants has had `beforeinput` event listeners r=smaug
When `HTMLEditor` instances are destroyed, I'd like to collect how much
instances are worked with `beforeinput` event listeners.  Before adding such
telemetry probe, this patch adds methods to set/get whether a `beforeinput`
event listener has had added or not to `nsPIDOMWindowInner`.

Differential Revision: https://phabricator.services.mozilla.com/D92546
2020-10-08 02:25:35 +00:00
Masayuki Nakano 2fde14a338 Bug 1623918 - part 2: Mark `nsINode::GetSelectionRootContent()` and its root callers as `MOZ_CAN_RUN_SCRIPT` as far as possible r=smaug
This patch tries to mark root callers of `nsINode::GetSelectionRootContent()`
which calls `nsINode::GetAnonymousRootElementOfTextEditor()` as far as possible
(and reasonable).

It's used by `ContentEventHandler` so that a lot of methods of
`EventStateManager`, `ContentEventHandler`, `IMEContentObserver` which are main
users of it are also marked as `MOZ_CAN_RUN_SCRIPT`.  I think that this is
reasonable.

On the other hand, it might not be reasonable to mark `IMEStateManager` methods
as `MOZ_CAN_RUN_SCRIPT` for initializing `IMEContentObserver` because
`IMEStateManager` may be able to initialize `IMEContentObserver` asynchronously
and its root callers are in XUL layout code.  Therefore, this patch uses
`MOZ_CAN_RUN_SCRIPT_BOUNDARY` for `IMEStateManager` at least for now.

Differential Revision: https://phabricator.services.mozilla.com/D92730
2020-10-09 02:37:47 +00:00
Mirko Brodesser 6ef121943b Bug 1639972: don't insert a node in `InsertNodeIntoProperAncestorWithTransaction` when there's no proper ancestor. r=masayuki
The previous behavior was added in bug 858918. However, it was wrong
when trying to insert a `<tr>` into a `<div contenteditable>`.

After this change, the test in bug 858918 still passes, so that specific
functionality doesn't break. However, the code is complex and one can't
exclude that other functionality breaks. The previous fix already
mentioned the same concern
https://bugzilla.mozilla.org/show_bug.cgi?id=858918#c25.

With this change,
https://searchfox.org/mozilla-central/rev/35245411b9e8a911fe3f5adb0632c3394f8b4ccb/editor/libeditor/HTMLEditorDataTransfer.cpp#938
doesn't insert the `<tr>`, but climbs up the `<tr>`'s ancestors, so that
a `<table>` is inserted. When `designMode = "on"`, this was already
previously the case.

The new code seems more correct, including pasting tables to
`contenteditable` elements working now. Therefore, it seems worth
submitting this patch, despite being unable to exclude regressions by
pure reasoning.

Differential Revision: https://phabricator.services.mozilla.com/D92590
2020-10-08 14:44:44 +00:00
Narcis Beleuzu c163b394ef Backed out 2 changesets (bug 1623918) for crashtest failure on 1623918.html CLOSED TREE
Backed out changeset 519ca1b069e5 (bug 1623918)
Backed out changeset d8a09a5fea47 (bug 1623918)
2020-10-08 12:06:58 +03:00
Masayuki Nakano da386ef224 Bug 1623918 - part 2: Mark `nsINode::GetSelectionRootContent()` and its root callers as `MOZ_CAN_RUN_SCRIPT` as far as possible r=smaug
This patch tries to mark root callers of `nsINode::GetSelectionRootContent()`
which calls `nsINode::GetAnonymousRootElementOfTextEditor()` as far as possible
(and reasonable).

It's used by `ContentEventHandler` so that a lot of methods of
`EventStateManager`, `ContentEventHandler`, `IMEContentObserver` which are main
users of it are also marked as `MOZ_CAN_RUN_SCRIPT`.  I think that this is
reasonable.

On the other hand, it might not be reasonable to mark `IMEStateManager` methods
as `MOZ_CAN_RUN_SCRIPT` for initializing `IMEContentObserver` because
`IMEStateManager` may be able to initialize `IMEContentObserver` asynchronously
and its root callers are in XUL layout code.  Therefore, this patch uses
`MOZ_CAN_RUN_SCRIPT_BOUNDARY` for `IMEStateManager` at least for now.

Differential Revision: https://phabricator.services.mozilla.com/D92730
2020-10-08 03:56:51 +00:00
Simon Giesecke 59dd6d410d Bug 1668757 - Fix lifetime extension issues with 0-length literals. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D92179
2020-10-06 15:03:01 +00:00
Masayuki Nakano ec2e1c9705 Bug 1669133 - Get rid of pref to disable `text` event in the default group and telemetry for it r=smaug
The telemetry probe was added in bug 1506434, and it's not necessary anymore
because of the event in the default group was completely disabled in
bug 1288640 (Gecko 65).

Therefore, we can get rid of the pref, and we can take back a room for a
bool member in `nsPIDOMWindowInner` for new telemetry probes which need
to know whether a specific event listener has been added or not.

Depends on D92395

Differential Revision: https://phabricator.services.mozilla.com/D92397
2020-10-05 11:17:17 +00:00
Timothy Nikkel 223e9bb630 Bug 1667612. Factor waitToClearOutAnyPotentialScrolls out from various tests and put it in apz_test_utils.js. r=kats
Differential Revision: https://phabricator.services.mozilla.com/D92318
2020-10-03 15:58:16 +00:00
Masayuki Nakano 49a0527874 Bug 1609291 - Make `AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent()` stop returning error when there is no proper event target of `beforeinput` event r=smaug
`editor/libeditor/tests/test_bug974309.html` and
`editor/libeditor/tests/test_bug1268736.html` start to throw exception if
`beforeinput` event is enabled.  They test XPCOM editor API when a non-editable
element has focus and it's outside of any editing hosts.  In this case,
we shouldn't throw an exception for backward compatibility.  Although the
all callers should stop handling any edit action in this case, let's make
`MaybeDispatchBeforeInputEvent()` return a special success code instead of
an error code for making all callers keep working with traditional paths.

Differential Revision: https://phabricator.services.mozilla.com/D91864
2020-10-01 09:15:19 +00:00
Masayuki Nakano ad49c80971 Bug 1609291 - Fix new failure of `test_bug430392.html` when `beforeinput` is enabled r=smaug
If `beforeinput` event is enabled, the assertion count hitting in
`WSRunScanner::GetEditableBlockParentOrTopmotEditableInlineContent()` becomes 0.
The reason is, `AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent()`
gets `nullptr` as the result of `HTMLEditor.GetInputEventTargetElement()`.
Then, it returns error and every edit action handlers stop handling it.
However, for the main purpose of `beforeinput`, i.e., overriding browsers'
default action, we need to dispatch `beforeinput` event even in such case.
(I.e., web apps may want to do something around the non-editable node.)

Therefore, this patch makes `HTMLEditor.GetInputEventTargetElement()` scan
editing host by itself if `HTMLEditor.GetActiveEditingHost()` returns `nullptr`
due to non-editable focus node.  And also make `test_bug430392.html` check
whether `beforeinput` events and `input` events are fired as expected.

I think that I should add new WPT to check nested editing host cases for
considering `beforeinput` and `input` event target, but I'd like to do it
in another bug for shipping `beforeinput` in Nightly channel as soon as
possible.

Differential Revision: https://phabricator.services.mozilla.com/D91863
2020-10-01 09:15:06 +00:00
Mirko Brodesser 96caedd514 Bug 1665645: add missing `requestFlakyTimeout` call to "editor/libeditor/tests/test_CF_HTML_clipboard.html". r=hsivonen
See <https://bugzilla.mozilla.org/show_bug.cgi?id=1665645#c7> for more
context.

Differential Revision: https://phabricator.services.mozilla.com/D90838
2020-09-28 08:13:33 +00:00
Masayuki Nakano a9cd962def Bug 1658702 - part 22: Get rid of wrong `MOZ_ASSERT`s in `WSRunScanner::GetRangeExtendToContainInvisibleWhiteSpacesAtRangeBoundaries()` r=m_kato
If deleting/replacing range selects a text node, it may shrink the range
to start and end of the text node.  So, the result may not be wider than
the original range.

This behavior is compatible with Blink.

Depends on D90639

Differential Revision: https://phabricator.services.mozilla.com/D90640
2020-09-27 06:02:38 +00:00
Masayuki Nakano d3fe79f0e9 Bug 1658702 - part 21 Initialize target ranges for all edit actions which runs `DeleteSelectionAsSubAction()` r=m_kato
A lot of edit actions calls `DeleteSelectionAsSubAction()` if selection is
not collapsed.  In such case, `getTargetRanges()` should return same result
as when the selection range is simply deleted.

This patch creates 2 methods to consider whether `EditAction` causes
running `DeleteSelectionAsSubAction()` with collapsed selection or
non-collapsed selection.

And makes `DeleteSelectionAsAction()` stop initializing the target ranges
itself.  Instead, makes `AutoEditActionDataSetter` do it immediately before
dispatching `beforeinput` event unless it's been already initialized manually.
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditor.cpp#492
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditor.cpp#731
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditorDataTransfer.cpp#503

The correctness of the new utility methods are tested with new `MOZ_ASSERT`
in `DeleteSelectionAsSubAction()`.

Additionally, this reorganizes `input-events-get-target-ranges-*.html`.
* Moving common code into `input-events-get-target-ranges.js`
* Moving non-collapsed selection cases into `input-events-get-target-ranges-non-collapsed-selection.html`
* Adding "typing a" case into the new test for testing this patch's behavior

Depends on D90542

Differential Revision: https://phabricator.services.mozilla.com/D90639
2020-09-27 04:49:41 +00:00
Mirko Brodesser 6726171836 Bug 1649121: part 95) Update `ElementInfo`'s documentation. r=m_kato
Helps understanding the members.

Differential Revision: https://phabricator.services.mozilla.com/D91145
2020-09-24 17:10:48 +00:00
Masayuki Nakano a2893f0106 Bug 1658702 - part 20: Get rid of all `nsIEditor::EStripWrappers` argument from all methods computing target ranges r=m_kato
Currently, target ranges do not extend the ranges even when deleting empty
parent elements of the range.  Therefore, the frag indicating whether empty
parents removed or not is not necessary for the methods.

Differential Revision: https://phabricator.services.mozilla.com/D90542
2020-09-24 12:47:03 +00:00
Masayuki Nakano 83ade05419 Bug 1658702 - part 19: Make `WSRunScanner::GetRangeForDeletingBlockElementBoundaries()` contain preceding invisible `<br>` element at start of joining blocks range r=m_kato
When joining 2 block elements, the left block element may ends with invisible
`<br>` element or the right block element may follows an invisible `<br>`
element if it's a descendant of the left block element.  In those cases, the
invisible `<br>` element must be start of the target range of the joining
block elements since it'll be deleted.

Differential Revision: https://phabricator.services.mozilla.com/D90541
2020-09-24 12:46:45 +00:00
Masayuki Nakano ddc2f11b46 Bug 1658702 - part 18: Implement the path to compute target ranges when deleting around an invisible `<br>` element r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/HTMLEditSubActionHandler.cpp#3431,3450,3459-3489,3511-3517

However, it seems that this is a dead path in most cases because most tests
added by this patch are handled as non-collapsed range deletion.  The
collapsed range is extended by `AutoRangeArray::ExtendAnchorFocusRangeFor()`.

Differential Revision: https://phabricator.services.mozilla.com/D90540
2020-09-24 12:46:22 +00:00
Masayuki Nakano 82f1264243 Bug 1658702 - part 17: Implement the last path to handle non-collapsed ranges deletion r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4812-4825,4839-4850
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4699-4706,4709,4734-4747

Like mentioned in the first link, the logic is completely broken so that this
just follows the broken logic to return actual "affected ranges".

Differential Revision: https://phabricator.services.mozilla.com/D90214
2020-09-24 12:46:15 +00:00
Mirko Brodesser b49443686f Bug 1649121: part 94) Factor adding flavors in best order out. r=m_kato
This clarifies why the flavors are added in a certain order and why
retrieving the first available one is the best one.

Moreover, this enables previously, accidentally disabled
`NS_WARNING_ASSERTIONS`.

Differential Revision: https://phabricator.services.mozilla.com/D90883
2020-09-24 12:38:09 +00:00
Mirko Brodesser 759a716466 Bug 1649121: part 93) Change `aTransferable` to `mTransferable`. r=m_kato
To adhere the style-guide.

Differential Revision: https://phabricator.services.mozilla.com/D90882
2020-09-24 12:37:57 +00:00
Mirko Brodesser 96f3ba77b4 Bug 1649121: part 92) Factor `HTMLTransferablePreparer` out. r=m_kato
Preparing the transferable has the hidden requirement that the order of
the added flavors matters.

This is the preparation for expressing this in code.

`aTransferable` is renamed in the following commit.

Differential Revision: https://phabricator.services.mozilla.com/D90881
2020-09-24 12:39:59 +00:00
Dorel Luca 1e813d19c8 Backed out 3 changesets (bug 1649121) for Build bustage in editor/libeditor/HTMLEditorDataTransfer.cpp. CLOSED TREE
Backed out changeset eedf67df5cde (bug 1649121)
Backed out changeset 081bc411deaf (bug 1649121)
Backed out changeset 4db50381fa96 (bug 1649121)
2020-09-24 14:53:40 +03:00
Mirko Brodesser c3f9a9042c Bug 1649121: part 94) Factor adding flavors in best order out. r=m_kato
This clarifies why the flavors are added in a certain order and why
retrieving the first available one is the best one.

Moreover, this enables previously, accidentally disabled
`NS_WARNING_ASSERTIONS`.

Differential Revision: https://phabricator.services.mozilla.com/D90883
2020-09-23 14:46:20 +00:00
Mirko Brodesser 2a0b5e8022 Bug 1649121: part 93) Change `aTransferable` to `mTransferable`. r=m_kato
To adhere the style-guide.

Differential Revision: https://phabricator.services.mozilla.com/D90882
2020-09-23 14:46:12 +00:00
Mirko Brodesser 87fbdd3f84 Bug 1649121: part 92) Factor `HTMLTransferablePreparer` out. r=m_kato
Preparing the transferable has the hidden requirement that the order of
the added flavors matters.

This is the preparation for expressing this in code.

`aTransferable` is renamed in the following commit.

Differential Revision: https://phabricator.services.mozilla.com/D90881
2020-09-23 14:46:04 +00:00
Simon Giesecke de7bab0f06 Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D82325
2020-09-23 15:17:15 +00:00
Mirko Brodesser cd6abf059e Bug 1649121: part 91) Document some arguments of some `DataTransfer`-related methods. r=m_kato
A step towards making `HTMLEditor::InsertFromDataTransfer`
understandable.

Differential Revision: https://phabricator.services.mozilla.com/D90689
2020-09-23 08:15:21 +00:00
Mirko Brodesser bd154d5816 Bug 1649121: part 90) Declare some editor methods `const` or `static`. r=m_kato
Simplifies reasoning about them.

Differential Revision: https://phabricator.services.mozilla.com/D90688
2020-09-22 16:03:55 +00:00
Nicholas Nethercote 3d3e201817 Bug 1665258 - Shrink `CSSEquivTable`. r=heycam
Better field packing reduces it from 48 bytes to 40 bytes on 64-bit.

This reduces the memory used by each process by 336 bytes on 64-bit.

Differential Revision: https://phabricator.services.mozilla.com/D90344
2020-09-23 01:08:21 +00:00
Simon Giesecke c8ed33ab9d Bug 1665850 - Remove specifics for reference error types from mozilla::Result. r=emilio,jandem
Also update the documentation on optimizations and representation to
better reflect the current situation.

Differential Revision: https://phabricator.services.mozilla.com/D90662
2020-09-21 13:14:28 +00:00
Simon Giesecke 2e065c64d6 Bug 1665614 - Make mozilla::Result work with non-copyable/non-param error types. r=emilio,jandem
Among other things, there were some misuses of std::forward, and
GenericErrorResult was (presumably accidentally) instatiated with
references as the template argument type, e.g. const nsresult&,
which circumvented the check for not calling it with NS_OK in
ResultExtensions.h

Differential Revision: https://phabricator.services.mozilla.com/D90561
2020-09-21 13:12:48 +00:00
Simon Giesecke f193981fb7 Bug 1665850 - Remove specifics for reference error types from mozilla::Result. r=emilio,jandem
Also update the documentation on optimizations and representation to
better reflect the current situation.

Differential Revision: https://phabricator.services.mozilla.com/D90662
2020-09-21 11:09:09 +00:00
Simon Giesecke 3b0420646e Bug 1665614 - Make mozilla::Result work with non-copyable/non-param error types. r=emilio,jandem
Among other things, there were some misuses of std::forward, and
GenericErrorResult was (presumably accidentally) instatiated with
references as the template argument type, e.g. const nsresult&,
which circumvented the check for not calling it with NS_OK in
ResultExtensions.h

Differential Revision: https://phabricator.services.mozilla.com/D90561
2020-09-21 10:38:19 +00:00
Sylvestre Ledru ec8859e69e Bug 1519636 - Reformat recent changes to the Google coding style r=andi
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D90793
2020-09-20 10:14:09 +00:00
Masayuki Nakano 6551ca6994 Bug 1658702 - part 16: Implement `AutoBlockElementsJoiner::ComputeRangesToDeleteContentInRanges()` and `AutoBlockElementsJoiner::ComputeRangesToJoinBlockElementsInSameParent()` r=m_kato
They need to just call
`AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction()` because
their corresponding methods calls `EditorBase::DeleteRangesWithTransaction()`
and do additional different jobs after that, but the they don't affect the
ranges.

* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4602,4627-4628,4639-4642
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4650,4669-4670,4676-4678,4685-4686

Depends on D90212

Differential Revision: https://phabricator.services.mozilla.com/D90213
2020-09-17 08:39:31 +00:00
Masayuki Nakano 3a879cadbe Bug 1658702 - part 15: Implement shortcut case of `AutoDeleteRangesHandler::HandleDeleteNonCollapsedRanges()` r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4500-4527

Depends on D90211

Differential Revision: https://phabricator.services.mozilla.com/D90212
2020-09-17 08:30:10 +00:00
Mirko Brodesser 60e705c860 Bug 1649121: part 88) Declare some methods around `DataTransfer` `const`. r=masayuki
Helps reasoning about them.

Differential Revision: https://phabricator.services.mozilla.com/D90528
2020-09-17 08:52:42 +00:00
Masayuki Nakano bddc344c4c Bug 1658702 - part 14: Implement a path to compute target ranges of `EditorBase::DeleteRangesWithTransaction()` r=m_kato
`HTMLEditor` falls back to `EditorBase::DeleteRangesWithTransaction()` in
some cases, especially when handling non-collapsed ranges.  Therefore, we
need to implement it for the following patches.

The code corresponds to:
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3848-3862
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3355,3371,3374,3376,3386-3387,3392
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3421,3431-3432,3435-3436,3444,3453-3455,3464-3465,3473-3474,3477-3478,3486,3495-3497,3506-3507,3515-3520,3526-3528,3535-3538,3543-3544,3546-3549,3558-3562,3570-3572,3579-3580
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/DeleteTextTransaction.cpp#34,49-51,59,69-71

Basically, we don't need to touch the ranges, but if `aDirectionAndAmount` is
`nsIEditor::eNext` or `nsIEditor::ePrevious`, each collapsed range is extened
for:
* previous character (treating only surrogate pair)
* next character (treating only surrogate pair)
* selecting another content node

This logic is much rougher than what `AutoDeleteRangesHandler` and its nested
classes do.  So, `HTMLEditor` should stop using it in the future, but we need
to keep using it for now.

Depends on D90210

Differential Revision: https://phabricator.services.mozilla.com/D90211
2020-09-17 08:29:27 +00:00
Mirko Brodesser 6007e4f7d3 Bug 1649121: part 87) Add minimal documentation to `HTMLEditor::ParseCFHTML`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D90419
2020-09-16 20:17:47 +00:00
Masayuki Nakano c808508f5a Bug 1664741 - Make `AutoBlockElementsJoiner::DeleteNodesEntirelyInRangeButKeepTableStructure()` check whether it deletes a visible content or not before deleting the contents r=m_kato
Oddly, it checks whether it deletes at least one visible thing after deleting
each content from the DOM tree.  It should be done before deleting from the
DOM tree because all text nodes become visible if they are not in the DOM tree
anymore.

Unfortunately, this change does not fix any automated test result, but the
base logic --only when it does not delete any visible things, join the adjacent
block elements-- sounds reasonable.  Therefore, let's take this change.
Note that without this change, cannot compute "affected ranges" of
`getTargetRanges()` in the case running this method later.

Differential Revision: https://phabricator.services.mozilla.com/D90065
2020-09-17 01:45:30 +00:00
Makoto Kato 0a0fc918b8 Bug 1663638 - Don't use edit transaction for editing UI. r=masayuki
Although we use CSS property for Inline table editing UI, we use edit
transaction for it unfortunately. When hiding this UI, since removing
element doesn't use edit transaction, transaction will be canceled before
showing this UI.

It is unnecessary to use edit transaction for UI, so we shouldn't use it.

Differential Revision: https://phabricator.services.mozilla.com/D90056
2020-09-14 05:10:08 +00:00
Masayuki Nakano 969699a0f3 Bug 1658702 - part 12: Implement paths to compute ranges to delete non-collapsed ranges r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#3531-3537
* https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#4443-4561
* https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#2778-2822

Note that the new failure of `input-events-get-target-ranges-forwarddelete.html`
is mismatch between target range (including the trailing white-space) and
actually deleted range (not including the trailing white-space).  Let's
accept this new failure for now since not so important problem and same test
with backspace has same bug.

Differential Revision: https://phabricator.services.mozilla.com/D89870
2020-09-16 10:55:22 +00:00
Masayuki Nakano e09be3fb17 Bug 1664109 - Fix `!=` operator of `EditorDOMRangeBase` r=m_kato
This is causes taking back bugs in
`WSRunScanner::GetNewInvisibleLeadingWhiteSpaceRangeIfSplittingAt()` and
`WSRunScanner::GetNewInvisibleTrailingWhiteSpaceRangeIfSplittingAt()`  (I.e.,
they were fixed by bug 1647556).  Therefore, this removes the odd `if` blocks
which are pointed with `XXX` comment for avoiding "regressions" (without them,
some WPTs for `InputEvents.getTargetRanges()` become failure).

Depends on D89582

Differential Revision: https://phabricator.services.mozilla.com/D89869
2020-09-16 02:17:33 +00:00
Masayuki Nakano a5c5234e6f Bug 1658702 - part 11: Implement a path to compute target ranges when joining 2 blocks from outer block boundary r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#3679-3697
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#2733-2751
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#4286-4302
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#4309-4355

`HandleDeleteCollapsedSelectionAtCurrentBlockBoundary()` delete leaf content
of the child block when the block is not joined with current block.  For
doing it, it creates another `AutoDeleteRangesHandler` with collapsing selection
in the child block.  Then, it may refer selection for handling bidi text.
Therefore, the computation code which is added by this patch may modify
selection temporarily for the child `AutoDeleteRangeHandler`.  However, the
selection change shouldn't cause running any scrip (even if chrome script)
because it's required only for this hack.  Therefore, this patch blocks all
notifications and selection change events with `AutoHideSelectionChanges`.
Therefore, this patch marks
`AutoBlockElementsJoiner::ComputeRangesToDeleteAtOtherBlockBoundary()` as
`MOZ_CAN_RUN_SCRIPT_BOUNDARY` for using `HTMLEditor::CollapseSelectionTo()`.

Differential Revision: https://phabricator.services.mozilla.com/D89582
2020-09-16 05:36:57 +00:00
longsonr dee8245fe3 Bug 1664788 - rewrite nsEditingSession::SetupEditorOnWindow r=masayuki
Avoid converting strings from UTF16 to ASCII

Differential Revision: https://phabricator.services.mozilla.com/D90092
2020-09-15 14:40:54 +00:00
Masayuki Nakano 620c728792 Bug 1658702 - part 10: Implement a path to compute target ranges when joining 2 blocks from current block boundary r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#3525-3543
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#2710-2719
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#4140-4165
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#5650-5716
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#97-213
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#218-386
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#391-480

In `WSRunObject.cpp`, joining 2 blocks code is split to 3 methods, they are
for:

1. left block element is an ancestor of right block element
2. right block element is an ancestor of left block element
3. left block element and right block element are siblings

The reason why they are split to is, they need to move descendants of child
block element or right block element with different logic.  However, this
difference is not a big problem when we compute target ranges because only
the difference is where we need to check whether there are invisible white-
spaces.  Therefore, this patch creates only a utility method in `WSRunScanner`
and makes `AutoInclusiveAncestorBlockElementsJoiner::ComputeRangesToDelete()`
much simpler than `AutoInclusiveAncestorBlockElementsJoiner::Run()`.

Differential Revision: https://phabricator.services.mozilla.com/D89278
2020-09-11 06:24:08 +00:00