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
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
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
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
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
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
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
`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
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
CLOSED TREE
Backed out changeset d3d67293f115 (bug 1623413)
Backed out changeset 75ed1b8a5c67 (bug 1623413)
Backed out changeset 0eef32d6a454 (bug 1623413)
`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
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
* 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
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
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
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
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
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
SplitNodeTransaction::Create() just hides what it does. For making its caller
clearer, let's create a factory method, SplitNodeTransaction::Create().
MozReview-Commit-ID: KDiC8dDrLuQ
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
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
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
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
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
Edit transactions should store their editor instance with strong reference and they should be released at destroying the editor.
MozReview-Commit-ID: D67KU8WFxyo