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

789 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano 1cc969671c Bug 1758420 - part 2: Clean up update timing of `TextComposition` r=m_kato
Currently, it's done at creating `CompositionTransaction`, not after executing
it.  Let's clean it up now.

Differential Revision: https://phabricator.services.mozilla.com/D141194
2022-04-21 03:37:56 +00:00
Masayuki Nakano 8b5390183f 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 9968200d7c 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 19103784eb Bug 1765018 - part 3: Make `EditorBase::FindBetterInsertionPoint` be a template method r=m_kato
To avoid the unnecessary conversion between `EditorDOMPoint` and
`EditorRawDOMPoint`, it should be a template method which can take/return either
`EditorDOMPoint` or `EditorRawDOMPoint`.

Differential Revision: https://phabricator.services.mozilla.com/D143880
2022-04-20 23:41:28 +00:00
Masayuki Nakano d58e1b92f7 Bug 1765018 - part 2: Make `EditorBase::Get(Start|End)Point` return `EditorDOMPoint` or `EditorRawDOMPoint` r=m_kato
This avoids unnecessary conversion at the callers' side, although they should be
omitted by the complier.

Differential Revision: https://phabricator.services.mozilla.com/D143879
2022-04-20 23:35:18 +00:00
Masayuki Nakano 08b1fe0b20 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 17fc88e168 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
Masayuki Nakano fc7b0ef770 Bug 1764679 - Make `GetInterlinePosition` and `SetInterlinePosition` work with new `enum class` r=smaug
It's hard to remember what the `bool` value of them means.  Therefore, there
are a lot of comment around the API users to explain what they do.  For making
it clearer and reducing the risk of specifying opposite value, they should work
with an `enum class`.

Differential Revision: https://phabricator.services.mozilla.com/D143812
2022-04-20 14:24:55 +00:00
Masayuki Nakano 36c2d519c8 Bug 1764238 - Backout the first and the second patch of bug 1758420 r=m_kato
Due to breaking `mobile.twitter.com/explore` for Hebrew IME users on Android,
this patch backs out the patches for bug 1753420 except the last patch which
just rename some methods and variables.

Differential Revision: https://phabricator.services.mozilla.com/D143684
2022-04-15 03:49:57 +00:00
Masayuki Nakano 728a229d8e Bug 1758420 - part 3: Rename `TextComposition::GetStartRef()` and `TextComposition::GetEndRef()` r=m_kato
They return IME selection range rather than composition string range.  I.e.,
when the composition does not have IME selections anymore, e.g., at committing,
they return non-set `RawRangeBoundary`.

For making the result meaning clearer, they should be
`FirstIMESelectionStartRef` and `LastIMESelectionEndRef`.

Depends on D141194

Differential Revision: https://phabricator.services.mozilla.com/D141195
2022-03-18 06:34:47 +00:00
Masayuki Nakano 6ff8aab6e3 Bug 1758420 - part 2: Clean up update timing of `TextComposition` r=m_kato
Currently, it's done at creating `CompositionTransaction`, not after executing
it.  Let's clean it up now.

Depends on D141193

Differential Revision: https://phabricator.services.mozilla.com/D141194
2022-03-18 06:34:47 +00:00
Eitan Isaacson d4418e9378 Bug 1713050 - P1: Add granularity to selection change notification. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D139745
2022-03-16 05:56:25 +00:00
Masayuki Nakano 45ba6f356a Bug 1753508 - Add logger of selection batch r=smaug
This was required for debugging the bug.

Differential Revision: https://phabricator.services.mozilla.com/D139350
2022-03-11 02:24:24 +00:00
Masayuki Nakano 5ee6119ad5 Bug 1753508 - Make `EditorBase::AutoEditActionDataSetter::UpdateSelectionCache` clean up and restart selection batch which the editor started r=smaug
When `Selection` instance is updated, the old selection may be in batch.
In the case, `UpdateSelectionCache` should clean up the batch in the old
selection and start new one in the new selection instead.

Differential Revision: https://phabricator.services.mozilla.com/D139349
2022-03-11 02:24:24 +00:00
Masayuki Nakano 0dd96f96d3 Bug 1756933 - part 1: Rename `JoinNodeTransaction` to `JoinNodesTransaction` r=m_kato
For consistency with the other things in editor module, it should be "nodes"
rather than "node" since 2 nodes are joined by it.

Differential Revision: https://phabricator.services.mozilla.com/D139715
2022-02-28 23:03:51 +00:00
Masayuki Nakano 380039601b Bug 1747132 - part 1: Make `EditorBase::IsSelectionEditable()` return `false` if selection is accidentally in a native anonymous subtree r=m_kato
Perhaps due to a bug Selection and/or Range API, selection may be in a native
anonymous subtree, and if the content is editable like in anonymous `<div>`
element in `<input>` or `<textarea>`, `HTMLEditor` may put unexpected element
into the anonymous `<div>` element.

For avoiding it, `EditorBase::IsSelectionEditable()` should return `false`
when it detects this odd situation.  Then, editing commands do not work in
the anonymous subtree.

Differential Revision: https://phabricator.services.mozilla.com/D134658
2021-12-25 21:58:43 +00:00
Masayuki Nakano fb2940808f Bug 1741148 - part 2: Re-implement `nsINode::ComputeIndexOf` as returning `Maybe<uint32_t>` rather than `int32_t` r=smaug
Offset in a node is declared as "unsigned long" by the standards and we don't
limit node can have less than `INT32_MAX`.  So it should return `uint32_t`, but
it also needs to represent the case of "not found".  For consistency with some
other APIs like `nsContentUtils::ComparePoints`, using `Maybe` must be a good
style rather than `Result<uint32_t, bool>`.

This patch fixes the callers in assertions for example.

Differential Revision: https://phabricator.services.mozilla.com/D131335
2021-12-09 09:21:52 +00:00
Masayuki Nakano f2baf0d9ab Bug 1741148 - part 1: Rename `nsINode::ComputeIndexOf` to `ComputeIndexOf_Deprecated` r=smaug
It's hard to fix some callers.  Therefore, in this bug, we should fix only
simple cases.  Therefore, we should rename existing API first.

