When all editor text is replaced while handling a user operation, editor
needs to dispatch "input" event. Therefore, in such case, i.e., EditAction
is eReplaceText, TextEditor::SetTextAsSubAction() needs to handle it instead
of TextEditRules::WillSetText().
Differential Revision: https://phabricator.services.mozilla.com/D12246
--HG--
extra : moz-landing-system : lando
This patch creates new path to insert a line break in TextEditor.
Declares new EditSubAction::eInsertLineBreak and makes the path use
EditAction::eInsertLineBreak instead of EditAction::eInsertParagraphSeparator.
Unfortunately, this patch makes TextEditor::InsertLineBreakAsAction() as
a virtual method for keeping this change as small as possible.
Differential Revision: https://phabricator.services.mozilla.com/D10524
--HG--
extra : moz-landing-system : lando
When TextEditRules::WillDoAction() and HTMLEditRules::WillDoAction() didn't
return error, didn't handle it, and didn't cancel it,
TextEditor::InsertParagraphSeparatorAsSubAction() inserts a line breaker.
However, this case is only when the instance is TextEditRules and
TextEditRules::WillInsertLineBreak() prepares to insert a line break without
any errors. So, we can move the part into TextEditRules::WillInsertLineBreak()
simply.
Differential Revision: https://phabricator.services.mozilla.com/D10523
--HG--
extra : moz-landing-system : lando
With this cleaning up, we can know when they return NS_OK with both
aCanceled is false and aHandled is false. (Look for EditActionIgnored().)
Additionally, this patch renames HTMLEditRules::WillInsertBreak() to
WillInsertParagraphSeparator() and TextEditRules::WillInsertBreak() to
TextEditRules::WillInsertLineBreak().
Differential Revision: https://phabricator.services.mozilla.com/D10522
--HG--
extra : moz-landing-system : lando
This patch creates new path to insert a line break in TextEditor.
Declares new EditSubAction::eInsertLineBreak and makes the path use
EditAction::eInsertLineBreak instead of EditAction::eInsertParagraphSeparator.
Unfortunately, this patch makes TextEditor::InsertLineBreakAsAction() as
a virtual method for keeping this change as small as possible.
Differential Revision: https://phabricator.services.mozilla.com/D10524
--HG--
extra : moz-landing-system : lando
When TextEditRules::WillDoAction() and HTMLEditRules::WillDoAction() didn't
return error, didn't handle it, and didn't cancel it,
TextEditor::InsertParagraphSeparatorAsSubAction() inserts a line breaker.
However, this case is only when the instance is TextEditRules and
TextEditRules::WillInsertLineBreak() prepares to insert a line break without
any errors. So, we can move the part into TextEditRules::WillInsertLineBreak()
simply.
Differential Revision: https://phabricator.services.mozilla.com/D10523
--HG--
extra : moz-landing-system : lando
With this cleaning up, we can know when they return NS_OK with both
aCanceled is false and aHandled is false. (Look for EditActionIgnored().)
Additionally, this patch renames HTMLEditRules::WillInsertBreak() to
WillInsertParagraphSeparator() and TextEditRules::WillInsertBreak() to
TextEditRules::WillInsertLineBreak().
Differential Revision: https://phabricator.services.mozilla.com/D10522
--HG--
extra : moz-landing-system : lando
When inputting any character in password field, character isn't masked
immediately since echo password is turned on Android. But when pasting text,
the text is masked immediately on Blink and Android OS.
So we should adopt this behaviour on Gecko too.
Differential Revision: https://phabricator.services.mozilla.com/D10530
--HG--
extra : rebase_source : b4bc026569e61fee697cb538719216fb258a11ae
When each method of TextEditRules and HTMLEditRules should be called only by
EditorBase/TextEditor/HTMLEditor while the editor instance has
AutoEditActionDataSetter instance. Therefore, we can get rid of all
pointers/references of Selection from each method's argument.
Additionally, this reimplements TextEditRules::SelectionRef() with
EditorBase::SelectionRefPtr() and make it return |const RefPtr<Selection>&|
rather than |Selection&| since RefPtr reference is required when we call
methods which are marked as MOZ_CAN_RUN_SCRIPT.
Differential Revision: https://phabricator.services.mozilla.com/D10010
--HG--
extra : moz-landing-system : lando
EditorBase::SelectionRefPtr() is now safe to use in editor and really fast to
retrieve Selection than EditorBase::GetSelection(). Therefore, we can get rid of
all Selection pointer/reference argument of each method which always take
normal Selection.
Note that this changes nsIHTMLEditor.checkSelectionStateForAnonymousButtons()
because its argument is only Selection. So, BlueGriffon should work even
though it calls the method with nsIEditor.selection.
Differential Revision: https://phabricator.services.mozilla.com/D10009
--HG--
extra : moz-landing-system : lando
HTMLEditRules::DocumentModifiedWorker() may be called asynchronously via
AddScriptRunnder. Therefore, this may not be in the stack while editor handles
an edit action. Then, HTMLEditRules cannot access edit action data which will
be put on the stack after fixing bug 1465702. So, it should do it after once
calling a method of editor instance (and editor instance should call back
proper HTMLEditRules method).
Differential Revision: https://phabricator.services.mozilla.com/D9536
--HG--
extra : moz-landing-system : lando
TextEditRules::Notify() is callback of the timer. Therefore, this won't be
in the stack while editor handles an edit action. Then, TextEditRules
cannot access edit action data which will be put on the stack after fixing
bug 1465702. So, it should do it after once calling a method of editor
instance (and editor instance should call back proper TextEditRules method).
Differential Revision: https://phabricator.services.mozilla.com/D9502
--HG--
extra : moz-landing-system : lando
HTMLEditor::IsModifiableNode() is enough simple and can be checked in
EditorBase. So, we should make it non-virtual and check if instance is
HTMLEditor in EditorBase::IsModifiableNode().
Differential Revision: https://phabricator.services.mozilla.com/D2706
--HG--
extra : moz-landing-system : lando
It's always created with non-nullptr. So, making it treat reference of
EditorBase makes its implementation simpler.
Note that this changes comment in EditorBase::InsertTextWithTransaction() to
a MOZ_ASSERT() for detecting bugs. However, the comment is wrong. When
the insertion is for updating composition string, callers don't need to create
AutoTransactionsConserveSelection since it'll be ignored by
CompositionTransaction. So, the new MOZ_ASSERT() checks whether it's
in composition or prevented transaction changing Selection.
MozReview-Commit-ID: 6jZ4LpksyoD
--HG--
extra : rebase_source : 61ca9272ddea165b3691cf1ce42dc6f4df099a36
InputEvent.inputType needs to distinguish whether inserting text is caused
by insertText command or replaced by autocomplete or spellchecker.
Therefore, nsTextEditorState::SetValue() cannot use
TextEditor::InsertTextAsAction() nor TextEditor::DeleteSelectionAsAction().
This patch reuses TextEditor::SetText()'s slow path for the new method.
Note that the new method uses EditSubAction::eInsertText as top level edit sub-
action because specifying this improves undo/redo behavior.
And also this patch modifies test_bug1368544.html. Oddly, only on Android,
we get different result. After removing all text with setUserInput(""),
TextEditor::DeleteSelectionAsSubAction() removes both text node and non-bogus
<br> element from the anonymous-div element. However, only on Android, new
<br> element is recreated. I've not understood where this difference comes
from yet.
MozReview-Commit-ID: GKNksctGik
--HG--
rename : toolkit/content/tests/chrome/file_autocomplete_with_composition.js => toolkit/content/tests/chrome/file_editor_with_autocomplete.js
rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_input.html => toolkit/content/tests/chrome/test_editor_for_input_with_autocomplete.html
rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_textbox.xul => toolkit/content/tests/chrome/test_editor_for_textbox_with_autocomplete.xul
extra : rebase_source : b90419d9e5a01e86f6e6418f8df002c91416acae
TextEditRules::HandleNewLines() is expensive since it may scan all of given
string twice and more. On the other hand, in most cases, given string does
not contain \n, \r nor \r\n.
First, for avoid using nsTString::FindCharInSet(), HandleNewLine() should
receive string which never contains \r nor \r\n. Then, it always can use
nsTSubstring::FindChar() instead.
Next, HandleNewLines() should do nothing if given string does not contain \n.
Finally, because of unused, this removes unnecessary HandleNewLines() argument
which can specify the way to handle new lines.
MozReview-Commit-ID: 8WSfxfkuFgN
--HG--
extra : rebase_source : 1c05721162a30288929d030c0a15fe83a50fe9d2
EditorBase::GetDocumentIsEmpty() is never called since it's overridden by
TextEditor::GetDocumentIsEmtpy() and never called directly. So, we can remove
its implementation.
Additionally, DocumentIsEmpty() is redundant. We can make it just IsEmpty().
MozReview-Commit-ID: CGsNzCHyVf
--HG--
extra : rebase_source : 3a8eeaf108bb387ea559e0643acfa96e26768577
TextEditor::DeleteSelectionAsAction() is called even if it's a part of edit
action. For example, it's called to prepare for inserting text.
For bug 1465702, editor itself and edit rules classes should not call
public DeleteSelectionAsAction() directly. Therefore, this patch creates
DeleteSelectionAsSubAction() for internal use.
Note that this patch adds NS_ASSERTION() to detect wrong caller. However,
it cannot distinguish if the call is valid, for example, it's allowed to
call DeleteSelectionAsSelection() even if it's handling an edit action but
the method is called via mutation event listener. So, we need to allow
some assertions with some tests. But unfortunately, 1405747.html uses
mutation event listener too many times (about 1,000 times) and the number
of assertion isn't stable. Therefore, this patch makes the test stop using
the mutation event listener 2nd time since I can reproduce the crash with
ESR 52 at the 2nd time.
MozReview-Commit-ID: 1TWaypmnoCC
--HG--
extra : rebase_source : a6a4fb1cbcaf2ab6f10c5f3e7168a6bc0fcb02ed
EditSubAction::ignore is declared for making HTMLEditRules::AfterEditInner()
ignores post-processing of handling edit action. Currently, this is used only
by TextEditRules::CreateBogusNodeIfNeeded() and
HTMLEditor::ReplaceHeadContentsWithHTML(). So, we should make them use
specific EditSubAction values which explain what they do and make
HTMLEditRules::AfterEditInner() ignore both of them.
MozReview-Commit-ID: JSHcgPfTrOE
--HG--
extra : rebase_source : c054c2db257dda7e1e3ace01f8e8831e07268f7e
When we implement InputEvent.inputType, we need to set a stack class to record
which edit action is currently handled. However, currently, we call smaller
jobs as edit action. For example, when user types a character at selecting
some characters, then, EditAction::deleteSelection is performed first, then,
EditAction::insertText is performed. However, for the InputEvent.inputType,
we need inserText information. So, for making new enum EditAction, we need
to rename current EditAction to EditSubAction.
And also this renames related stuff:
EditorBase::mIsInEditAction -> EditorBase::mIsInEditSubAction
EditorBase::IsInEditAction() -> EditorBase::IsInEditSubAction()
EditorBase::mAction -> EditorBase::mTopLevelEditSubAction
TextEditRules::mTheAction -> TextEditRules::mTopLevelEditSubAction
EditorBase::StartOperation() ->
EditorBase::OnStartToHandleTopLevelEditSubAction()
EditorBase::EndOperation() ->
EditorBase::OnEndHandlingTopLevelEditSubAction()
AutoRules -> AutoTopLevelEditSubActionNotifier
RulesInfo -> EditSubActionInfo
MozReview-Commit-ID: cvSkPUjFm1
--HG--
extra : rebase_source : baf527a3e353b7a8ebe9a46be2243b059c500234
EditorBase (and other editor classes) have 2 type of public methods. One is
true-public methods. I.e., they should be able to be called by anybody.
E.g., command handlers, event listeners, or JS via nsIEditor interface.
The other is semi-public methods. They are not called by the above examples
but called by other classes which are helper classes to handle edit actions.
E.g., TextEditRules, HTMLEditRules, HTMLEditUtils, CSSEditUtils and Transaction
classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make EditorBase have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in EditorBase.h
(except removes GetName() since there is no body of this method and removes
IterDirection since it's unused).
MozReview-Commit-ID: HBseKLL6pxx
--HG--
extra : rebase_source : 2251ff659d831d01a6778d38f4e2714fcf2d6ef4
This patch adds new rules of TextEditRules and HTMLEditRules about
NS_ERROR_EDITOR_DESTROYED.
Additionally, this patch moves some method explanation in each .cpp file to .h
file.
MozReview-Commit-ID: JqZFrWyrND8
--HG--
extra : rebase_source : d86385d9c26bb23adae1eca3b1be1a868c20e353
This patch also makes aCancel of TextEditRules::WillInsert() optional since
a lot of callers need to ignore the result.
MozReview-Commit-ID: JrvycxMQ9Mm
--HG--
extra : rebase_source : 9ecdc0fd363d9da33c12409f2993da9c58553598
This patch creates internal method for it as DeleteSelectionWithTransaction()
because it needs to create SelectionBatcher and destruction of it may cause
destroying the editor. Therefore, unfortunately, all callers of
DeleteSelectionWithTransaction() needs to check CanHandleEditAction()
manually. If we could use try-catch, we could make it safer, though.
MozReview-Commit-ID: 13enOQjEzNn
--HG--
extra : rebase_source : 5a902026bcc507fbf9f1949fdcf33a98aabd9a0b
And also this patch removes unnecessary arguments from the method.
MozReview-Commit-ID: UKscK4vFVX
--HG--
extra : rebase_source : 7f6b9405824a3f175f165a2d7d75a293108278f3
Note that HTMLEditRules::DocumentModifiedWorker() is a runnable method.
So, it cannot return nsresult. Therefore, it just checks the result
only with NS_WARNING_ASSERTION().
MozReview-Commit-ID: KBSpv5H5KGU
--HG--
extra : rebase_source : b356ab04d0459214df9dbb3dbfb0e3eecc686348
And also this patch marks it as MOZ_MUST_USE. All callers have to check if
the result is NS_ERROR_EDITOR_DESTROYED at least.
MozReview-Commit-ID: H4DfU1asPpe
--HG--
extra : rebase_source : c11cc00500aad44bd542147fb971e3cce4d634e2
First, this patch changes TextEditRules::CreateBRInternal() to a private method
for making any callers use CreateBR() or CreateMozBR() instead.
Then, this patch makes TextEditRules::CreateBRInternal() return both nsresult
and created <br> element with CreateElementResult class.
Finally, this patch makes all callers of them check if they don't return an
error code including NS_ERROR_EDITOR_DESTROYED.
MozReview-Commit-ID: 18OvPmbDVHK
--HG--
extra : rebase_source : 328a91146539763cec317105b92aa3ce5d4b8233
This patch defines NS_ERROR_EDITOR_DESTROYED error code as an editor module
specific error code.
And creates TextEditRules::CanHandleEditAction() to check if the instance
can keep handling edit action.
MozReview-Commit-ID: 4qECwNBO0yz
--HG--
extra : rebase_source : a925a9b6840d4d06e2792b9fe276e062288b0806
Some Did*() of TextEditRules and HTMLEditRules do nothing except returning
NS_OK. Let's remove them since there is no reason to keep them.
MozReview-Commit-ID: Jcdh5rnm5Yc
--HG--
extra : rebase_source : 54aedd8187edfa244bc8fbe8f560fb6ee064e9cf
Now, each protected/private method of TextEditRules and HTMLEditRules can
retrieve Selection instance safely and quickly. Therefore, their pointer or
reference of Selection arguments are not necessary. Therefore, this patch
removes them.
MozReview-Commit-ID: 1SPmKXmd7kz
--HG--
extra : rebase_source : 32dfd2d5e8b0667318a5b3766a8a7d8594bba8e7