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

136 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano e01c0de610 Bug 1642594 - part 4: Stop using "whitespace" in under libeditor r=m_kato
I realized that there is no word "whitespace" in formal English.  This patch
replaces it with "white-space" in comments, and change method names to use
"WhiteSpace".

Depends on D78654

Differential Revision: https://phabricator.services.mozilla.com/D78655
2020-06-10 13:44:10 +00:00
Masayuki Nakano 6d98bd00c0 Bug 1540037 - part 6: Move `TextEditor::DeleteSelectionAndCreateElement()` and `TextEditor::DeleteSelectionAndPrepareToCreateNode()` to `HTMLEditor` r=m_kato
Both of them are used only by `HTMLEditor` so that we can move them to
`HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D72830
2020-04-30 09:54:55 +00:00
Masayuki Nakano f3a31a9bda Bug 1632724 - part 4: Rename `HTMLEditor::DeleteSelectionWithTransaction()` r=m_kato
`HTMLEditor::DeleteSelectionWithTransaction()` calls `EditorBase`'s overridden
method and handles `nsIEditor::eStrip` case.  Therefore, we can rename it with
stop calling the `EditorBase::DeleteSelectionWithTransaction()`, and make it
called by `EditorBase::DeleteSelectionWithTransaction()` only when it's
necessary.

Additionally, we can make all internal method callers of editor classes always
set `nsIEditor::eNoStrip` if the instance is `TextEditor`.  This must make
the code easier to understand.

Depends on D72292

Differential Revision: https://phabricator.services.mozilla.com/D72293
2020-04-27 00:36:10 +00:00
Masayuki Nakano b67f6a5763 Bug 1632724 - part 2: Move `DeleteSelectionWithTransaction()` from `TextEditor` to `EditorBase` since it's used by `HTMLEditor` too r=m_kato
Depends on D72290

Differential Revision: https://phabricator.services.mozilla.com/D72291
2020-04-24 15:22:42 +00:00
Masayuki Nakano 6cbea10c99 Bug 1632724 - part 1: Move common methods for handling delete selection to `EditorBase` r=m_kato
`DeleteSelection*()` are members of `TextEditor`, but they are also used by
`HTMLEditor`.  Therefore, they and pref cache members for them should be
in `EditorBase` too.

Depends on D71911

Differential Revision: https://phabricator.services.mozilla.com/D72290
2020-04-24 14:55:09 +00:00
sanketh b2456e6ee7 Bug 1320229 - allow user pastes longer than input maxlength r=masayuki
Currently, all input (including user pastes) to an input field is truncated to
`maxlength`. This diff disables truncation for user pastes.

When (1) `GetEditAction` is `ePaste`, `ePasteAsQuotation`, `eDrop`, or
`eReplaceText` (ie we are dealing with a paste) and (2) `GetEditActionPrincipal`
is `nullptr` (ie we are dealing with a user edit and not a JS edit), allow a
paste without truncation. That means that, in this case, we will return
`EditActionIgnored` instead of trying to truncate the string.

This behavior is controlled by a new preference `editor.truncate_user_pastes`
which is `false` by default (set in `StaticPrefList.yaml`).

We also modify `editor/libeditor/tests/test_bug603556.html` which currently
expects the output of a paste longer than maxlength to be truncated.

Testing: Created
`editor/libeditor/tests/test_pasting_text_longer_than_maxlength.html` which
checks if a user can paste a password longer than `maxlength` and if the field
is then marked as `tooLong` (this was the original concern of the reporter of
Bug 1320229), and
`editor/libeditor/tests/test_setting_value_longer_than_maxlength_with_setUserInput.html`
which checks if `eReplaceText` has consistent behavior regardless of whether the
field has an associated editor (this test works by calling `setUserInput()`
before and after the element gets focus.) `./mach test editor/libeditor` tests
pass.

Differential Revision: https://phabricator.services.mozilla.com/D71689
2020-04-27 01:29:43 +00:00
Makoto Kato 67f4ec1ac0 Bug 1628192 - Use more const declarations on editor classes. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D70146

--HG--
extra : moz-landing-system : lando
2020-04-13 01:43:41 +00:00
Chris Peterson 589528cb8d Bug 1625834 - Replace MOZ_MUST_USE with [[nodiscard]] in editor. r=masayuki
Also move MOZ_MUST_USE before function declarations' specifiers and return type. While clang and gcc's __attribute__((warn_unused_result)) can appear before, between, or after function specifiers and return types, the [[nodiscard]] attribute must precede the function specifiers.

Differential Revision: https://phabricator.services.mozilla.com/D69315

--HG--
extra : moz-landing-system : lando
2020-04-02 05:43:31 +00:00
Arthur Iakab 7e869be20c Backed out changeset 5e89020502f7 (bug 1625834) for causing build bustages
CLOSED TREE
2020-04-01 04:32:11 +03:00
Chris Peterson b469a9d9db Bug 1625834 - Replace MOZ_MUST_USE with [[nodiscard]] in editor. r=masayuki
Also move MOZ_MUST_USE before function declarations' specifiers and return type. While clang and gcc's __attribute__((warn_unused_result)) can appear before, between, or after function specifiers and return types, the [[nodiscard]] attribute must precede the function specifiers.

Differential Revision: https://phabricator.services.mozilla.com/D68747

--HG--
extra : moz-landing-system : lando
2020-03-30 06:45:40 +00:00
Masayuki Nakano 0ccabd567d Bug 1620504 - part 23: Fix some inconsistent coding style in editor r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D67132

--HG--
extra : moz-landing-system : lando
2020-03-22 10:46:39 +00:00
Masayuki Nakano b1bf7e0db4 Bug 1540043 - part 1: Move all constants and methods of `nsIPlaintextEditor` to `nsIEditor` and make `nsIPlaintextEditor` inherit `nsIEditor` r=m_kato
For preparing to remove `nsIPlaintextEditor` interface, this patch moves
all of them to `nsIEditor`, but for avoiding bustage in comm-central, makes
`nsIPlaintextEditor` inherit `nsIEditor` for now (i.e., even with this patch,
script can access old `nsIPlaintextEditor` members with the interface.

In C++ code, this patch moves `SetWrapColumn()`, `InsertTextAsAction()`,
`InsertTextAsSubAction()` and `InsertLineBreakAsSubAction()` because
they do common things between `TextEditor` and `HTMLEditor`.  On the other
hand, this does not move `TextEditor::GetTextLength()` because it's designed
only for `TextEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D60820