Differential Revision: https://phabricator.services.mozilla.com/D131334
2021-12-09 08:32:30 +00:00
Masayuki Nakano 82e2013683 Bug 1735446 - part 4: Make `Selection::GetRangeAt()` take `uint32_t` instead of `int32_t` r=smaug
It's an internal API corresponding to `Selection.getRangeAt` DOM API.
I think that it should use `uint32_t` rather than `size_t` because of the
consistency with the DOM API and `Selection::RangeCount()`.

This patch fixes all callers of `GetRangeAt()`, and rewrites it with ranged-
loops unless original ones do not refer `RangeCount()` every time and may run
script in the loop.

Differential Revision: https://phabricator.services.mozilla.com/D128848
2021-12-09 07:35:09 +00:00
Masayuki Nakano 78430c342b Bug 1734507 - Make `TextEditor` guarantee that ranges to delete are in the text node r=saschanaz
Our internal code can touch internal `Selection` object of `<input>` and
`<textarea>`, thus, selection ranges in them may be not in the text node.
Therefore, we should make `TextEditor` instance try to shrink the deleting
ranges into the text node first.

In a followup bug (perhaps, bug 1734846), we should split the deletion code into
`TextEditor` and `HTMLEditor` for making the code simpler and never regressed.

Differential Revision: https://phabricator.services.mozilla.com/D133181
2021-12-08 21:37:22 +00:00
Masayuki Nakano 44969eec1c Bug 1740872 - part 1: Move `EditorBase::CreateElementWithTransaction()` into `HTMLEditor` r=m_kato
I realized that it's now used only by `HTMLEditor` so that we can move it
into `HTMLEditor` and we can make `CreateElementTransaction` treat `HTMLEditor`
directly rather than via `EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D131198
2021-11-17 04:08:46 +00:00
Greg Tatum ec908112f4 Bug 1738057 - Split out BidiEmbeddingLevel into its own file; r=platform-i18n-reviewers,dminor
This should speed up re-compile times, as mozilla/intl/Bidi.h will only
be included in a few places.

Differential Revision: https://phabricator.services.mozilla.com/D129662
2021-11-16 15:11:58 +00:00
Masayuki Nakano 925fc15324 Bug 1739933 - Make `TopLevelEditSubActionData::DidSplitNode()` handle both cases that either left or right node is a new node r=m_kato
Currently, it assumes that new node is the left node and split node is the
right node.  However, we need to make it possible to handle the case that
right node is new one for fixing bug 1735608.

Depends on D130458

Differential Revision: https://phabricator.services.mozilla.com/D130624
2021-11-09 07:11:23 +00:00
ssummar e519897f5a Bug 1738837 - Replaced usages of mozilla::Tuple with std::tuple in editor/ r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D130146
2021-11-06 13:25:27 +00:00
Masayuki Nakano 94cfff6b9a Bug 1739315 - part 1: Make `HTMLEditor::JoinNodesWithTransaction()` directly notify `TopLevelEditSubActionData::DidJoinNodes()` of joined position r=m_kato
`TopLevelEditSubActionData::WillJoinNodes()` and
`TopLevelEditSubActionData::DidJoinNodes()` are called only by
`HTMLEditor::JoinNodesWithTransaction()`.  `WillJoinNodes()` assumes that
all children or text data in `aLeftContent` is moved to head of `aRightContent`.
Therefore, it just stores length of `aLeftContent` and `DidJoinNodes()` lets
`AddPointToChangedRange()` know the joined point.

Same value is stored by `HTMLEditor::JoinNodesWithTransaction()`.  Therefore,
it can create same DOM point at calling `DidJoinNodes()` so that we can get
rid of `WillJoinNodes()`.

Differential Revision: https://phabricator.services.mozilla.com/D130348
2021-11-05 10:14:35 +00:00
Cristian Tuns bdf50d3542 Backed out 2 changesets (bug 1739315) for causing android wpt failures.
Backed out changeset cef70047defb (bug 1739315)
Backed out changeset c50c8ac11ff7 (bug 1739315)
2021-11-05 07:18:22 -04:00
Masayuki Nakano fdb27c99f9 Bug 1739315 - part 1: Make `HTMLEditor::JoinNodesWithTransaction()` directly notify `TopLevelEditSubActionData::DidJoinNodes()` of joined position r=m_kato
`TopLevelEditSubActionData::WillJoinNodes()` and
`TopLevelEditSubActionData::DidJoinNodes()` are called only by
`HTMLEditor::JoinNodesWithTransaction()`.  `WillJoinNodes()` assumes that
all children or text data in `aLeftContent` is moved to head of `aRightContent`.
Therefore, it just stores length of `aLeftContent` and `DidJoinNodes()` lets
`AddPointToChangedRange()` know the joined point.

Same value is stored by `HTMLEditor::JoinNodesWithTransaction()`.  Therefore,
it can create same DOM point at calling `DidJoinNodes()` so that we can get
rid of `WillJoinNodes()`.

Differential Revision: https://phabricator.services.mozilla.com/D130348
2021-11-05 10:14:35 +00:00
Greg Tatum ee2694c97d Bug 1719546 - Replace nsBidi with mozilla::intl::Bidi; r=platform-i18n-reviewers,dminor
Differential Revision: https://phabricator.services.mozilla.com/D128793
2021-10-20 14:01:21 +00:00
Masayuki Nakano acf1af36a8 Bug 1736507 - Make `HTMLEditor` updates its specific UI (if there is) after dispatching `input` event r=m_kato
Currently, `EditorBase::EndUpdateViewBatch()` does this, but it's before `input`
event.  Therefore, if an `input` event listener changes the target elements'
position and/or size, user will see broken UI.  Therefore, it should be updated
at editor finishes everything.

Differential Revision: https://phabricator.services.mozilla.com/D128871
2021-10-19 20:45:37 +00:00
Butkovits Atila 01c5e2aed8 Backed out 3 changesets (bug 1719546) for causing SM bustages at Bidi.h. CLOSED TREE
Backed out changeset c4d6ffc7e445 (bug 1719546)
Backed out changeset a1f7ed6c4251 (bug 1719546)
Backed out changeset e69fc596f2c3 (bug 1719546)
2021-10-19 21:09:47 +03:00
Greg Tatum f250d90114 Bug 1719546 - Replace nsBidi with mozilla::intl::Bidi; r=platform-i18n-reviewers,dminor
Differential Revision: https://phabricator.services.mozilla.com/D128793
2021-10-19 16:55:36 +00:00
Masayuki Nakano d37daf2f82 Bug 1729115 - part 3: Make `IMEStateManager` check whether given focused content matches with null `sContent` in design mode r=m_kato
`nsFocusManager` does not send `focus` event in some cases, e.g., non-editable
root element gets focus.  However, the element may become editable later without
a focus move.  Therefore, even if `IMEStateManager::sContent` is `nullptr`,
`IMEStateManager::UpdateIMEState()` and `IMEStateManager::FocusInEditor()` are
called with focused content when the uncomposed document is in design mode.

With this change, editor does not need to call `IMEStateManager` methods with
`nullptr` when it's in `designMode`.  Therefore, we can get rid of
`GetFocusedContentForIME()` which just returns `nullptr` if focused content is
in design mode.

Differential Revision: https://phabricator.services.mozilla.com/D127612
2021-10-12 04:41:14 +00:00
Masayuki Nakano 25a3c48305 Bug 1732845 - Add `nsINode::IsInDesignMode()` to check whether the node is directly in design mode r=smaug
There are a lot of check of `Document`'s editable state **with** comments. This
means that it's unclear for developers that only `Document` node is editable in
design mode.

Additionally, there are some points which use composed document rather than
uncomposed document even though the raw API uses uncomposed document. Comparing
with the other browsers, checking uncomposed document is compatible behavior,
i.e., nodes in shadow trees are not editable unless `contenteditable`.

Therefore, `nsINode` should have a method to check whether it's in design mode
or not.

Note that it may be called with a node in UA widget.  Therefore, this patch
adds new checks if it's in UA widget subtree or native anonymous subtree,
checking whether it's in design mode with its host.

Differential Revision: https://phabricator.services.mozilla.com/D126764
2021-10-12 03:14:43 +00:00
Masayuki Nakano eecd5a5f1c Bug 1727840 - Make `DeleteNodeTransaction` allow to create its instance for non-editable text node which was created or modified by an editor r=m_kato
Although we don't have a testcase, `HTMLEditor` may need to delete a text node
if it's created for composition.  If it's not allowed, users may see staying
composition string in disabled editor.

Differential Revision: https://phabricator.services.mozilla.com/D125502
2021-09-15 00:20:19 +00:00
Masayuki Nakano 153b43e7e2 Bug 1720809 - part 2: Make `insertLineBreak` command handler in `HTMLEditor` insert a linefeed character instead of `<br>` element in same condition as Blink/WebKit r=m_kato
Similar to the previous patch, this patch makes `insertLineBreak` command
handler of `HTMLEditor` may insert a linefeed character instead of `<br>`
element for compatibility with Blink/WebKit.

Note that for making same name rules as `insertParagraphSeparator` command
handlers, this patch renames
`HTMLEditor::InsertBRElementAtSelectionWithTransaction()` to
`InsertLineBreakAsSubAction()` and moves
`EditorBase::InsertLineBreakAsSubAction()` to `TextEditor` since it's
used only by `TextEditor` instance.

Depends on D124731

Differential Revision: https://phabricator.services.mozilla.com/D124732
2021-09-10 21:45:47 +00:00
Neil Deakin 4d1d84fe2f Bug 1727176, use the principal to determine the source of the drag, r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D123522
2021-08-31 00:58:35 +00:00
Masayuki Nakano 622c7ee8f0 Bug 1727185 - part 2: Add removable node checks for more callers of `DeleteNodeTransaction::MaybeCreate()` r=m_kato
I just missed some callers of it.  And I also make
`EditorBase::DeleteNodeTransaction()` a virtual method and `HTMLEditor` override
it.  Then, even if it's called by helper classes, the `HTMLEditor` version is
always called.

Differential Revision: https://phabricator.services.mozilla.com/D123578
2021-08-27 00:49:35 +00:00
Masayuki Nakano 6122a660a0 Bug 1723125 - Ignore normal selection when updating composition string r=m_kato
Web apps can modify normal selection even during IME composition and no
browsers stop composition by it.  However, our editor tries to delete
non-collapsed selected range before updating composition.  Therefore,
we need additional state at handling inserting text whether selection
should be deleted or ignored.

Depends on D121371

Differential Revision: https://phabricator.services.mozilla.com/D121372
2021-08-02 08:23:50 +00:00
Masayuki Nakano f4d6fde8cd Bug 1718924 - part 13: Move `TextServicesDocument::NodeHasOffsetEntry()` into `OffsetEntryArray` r=m_kato
Depends on D119159

Differential Revision: https://phabricator.services.mozilla.com/D119160
2021-07-13 10:46:40 +00:00
Masayuki Nakano 637a88b524 Bug 1718815 - part 4: Move `EditorBase::AppendNodeToSelectionAsRange()` and `EditorBase::ClearSelection()` to `HTMLEditor` r=m_kato
Depends on D119003

Differential Revision: https://phabricator.services.mozilla.com/D119004
2021-07-02 08:23:46 +00:00
Masayuki Nakano a68528b057 Bug 1718815 - part 2: Move `EditorBase::AutoSelectionRestorer` and `EditorBase` methods called only by it to `HTMLEditor` r=m_kato
Unfortunately, marking its constructor and destructor as `MOZ_CAN_RUN_SCRIPT`,
`Maybe<AutoSelectionRestorer>::reset()` and
`Maybe<AutoSelectionRestorer>::emplace()` cause bustage.  Therefore, this patch
just mark them as `MOZ_CAN_RUN_SCRIPT_BOUNDARY`.

Note that `EditorBase::SavedSelectionRef()` cannot be moved to `HTMLEditor`
because `mEditActionData` is a private member of `EditorBase`.

Depends on D119001

Differential Revision: https://phabricator.services.mozilla.com/D119002
2021-07-02 08:23:45 +00:00
Masayuki Nakano 347bc5719a Bug 1714914 - Make editor classes treat offset in parent node as uint32_t r=m_kato
It should be treated as `uint32_t` since DOM API does so.  However, there are
some exceptions:

* Result of `nsINode::ComputeIndexOf()`
* Result of `nsAString` methods

They return `-1` as not found, and anyway, they cannot treat large integer
than `INT32_MAX`.  Therefore, this patch does not touch around them.

Differential Revision: https://phabricator.services.mozilla.com/D118933
2021-06-30 07:07:28 +00:00
Masayuki Nakano f8426533d4 Bug 1717178 - part 8: Get rid of `nsIEditor.doTransaction()` because of unused r=m_kato
Depends on D118803

Differential Revision: https://phabricator.services.mozilla.com/D118805
2021-06-28 12:08:51 +00:00
Masayuki Nakano 917dc274f8 Bug 1717178 - part 7: Get rid of `nsIEditor::AddEditorObserver()` and `nsIEditorObserver` interface because of unused r=m_kato
Depends on D118802

Differential Revision: https://phabricator.services.mozilla.com/D118803
2021-06-28 12:08:51 +00:00
Masayuki Nakano 63d372da2f Bug 1676702 - part 2: Make `TextControlState` initialize `TextEditor` with `PasswordMaskData` r=m_kato
During a `TextControlState` alive, `PasswordMaskData` should be alive too.
Otherwise, we cannot keep unmasked range at reframing.

Depends on D118756

Differential Revision: https://phabricator.services.mozilla.com/D118757
2021-06-28 04:37:54 +00:00
Masayuki Nakano 88b5b85325 Bug 1717749: Drop `MOZ_ASSERT` check for `nsIEditor.eEditorMailMask` r=m_kato
In my understanding at fixing bug 1717156, `nsIEditor.eEditorMailMask` won't be
set to `TextEditor` instance.  However for making consistent **spellchecker**
behavior on email composer, subject editor is also set this flag.  So, we need
to drop the check in `SetFlags` and IsMailEditor.

Differential Revision: https://phabricator.services.mozilla.com/D118561
2021-06-23 23:01:48 +00:00
Masayuki Nakano 3485a15088 Bug 1717156 - part 6: Get rid of `nsIEditor::eEditorDontEchoPassword` r=m_kato
It's used only by password field, i.e., only by `TextEditor`, and used
temporarily.  Additionally, there is some space in `TextEditor`.  So, we
can get rid of it, and make `TextEditor` store it directly.

Note that this allows to skip expensive `nsIEditor::SetFlags()` calls by
`AutoRestoreEditorState`.  This may improve setting `<input>.value` performance.

Differential Revision: https://phabricator.services.mozilla.com/D118266
2021-06-22 00:18:08 +00:00
Masayuki Nakano e178e6da17 Bug 1717156 - part 5: Get rid of `nsIEditor::eEditorNoCSSMask` r=m_kato
Now, `nsIEditor::eEditorNoCSSMask` is used only in the editor internally.
And it's available and meaningful only with `HTMLEditor` instance.  So,
we can get rid of it from `EditorBase`.  Fortunately, `HTMLEditor` always
creates `CSSEditUtils` and it stores the raw value indicating whether the
editor manager enabled or disabled CSS.  Therefore, we don't need new
member variable in `HTMLEditor` for storing the flag.  And this allows us
to remove `nsIEditor::SetFlags()` override of `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D118265
2021-06-22 00:18:07 +00:00
Masayuki Nakano 148a74cbc3 Bug 1717156 - part 4: Drop `Tab` key handling in `EditorBase` r=m_kato
Now, `EditorBase::IsTabable()` returns true only when it's an `HTMLEditor`
instance and `nsIEditor::eEditorAllowInteraction` is not set.  Additionally,
nobody controls the flag of `TextEditor`.  So, we can make the flag available
only with `HTMLEditor` instance, and `Tab` key handling in `EditorBase`
can be moved to `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D118264
2021-06-22 00:18:07 +00:00
Masayuki Nakano 666946b157 Bug 1717156 - part 2: Get rid of `nsIEditor::eEditorWidgetMask` and its accessor r=m_kato
With the previous patch, we know `nsIEditor::eEditorWidgetMask` always
matches with `EditorBase::IsTextEditor()`.  And it's not referred from JS
(including comm-central and BlueGriffon).  So, we can get rid of it.

Differential Revision: https://phabricator.services.mozilla.com/D118262
2021-06-22 00:18:06 +00:00
Masayuki Nakano 0e68fa3f7e Bug 1717156 - part 1: Make editor type specific flags clearer with `MOZ_ASSERT` r=m_kato
Some `nsIEditor::eEditor*Mask` flags are now only for `TextEditor` or
`HTMLEditor`.  For making it clearer, add `MOZ_ASSERT` to the `SetFlags` and
each flag accessor.

Differential Revision: https://phabricator.services.mozilla.com/D118261
2021-06-22 00:18:05 +00:00
Kagami Sascha Rosylight e40714855d Bug 1716728 - Part 7: Move mPaddingBRElementForEmptyEditor to HTMLEditor r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D118074
2021-06-21 01:49:01 +00:00
Kagami Sascha Rosylight 89ab198242 Bug 1716728 - Part 6: Add HTMLEditor::ReflectPaddingBRElementForEmptyEditor() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D118071
2021-06-21 01:49:00 +00:00
Kagami Sascha Rosylight 17fdc5f56b Bug 1716728 - Part 5: Move EnsureNoPaddingBRElementForEmptyEditor to HTMLEditor r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D118068
2021-06-21 01:49:00 +00:00
Kagami Sascha Rosylight 24eb2dca60 Bug 1716728 - Part 3: Move MaybeCreatePaddingBRElementForEmptyEditor to HTMLEditor r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D118065
2021-06-21 01:48:59 +00:00
Kagami Sascha Rosylight 7851edce6e Bug 1716728 - Part 1: Use IsEmpty() instead of mPaddingBRElementForEmptyEditor existence check r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D118063
2021-06-21 01:48:58 +00:00
Masayuki Nakano 698fd90470 Bug 1716746 - Rename `EditorBase::IsPlaintextEditor()` to `IsInPlaintextMode()` r=m_kato
Developers may be confused at `IsTextEditor()` and `IsPlaintextEditor()`. When
the latter is `true`, the former is always `true`, but it may be `true` when the
editor is `HTMLEditor` too. So, it's a mode of  `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D118246
2021-06-18 20:35:48 +00:00
Kagami Sascha Rosylight 673eb02a8f Bug 1713334 - Part 4: Always select the text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117474
2021-06-18 00:36:55 +00:00
Kagami Sascha Rosylight 688fa49f4c Bug 1713334 - Part 3: Assume TextEditor always have a text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117023
2021-06-18 00:36:54 +00:00
Kagami Sascha Rosylight 9b640ade5b Bug 1713334 - Part 2: Initialize TextEditor always with a text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117022
2021-06-18 00:36:54 +00:00
Kagami Sascha Rosylight 8bbe7f3f11 Bug 1713334 - Part 1: Keep a text node inside text controls even if empty r=masayuki,Jamie
Doing so prevents confusion when detecting selection change.

