зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1574852 - part 14: Move `HTMLEditRules::InsertBRElement()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42785 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
76cfa3e3e3
Коммит
bee148c761
|
@ -1753,7 +1753,8 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
|
||||||
// If we cannot insert a <p>/<div> element at the selection, we should insert
|
// If we cannot insert a <p>/<div> element at the selection, we should insert
|
||||||
// a <br> element instead.
|
// a <br> element instead.
|
||||||
if (insertBRElement) {
|
if (insertBRElement) {
|
||||||
nsresult rv = InsertBRElement(atStartOfSelection);
|
nsresult rv =
|
||||||
|
MOZ_KnownLive(HTMLEditorRef()).InsertBRElement(atStartOfSelection);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return EditActionIgnored(rv);
|
return EditActionIgnored(rv);
|
||||||
}
|
}
|
||||||
|
@ -1796,7 +1797,7 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
|
||||||
}
|
}
|
||||||
if (NS_WARN_IF(blockParent == host)) {
|
if (NS_WARN_IF(blockParent == host)) {
|
||||||
// Didn't create a new block for some reason, fall back to <br>
|
// Didn't create a new block for some reason, fall back to <br>
|
||||||
rv = InsertBRElement(atStartOfSelection);
|
rv = MOZ_KnownLive(HTMLEditorRef()).InsertBRElement(atStartOfSelection);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return EditActionIgnored(rv);
|
return EditActionIgnored(rv);
|
||||||
}
|
}
|
||||||
|
@ -1890,15 +1891,15 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If nobody handles this edit action, let's insert new <br> at the selection.
|
// If nobody handles this edit action, let's insert new <br> at the selection.
|
||||||
rv = InsertBRElement(atStartOfSelection);
|
rv = MOZ_KnownLive(HTMLEditorRef()).InsertBRElement(atStartOfSelection);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return EditActionIgnored(rv);
|
return EditActionIgnored(rv);
|
||||||
}
|
}
|
||||||
return EditActionHandled();
|
return EditActionHandled();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
nsresult HTMLEditor::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
MOZ_ASSERT(IsEditorDataAvailable());
|
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||||
|
|
||||||
if (NS_WARN_IF(!aPointToBreak.IsSet())) {
|
if (NS_WARN_IF(!aPointToBreak.IsSet())) {
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
@ -1910,9 +1911,8 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
// First, insert a <br> element.
|
// First, insert a <br> element.
|
||||||
RefPtr<Element> brElement;
|
RefPtr<Element> brElement;
|
||||||
if (IsPlaintextEditor()) {
|
if (IsPlaintextEditor()) {
|
||||||
brElement = MOZ_KnownLive(HTMLEditorRef())
|
brElement = InsertBRElementWithTransaction(aPointToBreak);
|
||||||
.InsertBRElementWithTransaction(aPointToBreak);
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
if (NS_WARN_IF(!brElement)) {
|
if (NS_WARN_IF(!brElement)) {
|
||||||
|
@ -1920,7 +1920,7 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
EditorDOMPoint pointToBreak(aPointToBreak);
|
EditorDOMPoint pointToBreak(aPointToBreak);
|
||||||
WSRunObject wsObj(&HTMLEditorRef(), pointToBreak);
|
WSRunObject wsObj(this, pointToBreak);
|
||||||
WSType wsType;
|
WSType wsType;
|
||||||
wsObj.PriorVisibleNode(pointToBreak, &wsType);
|
wsObj.PriorVisibleNode(pointToBreak, &wsType);
|
||||||
if (wsType & WSType::block) {
|
if (wsType & WSType::block) {
|
||||||
|
@ -1935,12 +1935,9 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
RefPtr<Element> linkNode =
|
RefPtr<Element> linkNode =
|
||||||
HTMLEditor::GetLinkElement(pointToBreak.GetContainer());
|
HTMLEditor::GetLinkElement(pointToBreak.GetContainer());
|
||||||
if (linkNode) {
|
if (linkNode) {
|
||||||
SplitNodeResult splitLinkNodeResult =
|
SplitNodeResult splitLinkNodeResult = SplitNodeDeepWithTransaction(
|
||||||
MOZ_KnownLive(HTMLEditorRef())
|
*linkNode, pointToBreak, SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||||
.SplitNodeDeepWithTransaction(
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
*linkNode, pointToBreak,
|
|
||||||
SplitAtEdges::eDoNotCreateEmptyContainer);
|
|
||||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
if (NS_WARN_IF(splitLinkNodeResult.Failed())) {
|
if (NS_WARN_IF(splitLinkNodeResult.Failed())) {
|
||||||
|
@ -1950,7 +1947,7 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
}
|
}
|
||||||
brElement = wsObj.InsertBreak(MOZ_KnownLive(*SelectionRefPtr()),
|
brElement = wsObj.InsertBreak(MOZ_KnownLive(*SelectionRefPtr()),
|
||||||
pointToBreak, nsIEditor::eNone);
|
pointToBreak, nsIEditor::eNone);
|
||||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
if (NS_WARN_IF(!brElement)) {
|
if (NS_WARN_IF(!brElement)) {
|
||||||
|
@ -1977,7 +1974,7 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
EditorRawDOMPoint point(brElement);
|
EditorRawDOMPoint point(brElement);
|
||||||
error = NS_OK;
|
error = NS_OK;
|
||||||
SelectionRefPtr()->Collapse(point, error);
|
SelectionRefPtr()->Collapse(point, error);
|
||||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
error.SuppressException();
|
error.SuppressException();
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
|
@ -1991,7 +1988,7 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
DebugOnly<bool> advanced = afterBRElement.AdvanceOffset();
|
DebugOnly<bool> advanced = afterBRElement.AdvanceOffset();
|
||||||
NS_WARNING_ASSERTION(advanced,
|
NS_WARNING_ASSERTION(advanced,
|
||||||
"Failed to advance offset after the new <br> element");
|
"Failed to advance offset after the new <br> element");
|
||||||
WSRunObject wsObj(&HTMLEditorRef(), afterBRElement);
|
WSRunObject wsObj(this, afterBRElement);
|
||||||
nsCOMPtr<nsINode> maybeSecondBRNode;
|
nsCOMPtr<nsINode> maybeSecondBRNode;
|
||||||
WSType wsType;
|
WSType wsType;
|
||||||
wsObj.NextVisibleNode(afterBRElement, address_of(maybeSecondBRNode), nullptr,
|
wsObj.NextVisibleNode(afterBRElement, address_of(maybeSecondBRNode), nullptr,
|
||||||
|
@ -2005,11 +2002,9 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
// the style from the line above.
|
// the style from the line above.
|
||||||
EditorDOMPoint atSecondBRElement(maybeSecondBRNode);
|
EditorDOMPoint atSecondBRElement(maybeSecondBRNode);
|
||||||
if (brElement->GetNextSibling() != maybeSecondBRNode) {
|
if (brElement->GetNextSibling() != maybeSecondBRNode) {
|
||||||
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
|
nsresult rv = MoveNodeWithTransaction(
|
||||||
.MoveNodeWithTransaction(
|
MOZ_KnownLive(*maybeSecondBRNode->AsContent()), afterBRElement);
|
||||||
MOZ_KnownLive(*maybeSecondBRNode->AsContent()),
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
afterBRElement);
|
|
||||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
@ -2035,7 +2030,7 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
|
||||||
"Failed to set or unset interline position");
|
"Failed to set or unset interline position");
|
||||||
error = NS_OK;
|
error = NS_OK;
|
||||||
SelectionRefPtr()->Collapse(afterBRElement, error);
|
SelectionRefPtr()->Collapse(afterBRElement, error);
|
||||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
if (NS_WARN_IF(Destroyed())) {
|
||||||
error.SuppressException();
|
error.SuppressException();
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,15 +139,6 @@ class HTMLEditRules : public TextEditRules {
|
||||||
MOZ_CAN_RUN_SCRIPT
|
MOZ_CAN_RUN_SCRIPT
|
||||||
MOZ_MUST_USE nsresult DeleteNodeIfCollapsedText(nsINode& aNode);
|
MOZ_MUST_USE nsresult DeleteNodeIfCollapsedText(nsINode& aNode);
|
||||||
|
|
||||||
/**
|
|
||||||
* InsertBRElement() inserts a <br> element into aInsertToBreak.
|
|
||||||
*
|
|
||||||
* @param aInsertToBreak The point where new <br> element will be
|
|
||||||
* inserted before.
|
|
||||||
*/
|
|
||||||
MOZ_CAN_RUN_SCRIPT
|
|
||||||
MOZ_MUST_USE nsresult InsertBRElement(const EditorDOMPoint& aInsertToBreak);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before deleting selected contents. This method actually removes
|
* Called before deleting selected contents. This method actually removes
|
||||||
* selected contents.
|
* selected contents.
|
||||||
|
|
|
@ -1193,6 +1193,20 @@ class HTMLEditor final : public TextEditor,
|
||||||
*/
|
*/
|
||||||
bool CanContainParagraph(Element& aElement) const;
|
bool CanContainParagraph(Element& aElement) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InsertBRElement() inserts a <br> element into aInsertToBreak.
|
||||||
|
* This may split container elements at the point and/or may move following
|
||||||
|
* <br> element to immediately after the new <br> element if necessary.
|
||||||
|
* XXX This method name is too generic and unclear whether such complicated
|
||||||
|
* things will be done automatically or not.
|
||||||
|
* XXX This modifies Selection, but should return CreateElementResult instead.
|
||||||
|
*
|
||||||
|
* @param aInsertToBreak The point where new <br> element will be
|
||||||
|
* inserted before.
|
||||||
|
*/
|
||||||
|
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
|
||||||
|
InsertBRElement(const EditorDOMPoint& aInsertToBreak);
|
||||||
|
|
||||||
protected: // Called by helper classes.
|
protected: // Called by helper classes.
|
||||||
virtual void OnStartToHandleTopLevelEditSubAction(
|
virtual void OnStartToHandleTopLevelEditSubAction(
|
||||||
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче