Commit Graph

53 Commits

Author SHA1 Message Date
Masayuki Nakano
adea39d1ad Bug 1762115 - part 5: Make SplitNodeResult store and suggest new caret position r=m_kato
This patch allows methods which split some nodes to return new candidate
caret position and makes callers of them consider whether applying it to
the selection immediately or not.

Differential Revision: https://phabricator.services.mozilla.com/D144648
2022-05-03 00:06:16 +00:00
Masayuki Nakano
0ed912d4d2 Bug 1762115 - part 4: Make SplitNodeTransaction::DoTransaction() stop touching selection r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144647
2022-05-02 23:44:00 +00:00
Masayuki Nakano
57ba857907 Bug 1764684 - part 2: Make editor use methods of EditorBase to collapse Selection r=m_kato
First, move methods of `HTMLEditor` which collapse `Selection` to `EditorBase`.
Then, make editor stop accessing `Selection::CollapseInLimiter` directly.

Differential Revision: https://phabricator.services.mozilla.com/D143814
2022-04-20 14:36:52 +00:00
Masayuki Nakano
613c3e6874 Bug 1757911 - part 3: Make HTMLEditor::DoJoinNodes() notify RangeUpdater r=m_kato
Currently, it's notified by `JoinNodesTransaction::DoTransactionInternal` so
that it's `SplitNodeTransaction::UndoTransaction` cannot track the DOM point
and this might cause odd editing result if `execCommand("undo")` is called
while `HTMLEditor` handles an edit action.

For avoiding to duplicate the code, it should be handled in
`HTMLEditor::DoJoinNodes`.

Differential Revision: https://phabricator.services.mozilla.com/D140463
2022-03-10 10:27:54 +00:00
Masayuki Nakano
9f1ed28e57 Bug 1757911 - part 2: Make SplitNodeTransaction::DoTransaction and RedoTransaction share the code doing split r=m_kato
They have duplicated code so that they should be merged to a new internal
method.

Differential Revision: https://phabricator.services.mozilla.com/D140462
2022-03-10 10:19:07 +00:00
Masayuki Nakano
9eb26e98d4 Bug 1757911 - part 1: Clean up SplitNodeTransaction r=m_kato
First, it should not store split point with `EditorDOMPoint` because it has
child node pointer and other flags but they are never used and they make
the footprint worse.  Therefore, this patch makes it exactly same structure
as `JoinNodesTransaction`.

Additionally, this patch removes "left" and "right" words especially from
the member names and variable names (preparation of bug 1735608).

Differential Revision: https://phabricator.services.mozilla.com/D140461
2022-03-10 10:09:44 +00:00
Iulian Moraru
a457578a3c Backed out 4 changesets (bug 1757911) for causing build bustages on HTMLEditor.cpp.
Backed out changeset 0a12415ff7cf (bug 1757911)
Backed out changeset 1edde90f24cc (bug 1757911)
Backed out changeset 64ae36546100 (bug 1757911)
Backed out changeset e0e951dc9594 (bug 1757911)
2022-03-10 06:24:41 +02:00
Masayuki Nakano
9492284581 Bug 1757911 - part 3: Make HTMLEditor::DoJoinNodes() notify RangeUpdater r=m_kato
Currently, it's notified by `JoinNodesTransaction::DoTransactionInternal` so
that it's `SplitNodeTransaction::UndoTransaction` cannot track the DOM point
and this might cause odd editing result if `execCommand("undo")` is called
while `HTMLEditor` handles an edit action.

For avoiding to duplicate the code, it should be handled in
`HTMLEditor::DoJoinNodes`.

Depends on D140462

Differential Revision: https://phabricator.services.mozilla.com/D140463
2022-03-09 23:14:37 +00:00
Masayuki Nakano
9c34202758 Bug 1757911 - part 2: Make SplitNodeTransaction::DoTransaction and RedoTransaction share the code doing split r=m_kato
They have duplicated code so that they should be merged to a new internal
method.

Depends on D140461