Differential Revision: https://phabricator.services.mozilla.com/D116303
2021-06-18 00:36:53 +00:00
Ryan VanderMeulen a337a14382 Backed out 5 changesets (bug 1713334) for causing bug 1716714.
Backed out changeset bd1c37ce2c61 (bug 1713334)
Backed out changeset 876ed18c5126 (bug 1713334)
Backed out changeset 5a4f4514d99a (bug 1713334)
Backed out changeset 7d7feef654c7 (bug 1713334)
Backed out changeset 61e15374e617 (bug 1713334)
2021-06-17 10:57:32 -04:00
Kagami Sascha Rosylight 7916262845 Bug 1713334 - Part 4: Always select the text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117474
2021-06-14 19:56:23 +00:00
Kagami Sascha Rosylight d6d3699b31 Bug 1713334 - Part 3: Assume TextEditor always have a text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117023
2021-06-14 19:56:23 +00:00
Kagami Sascha Rosylight 4a9087283b Bug 1713334 - Part 2: Initialize TextEditor always with a text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117022
2021-06-14 19:56:23 +00:00
Kagami Sascha Rosylight 52d022e717 Bug 1713334 - Part 1: Keep a text node inside text controls even if empty r=masayuki,Jamie
Doing so prevents confusion when detecting selection change.

