Commit Graph

419 Commits

Author SHA1 Message Date
Masayuki Nakano
eca7291981 Bug 1770877 - part 38: Make HTMLEditor::InsertParagraphSeparatorAsSubAction stop updating Selection while handling its job r=m_kato
Finally, this patch makes it update `Selection` once after finishing its
preparation.

Differential Revision: https://phabricator.services.mozilla.com/D149109
2022-06-22 13:57:07 +00:00
Masayuki Nakano
982e1e45fb Bug 1770877 - part 37: Make HTMLEditor::HandleInsertLinefeed stop touching Selection directly r=m_kato
Note that the odd path which always returns `NS_ERROR_FAILURE` is not covered by
the tests.  Therefore, this patch adds `MOZ_ASSERT` to make somebody hit it and
report a bug.

Differential Revision: https://phabricator.services.mozilla.com/D149108
2022-06-22 13:14:17 +00:00
Masayuki Nakano
ce07a931ae Bug 1770877 - part 36: Make HTMLEditor::CreateStyleForInsertText stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149107
2022-06-22 13:07:05 +00:00
Masayuki Nakano
99aa2d876f Bug 1770877 - part 35: Make HTMLEditor::SetInlinePropertyOnNode and HTMLEditor::SetInlinePropertyOnNodeImpl stop touching Selection directly r=m_kato
Note that `CSSEditUtils` does not change `Selection` except
`RemoveCSSInlineStyleWithTransaction` which is used only by aligning in a block.
Therefore, this patch does not touch `CSSEditUtils`.

Differential Revision: https://phabricator.services.mozilla.com/D149106
2022-06-22 12:57:51 +00:00
Masayuki Nakano
db9c8aa4f4 Bug 1770877 - part 33: Make HTMLEditor::RelativeFontChangeOnTextNode stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149104
2022-06-22 08:18:40 +00:00
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
d3f84bd498 Bug 1770877 - part 31-3: Replace insertLineBreak variable in HTMLEditor::InsertParagraphSeparatorAsSubAction with a lambda r=m_kato
This can encapsule the long if-elseif-else blocks into the lambda.

Differential Revision: https://phabricator.services.mozilla.com/D149102
2022-06-22 02:54:34 +00:00
Masayuki Nakano
341b28f4a6 Bug 1770877 - part 31-2: Make HTMLEditor::InsertParagraphSeparatorAsSubAction call HandleInsertParagraphInParagraph without Selection r=m_kato
The preceding call of `InsertBRElement` may collapse selection at the inserted
padding `<br>` element.  Only when calling `HandleInsertParagraphInParagraph`,
`InsertParagraphSeparatorAsSubAction` uses `Selection`.  So, only in this case,
we need to recompute the point to split for keeping current (odd) behavior.

Note that in normal cases, using `atStartOfSelection` gets same result.
However, if there are some invisible nodes such as comment nodes, doing it
may change the behavior.  For now, we should keep the current behavior.  It
should be sorted out when we make it stop inserting `<br>` elements for the
preparation of split without checking whether it's actually necessary.

Differential Revision: https://phabricator.services.mozilla.com/D149101
2022-06-22 01:52:32 +00:00
Masayuki Nakano
5716906480 Bug 1770877 - part 30: Make HTMLEditor::HandleInsertParagraphInListItemElement stop touching Selection directly r=m_kato
It touches `Selection` redundantly (i.e., immediately after that, it or its
caller collapse `Selection`).  So we can just stop it because we can ignore
the cases when the handling fails after the redundant `Selection` update and
it can be caused by tricky things with the mutation event listeners.

Note that without changing `SplitNodeResult` a lot, we cannot make it return
`SplitNodeResult`, and currently there is no motivation to do it because the
only caller does not need the detail of the split.  Therefore, I give up doing
it.

