Commit Graph

744 Commits

Author SHA1 Message Date
Masayuki Nakano
788f5cd59f Bug 1770877 - part 32: Make HTMLEditor::InsertContainerWithTransaction stop touching Selection directly r=m_kato
This changes the behavior a little bit, unfortunately.

`InsertContainerWithTransaction` starts return code.  And the behavior changed
WPTs are hit here:
https://searchfox.org/mozilla-central/rev/a8bdd0feeb7ae596a202333ee324a68153f9f4c4/editor/libeditor/EditorBase.cpp#2179-2180

Then, the editor specific error will be converted to `NS_OK` at the
corresponding public method.  Therefore, the return code may be changed from
`NS_ERROR_FAILURE` to `NS_OK`, and that causes the return value change of
`Document.execCommand`.

Differential Revision: https://phabricator.services.mozilla.com/D149103
2022-06-22 08:04:26 +00:00
Masayuki Nakano
71dde570e5 Bug 1770877 - part 25: Make HTMLEditor::FormatBlockContainerWithTransaction stop touching Selection directly r=m_kato
This patch makes it take `AutoRangeArray` and it can save a snapshot of the
ranges and restore it like `AutoSelectionRestorer`.

For accessing `HTMLEditor::RangeUpdaterRef` for clearing the saved ranges,
`AutoRangeArray` needs to store `HTMLEditor`.  Therefore, its constructors
and the destructor cannot be inlined in the header due to the include-hell.

Differential Revision: https://phabricator.services.mozilla.com/D149089
2022-06-21 05:58:45 +00:00
Masayuki Nakano
fe2186dd7f Bug 1770877 - part 22: Move HTMLEditor::CollectEditTargetNodes into AutoRangeArray r=m_kato
And also this moves `HTMLEditor::CollectChildren` to `HTMLEditUtils`.

Differential Revision: https://phabricator.services.mozilla.com/D149086
2022-06-21 01:19:25 +00:00
Masayuki Nakano
3d4768d7d6 Bug 1770877 - part 19: Make HTMLEditor::SplitParentInlineElementsAtRangeEdges stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149083
2022-06-20 23:09:29 +00:00
Masayuki Nakano
4f89f0e183 Bug 1770877 - part 15: Implement equivalent of HTMLEditor::GetSelectionRangesExtendedToHardLineStartAndEnd r=m_kato
It's always work with `Selection` ranges.  Then, it should be treated within
`AutoRangeArray` which can be initialized with `Selection` ranges automatically.
Then, we can making `HTMLEditor` simpler.