Differential Revision: https://phabricator.services.mozilla.com/D116303
2021-06-14 19:56:22 +00:00
Csoregi Natalia 85bb87115a Backed out 5 changesets (bug 1713334) for failures on test_texteditor_keyevent_handling.html. CLOSED TREE
Backed out changeset ab7b2061f5e8 (bug 1713334)
Backed out changeset f4032094748d (bug 1713334)
Backed out changeset 858410646bf7 (bug 1713334)
Backed out changeset 875b520387b8 (bug 1713334)
Backed out changeset 78b0cdebc890 (bug 1713334)
2021-06-14 20:58:37 +03:00
Kagami Sascha Rosylight ca55613fb3 Bug 1713334 - Part 4: Always select the text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117474
2021-06-14 13:08:33 +00:00
Kagami Sascha Rosylight 237a6dbabc Bug 1713334 - Part 3: Assume TextEditor always have a text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117023
2021-06-14 13:08:33 +00:00
Kagami Sascha Rosylight 760acf8789 Bug 1713334 - Part 2: Initialize TextEditor always with a text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117022
2021-06-14 13:08:32 +00:00
Kagami Sascha Rosylight b327288d9d Bug 1713334 - Part 1: Keep a text node inside text controls even if empty r=masayuki,Jamie
Doing so prevents confusion when detecting selection change.