Differential Revision: https://phabricator.services.mozilla.com/D149099
2022-06-22 01:34:03 +00:00
Masayuki Nakano
9ad7147689 Bug 1770877 - part 29: Make HTMLEditor::HandleInsertParagraphInHeadingElement stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149098
2022-06-22 01:25:04 +00:00
Masayuki Nakano
8639dbe837 Bug 1770877 - part 28-6: Make HTMLEditor::HandleInsertParagraphInParagraph stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149097
2022-06-22 01:18:35 +00:00
Masayuki Nakano
6050c3783c Bug 1770877 - part 28-5: Get rid of unnecessary duplication of EditorDOMPoint in HTMLEditor::HandleInsertParagraphInParagraph r=m_kato
I tried to make the latter half preparation to call
`HTMLEditor::SplitParagraphWithTransaction`, but I cannot make it cleaner
because it needs to return `HTMLBRElement*` and `EditorDOMPoint` with maybe
modifying the DOM tree.  So, I keep it as-is, but I make replace the unnecessary
duplicated `EditorDOMPoint` with the original one which is adjusted to avoid
to create new empty link in the right paragraph.

Differential Revision: https://phabricator.services.mozilla.com/D149096
2022-06-22 01:05:47 +00:00
Masayuki Nakano
7177fc5d13 Bug 1770877 - part 28-4: Make HTMLEditor::HandlerInsertParagraphInParagraph take a split point and editing host r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149095
2022-06-22 01:00:42 +00:00
Masayuki Nakano
cb4aff20eb Bug 1770877 - part 28-3: Make HTMLEditor::HandleInsertParagraphInParagraph insert <br> element immediately after considering so r=m_kato
Using the wide scope `EditorDOMPoint pointToInsertBR` makes it harder to read.
Although this duplicates a call of `HTMLEditor::InsertBRElement` and a couple of
post processing, but I think that it's easier to read/understand.

Differential Revision: https://phabricator.services.mozilla.com/D149094
2022-06-22 00:40:20 +00:00
Masayuki Nakano
ff85913ec0 Bug 1770877 - part 28-2: Make HTMLEditor::HandleInsertParagraphInParagraph return earlier if should be default to insert <br> instead r=m_kato
If it needs to insert a `<br>` but the editor does not want to create new
paragraph, its caller should be default to insert a `<br>` element.  Rather
than checking this at inserting `<br>` element, it should do it at considering
the place to insert the new `<br>`.

Differential Revision: https://phabricator.services.mozilla.com/D149093
2022-06-21 23:50:42 +00:00
Masayuki Nakano
4956f5f256 Bug 1770877 - part 28-1: Isolate the part of adjusting split point for avoiding to create new empty link in HTMLEditor::HandleInsertParagraphInParagraph r=m_kato
The method does several different things.  For making each part isolated,
this patch wraps the first part with a lambda.

Differential Revision: https://phabricator.services.mozilla.com/D149092
2022-06-21 23:38:06 +00:00
Masayuki Nakano
e890bf70eb Bug 1770877 - part 27: Make HTMLEditor::SplitParagraph stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149091
2022-06-21 08:49:51 +00:00
Masayuki Nakano
c9421c2f5c Bug 1770877 - part 26: Make HTMLEditor::InsertBRElementIfEmptyBlockElement a lambda since it's used only by one method r=m_kato
And its selection update are not used except the legacy mutation event
listeners so that we can drop them.

Differential Revision: https://phabricator.services.mozilla.com/D149090
2022-06-21 08:19:37 +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
8b61312c02 Bug 1770877 - part 24: Make HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149088
2022-06-21 03:11:42 +00:00
Masayuki Nakano
66b0ffb0f3 Bug 1770877 - part 23: Clean up callers of AutoRangeArray::SplitTextNodesAtEndBoundariesAndParentInlineElementsAtBoundaries r=m_kato
They at most twice updates the `Selection` right now.  We can make them update
`Selection` once.  And this patch makes the scope of `AutoRangeArray` clearer.

Differential Revision: https://phabricator.services.mozilla.com/D149087
2022-06-21 01:26:20 +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
989e00f9e6 Bug 1770877 - part 21: Get rid of HTMLEditor::SplitInlinesAndCollectEditTargetNodes r=m_kato
It's callers become messy with this patch.  The following patches try to make
them smaller.

Differential Revision: https://phabricator.services.mozilla.com/D149085
2022-06-21 01:07:10 +00:00
Masayuki Nakano
b788c06be9 Bug 1770877 - part 20: Move HTMLEditor::SplitTextNodesAtRangeEnd and HTMLEditor::SplitParentInlineElementsAtRangeEdges into AutoRangeArray r=m_kato
Although they update the DOM tree with transactions, but for making `HTMLEditor`
smaller, and the following patches makes the related code simpler, we need to
move them into `AutoRangeArray`.