--HG--
rename : editor/libeditor/tests/test_nsIPlaintextEditor_insertLineBreak.html => editor/libeditor/tests/test_nsIEditor_insertLineBreak.html
extra : moz-landing-system : lando
2020-01-24 08:33:42 +00:00
Masayuki Nakano 36606b82d3 Bug 1597829 - part 3: Make `TextEditor::OnDrop()` use another editor which is drag source editor to remove selection r=m_kato
User can move DnD between different 2 editors.  Then, deleting selection in
drag source editor should be handled by the drag source editor rather than
drop target editor.  Therefore, `TextEditor::OnDrop()` should look for
editor instance for drag source node and call is "deleteByDrag" handler.

Differential Revision: https://phabricator.services.mozilla.com/D57449

--HG--
extra : moz-landing-system : lando
2019-12-21 12:30:17 +00:00
Masayuki Nakano 9973ff7319 Bug 1540029 - part 11: Get rid of `AutoEditInitRulesTrigger` r=m_kato
Only for solving the order of `AutoEditInitRulesTrigger` destruction when
`HTMLEditor::Init()` calls `TextEditor::Init()`, `TextEditor` has unnecessary
counter and the initialization code is made harder to understand.

Therefore, this patch makes `TextEditor::Init()` and `HTMLEditor::Init()`
directly call `InitEditorContentAndSelection()` at appropriate time.
Additionally, `HTMLEditor::Init()` can call `EditorBase::Init()` instead of
`TextEditor::Init()` since `TextEditor::Init()` does nothing for `HTMLEditor`
actually.