Differential Revision: https://phabricator.services.mozilla.com/D116303
2021-06-14 13:08:32 +00:00
Masayuki Nakano 5423cae57c Bug 1560396 - Replace `EditorBase::GetNodeAtRangeOffsetPoint()` with new API in `EditorDOMPointBase` r=m_kato
It's a static method and called only with `EditorDOMPointBase` instances.
So, we can add new API to `EditorDOMPointBase` instead.

Note that it's changed to return container when the container is a data node
rather than a text node.  This should be better because no data node can
have children.

Depends on D117382

Differential Revision: https://phabricator.services.mozilla.com/D117490
2021-06-11 08:57:18 +00:00
Masayuki Nakano db1228b24c Bug 1714918 - Sort out editor class accessors of `nsIEditor` r=m_kato
For consistency with the similar internal DOM API, `As*()` should just cast
the type without checking editor type.  Instead, `GetAs*()` should do it.

Differential Revision: https://phabricator.services.mozilla.com/D117381
2021-06-11 03:01:08 +00:00
Masayuki Nakano 96627061a2 Bug 1540037 - part 47: Move `TextEditor::InitEditorContentAndSelection()` to `EditorBase` r=m_kato
Depends on D117114

Differential Revision: https://phabricator.services.mozilla.com/D117115
2021-06-09 03:47:38 +00:00
Masayuki Nakano f41bc0674d Bug 1540037 - part 46: Move `TextEditor::EnsurePaddingBRElementInMultilineEditor()` into `EditorBase` r=m_kato
It's used by `TextEditor` and `HTMLEditor` in the plaintext mode.  Therefore,
it should be moved into `EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D117114
2021-06-09 03:47:38 +00:00
Masayuki Nakano 25db446d2f Bug 1540037 - part 45: Move `TextEditor::OnDrop()` into `EditorBase` r=m_kato
Depends on D116802

Differential Revision: https://phabricator.services.mozilla.com/D116803
2021-06-07 11:38:18 +00:00
Masayuki Nakano 78c3880b23 Bug 1540037 - part 42: Move `TextEditor::DeleteSelectionByDragAsAction()` into `EditorBase` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D116569
2021-06-04 05:23:05 +00:00
Masayuki Nakano 875fdeac2f Bug 1540037 - part 41: Split `TextEditor::PasteAsAction()` r=m_kato
It should be a virtual method derived from `EditorBase`, and `TextEditor`
and `HTMLEditor` should override it.  Then, `nsIEditor::Paste()` requires
referring vtable again if we keep implementing it only in `EditorBase`.
Therefore, this patch avoid it with implementing it in both `TextEditor`
and `HTMLEditor`.

Depends on D116567

Differential Revision: https://phabricator.services.mozilla.com/D116568
2021-06-04 05:01:39 +00:00
Masayuki Nakano 0ffb058047 Bug 1540037 - part 40: Move `TextEditor::PrepareTransferable()` into `EditorUtils` r=m_kato
It just creates an `nsITransferable` instance and add 2 flavors for storing
plain text.  Therefore, it can be in `EditorUtils` instead.

Depends on D116566

Differential Revision: https://phabricator.services.mozilla.com/D116567
2021-06-04 04:32:28 +00:00
Masayuki Nakano 9bb09489ad Bug 1540037 - part 39: Move `TextEditor::IsSafeToInsertData()` into `EditorBase` r=m_kato
Depends on D116565

Differential Revision: https://phabricator.services.mozilla.com/D116566
2021-06-04 03:28:24 +00:00
Masayuki Nakano 957175245e Bug 1540037 - part 38: Move `TextEditor::InsertTextAt()` into `EditorBase` r=m_kato
Depends on D116564

Differential Revision: https://phabricator.services.mozilla.com/D116565
2021-06-03 21:00:07 +00:00
Masayuki Nakano b5894800b8 Bug 1540037 - part 37: Move `TextEditor::PrepareToInsertContent()` into `EditorBase` r=m_kato
Depends on D116541

Differential Revision: https://phabricator.services.mozilla.com/D116564
2021-06-03 19:48:47 +00:00
Masayuki Nakano d064dce6e2 Bug 1713867 - Make `EditorBase::ComputeValueInternal` handle the case when there is only a padding <br> element for empty editor r=m_kato
It stopped using `ComputeValueFromTextNodeAndBRElement` for `HTMLEditor` case.
However, `ComputeValueFromTextNodeAndBRElement` handles the case that there is
only padding `<br>` element for empty editor even if the instance is
`HTMLEditor`.

So, this patch makes it handle this special case by itself before checking
whether the instance is `TextEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D116541
2021-06-03 08:03:41 +00:00
Masayuki Nakano 11211e435b Bug 1540037 - part 36: Make `EditorBase` handle `Delete`, `Backspace` and `Tab` of plaintext editor mode r=m_kato
`Delete` and `Backspace` keys are handled by same code.  So, the code should
be in `EditorBase` instead of `TextEditor`.

