mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1574852 - part 12: Move HTMLEditRules::SplitMailCites()
to HTMLEditor
r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42783 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
afaaa019c8
commit
d0797846a4
@ -1673,7 +1673,13 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
|
||||
// Split any mailcites in the way. Should we abort this if we encounter
|
||||
// table cell boundaries?
|
||||
if (IsMailEditor()) {
|
||||
EditActionResult result = SplitMailCites();
|
||||
EditorDOMPoint pointToSplit(EditorBase::GetStartPoint(*SelectionRefPtr()));
|
||||
if (NS_WARN_IF(!pointToSplit.IsSet())) {
|
||||
return EditActionIgnored(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
EditActionResult result =
|
||||
MOZ_KnownLive(HTMLEditorRef()).SplitMailCiteElements(pointToSplit);
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
return result;
|
||||
}
|
||||
@ -2039,20 +2045,19 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
MOZ_ASSERT(IsEditorDataAvailable());
|
||||
EditActionResult HTMLEditor::SplitMailCiteElements(
|
||||
const EditorDOMPoint& aPointToSplit) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
MOZ_ASSERT(aPointToSplit.IsSet());
|
||||
|
||||
EditorDOMPoint pointToSplit(EditorBase::GetStartPoint(*SelectionRefPtr()));
|
||||
if (NS_WARN_IF(!pointToSplit.IsSet())) {
|
||||
return EditActionIgnored(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
RefPtr<Element> citeNode = HTMLEditorRef().GetMostAncestorMailCiteElement(
|
||||
*pointToSplit.GetContainer());
|
||||
RefPtr<Element> citeNode =
|
||||
GetMostAncestorMailCiteElement(*aPointToSplit.GetContainer());
|
||||
if (!citeNode) {
|
||||
return EditActionIgnored();
|
||||
}
|
||||
|
||||
EditorDOMPoint pointToSplit(aPointToSplit);
|
||||
|
||||
// If our selection is just before a break, nudge it to be just after it.
|
||||
// This does two things for us. It saves us the trouble of having to add
|
||||
// a break here ourselves to preserve the "blockness" of the inline span
|
||||
@ -2062,7 +2067,7 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
// The latter can confuse a user if they click there and start typing,
|
||||
// because being in the mailquote may affect wrapping behavior, or font
|
||||
// color, etc.
|
||||
WSRunObject wsObj(&HTMLEditorRef(), pointToSplit);
|
||||
WSRunObject wsObj(this, pointToSplit);
|
||||
nsCOMPtr<nsINode> visNode;
|
||||
WSType wsType;
|
||||
wsObj.NextVisibleNode(pointToSplit, address_of(visNode), nullptr, &wsType);
|
||||
@ -2080,12 +2085,9 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
return EditActionIgnored(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
SplitNodeResult splitCiteNodeResult =
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.SplitNodeDeepWithTransaction(
|
||||
*citeNode, pointToSplit,
|
||||
SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
SplitNodeResult splitCiteNodeResult = SplitNodeDeepWithTransaction(
|
||||
*citeNode, pointToSplit, SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_WARN_IF(splitCiteNodeResult.Failed())) {
|
||||
@ -2113,9 +2115,8 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
EditorDOMPoint endOfPreviousNodeOfSplitPoint;
|
||||
endOfPreviousNodeOfSplitPoint.SetToEndOf(previousNodeOfSplitPoint);
|
||||
RefPtr<Element> invisibleBrElement =
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.InsertBRElementWithTransaction(endOfPreviousNodeOfSplitPoint);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
InsertBRElementWithTransaction(endOfPreviousNodeOfSplitPoint);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
NS_WARNING_ASSERTION(invisibleBrElement,
|
||||
@ -2128,9 +2129,8 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
// cite node, <br> should be inserted before the current cite.
|
||||
EditorDOMPoint pointToInsertBrNode(splitCiteNodeResult.SplitPoint());
|
||||
RefPtr<Element> brElement =
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.InsertBRElementWithTransaction(pointToInsertBrNode);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
InsertBRElementWithTransaction(pointToInsertBrNode);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_WARN_IF(!brElement)) {
|
||||
@ -2147,7 +2147,7 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
NS_WARNING_ASSERTION(!error.Failed(), "Failed to set interline position");
|
||||
error = NS_OK;
|
||||
SelectionRefPtr()->Collapse(atBrNode, error);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
error.SuppressException();
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
@ -2164,7 +2164,7 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
EditorDOMPoint pointToCreateNewBrNode(atBrNode.GetContainer(),
|
||||
atBrNode.Offset());
|
||||
|
||||
WSRunObject wsObj(&HTMLEditorRef(), pointToCreateNewBrNode);
|
||||
WSRunObject wsObj(this, pointToCreateNewBrNode);
|
||||
WSType wsType;
|
||||
wsObj.PriorVisibleNode(pointToCreateNewBrNode, nullptr, nullptr, &wsType);
|
||||
if (wsType == WSType::normalWS || wsType == WSType::text ||
|
||||
@ -2173,15 +2173,14 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
DebugOnly<bool> advanced = pointAfterNewBrNode.AdvanceOffset();
|
||||
NS_WARNING_ASSERTION(advanced,
|
||||
"Failed to advance offset after the <br> node");
|
||||
WSRunObject wsObjAfterBR(&HTMLEditorRef(), pointAfterNewBrNode);
|
||||
WSRunObject wsObjAfterBR(this, pointAfterNewBrNode);
|
||||
wsObjAfterBR.NextVisibleNode(pointAfterNewBrNode, &wsType);
|
||||
if (wsType == WSType::normalWS || wsType == WSType::text ||
|
||||
wsType == WSType::special ||
|
||||
// In case we're at the very end.
|
||||
wsType == WSType::thisBlock) {
|
||||
brElement = MOZ_KnownLive(HTMLEditorRef())
|
||||
.InsertBRElementWithTransaction(pointToCreateNewBrNode);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
brElement = InsertBRElementWithTransaction(pointToCreateNewBrNode);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_WARN_IF(!brElement)) {
|
||||
@ -2197,16 +2196,14 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
// delete any empty cites
|
||||
bool bEmptyCite = false;
|
||||
if (previousNodeOfSplitPoint) {
|
||||
nsresult rv = HTMLEditorRef().IsEmptyNode(previousNodeOfSplitPoint,
|
||||
&bEmptyCite, true, false);
|
||||
nsresult rv =
|
||||
IsEmptyNode(previousNodeOfSplitPoint, &bEmptyCite, true, false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return EditActionIgnored(rv);
|
||||
}
|
||||
if (bEmptyCite) {
|
||||
rv = MOZ_KnownLive(HTMLEditorRef())
|
||||
.DeleteNodeWithTransaction(
|
||||
MOZ_KnownLive(*previousNodeOfSplitPoint));
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
rv = DeleteNodeWithTransaction(MOZ_KnownLive(*previousNodeOfSplitPoint));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
@ -2216,14 +2213,13 @@ EditActionResult HTMLEditRules::SplitMailCites() {
|
||||
}
|
||||
|
||||
if (citeNode) {
|
||||
nsresult rv =
|
||||
HTMLEditorRef().IsEmptyNode(citeNode, &bEmptyCite, true, false);
|
||||
nsresult rv = IsEmptyNode(citeNode, &bEmptyCite, true, false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return EditActionIgnored(rv);
|
||||
}
|
||||
if (bEmptyCite) {
|
||||
rv = MOZ_KnownLive(HTMLEditorRef()).DeleteNodeWithTransaction(*citeNode);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
rv = DeleteNodeWithTransaction(*citeNode);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -148,15 +148,6 @@ class HTMLEditRules : public TextEditRules {
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
MOZ_MUST_USE nsresult InsertBRElement(const EditorDOMPoint& aInsertToBreak);
|
||||
|
||||
/**
|
||||
* SplitMailCites() splits mail-cite elements at start of Selection if
|
||||
* Selection starts from inside a mail-cite element. Of course, if it's
|
||||
* necessary, this inserts <br> node to new left nodes or existing right
|
||||
* nodes.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
MOZ_MUST_USE EditActionResult SplitMailCites();
|
||||
|
||||
/**
|
||||
* Called before deleting selected contents. This method actually removes
|
||||
* selected contents.
|
||||
|
@ -42,6 +42,7 @@ class nsRange;
|
||||
namespace mozilla {
|
||||
class AutoSelectionSetterAfterTableEdit;
|
||||
class AutoSetTemporaryAncestorLimiter;
|
||||
class EditActionResult;
|
||||
class EmptyEditableFunctor;
|
||||
class ResizerSelectionListener;
|
||||
enum class EditSubAction : int32_t;
|
||||
@ -1176,6 +1177,16 @@ class HTMLEditor final : public TextEditor,
|
||||
*/
|
||||
Element* GetMostAncestorMailCiteElement(nsINode& aNode) const;
|
||||
|
||||
/**
|
||||
* SplitMailCiteElements() splits mail-cite elements at start of Selection if
|
||||
* Selection starts from inside a mail-cite element. Of course, if it's
|
||||
* necessary, this inserts <br> node to new left nodes or existing right
|
||||
* nodes.
|
||||
* XXX This modifies Selection, but should return SplitNodeResult() instead.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
|
||||
SplitMailCiteElements(const EditorDOMPoint& aPointToSplit);
|
||||
|
||||
protected: // Called by helper classes.
|
||||
virtual void OnStartToHandleTopLevelEditSubAction(
|
||||
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
||||
|
Loading…
Reference in New Issue
Block a user