Differential Revision: https://phabricator.services.mozilla.com/D149084
2022-06-20 23:45:02 +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
edb9e1e66d Bug 1770877 - part 18: Make HTMLEditor::SplitTextNodesAtRangeEnd stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149082
2022-06-20 08:54:47 +00:00
Masayuki Nakano
bc7f30ea77 Bug 1770877 - part 17: Make HTMLEditor::SplitElementsAtEveryBRElement and HTMLEditor::MaybeSplitElementsAtEveryBRElement stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149081
2022-06-19 20:57:21 +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
Masayuki Nakano
fbef891380 Bug 1770877 - part 13: Move HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd into AutoRangeArray r=m_kato
This patch makes them take `const Element& aEditingHost` so that this patch
becomes bigger than what this patch does.

Differential Revision: https://phabricator.services.mozilla.com/D149077
2022-06-17 08:23:20 +00:00
Masayuki Nakano
5058c3606f Bug 1770877 - part 12: Make HTMLEditor treat array of nsRange with OwningNonNull rather than RefPtr r=m_kato
`AutoRangeArran` uses `OwningNonNull`.  So making the following patch simpler
and smaller, all places should use array of `OwningNonNull<nsRange>` instead of
`RefPtr<nsRange>`.

Differential Revision: https://phabricator.services.mozilla.com/D149076
2022-06-17 07:40:37 +00:00
Masayuki Nakano
48706b3a98 Bug 1770877 - part 11: Move HTMLEditor::GetCurrentHardLineStartPoint and HTMLEditor::GetCurrentHardLineEndPoint r=m_kato
Similar to the previous patch, you must feel odd to move the methods.  They
will be static methods in the `EditorUtils.cpp` file later.

Differential Revision: https://phabricator.services.mozilla.com/D149075
2022-06-17 07:33:56 +00:00
Masayuki Nakano
85bb52a638 Bug 1770877 - part 10: Move HTMLEditor::SelectBRElementIfCollapsedInEmptyBlock to AutoRangeArray r=m_kato
This must make you feel odd. However, this is a separate patch for making easier
to review the following patches.  This will be a private member of
`AutoRangeArray`.

Differential Revision: https://phabricator.services.mozilla.com/D149074
2022-06-17 05:43:02 +00:00
Masayuki Nakano
b0368e31c8 Bug 1770877 - part 9: Get rid of HTMLEditor::GetSelectionRangesExtendedToIncludeAdjuscentWhiteSpaces because of unused r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149073
2022-06-17 04:41:30 +00:00
Masayuki Nakano
d05bec5fba Bug 1770877 - part 7: Get rid of HTMLEditor::SplitInlinesAndCollectEditTargetNodesInExtendedSelectionRanges r=m_kato
Similar to the previous patch, but there are more callers than the previous one,
we should unwrap it temporarily for the following patches.

Differential Revision: https://phabricator.services.mozilla.com/D149071
2022-06-17 03:10:11 +00:00
Masayuki Nakano
9a858bb163 Bug 1770877 - part 5: Make HTMLEditor::MoveNodesIntoNewBlockquoteElement stop touching Selection directly r=m_kato
Similar to the previous patches, nobody uses the result, but it should return
the suggestion.

Differential Revision: https://phabricator.services.mozilla.com/D149069
2022-06-16 08:16:43 +00:00
Masayuki Nakano
9f9cde52a7 Bug 1770877 - part 4: Make HTMLEditor::RemoveBlockContainerElements stop touching Selection directly r=m_kato
For aligning the style of similar methods, this makes it suggest caret position,
but nobody uses it.

Differential Revision: https://phabricator.services.mozilla.com/D149068
2022-06-16 03:34:19 +00:00
Masayuki Nakano
14344d825d Bug 1770877 - part 3: Make HTMLEditor::SplitRangeOffFromBlockAndRemoveMiddleContainer stop touching Selection directly r=m_kato
And this renames it to `RemoveBlockContainerElementWithTransactionBetween` to
explain its job simpler.