If `HTMLEditor` is in the plaintext editing mode of mail composer, `Tab` key
is also handled by the same code as `TextEditor`.  So, the code in `TextEditor`
should be moved to `EditorBase` too and `HTMLEditor` should call `EditorBase`'s
method only when it's in the plaintext mode.

Depends on D116352

Differential Revision: https://phabricator.services.mozilla.com/D116353
2021-06-01 08:51:25 +00:00
Masayuki Nakano 4814221877 Bug 1540037 - part 35: Make `TextEditor` and `HTMLEditor` handle modifier keys' `eKeyPress` event directly r=m_kato
Such events shouldn't be fired, but for now, we should make them handled in
the overrides.  Then, we can avoid the skipping `TextEditor` case from
`HTMLEditor`.

Depends on D116351

Differential Revision: https://phabricator.services.mozilla.com/D116352
2021-06-01 08:29:17 +00:00
Masayuki Nakano c9d764ea8a Bug 1540037 - part 34: Create `HandleKeyPressEventInReadOnlyMode()` r=m_kato
In any types of editor, `EditorBase` handles if it's in the read-only mode.
For making `HandleKeyPressEvent` relation between classes simpler, let's
handle it in an independent method.

Depends on D116350

Differential Revision: https://phabricator.services.mozilla.com/D116351
2021-06-01 07:51:48 +00:00
Masayuki Nakano e3e525a13b Bug 1540037 - part 33: Implement `nsIEditor::OutputToString()` in `EditorBase` rather than `TextEditor` r=m_kato
It's used both with `TextEditor` instance and `HTMLEditor` instance.  So, it
should be implemented in `EditorBase`.

Depends on D116349

Differential Revision: https://phabricator.services.mozilla.com/D116350
2021-06-01 07:51:47 +00:00
Masayuki Nakano 236d1d1228 Bug 1540037 - part 32: Move `TextEditor::ComputeValueInternal()` into `EditorBase` r=m_kato
Depends on D116348

Differential Revision: https://phabricator.services.mozilla.com/D116349
2021-06-01 02:17:50 +00:00
Masayuki Nakano 11f319ab64 Bug 1540037 - part 31: Move `TextEditor::GetAndIniitDocEncoder()` into `EditorBase` r=m_kato
It's a helper method of `TextEditor::ComputeValueInternal()` which is used by
`TextEditor` and `HTMLEditor::Rewrap()`.  So, before we move
`ComputeValueInternal()`, we need to move this first.

Depends on D116347

Differential Revision: https://phabricator.services.mozilla.com/D116348
2021-05-31 23:41:00 +00:00
Masayuki Nakano abb1aff2ff Bug 1540037 - part 29: Move `nsIEditor.documentCharacterSet` definitions into `HTMLEditor` r=m_kato
The attribute is used only with `HTMLEditor`, and it does not make sense to
access document's character-set via `TextEditor`.  Therefore, this patch
makes it implement in `HTMLEditor` (`EditorBase` will return
`NS_ERROR_NOT_AVAILABLE` both getter and setter).

Note that `EditorBase::GetDocumentCharsetInternal()` is required by
`TextEditor::ComputeValueInternal()`.  Therefore, it needs to stay in
`EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D115948
2021-05-26 07:45:02 +00:00
Masayuki Nakano 3104bf1689 Bug 1540037 - part 28: Add pure virtual methods to `EditorBase`, which are originated from `TextEditor` r=m_kato
`TextEditor` declares some virtual methods newly.  However, for moving some
methods from `TextEditor` to `EditorBase`, they should be accessible from
`EditorBase`.  Therefore, this patch adds declarations of pure virtual
methods of them to `EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D115796
2021-05-26 02:00:45 +00:00
Masayuki Nakano 85cc2d756b Bug 1540037 - part 26: Get rid of `TextEditor::Copy()` r=m_kato
It's common method of `TextEditor` and `HTMLEditor`, but implemented by
`TextEditor` even though it's an override of `nsIEditor`'s method.