Differential Revision: https://phabricator.services.mozilla.com/D45793

--HG--
extra : moz-landing-system : lando
2019-09-18 10:14:40 +00:00
Masayuki Nakano 6789366d5e Bug 1540029 - part 10: Get rid of `TextEditRules` and `HTMLEditRules` r=m_kato
Now, we can get rid of `TextEditRules` and `HTMLEditRules` completely.
And also this patch renames their cpp files to `TextEditSubActionHandler`
and `HTMLEditSubActionHandler`.

`TextEditor::Init()` and `HTMLEditor::Init()` are still complicated due to
`AutoEditInitRulesTrigger`.  The following patch will remove it.

Differential Revision: https://phabricator.services.mozilla.com/D45792

--HG--
rename : editor/libeditor/HTMLEditRules.cpp => editor/libeditor/HTMLEditSubActionHandler.cpp
rename : editor/libeditor/TextEditRules.cpp => editor/libeditor/TextEditSubActionHandler.cpp
extra : moz-landing-system : lando
2019-09-18 08:40:08 +00:00
Masayuki Nakano d2ae4d5d88 Bug 1540029 - part 9: Move `TextEditRules::Init()` and `HTMLEditRules::Init()` to `TextEditor` and `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D45791

--HG--
extra : moz-landing-system : lando
2019-09-18 08:21:37 +00:00
Masayuki Nakano b3115e6972 Bug 1540029 - part 4: Merge `BeforeEdit()` and `OnStartToHandleTopLevelEditSubAction()`, and `AfterEdit()` and `OnEndHandlingTopLevelEditSubAction()` r=m_kato
And also this patch make each `AutoEditSubActionNotifier` creator check
the result of `OnStartToHandleTopLevelEditSubAction()` at least for
`NS_ERROR_EDITOR_DESTROYED`.

We need to take care of its destructor's result later, though.

Differential Revision: https://phabricator.services.mozilla.com/D45786

--HG--
extra : moz-landing-system : lando
2019-09-18 03:01:28 +00:00
Masayuki Nakano db32271cec Bug 1540029 - part 2: Get rid of `TextEditRules::DocumentIsEmpty()` and `HTMLEditRules::DocumentIsEmpty()` r=m_kato
`TextEditRules::DocumentIsEmpty()` is a wrapper of `TextEditor::IsEmpty()` so
that we can get rid of it simply.

`HTMLEditRules::DocumentIsEmpty()` needs to change.  It's oddly checks only
`EditorBase::mPaddingBRElementForEmptyEditor` is `nullptr` or not.  However,
the editor may be completely empty.  And the result may be different from
`TextEditor::IsEmpty()` which is not overridden by `HTMLEditor`.  For partially
solving this issue, this patch makes `HTMLEditor` overrides `IsEmpty()` and
optimizes `TextEditor::IsEmpty()`.

With this change, the caller of `HTMLEditRules::DocumentIsEmpty()` may behave
differently in the only caller, `HTMLEditor::SelectEntireDocument()`.  And
unfortunately, its root called from `SelectAllCommand::DoCommand()`.  However,
it does just collapse `Selection` into the root element (`<body>` or
`Document.documentElement`) if it returns `true`.  Therefore, this change
must be safe since anyway `SelectionRefPtr()->SelectAllChildren()` with
the root element is exactly same as `SelectionRefPtr()->Collapse()` with
the empty root element if it's truly empty.

Differential Revision: https://phabricator.services.mozilla.com/D45784

--HG--
extra : moz-landing-system : lando
2019-09-17 06:58:06 +00:00
Masayuki Nakano bbcb8b3a63 Bug 1574852 - part 113: Move `TextEditRules::CreateTrailingBRIfNeeded()` and `TextEditRules::CollapseSelectionToTrailingBRIfNeeded()` to `TextEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D45496