Differential Revision: https://phabricator.services.mozilla.com/D140462
2022-03-09 23:06:44 +00:00
Masayuki Nakano
bc371d672a Bug 1757911 - part 1: Clean up SplitNodeTransaction r=m_kato
First, it should not store split point with `EditorDOMPoint` because it has
child node pointer and other flags but they are never used and they make
the footprint worse.  Therefore, this patch makes it exactly same structure
as `JoinNodesTransaction`.

Additionally, this patch removes "left" and "right" words especially from
the member names and variable names (preparation of bug 1735608).

Differential Revision: https://phabricator.services.mozilla.com/D140461
2022-03-09 22:35:07 +00:00
Masayuki Nakano
070d7477d0 Bug 1639287 - part 2: Make SplitNodeTransaction::RedoTransaction() use HTMLEditor::DoSplitNode() r=m_kato
Similarly, `SplitNodeTransaction::RedoTransaction()` has its own code, but it
does not work well.  Let's make it use `HTMLEditor::DoSplitNode()` instead.

This fixes bug 1740656.

Differential Revision: https://phabricator.services.mozilla.com/D132123
2021-11-29 10:17:21 +00:00
Masayuki Nakano
294a274dcb Bug 1639287 - part 1: Make JoinNodeTransaction::UndoTransaction() use HTMLEditor::DoSplitNode() r=m_kato
`JoinNodeTransaction::UndoTransaction()` has its own splitting code.  However,
it has some bugs, it does not handle surrogate pairs correctly and it does not
care selections.  `HTMLEditor::DoSplitNode()` is used for splitting a DOM node
from `SplitNodeTransaction::DoTransaction()`.  So that we should make
`JoinNodeTransaction::UndoTransaction()` should use `HTMLEditor::DoSplitNode()`
for saving the maintenance cost.

Differential Revision: https://phabricator.services.mozilla.com/D132122
2021-11-29 10:17:21 +00:00
Masayuki Nakano
f09046d90e Bug 1727185 - Add MOZ_DIAGNOSTIC_ASSERT to the constructors of DeleteNodeTransaction and SplitNodeTransaction and make their users return error before hitting it r=m_kato
On Thunderbird, we still have a bug to delete `<html>` and `<body>` elements
(bug 1727201).  However, it's hard to know where deletes the unexpected elements
from warning messages in the log.  Additionally, it's really serious bug
because editor and layout code rely on the basic structure of HTML document.
Therefore, we should block the worst scenario before deleting such nodes.

Differential Revision: https://phabricator.services.mozilla.com/D123418
2021-08-25 00:39:41 +00:00
Masayuki Nakano
adf47de4ae Bug 1697876 - part 1: Add logging code to transaction classes for making easier to debug r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D110714
2021-04-05 11:35:48 +00:00
Kagami Sascha Rosylight
a20339adb5 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
d775b8dd6d 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
3eab64fd31 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
b7e95d5775 Bug 1644903 - Make nsINode::InsertBefore() callers call ErrorResult::WouldReportJSException() when inserting node may be in another document r=m_kato
`nsINode::InsertBefore()` removes inserting node from a document if it's in
a document including different document.  In this case, `UpdateReflectorGlobal`
in BindingUtils.cpp calls `ErrorResult::MightThrowJSException()`, but editor
never throws exception with `ErrorResult`.  Therefore, editor needs to call
`ErrorResult::WouldReportJSException()` explicitly if the inserting node may
be in another document.

As far as I checked, it can happen only when undoing or redoing a transaction.
Therefore, this patch touches only transaction classes.

Depends on D81683

Differential Revision: https://phabricator.services.mozilla.com/D81684
2020-07-01 13:13:13 +00:00
Masayuki Nakano
46a37854a9 Bug 1540037 - part 10: Move EditorBase::DoJoinNodes() to HTMLEditor r=m_kato
Then, we can make `JoinNodeTransaction` store `HTMLEditor` instead of
`EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D72835
2020-04-30 15:26:09 +00:00
Masayuki Nakano
5254b34421 Bug 1540037 - part 9: Move EditorBase::DoSplitNode() to HTMLEditor r=m_kato
And then, `SplitNodeTransaction` needs to be store `HTMLEditor` instead of
`EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D72833
2020-04-30 13:33:40 +00:00
Masayuki Nakano
e951b45289 Bug 1627175 - part 5: Get rid of EditorBase::GetChildOffset() and EditorBase::GetNodeLocation() r=m_kato
Their users should use `EditorDOMPoint` or something instead.