Therefore, it should be implemented in `EditorBase` instead.

Differential Revision: https://phabricator.services.mozilla.com/D115794
2021-05-26 01:13:23 +00:00
Masayuki Nakano 98b26adadd Bug 1540037 - part 25: Move `TextEditor::CutAsAction()` to `EditorBase` r=m_kato
It's a common method to cut selection.  Therefore, it should be in `EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D115793
2021-05-26 00:25:30 +00:00
Masayuki Nakano f5499c4636 Bug 1540037 - part 24: Move `TextEditor::FireClipboardEvent()` to `EditorBase` r=m_kato
It's used by `HTMLEditor` too.  So, we should move it into `EditorBase`.

Depends on D115791

Differential Revision: https://phabricator.services.mozilla.com/D115792
2021-05-25 11:47:14 +00:00
Masayuki Nakano 8b5b4c1e04 Bug 1540037 - part 23: Move `TextEditor::AreClipboardCommandsUnconditionallyEnabled()` into `EditorBase` r=m_kato
This is used by `HTMLEditor` too.  So, this should be a method of `EditorBase`.

Depends on D115790

Differential Revision: https://phabricator.services.mozilla.com/D115791
2021-05-25 11:47:14 +00:00
Masayuki Nakano 585be1beb9 Bug 1540037 - part 22: Move `IsCopyCommandEnabled()` and `IsCutCommandEnabled()` from `TextEditor` to `HTMLEditor` r=m_kato
Of course, they are used for `HTMLEditor` instances too.  Therefore, they
should be in `EditorBase` rather than `TextEditor`.

Depends on D115789

Differential Revision: https://phabricator.services.mozilla.com/D115790
2021-05-25 08:32:57 +00:00
Masayuki Nakano c0aa5a2f3f Bug 1540037 - part 20: Move `UndoAsAction()` and `RedoAsAction()` from `TextEditor` to `EditorBase` r=m_kato
They just work with a transaction manager and transactions, and they are used
by both `TextEditor` and `HTMLEditor`.  Therefore, they should be in
`EditorBase` for making `HTMLEditor` stop inheriting `TextEditor` in the
future.

Depends on D115787

Differential Revision: https://phabricator.services.mozilla.com/D115788
2021-05-25 06:46:18 +00:00
Masayuki Nakano 95c41d54c3 Bug 1540037 - part 19: Make `IsEmpty()` be a virtual method of `EditorBase` and implement `nsIEditor::GetDocumentIsEmpty()` in `EditorBase` r=m_kato
Currently, `EditorBase::GetDocumentIsEmpty()` is implemented by `TextEditor`,
and it refers only `IsEmpty()` which is implemented both by `TextEditor` and
`HTMLEditor`.  So, `IsEmpty()` should be a virtual method of `EditorBase`,
then, `EditorBase` can implement `GetDocumentIsEmpty()`.

Depends on D115786

Differential Revision: https://phabricator.services.mozilla.com/D115787
2021-05-25 04:53:01 +00:00
Masayuki Nakano ae69b73075 Bug 1540037 - part 18: Move `ReplaceTextAsAction()` and `ReplaceSelectionAsSubAction()` to `EditorBase` r=m_kato
They are used by setting text value of `TextEditor` or replacing a misspelled
word with a new word in both `TextEditor` and `HTMLEditor`.  Therefore,
they should be in the `EditorBase` rather than `TextEditor`.

Note that the path of the former case may be in a hot path.  Therefore, we need
to keep redirecting to `TextEditor` for keeping the performance only in the
case.

Depends on D115785

Differential Revision: https://phabricator.services.mozilla.com/D115786
2021-05-25 04:26:14 +00:00
Masayuki Nakano de91059947 Bug 1540037 - part 17: Move `TextEditor::OnInputText()` into `EditorBase` r=m_kato
This method is semi-public method, meaning that this is commonly used by
public methods which handle various user input and that causes inputting
text, both in `TextEditor` and `HTMLEditor`.

Therefore, for making `HTMLEditor` stop inheriting `TextEditor` class in the
future, we should move it into `EditorBase`.

Depends on D115784

Differential Revision: https://phabricator.services.mozilla.com/D115785
2021-05-25 04:12:14 +00:00
Masayuki Nakano 1a7abaeafa Bug 1540037 - part 16: Move composition event handlers from `TextEditor` to `EditorBase` r=m_kato
IME is available in both `TextEditor` and `HTMLEditor`, and the handling
code is almost same (they partially do different things with checking
`IsHTMLEditor()`).  Therefore, we should move them to `EditorBase` for
making `HTMLEditor` possible to inherit only `EditorBase` in the future.

Differential Revision: https://phabricator.services.mozilla.com/D115784
2021-05-25 02:06:32 +00:00
Masayuki Nakano 1a6a786787 Bug 1627175 - part 65: Move `HTMLEditor::GetDeepestEditableOnlyChildDivBlockquoteOrListElement()` to `HTMLEditUtils` r=m_kato
And also `HTMLEditor::CountEditableChildren()` is moved since it's used only by
it.

Despite the long method name, it's really unclear what it does.  I try to
explain it with new name, but the things which the method does are not make
sense.  So, if you have better name idea, I'll take it...

Differential Revision: https://phabricator.services.mozilla.com/D115177
2021-05-18 05:52:25 +00:00
Masayuki Nakano 91727d78a7 Bug 1627175 - part 48: Get rid of `HTMLEditUtils::GetFirstEditableLeafContent()` due to unused r=m_kato
I realized that it's used only by the dead path because the only caller,
`EditorBase::BeginningOfDocument()` is overridden by `HTMLEditor` and
is never called.

Differential Revision: https://phabricator.services.mozilla.com/D115117
2021-05-17 05:37:24 +00:00
Masayuki Nakano 812ed2fc52 Bug 1707630 - part 3: Make `EditorBase::CreateNodeWithTransaction()` return error if failed r=m_kato
Depends on D113473