--HG--
extra : moz-landing-system : lando
2019-09-17 02:47:49 +00:00
Masayuki Nakano 5b0eb574be Bug 1574852 - part 112: Make `TextEditor::InsertWithQuotationsAsSubAction()` virtual and `HTMLEditor` override it r=m_kato
It requires different preparation in `TextEditor` and `HTMLEditor` but it's
not split.  Therefore, we should make it virtual and override it to use
different preparation code.  Fortunately, its code is enough simple to
duplicate.

Additionally, this removes unnecessary code from `TextEditRules` and
`HTMLEditRules` including `WillDoAction()` and `DidDoAction()`!

Differential Revision: https://phabricator.services.mozilla.com/D45495

--HG--
extra : moz-landing-system : lando
2019-09-17 02:47:26 +00:00
Masayuki Nakano 0da92b7d7d Bug 1574852 - part 109: Move `TextEditRules::WillSetText()` to `TextEditor` r=m_kato
And also renaming `EditorBase::SetTextImpl()`.

Differential Revision: https://phabricator.services.mozilla.com/D45492

--HG--
extra : moz-landing-system : lando
2019-09-17 02:21:35 +00:00
Gurzau Raul ba23dcf114 Backed out 2 changesets (bug 1574852) for assertion failures at TextEditRules.cpp
Backed out changeset f54f6af6359d (bug 1574852)
Backed out changeset 2b6968592570 (bug 1574852)
2019-09-15 02:32:09 +03:00
Masayuki Nakano 87f73d9008 Bug 1574852 - part 109: Move `TextEditRules::WillSetText()` to `TextEditor` r=m_kato
And also renaming `EditorBase::SetTextImpl()`.

Differential Revision: https://phabricator.services.mozilla.com/D45492

--HG--
extra : moz-landing-system : lando
2019-09-14 15:12:03 +00:00
Masayuki Nakano 75507785e6 Bug 1574852 - part 108: Move `TextEditRules::WillOutputText()` to `TextEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D45491

--HG--
extra : moz-landing-system : lando
2019-09-13 03:44:33 +00:00
Masayuki Nakano 438470f81e Bug 1574852 - part 106-2: Move calling `DeleteSelectionWithTransaction()` and `HTMLEditor` specific post handling into `HandleDeleteSelection()` from `TextEditor::DeleteSelectionAsSubAction()` r=m_kato
In `TextEditor::HandleDeleteSelection()`, we have only one path of returning
`EditActionIgnored()`.  Therefore, it should call
`DeleteSelectionWithTransaction()` directly.

On the other hand, it's not clear in `HTMLEditor::HandleDeleteSelection()`
since it may be called recursively by its helper methods.  Therefore,
this patch creates `HTMLEditor::HandleDeleteSelectionInternal()` for the
recursive calls and makes `HTMLEditor::HandleDeleteSelection()` call
`DeleteSelectionWithTransaction()` if nobody handled it and to the
`HTMLEditor` specific post-process in it.

Differential Revision: https://phabricator.services.mozilla.com/D45301

--HG--
extra : moz-landing-system : lando
2019-09-13 03:20:04 +00:00
Masayuki Nakano 053579099d Bug 1574852 - part 106-1: Move `TextEditRules::WillDeleteSelection()` and `TextEditRules::DeleteSelectionWithTransaction()` to `TextEditor` and make `HTMLEditor::HandleDeleteSelection()` override the former r=m_kato
`TextEditor::DeleteSelectionAsSubAction()` starts to handle all
"delete selection" sub-actions (i.e., even if the instance is `HTMLEditor`).
Therefore, `TextEditRules::WillDeleteSelection()` should be renamed to
`TextEditor::HandleDeleteSelection()` and we need to make it virtual.

Differential Revision: https://phabricator.services.mozilla.com/D45300

--HG--
extra : moz-landing-system : lando
2019-09-13 02:49:43 +00:00
Masayuki Nakano f521a40385 Bug 1574852 - part 104: Move `TextEditRules::WillInsertText()` to `TextEditor` and make `HTMLEditor::WillInsertText()` override it r=m_kato
And also this patch moves `TextEditRules::HandleNewLines()` and
`TextEditRules::DontEchoPassword()` to `TextEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D45298