Differential Revision: https://phabricator.services.mozilla.com/D149067
2022-06-16 01:57:57 +00:00
Masayuki Nakano
e396b0eb58 Bug 1770877 - part 2: Make HTMLEditor::SplitRangeOffFromBlock stop touching Selection directly r=m_kato
The constructor of `SplitRangeOffFromNodeResult` is used only by the method.
Therefore, we can customize the constructor and make it store the caret
suggestion.

Differential Revision: https://phabricator.services.mozilla.com/D149066
2022-06-15 23:38:54 +00:00
Masayuki Nakano
cfc4b6cf51 Bug 1770877 - part 1: Make HTMLEditor::CreateOrChangeBlockContainerElement stop touching Selection directly r=m_kato
Although the its only caller does not need the caret position, it should return
a candidate caret position for aligning to the other methods.

Differential Revision: https://phabricator.services.mozilla.com/D149065
2022-06-15 22:31:38 +00:00
criss
c1b045ddda Backed out 9 changesets (bug 1772006) causing build bustages on nsTString.cpp. CLOSED TREE
Backed out changeset f17c7565707b (bug 1772006)
Backed out changeset c725fe1f5882 (bug 1772006)
Backed out changeset d19663161261 (bug 1772006)
Backed out changeset b6611ab002d9 (bug 1772006)
Backed out changeset 790f42b64af9 (bug 1772006)
Backed out changeset 79a734b4e4d9 (bug 1772006)
Backed out changeset 42730aae16ea (bug 1772006)
Backed out changeset b2542aef3054 (bug 1772006)
Backed out changeset 962bfea4a309 (bug 1772006)
2022-06-11 01:13:42 +03:00
Nika Layzell
c1e4a1e52c Bug 1772006 - Part 6: Simplify and move the string searching APIs from ns[T]StringObsolete, r=xpcom-reviewers,necko-reviewers,eeejay,dragana,barret
The biggest set of APIs from ns[T]StringObsolete which are still heavily used
are the string searching APIs. It appears the intention was for these to be
replaced by the `FindInReadable` APIs, however that doesn't appear to have
happened.

In addition, the APIs have some quirks around their handling of mixed character
widths. These APIs generally supported both narrow strings and the native
string type, probably because char16_t string literals weren't available until
c++11. Finally they also used easy-to-confuse unlabeled boolean and integer
optional arguments to control behaviour.

These patches do the following major changes to the searching APIs:

1. The ASCII case-insensitive search method was split out as
   LowerCaseFindASCII, rather than using a boolean. This should be less
   error-prone and more explicit, and allows the method to continue to use
   narrow string literals for all string types (as only ASCII is supported).
2. The other [R]Find methods were restricted to only support arguments with
   matching character types. I considered adding a FindASCII method which would
   use narrow string literals for both wide and narrow strings but it would've
   been the same amount of work as changing all of the literals to unicode
   literals.
   This ends up being the bulk of the changes in the patch.
3. All find methods were re-implemented using std::basic_string_view's find
   algorithm or stl algorithms to reduce code complexity, and avoid the need to
   carry around the logic from nsStringObsolete.cpp.
4. The implementations were moved to nsTStringRepr.cpp.
5. An overload of Find was added to try to catch callers which previously
   called `Find(..., false)` or `Find(..., true)` to set case-sensitivity, due
   to booleans normally implicitly coercing to `index_type`. This should
   probably be removed at some point, but may be useful during the transition.

Differential Revision: https://phabricator.services.mozilla.com/D148300
2022-06-10 21:12:08 +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
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
3838efc999 Bug 1767386 - part 1: Make some CSSEditUtils methods using GetCSSEquivalentToHTMLInlineStyleSetInternal return error with Result r=m_kato
`CSSEditUtils::GetCSSEquivalentToHTMLInlineStyleSetInternal` may return error
which is unexpected.  And the methods changed by this patch may cause destroying
editor if and only if they treat computed style.  Therefore, they should be
non-static members and they should return error to make each caller avoid the
unexpected cases if necessary.

Differential Revision: https://phabricator.services.mozilla.com/D145303
2022-05-09 06:03:21 +00:00