This patch cleans up `EditorBase::DoJoinNodes()` too because of their heavy
user.  It requires only joined nodes because `aParent` is used only for
removing `aContentToJoin`, but we now have `nsINode::Remove()` which does
not require parent node and never fails.

Depends on D70877

Differential Revision: https://phabricator.services.mozilla.com/D70878
2020-04-16 01:21:17 +00:00
Masayuki Nakano
389c68b4c8 Bug 1619914 - part 2: Mark transaction class methods and their caller methods as `MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D69303
2020-04-03 08:32:01 +00:00
Masayuki Nakano
e2fd42da90 Bug 1619914 - part 1: Make each transaction class grab their members with local variable before touching the DOM tree r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D69302
2020-04-03 08:30:37 +00:00
Mihai Alexandru Michis
2f4e21ee38 Backed out 2 changesets (bug 1619914) for causing gtest failures regarding TransactionManager.
CLOSED TREE

Backed out changeset d3816f82c0b9 (bug 1619914)
Backed out changeset 876b1031a6ae (bug 1619914)
2020-04-03 07:57:06 +03:00
Masayuki Nakano
2ff2244878 Bug 1619914 - part 2: Mark transaction class methods and their caller methods as `MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D69303
2020-04-03 01:39:36 +00:00
Masayuki Nakano
c47ea28eea Bug 1619914 - part 1: Make each transaction class grab their members with local variable before touching the DOM tree r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D69302
2020-04-03 01:38:22 +00:00
Masayuki Nakano
6ccd126a6e Bug 1620504 - part 18: Clean up warnings in SplitNodeTransaction r=m_kato
Depends on D66179

Differential Revision: https://phabricator.services.mozilla.com/D66226
2020-03-11 06:13:26 +00:00
Masayuki Nakano
6a2018d7e9 Bug 1620135 - Clean up trivial constructor and destructor under libeditor r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D65448
2020-03-06 04:38:25 +00:00
Masayuki Nakano
99847fa470 Bug 1610750 - Get rid of unused nsIEditor methods r=m_kato
* getAttributeValue
* cloneAttribute
* splitNode
* joinNodes
* markNodeDirty
* removeEditorObserver

are not used from script.  Therefore, we can get rid of them from `nsIEditor`.

However, `EditorBase::GetAttributeValue()` is referred by
`HTMLEditor::CopyCellBackgroundColor()` and it's just a wrapper of
`Element::GetAttr()`.  Therefore, this patch makes
`HTMLEditor::CopyCellBackgroundColor()` use `Element::GetAttr()` directly.

And also `EditorBase::MarkNodeDirty()` is used from some friend classes.
Therefore, this patch redesigns it as `MarkElementDirty()` and make all of
them check whether the method call destroys the editor.

Differential Revision: https://phabricator.services.mozilla.com/D60796
2020-01-23 12:27:00 +00:00
Masayuki Nakano
cbc64af13d Bug 1548389 - part 0: Wrap modifying text node in editor with particular methods r=m_kato
In the next patch, we need to update unmasked range when anonymous text node
in `<input type="password">` is modified.  This patch makes editor manage it
easier to update the range.

Note that the next patch also handles text node creation and destruction.

Differential Revision: https://phabricator.services.mozilla.com/D38003
2019-07-22 03:53:29 +00:00
Masayuki Nakano
ad34e89b46 Bug 1543315 - part 9: Mark nsIPresShell::FlushPendingNotifications() as MOZ_CAN_RUN_SCRIPT r=smaug
So, this patch makes all caller of it safe including its arguments unless
they come from other methods.

Differential Revision: https://phabricator.services.mozilla.com/D27225
2019-04-13 12:43:57 +00:00
Masayuki Nakano
a4d40d8f8b Bug 1525481 - part 2: Make EditorBase::DoSplitNode() return error if split nodes are moved/removed unexpectedly r=m_kato
We should stop handling splitting nodes if mutation event listeners move or
remove the split nodes unexpectedly because the post processors may not be
able to keep handling the nodes.  For example, if a node is moved to outside
of editing host, we shouldn't touch it anymore due to non-editable.