--HG--
extra : moz-landing-system : lando
2019-09-13 02:40:09 +00:00
Masayuki Nakano d0bf28c6cc Bug 1574852 - part 103: Move `TextEditRules::WillInsertLineBreak()` to `TextEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D45297

--HG--
extra : moz-landing-system : lando
2019-09-12 08:03:57 +00:00
Masayuki Nakano 80be9ab956 Bug 1574852 - part 102: Move `TextEditRules::TruncateInsertionIfNeeded()` to `TextEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D45296

--HG--
extra : moz-landing-system : lando
2019-09-12 07:48:29 +00:00
Masayuki Nakano 0cc09df825 Bug 1572685 - part 9: Move `HTMLEditRules::mDocChangeRange` to `TopLevelEditSubActionData` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42104

--HG--
extra : moz-landing-system : lando
2019-08-20 01:51:59 +00:00
Masayuki Nakano 7759842058 Bug 1572681 - part 4: Get rid of arguments of `TextEditRules::BeforeEdit()` and `TextEditRules::AfterEdit()` r=m_kato
`TextEditRules::BeforeEdit()`, `TextEditRules::AfterEdit()`,
`HTMLEditRules::BeforeEdit()` and `HTMLEditRules::AfterEdit()` are always
called with same values as the result of
`EditorBase::GetTopLevelEditSubAction()` and
`EditorBase::GetDirectionOfTopLevelEditSubAction()`.

For making what they do clearer, we should make them access with those
`EditorBase` members for now.  This makes those methods ugly due to increasing
number of long lines.  However, this issue should be solved when we move them
into `TextEditor` and `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D41399

--HG--
extra : moz-landing-system : lando
2019-08-13 04:41:18 +00:00
Masayuki Nakano 13b14b9b2f Bug 1572681 - part 1: Move `TextEditRules::mCachedSelection*` to `EditorBase::AutoEditActionDataSetter` r=m_kato
Despite of their names, `TextEditRules::mCachedSelectionNode` and
`TextEditRules::mCachedSelectionOffset` are used only for calling
`EditorBase::HandleInlineSpellCheck()` so that they should be renamed to
explain the purpose.

Additionally, they are not necessary to be in the heap since they are
necessary until `TextEditRules::AfterEdit()` is called.  Therefore, we can
move them into `EditorBase::HandleInlineSpellCheck()`.

Finally, `TextEditRules::BeforeEdit()` and `TextEditRules::AfterEdit()` are
called only by `TextEditor::OnStartToHandleTopLevelEditSubAction()` and
`TextEditor::OnEndHandlingTopLevelEditSubAction()`.  Therefore, we can move
the setter to `TextEditor::OnStartToHandleTopLevelEditSubAction()`.

Differential Revision: https://phabricator.services.mozilla.com/D41396

--HG--
extra : moz-landing-system : lando
2019-08-13 01:24:01 +00:00
Masayuki Nakano c1906f614d Bug 1572375 - part 5: Move `TextEditRules::CreatePaddingBRElementForEmptyEditorIfNeeded()` into `EditorBase` r=m_kato
`TextEditRules::CreatePaddingBRElementForEmptyEditorIfNeeded()` is used by
both `TextEditor` and `HTMLEditor` so that this moves it into `EditorBase`.

Additionally, making `TextEditor::MaybeChangePaddingBRElementForEmptyEditor()`
call it if there is no content.  Then, we can avoid the dependency of them.

Differential Revision: https://phabricator.services.mozilla.com/D41159

--HG--
extra : moz-landing-system : lando
2019-08-09 10:19:11 +00:00
Masayuki Nakano 3b82fdde10 Bug 1572375 - part 4: Move `TextEditRules::RemoveRedundantTrailingBR()` into `TextEditor` r=m_kato
`TextEditRules::RemoveRedundantTrailingBR()` is used only by multiline text
editor (i.e., `<textarea>`).  Therefore, it should be moved into `TextEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D41158