Note tha this tries to make it get editing host when the corresponding
public method is called (after dispatched `beforeinput` event if handling a
users' operation).  However, as commented in
`HTMLEditor::SetParagraphFormatAsAction`, it breaks a tricky crash test.
Therefore, only the format block path computes it after the preparation.

Differential Revision: https://phabricator.services.mozilla.com/D149079
2022-06-17 21:28:36 +00:00
Emilio Cobos Álvarez
1c58e2a928 Bug 1773070 - Unify Gecko and Servo EventState/ElementState bits. r=smaug
Add a dom/base/rust crate called just "dom" where we can share these.

Most of the changes are automatic:

  s/mozilla::EventStates/mozilla::dom::ElementState/
  s/EventStates/ElementState/
  s/NS_EVENT_STATE_/ElementState::/
  s/NS_DOCUMENT_STATE_/DocumentState::/

And so on. This requires a new cbindgen version to avoid ugly casts for
large shifts.

Differential Revision: https://phabricator.services.mozilla.com/D148537
2022-06-07 23:09:52 +00:00
Masayuki Nakano
8b7dbfe141 Bug 1772022 - Make EditorBase::DeleteNodeWithTransaction() return NS_ERROR_EDITOR_DESTROYED if so r=m_kato
Its callers check `EditorBase::Destroyed()` with at least adding 4 lines, and
some callers do not check this important state.  So, we should make it check
`Destroyed()` at last and omit the additional error check in the caller sites.

Note that it's a virtual method, but `HTMLEditor` checks whether it's a
removable node or not.  So, we should can merge it into `EditorBase`.  This
patch does it too.

Differential Revision: https://phabricator.services.mozilla.com/D148084
2022-06-03 02:03:47 +00:00
Masayuki Nakano
71411e3fb4 Bug 1771448 - part 4: Rename HTMLEditor::GetActiveEditingHost to ComputeEditingHost r=m_kato
It's currently computes the corresponding editing host from the focus node of
`Selection` with climbing up the DOM tree.  So, it does not just return a stored
element.  Therefore, some callers use it multiple times.  For avoiding it, we
should rename it to explain that it computes the editing host.

Note that I think that we should make it takes a node to compute editing host
without `Selection` for solving the case of no selection ranges.  Therefore,
I don't like to include more information into the name.

Differential Revision: https://phabricator.services.mozilla.com/D147504
2022-05-31 03:41:01 +00:00
Masayuki Nakano
3b9dee039a Bug 1771448 - part 3: Get rid of EditorBase::GetEditorRoot r=m_kato
It returns the anonymous `<div>` element if the instance is a `TextEditor`, and
compute editing host otherwise.  So it's unclear what it returns.  Additionally,
all users except `EditorBase::CreateTransactionForCollapsedRange` are the
methods of `HTMLEditor`.  Therefore, we should remove it and unwrap the code
which it's done.

Differential Revision: https://phabricator.services.mozilla.com/D147503
2022-05-31 03:41:01 +00:00
Masayuki Nakano
6536c89a75 Bug 1771448 - part 2: Get rid of EditorBase::IsDescendantOfEditorRoot r=m_kato
With this patch, there are some odd points.  We should investigate them later...

Differential Revision: https://phabricator.services.mozilla.com/D147502
2022-05-31 03:41:01 +00:00
Masayuki Nakano
21777f8ff2 Bug 1770874 - part 8: Make EditorBase::OnBlur temporarily a virtual method r=m_kato
Similar to the previous patch, we should split the method into `TextEditor`
and `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D147144
2022-05-27 04:09:19 +00:00
Masayuki Nakano
9a55d9833a Bug 1770874 - part 7: Make EditorBase::OnFocus temporarily a virtual method r=m_kato
I'd like to split it for `TextEditor` and `HTMLEditor`.  `HTMLEditor` does not
require flushing the layout because it's required by `TextEditor` if and only if
a preceding `focus` event listener or the `Element.focus` caller reframes
`<input>` or `<textarea>` element (bug 1755104).  So this would fix bug 1760045.

Differential Revision: https://phabricator.services.mozilla.com/D147143
2022-05-27 04:09:19 +00:00
Masayuki Nakano
5e962c88c5 Bug 1770874 - part 1: Make some clean ups around EditorBase::OnFocus r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D147137
2022-05-27 03:47:33 +00:00
Masayuki Nakano
565d584782 Bug 1770133 - part 3: Make EditorBase::GetFocusedContent() return Element* instead of nsIContent* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D147134
2022-05-26 07:03:20 +00:00
Masayuki Nakano
b70c34fad4 Bug 1766355 - part 9: Make HTMLEditor::ReplaceContainerWithTransactionInternal and its callers use MoveNodeTransaction and return CreateElementResult r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146405
2022-05-20 10:44:04 +00:00
Masayuki Nakano
79a45c6f56 Bug 1766355 - part 8: Make HTMLEditor::RemoveBlockContainerWithTransaction stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146404
2022-05-20 09:57:38 +00:00
Masayuki Nakano
e274b4ce87 Bug 1766355 - part 7: Rewrite HTMLEditor::RemoveContainerWithTransaction with MoveNodeTransaction and make it stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146403
2022-05-20 09:01:40 +00:00
Masayuki Nakano
7bfa21cc89 Bug 1766355 - part 4: Make HTMLEditor::MoveNodeWithTransaction and HTMLEditor::MoveNodeToEndWithTransaction return MoveNodeResult r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146400
2022-05-20 08:28:09 +00:00
Masayuki Nakano
4779f9e6d1 Bug 1766355 - part 1: Add MoveNodeTransaction to handle delete node and insert node in a transaction class instance r=m_kato
Creating both `DeleteNodeTransaction` and `InsertNodeTransaction` wastes
memory.  They should be done in an instance instead.

Fortunately, no edit action listener checks whether the deleted node is still
in the composed document or not, etc.  Therefore, we can simply notify them of
both deletion and insertion which were done in
`EditorBase::InsertNodeWithTransaction` and
`EditorBase::DeleteNodeWithTransaction`.  Note that previously, the range
updater needs to ignore the notifications from them while the node is being
moved.  However, it does not require anymore.  Therefore, this patch makes it
stop locking, and that would fix minor problem in the case of legacy mutation
event listeners run another edit action.

On the other hand, this changes some edge cases handling of
`MoveNodeWithTransaction` which are detected by the WPT.  According to the
previous result of applying this patch, `nsINode::InsertBefore` fails and that
leads some errors at updating the changed range.  I guess that the cause is
that there is some bugs at updating insertion point after deleting the node from
the DOM tree around here:
https://searchfox.org/mozilla-central/rev/0ffae75b690219858e5a45a39f8759a8aee7b9a2/editor/libeditor/HTMLEditor.cpp#5058-5071

However, it's safely fixed by the new code which does not remove the node from
the DOM tree explicitly.  So, I think that it's safe to accept this behavior
change for web apps in the wild.

Differential Revision: https://phabricator.services.mozilla.com/D146397
2022-05-20 08:28:08 +00:00
Masayuki Nakano
57e39bc290 Bug 1730442 - part 7: Rewrite HTMLEditor::InsertTableRowsWithTransaction() to collect any cell information before touching the DOM tree r=m_kato
This patch also makes it inserts table rows immediately after the previous
row element of the found reference row element to make it insert new table
rows immediately after there when inserting position is "after".  Typically,
it's the parent `<tr>` element of `aCellElement`.  Therefore, this approach
can preserve text nodes immediately after it which was intentionally inserted
by the web apps.

Differential Revision: https://phabricator.services.mozilla.com/D146365
2022-05-20 07:39:53 +00:00
Masayuki Nakano
856eca7a46 Bug 1730442 - part 4: Rewrite HTMLEditor::GetFirstTableRowElement() as returing Result<RefPtr<Element>, nsresult> r=m_kato
This change is tested by `test_nsITableEditor_getFirstRow.html` and
`test_nsITableEditor_insertTableColumn.html`.

Differential Revision: https://phabricator.services.mozilla.com/D146362
2022-05-20 07:39:52 +00:00
Masayuki Nakano
d44806526e Bug 1730442 - part 2: Rewrite HTMLEditor::GetSelectedOrParentTableElement() as returing Result<RefPtr<Element>, nsresult> r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146360
2022-05-20 07:39:51 +00:00
Masayuki Nakano
bf2814531c Bug 1730442 - part 1: Make all nsITableEditor features flush pending layout at start to handle their jobs r=m_kato
Our table editor depends on layout information for getting raw/column position
of a cell, checking rawspan/colspan information and table size.  Therefore,
they require the latest information, but they don't flush pending layout by
themselves.  Therefore, this patch makes them do it by themselves and deleting
unnecessary hack from their tests.

Differential Revision: https://phabricator.services.mozilla.com/D146359
2022-05-20 07:39:51 +00:00
Bogdan Szekely
2e6bbe8888 Merge autoland to mozilla-central. a=merge 2022-05-17 12:26:46 +03:00
Molnar Sandor
13ebce2a4b Backed out 7 changesets (bug 1730442) for causing reftest failures in editor/reftests/inline-table-editor-position-after-updating-table-size-from-input-event-listener.html. CLOSED TREE
Backed out changeset f6d7f162e57a (bug 1730442)
Backed out changeset e5d1671b3bbc (bug 1730442)
Backed out changeset e60a5cd69184 (bug 1730442)
Backed out changeset 943d4e4b0770 (bug 1730442)
Backed out changeset bd3324b635f4 (bug 1730442)
Backed out changeset ada0dda5bcde (bug 1730442)
Backed out changeset b67c4035c12f (bug 1730442)
2022-05-17 04:23:36 +03:00
Masayuki Nakano
a879a3a5b1 Bug 1730442 - part 7: Rewrite HTMLEditor::InsertTableRowsWithTransaction() to collect any cell information before touching the DOM tree r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146365
2022-05-17 00:12:11 +00:00
Masayuki Nakano
a8325c96c2 Bug 1730442 - part 4: Rewrite HTMLEditor::GetFirstTableRowElement() as returing Result<RefPtr<Element>, nsresult> r=m_kato
This change is tested by `test_nsITableEditor_getFirstRow.html` and
`test_nsITableEditor_insertTableColumn.html`.

Depends on D146361

Differential Revision: https://phabricator.services.mozilla.com/D146362
2022-05-17 00:12:10 +00:00
Masayuki Nakano
d035d0bdc4 Bug 1730442 - part 2: Rewrite HTMLEditor::GetSelectedOrParentTableElement() as returing Result<RefPtr<Element>, nsresult> r=m_kato
Depends on D146359

Differential Revision: https://phabricator.services.mozilla.com/D146360
2022-05-17 00:12:09 +00:00
Masayuki Nakano
c74c282325 Bug 1730442 - part 1: Make all nsITableEditor features flush pending layout at start to handle their jobs r=m_kato
Our table editor depends on layout information for getting raw/column position
of a cell, checking rawspan/colspan information and table size.  Therefore,
they require the latest information, but they don't flush pending layout by
themselves.  Therefore, this patch makes them do it by themselves and deleting
unnecessary hack from their tests.

Differential Revision: https://phabricator.services.mozilla.com/D146359
2022-05-17 00:12:08 +00:00
Daisuke Akatsuka
b7719d2c16 Bug 1457149: Make Ctrl+Backspace behavior on text editor in Windows during text selection the same as other OS. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D146392
2022-05-16 09:30:29 +00:00
Kagami Sascha Rosylight
2b3baf8dfe Bug 1767998 - Apply readability-make-member-function-const on editor/libeditor r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D145626
2022-05-13 05:35:25 +00:00
Masayuki Nakano
9b86482e84 Bug 1767876 - part 2: Make ComposerCommandsUpdater stop inheriting nsITransactionListener r=m_kato
This patch makes `TransactionManager` store `HTMLEditor`, and `HTMLEditor`
send notifications from `TransactionManager` to `ComposerCommandsUpdater`.

Depends on D145663

Differential Revision: https://phabricator.services.mozilla.com/D145664
2022-05-09 12:13:10 +00:00
Masayuki Nakano
9db4baa95c Bug 1766956 - part 3: Make SelectionState stop using nsRange to compare DOM points r=m_kato
The creation and initialization cost of `nsRange` is expensive.  And just
comparing DOM points does not require the checks of ancestors which are
required by `nsRange` to observe DOM mutations.  Therefore, although the
logic is not exactly same, we can skip the additional unnecessary cost.
Note that the Editor module checks without `nsRange`'s strict initialization
in most places so that it must not be required to do the strict check only in
`SelectionState`.

Additionally, this moves some definitions of `SelectionState` methods to
its header for making them inlined since the dependency is now reduced.

Finally, some methods are renamed to align to `Selection` API.

Depends on D145226

Differential Revision: https://phabricator.services.mozilla.com/D145227
2022-05-09 05:01:58 +00:00
Masayuki Nakano
fdbdb18b03 Bug 1762115 - part 15: Make HTMLEditor::InsertNodeIntoProperAncestorWithTransaction() stop touching Selection directly r=m_kato
This patch also makes that `HTMLWithContextInserter::InsertContents`
collect moving children first.  Then, move each one with a transaction.
This is standard manner in these days to avoid infinite loop caused by
moving the removed child back by a mutation event listener.

Differential Revision: https://phabricator.services.mozilla.com/D144658
2022-05-03 01:38:57 +00:00
Masayuki Nakano
ed197035df Bug 1762115 - part 13: Make EditorBase::InsertNodeWithTransaction stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144656
2022-05-03 01:21:51 +00:00
Masayuki Nakano
24cafb66c8 Bug 1762115 - part 11: Make HTMLEditor::CopyLastEditableChildStylesWithTransaction stop touching Selection directly r=m_kato
It's called only by `HTMLEditor::HandleInsertParagraphInListItemElement` and
it also just returns a point to put caret computed from the result of
`CopyLastEditableChildStylesWithTransaction` and its caller changes the
selection.  Therefore, it's enough to make it return a recommend point to
put caret.

Differential Revision: https://phabricator.services.mozilla.com/D144654
2022-05-03 01:09:15 +00:00
Masayuki Nakano
dfde4fb973 Bug 1762115 - part 10: Make HTMLEditor::InsertBRElement stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144653
2022-05-03 01:03:05 +00:00
Masayuki Nakano
e67e2e79b6 Bug 1762115 - part 7: Make HTMLEditor::SplitNodeDeepWithTransaction stop touching Selection r=m_kato
Now, it does not require to update selection, and its result may have a point
to put caret it is used to doing.  This patch makes it stop collapsing selection
after each split, and instead, makes all callers of it collapse selection if
it's (probably) necessary.

Note that the method may not split any nodes but return it as "handled".
Therefore, the callers do not check whether a splitting node occurred **but**
suggesting point to put caret is invalid or the other cases.  Therefore, in
strictly speaking, this patch changes the existing behavior, but it should not
affects web apps in the wild because of the low usage of the legacy mutation
event listeners.

Differential Revision: https://phabricator.services.mozilla.com/D144650
2022-05-03 00:19:16 +00:00
Masayuki Nakano
21f26a7ae8 Bug 1762115 - part 6: Make HTMLEditor::SplitNodeWithTransaction stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144649
2022-05-03 00:12:01 +00:00
Masayuki Nakano
adea39d1ad Bug 1762115 - part 5: Make SplitNodeResult store and suggest new caret position r=m_kato
This patch allows methods which split some nodes to return new candidate
caret position and makes callers of them consider whether applying it to
the selection immediately or not.

Differential Revision: https://phabricator.services.mozilla.com/D144648
2022-05-03 00:06:16 +00:00
Masayuki Nakano
0ed912d4d2 Bug 1762115 - part 4: Make SplitNodeTransaction::DoTransaction() stop touching selection r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144647
2022-05-02 23:44:00 +00:00
Masayuki Nakano
ec4a4d20ee Bug 1762115 - part 3: Make HTMLEditor::CreateAndInsertElement stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144646
2022-05-02 23:25:30 +00:00
Masayuki Nakano
806d2bdd53 Bug 1762115 - part 2: Make InsertNodeTransaction::DoTransaction() stop touching Selection directly r=m_kato
Unfortunately, we need to keep `InsertNodeTransaction::RedoTransaction()`
touching `Selection` for now because redoing `Selection` management is out
of scope of this bug (it's probably require big changes, but no benefits for
now).

Differential Revision: https://phabricator.services.mozilla.com/D144645
2022-05-02 23:17:18 +00:00
Masayuki Nakano
54bb966fad Bug 1765018 - part 7: Make some methods which return an instance (not reference) of EditorDOMPointBase be template methods r=m_kato
For avoiding to use `To<EditorDOMPoint>()` etc from temporary object, such
methods should be templated.

Differential Revision: https://phabricator.services.mozilla.com/D143884
2022-04-20 23:58:04 +00:00
Masayuki Nakano
c56be53f24 Bug 1765018 - part 4: Make EditorBase::InsertTextWithTransaction treat only EditorDOMPoint r=m_kato
In theory, methods which touch the DOM tree should take `EditorDOMPoint` rather
than `EditorRawDOMPoint`.  And now, we can return meaningful value if it
succeeded, with `Result`.

Therefore, this patch makes it return `Result<EditorDOMPoint, nsresult>` instead
of taking an out argument, and take only `EditorDOMPoint` rather than taking any
type of `EditorDOMPointBase` since it's always converted to `EditorDOMPoint`.

Differential Revision: https://phabricator.services.mozilla.com/D143881
2022-04-20 23:46:19 +00:00
Masayuki Nakano
cd80bdce17 Bug 1765018 - part 1: Get rid of implicit conversion between EditorDOMPointBase instances r=m_kato
The implicit copy constructors and `operator=` makes it harder to realize
that implicit conversion wastes the runtime cost.  Therefore, this patch
replaces them with a template method to convert the `EditorDOMPointBase` type.

Differential Revision: https://phabricator.services.mozilla.com/D143878
2022-04-20 22:41:02 +00:00
Masayuki Nakano
0ce8e872fd Bug 1764866 - Add "mozilla/EditorForwards.h" r=m_kato
Headers in editor module has a lot of forward declarations for avoiding the
include hell and has a lot of helper template classes.

Forward declarations of template classes is really messy and I'd want to
avoid the duplication because it blocks changing template class.  Therefore,
centralizing forward declarations makes the headers cleaner and maintaining
template classes easier.  Therefore, this patch adds a new header file which
has only forward declarations and some aliases.

It'd be better to define `enum class`es in it like `EventForwards.h` for
reducing the dependencies between headers, but currently this does not do it
for making the new file simpler as far as possible.

Removing `EditActionListener.h` is because it's unused.

Removing `AutoTopLevelEditSubActionNotifier` is because it's renamed to
`AutoEditSubActionNotifier`.
https://hg.mozilla.org/mozilla-central/rev/6de55c5b5f8d5f92389d0d244d2bced1f979ade9

Differential Revision: https://phabricator.services.mozilla.com/D143817
2022-04-20 14:46:16 +00:00
Masayuki Nakano
c967f41237 Bug 1764684 - part 4: Make editor stop calling SelectionRef().SetInterlinePosition if followed by a call of EditorBase::CollapseSelectionTo* r=m_kato
Now, `EditorBase::CollapseSelectionTo*()` set the interline position if it's
explicitly set to the `EditorDOMPointBase` parameter.  Therefore, editor should
use the feature as far as possible instead of calling
`Selection::SetInterlinePosition` directly.

Differential Revision: https://phabricator.services.mozilla.com/D143816
2022-04-20 14:46:15 +00:00
Masayuki Nakano
a8350c4163 Bug 1764684 - part 3: Fix and improve warnings of the result of EditorBase::CollapseSelectionTo* r=m_kato
Some of them were `HTMLEditor` so that we need to fix it to `EditorBase`, and
also this patch fixes `NS_ERROR_EDITOR_DESTROYED` handling around them.

Differential Revision: https://phabricator.services.mozilla.com/D143815
2022-04-20 14:36:53 +00:00
Masayuki Nakano
57ba857907 Bug 1764684 - part 2: Make editor use methods of EditorBase to collapse Selection r=m_kato
First, move methods of `HTMLEditor` which collapse `Selection` to `EditorBase`.
Then, make editor stop accessing `Selection::CollapseInLimiter` directly.

Differential Revision: https://phabricator.services.mozilla.com/D143814
2022-04-20 14:36:52 +00:00