This patch makes `EditorBase::DoSplitNode()` return new error for making
any parent callers stop their job, but note that the following patch makes
any public methods expose the new error as exception for compatibility with
Chrome.

Differential Revision: https://phabricator.services.mozilla.com/D20810
2019-02-25 08:29:38 +00:00
Masayuki Nakano
7979470dcc Bug 1525481 - part 1: Make SplitNodeTransaction::DoTransaction() always check the result of EditorBase::DoSplitNode() r=m_kato
Oddly, `SplitNodeTransaction::DoTransaction()` checks the result of
`EditorBase::DoSplitNode()` only when it's not allowed to change `Selection`.
We should make it always check the result.

Differential Revision: https://phabricator.services.mozilla.com/D20809
2019-02-25 05:00:27 +00:00
Sylvestre Ledru
e5a134f73a Bug 1511181 - Reformat everything to the Google coding style r=ehsan a=clang-format
# ignore-this-changeset
2018-11-30 11:46:48 +01:00
Masayuki Nakano
8fbb74045d Bug 1480055 - part 2: Rename EditorBase::GetShouldTxnSetSelection() to EditorBase::AllowsTransactionsToChangeSelection() r=m_kato
For explaining what it does clearer, we should rename it and corresponding
member.

MozReview-Commit-ID: 6U8FgfHBbCL
2018-08-01 20:53:57 +09:00
Boris Zbarsky
fd021e28a2 Bug 1463981 part 3. Remove nsIDOMNode usage in editor. r=masayuki 2018-05-24 13:18:34 -04:00
Masayuki Nakano
d6d0996c03 Bug 1451672 - part 6: Rename EditorBase::JoinNodesImpl() to EditorBase::DoJoinNodes() r=m_kato
MozReview-Commit-ID: 9fqa4fKkAF5
2018-04-10 03:56:46 +09:00
Masayuki Nakano
e4852f5cf2 Bug 1451672 - part 4: Rename EditorBase::SplitNodeImpl() to EditorBase::DoSplitNode() r=m_kato
EditorBase::SplitNodeImpl() is called by SplitNodeTransaction::DoTransaction()
for actually splitting a node.  However, "WithoutTransaction" postfix is really
redundant.  Perhaps, just naming DoSplitNode() is better since "Impl" isn't
unclear and not useful if somebody wants to use it as a utility method and
there has already been EditorBase::SplitNode() which is an override of
nsIEditor::SplitNode().  It must not be good to use same name for different
purpose (EditorBase::SplitNode() creates a transaction).

MozReview-Commit-ID: Akjeyp52vVv
2018-04-10 02:32:33 +09:00
Masayuki Nakano
1987f066fb Bug 1447213 - Change editor methods which take |const EditorRawDOMPoint&| but called with EditorDOMPoint.AsRaw() to template methods r=m_kato
A lot of methods take |const EditorRawDOMPoint&| as their argument.  However,
some of them are called with EditorDOMPoint::AsRaw(). This is not good for
performance because:
1. Needs to create temporary instance of EditorRawDOMPoint.
2. EditorRawDOMPoint::AsRaw() may be used by simple mistake.
3. Such methods may call EditorRawDOMPoint::Offset(), however, it's not copied
   to the original EditorDOMPoint instance.  So, callers may need to compute
   offset again.

So, such methods should be changed to template methods if they are not virtual
method and AsRaw() should be gotten rid of for prevent it looking not expensive.

MozReview-Commit-ID: DAqqW4a2EMS
2018-03-20 14:05:47 +09:00
Boris Zbarsky
0e65c74925 Bug 1446533 part 8. Remove nsIDOMCharacterData::DeleteData. r=mystor
MozReview-Commit-ID: 7100YyU5jOG
2018-03-19 15:45:31 -04:00
Adrian Wielgosik
2043bf744f Bug 1379891 - remove nsPIEditorTransaction interface, GetTxnDescription methods. r=m_kato,masayuki
MozReview-Commit-ID: 4NLeMrrqIv5
2018-01-14 16:01:41 +01:00
Masayuki Nakano
6e53432859 Bug 1425412 - part 7: Create SplitNodeTransaction::Create() and remove EditorBase::CreateTxnForSplitNode() r=m_kato
SplitNodeTransaction::Create() just hides what it does.  For making its caller
clearer, let's create a factory method, SplitNodeTransaction::Create().