--HG--
extra : moz-landing-system : lando
2019-08-09 09:01:56 +00:00
Masayuki Nakano b0606032ba Bug 1572375 - part 2: Split `TextEditRules::WillInsert()` r=m_kato
`TextEditRules::WillInsert()` is not used with initial purpose since
`HTMLEditor` always works with `HTMLEditRules` and its `WillDoAction()`
always handles `EditSubAction::eInsertElement`.

Additionally, its name is too generic since it does non-related 3 things.

One is checking whether the editor is readonly or disabled.  However, this
may not be necessary since its callers may have already checked it or
just ignored the result.  So, this should be check by each caller.

Next one is masking password if auto-masking is enabled.  This is `TextEditor`
specific feature so that this patch moves the code into
`TextEditor::MaybeDoAutoPasswordMasking()`.

Final one is removing empty `<br>` element for empty editor if there is.
This is common feature so that this patch moves this code into
`EditorBase::EnsureNoPaddingBRElementForEmptyEditor()`.

Differential Revision: https://phabricator.services.mozilla.com/D41156

--HG--
extra : moz-landing-system : lando
2019-08-09 08:25:37 +00:00
Masayuki Nakano 11ae238f0f Bug 1569902 - part 4: Make `TextEditor` inserts padding `<br>` element for empty last line after setting flags to `NS_PADDING_FOR_EMPTY_LAST_LINE` r=m_kato
Stopping using attribute for "moz-br", `IMEContentObserver` cannot know when
new `<br>` element is changed to padding element for empty last line.
Therefore, editor needs to insert padding `<br>` element after setting the
flag properly.  Then, `IMEContentObserver` does not need to recompute the
length of `<br>` element (if it's for padding, it computes the length as 0).

Unfortunately, `TextEditor::InsertBrElementWithTransaction()` is used in too
many places and it already has optional argument.  Therefore, it's difficult
to change it.  However, we should share the preparation before creating `<br>`
element in it with new method.  Therefore, this patch creates
`EditorBase::PrepareToInsertBRElement()` to share the preparation point (almost
just moved from the method).  Then, new method is created as
`EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction()` because
it's used both in `TextEditor` and `HTMLEditor`.  Finally, `TextEditor` won't
insert `<br>` element with `InsertBrElementWithTransaction()`.  Therefore, it's
moved to `HTMLEditor` with renaming to `InsertBRElementWithTransaction()`.

Differential Revision: https://phabricator.services.mozilla.com/D39860

--HG--
extra : moz-landing-system : lando
2019-08-02 05:46:41 +00:00
Masayuki Nakano 765e91b497 Bug 1569902 - part 1: Stop using attribute to consider whether a `<br>` element is an editor bogus node or not r=m_kato,smaug
Editor creates a `<br>` element when it's root element is empty.
Then, it's stored by `TextEditRules::mBogusNode` and used for checking
whether the editor is empty quickly.  However, this `<br>` element has
`mozeditorbogusnode` attribute whose value is `true`.  However, adding or
removing the attribute is not cheap and web apps can refer such illegal
attribute.

Therefore, this patch makes `HTMLBRElement` take a specific flag whether
it's a bogus node or not.  However, this means that this hacky thing will be
exposed outside editor module.  For making what is the bogus node clearer,
this patch calls the such `<br>` elements as "padding `<br>` element for
empty editor".  So, this patch also includes a lot of renaming methods and
variables, and modifying related comments.

Differential Revision: https://phabricator.services.mozilla.com/D39857

--HG--
extra : moz-landing-system : lando
2019-08-02 05:44:40 +00:00
Masayuki Nakano fafe168f04 Bug 1560032 - part 2: Make cut/copy in password field available r=m_kato,smaug
First, we need to make `nsCopySupport::FireClipboardEvent()` keep handling
`eCopy` and `eCut` event even in password field, only if `TextEditor` allows
them.

Then, we need to make `nsPlainTextSerializer::AppendText()` not expose
masked password for making users safer.  Although `TextEditor` does not allow
`eCopy` nor `eCut` when selection is not in unmasked range.  Fortunately,
retrieving masked and unmasked password from `nsTextFragment` has already
been implemented in `ContentEventHandler.cpp`.  This patch moves it into
`EditorUtils` and makes `ContentEventHandler.cpp` and `nsPlaintextSerializer`
share it.

Differential Revision: https://phabricator.services.mozilla.com/D39000

--HG--
extra : moz-landing-system : lando
2019-07-29 06:21:42 +00:00
Masayuki Nakano ffbb14909f Bug 1560032 - part 1: Make `TextEditor` for password allow to copy password when selected range is in unmasked range r=m_kato
It does not make sense to copy masked password with mask characters.
Therefore, we should allow users to copy/cut in password fields only when
selected range is in unmasked range.

Note that for web-compat, copy/cut are always enabled in HTML/XHTML document
in content.  Therefore this patch changes the behavior only in chrome's
password fields.

Additionally, only the test uses `nsIEditor.canDelete()`.  Therefore, this
removes it and make the test use `nsIDocShell.isCommandEnabled()` instead.
Unfortunately, `nsIEditor.canCopy()` and `nsIEditor.canCut()` are used by
BlueGriffon, therefore, we cannot get rid of them for now.

Differential Revision: https://phabricator.services.mozilla.com/D38999

--HG--
rename : editor/libeditor/tests/test_bug1067255.html => editor/libeditor/tests/test_cut_copy_delete_command_enabled.html
extra : moz-landing-system : lando
2019-07-29 06:21:14 +00:00
Masayuki Nakano 1c2108934c Bug 1548389 - part 6: Add automated tests for new API and rendering of password fields r=m_kato,Jamie
Differential Revision: https://phabricator.services.mozilla.com/D38010

--HG--
extra : moz-landing-system : lando
2019-07-22 03:55:13 +00:00
Masayuki Nakano b8d245a76d Bug 1548389 - part 2: Make `TextEditRules` use the new editor API to mask/unmask characters in password editor r=m_kato
Now, `TextEditRules` should use the new editor API to mask/unmask characters
if it's for a password editor.  With this change, it does not need to manage
masked characters and unmasked characters separately since the anonymous
text node always have unmasked characters and `nsTextFrame` will mask the
characters at painting time.

Differential Revision: https://phabricator.services.mozilla.com/D38005

--HG--
extra : moz-landing-system : lando
2019-07-22 03:53:58 +00:00
Masayuki Nakano 010cde10c1 Bug 1548389 - part 1: Implement API to get/set unmask-range of password editor r=m_kato
This patch creates editor API to get/set unmask-range of password field.
Its design is similar to `setSelectionRange()` and `selectionStart`/
`selectionEnd` attributes.   The unmasked range is automatically
masked if `aTimeout` of `unmask()` is set to non-zero.
Otherwise, unmasked range won't be masked automatically even after user
or web apps modifies the editor, and inserting new character expands
unmasking range.

The following patch makes `TextEditRules` use these API to implement
delayed masking of password.

Note that editor has never supported dynamic `eEditorPasswordMask` change.
E.g., if you have typed some characters into an editor and toggle the flag,
the characters are not unmasked nor masked.  Then, if you type new characters,
only they are correctly masked or unmasked.  This patch puts `MOZ_ASSERT()`
to reject this feature completely on debug build for making the unmasking
implementation simpler.

Differential Revision: https://phabricator.services.mozilla.com/D38004

--HG--
extra : moz-landing-system : lando
2019-07-22 03:53:36 +00:00
Masayuki Nakano 84cbc7e792 Bug 1529884 - part 6: Through subject principal at Document::ExecCommand() to constructor of EditorBase::AutoEditActionDataSetter r=smaug
`Document::ExecCommand()` knows subject principal.  This patch makes it tell
`EditorCommand::DoCommand()` and `EditorCommand::DoCommandParam()`.  Then,
makes they tell each editor public methods which may cause dispatching
`beforeinput` event once we implement it.  Finally, each editor public
method sets it to the constructor of `EditorBase::AutoEditActionDataSetter`.
This means that when editor tries to dispatch `beforeinput` event, editor
can check whether it's called by JS or not from everywhere.

Differential Revision: https://phabricator.services.mozilla.com/D29635

--HG--
extra : moz-landing-system : lando
2019-06-10 10:27:07 +00:00
Masayuki Nakano 4579004eac Bug 1549319 - Make template methods marked as MOZ_CAN_RUN_SCRIPT take only EditorDOMPoint (i.e., not allow EditorRawDOMPoint) r=m_kato
It'd be better to change copy constructor of `EditorDOMPointBase` to explicit,
but it'd require too many changes in editor code.  So, this patch just changes
each method callers only.

Differential Revision: https://phabricator.services.mozilla.com/D30054

--HG--
extra : moz-landing-system : lando
2019-05-08 09:40:17 +00:00
Masayuki Nakano ed4cc22661 Bug 1549270 - part 3: Mark EditorBase::SetAttributeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30047

--HG--
extra : moz-landing-system : lando
2019-05-08 06:26:25 +00:00
Masayuki Nakano f440ac739a Bug 1549264 - Mark EditorBase::SplitNodeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30039

--HG--
extra : moz-landing-system : lando
2019-05-07 22:34:28 +00:00
Masayuki Nakano 0925cb9a70 Bug 1549155 - Mark EditorBase::DeleteNodeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30038

--HG--
extra : moz-landing-system : lando
2019-05-07 22:27:29 +00:00
Masayuki Nakano 9405d61cb8 Bug 1546577 - Make overloads of CanCut(), CanCopy(), CanDelete() and CanPaste() which return bool instead of nsresult r=m_kato
`CanCut()`, `CanCopy()` and `CanPaste()` return error only when the editor has
already been destroyed or not been initialized yet, or when failed to access
clipboard when the document is not HTML/XHTML.

`CanDelete()` returns error only when the editor has already been destroyed or
not been initialized yet.

So, these error result won't be exposed to the web in most cases and such
exception shouldn't stop any content script because Chrome basically does not
throw exception in such situation as far as I know.

Therefore, there should be overloads of them to return `bool` result directly
for making their callers simpler.

Differential Revision: https://phabricator.services.mozilla.com/D28608

--HG--
extra : moz-landing-system : lando
2019-04-25 07:14:39 +00:00
Masayuki Nakano 3e64f2c30d Bug 1539356 - Mark EditorBase::InsertNodeTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
This patch marks `EditorBase::InsertNodeTransaction()` **and** its callers as `MOZ_CAN_RUN_SCRIPT`.

Unfortunately, this patch tells us that some `GetSomething()` methods may destroy the editor since `HTMLEditRules::GetNodesForOperation()`, `HTMLEditRules::GetNodesFromPoint()` and `HTMLEditRules::GetNodesFromSelection()` may change the DOM tree.  Additionally, initialization methods may destroy the editor since it may insert a bogus `<br>` node.

Note that this patch also removes some unused methods. I.e., they are not result of some cleaning up the code. This patch just avoids marking unused methods as `MOZ_CAN_RUN_SCRIPT`.

Differential Revision: https://phabricator.services.mozilla.com/D25027

--HG--
extra : moz-landing-system : lando
2019-03-30 11:55:29 +00:00
Oana Pop Rus 43fadb6745 Backed out changeset 447c87c2d139 (bug 1539356) on request of Jorg K. a=backout 2019-03-30 00:42:32 +02:00