Differential Revision: https://phabricator.services.mozilla.com/D113474
2021-04-28 03:33:26 +00:00
Masayuki Nakano 39b71b059e Bug 1707630 - part 2: Make `HTMLEditor::PrepareToInsertBRElement()` return error if failed r=m_kato
Depends on D113472

Differential Revision: https://phabricator.services.mozilla.com/D113473
2021-04-28 03:33:26 +00:00
Masayuki Nakano 3aef835f6c Bug 1627175 - part 38: Move `EditorBase::GetNextContent()` and `EditorBase::GetPreviousContent()` to `HTMLEditUtils` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D113242
2021-04-27 11:17:44 +00:00
Masayuki Nakano 7da0836039 Bug 1627175 - part 37: Get rid of editor type argument from `EditorBase::GetNextContent()` and `EditorBase::GetPreviousContent()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D113241
2021-04-27 11:17:43 +00:00
Masayuki Nakano 267025f6e5 Bug 1627175 - part 36: Make `EditorBase::CreateTransactionForCollapsedRange()` use `EditorBase::GetNextContent()` and `EditorBase::GetPreviousContent()` only when it's an `HTMLEditor` r=m_kato
If the editor instance is a `TextEditor`, the root element has to be
anonymous `<div>` element and it has only one text node when it has non-empty
value.  Therefore, if it's in `TextEditor`, the method does not need to use
the complicated APIs for finding a text node from the anonymous `<div>` element
or padding `<br>` element since it can adjust the given point into the text
node without such API.

Differential Revision: https://phabricator.services.mozilla.com/D113240
2021-04-27 11:17:43 +00:00
Masayuki Nakano 4e78552ddb Bug 1627175 - part 35: Move `EditorBase::GetFirstEditableNode()` into `HTMLEditUtils` r=m_kato
Only the user is `EditorBase::BeginningOfDocument()` which is used by both
`TextEditor` and `HTMLEditor`.  However, if it's a `TextEditor`, expected
result is only the first text node only when there is one.  Therefore, we can
move it into `HTMLEditUtils` and make `EditorBase::BeginningOfDocument()`
find the text node by it self.  Then, we can get rid of using
`EditorBase::GetEditorType()` in this case.

Differential Revision: https://phabricator.services.mozilla.com/D113239
2021-04-27 11:17:43 +00:00
Masayuki Nakano 1b0d3e96c4 Bug 1627175 - part 34: Make `EditorBase::GetNextContent()` and `EditorBase::GetPreviousContent()` static r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D113238
2021-04-27 11:17:42 +00:00
Masayuki Nakano 4debffd39d Bug 1627175 - part 33: Make `EditorBase::FindNode()` and `EditorBase::FindNextLeafNode()` static r=m_kato
They are instance members of `EditorBase` only for referring editor type and
editing host.  Therefore, we can make them static with making them take
editor type and ancestor limiter as arguments.

Depends on D113236

Differential Revision: https://phabricator.services.mozilla.com/D113237
2021-04-27 11:17:42 +00:00
Masayuki Nakano 1cc0a524f6 Bug 1627175 - part 31: Get rid of `EditorBase::GetNextEditableNode()` and `EditorBase::GetPreviousEditableNode()` r=m_kato
Depends on D113234

Differential Revision: https://phabricator.services.mozilla.com/D113235
2021-04-27 11:17:41 +00:00
Masayuki Nakano 82aa5b8992 Bug 1627175 - part 26: Rename `EditorBase::Get*NodeInternal()` to `Get*Content()` r=m_kato
The following patches will get rid of inline wrapper methods of them.
Therefore, they shouldn't be called as "internal".  And they return
`nsIContent*` instead of `nsINode*` so, `Get*Content()` is better name for
them.

Depends on D113229

Differential Revision: https://phabricator.services.mozilla.com/D113230
2021-04-27 11:17:39 +00:00
Masayuki Nakano a525512d98 Bug 1627175 - part 25: Rename `WalkTreeOption::FindAnyDataNode` to `WalkTreeOption::IgnoreDataNodeExceptText` r=m_kato
So, the meaning is reverted of this action.  But with this change, the scanner
methods scans any nodes by default.  This is simpler to understand from the
callers.

Depends on D113228

Differential Revision: https://phabricator.services.mozilla.com/D113229
2021-04-27 11:17:39 +00:00
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 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 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
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 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 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
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
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
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
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
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
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
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 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 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
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
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 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
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
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
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
Kagami Sascha Rosylight 11ef0ef23e Bug 1623413 - Part 2: Rename Collapse() to CollapseInLimiter() r=masayuki
Depends on D88702

Differential Revision: https://phabricator.services.mozilla.com/D88920
2020-09-03 03:45:26 +00:00
Mihai Alexandru Michis 0600dacd03 Backed out 3 changesets (bug 1623413) for causing failures in Selection_collapse.html
CLOSED TREE

Backed out changeset d3d67293f115 (bug 1623413)
Backed out changeset 75ed1b8a5c67 (bug 1623413)
Backed out changeset 0eef32d6a454 (bug 1623413)
2020-09-03 05:37:49 +03:00
Kagami Sascha Rosylight 010d7de462 Bug 1623413 - Part 2: Rename Collapse() to CollapseInLimiter() r=masayuki
Depends on D88702

Differential Revision: https://phabricator.services.mozilla.com/D88920
2020-09-02 23:42:27 +00:00
Masayuki Nakano 06407fa939 Bug 1658702 - part 4: Make `AutoDeleteRangesHandler::ComputeRangesToDelete()` extend collapsed ranges for deleting adjacent character or word or the line r=m_kato
This patch adding computation code corresponding to:
https://searchfox.org/mozilla-central/rev/27932d4e6ebd2f4b8519865dad864c72176e4e3b/editor/libeditor/HTMLEditSubActionHandler.cpp#3157-3185

For `beforeinput` event listeners, `AutoSetTemporaryAncestorLimiter` is not
enough since when `beforeinput` event listeners modifies `Selection`, the
ancestor limit is not set when it has a job.  Perhaps, we should make editor
stop using focus/blur event listener and makes `nsFocusManager` notifies
editor of them synchronously before dispatching the events.  But it's not
scope of this bug at least.

Differential Revision: https://phabricator.services.mozilla.com/D88379
2020-09-01 02:04:02 +00:00