MozReview-Commit-ID: KDiC8dDrLuQ
2017-12-15 21:37:23 +09:00
Masayuki Nakano
7d375463c7 Bug 1423835 - part 3: Rename EditorDOMPointBase::GetChildAtOffset() to EditorDOMPointBase::GetChild() r=m_kato
Different from RangeBoundaryBase, EditorDOMPointBase can store only child node.
I.e., mOffset may be invalid until its Offset() is called.  So,
GetChildAtOffset() isn't good name.  It should be just GetChild().

Similarly, GetNextSiblingOfChildAtOffset() and
GetPreviousSiblingOfChildAtOffset() should be renamed to GetNextSiblingOfChild()
and GetPreviousSiblingOfChild().

MozReview-Commit-ID: WpkPmDwkrL
2017-12-07 19:08:56 +09:00
Masayuki Nakano
d211bc94b6 Bug 1423835 - part 2: Rename EditorDOMPointBase::Container() to EditorDOMPointBase::GetContainer() and add some useful methods to access its container r=m_kato
EditorDOMPointBase::Container() may return nullptr.  So, it should be renamed
to GetContainer().

Then, the method name becomes longer and a lot of callers access the result
directly.  So, there should be following methods to make the callers shorter:

- GetContainerAsContent() to return the container as nsIContent*.
- GetContainerAsElement() to return the container as dom::Element*.
- GetContainerAsText() to return the container as dom::Text.
- GetContainerAsDOMNode() to return the container as nsIDOMNode*.
- CanContainerHaveChildren() to check if the container can have child nodes.
- IsInDataNode() to check if the point is in a data node including text node.
- IsInTextNode() to check if the point is in a text node.
- IsContainerHTMLElement() to check if the container is specific HTML element.
- IsContainerAnyOfHTMLElements() to check if the container is one of the
  specified HTML elements.

MozReview-Commit-ID: LkN2WBbCPj0
2017-12-07 18:45:52 +09:00
Masayuki Nakano
6a964e7221 Bug 1423835 - part 1: Add EditorDOMPointBase::SetToEndOf() to initialize the instance at end of container node r=m_kato
Editor code sometimes sets a DOM point to end of a node.  In this case, we
need to write |Set(node, node->Length())|.  So, it should have
|void SetToEndOf(const nsINode* aContainer)| for making meaning of the code
clearer.

MozReview-Commit-ID: 91shMCD2d84
2017-12-07 17:27:20 +09:00
Masayuki Nakano
f575ac0d37 Bug 1413181 - part 2: SplitNodeTransaction should store start of existing right node with RangeBoundary r=m_kato
Make SplitNodeTransaction stores start of existing right node (which will be
split) instead of split point as a pair of the right node and offset in it.

MozReview-Commit-ID: 2DIpJGSuNaC
2017-11-12 09:27:19 +09:00
Masayuki Nakano
fb4b14b23e Bug 1413181 - part 1: Redesign EditorBase::SplitNodeImpl() with EditorDOMPoint r=m_kato
EditorBaseSplitNodeImpl() should be clean up with EditorDOMPoint which should
be an argument to point the first point of right node (existing split node).

MozReview-Commit-ID: DN0yHm9G9yT
2017-11-12 08:38:56 +09:00
Masayuki Nakano
b1e0f93335 Bug 1349138 Edit transactions should store their editor instance with strong reference r=smaug
Edit transactions should store their editor instance with strong reference and they should be released at destroying the editor.

MozReview-Commit-ID: D67KU8WFxyo
2017-03-21 19:00:36 +09:00
Olli Pettay
45a7bbd8ea Bug 1309720, ensure expected DOM tree operations when calling insertBefore, r=ehsan 2016-10-14 15:33:42 +03:00
Masayuki Nakano
f55cf1ebb4 Bug 1260651 part.61 Replace "etc" with "etc." r=mccr8
MozReview-Commit-ID: JFgd0t2bqzu
2016-07-08 14:15:21 +09:00