зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1574852 - part 75: Move `HTMLEditRules::OutdentPartOfBlock()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44779 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d64c6562b7
Коммит
a322625816
|
@ -467,6 +467,7 @@ class MOZ_STACK_CLASS SplitRangeOffFromNodeResult final {
|
|||
bool Succeeded() const { return NS_SUCCEEDED(mRv); }
|
||||
bool Failed() const { return NS_FAILED(mRv); }
|
||||
nsresult Rv() const { return mRv; }
|
||||
bool EditorDestroyed() const { return mRv == NS_ERROR_EDITOR_DESTROYED; }
|
||||
|
||||
/**
|
||||
* GetLeftContent() returns new created node before the part of quarried out.
|
||||
|
|
|
@ -5686,7 +5686,8 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
nsCOMPtr<nsIContent> rightContentOfLastOutdented;
|
||||
nsCOMPtr<Element> curBlockQuote;
|
||||
nsCOMPtr<nsIContent> firstBQChild, lastBQChild;
|
||||
bool curBlockQuoteIsIndentedWithCSS = false;
|
||||
HTMLEditor::BlockIndentedWith curBlockIndentedWith =
|
||||
HTMLEditor::BlockIndentedWith::HTML;
|
||||
for (uint32_t i = 0; i < arrayOfNodes.Length(); i++) {
|
||||
if (!arrayOfNodes[i]->IsContent()) {
|
||||
continue;
|
||||
|
@ -5706,8 +5707,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
// with any curBlockQuote first.
|
||||
if (curBlockQuote) {
|
||||
SplitRangeOffFromNodeResult outdentResult =
|
||||
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockQuoteIsIndentedWithCSS);
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockIndentedWith);
|
||||
if (NS_WARN_IF(outdentResult.Failed())) {
|
||||
return outdentResult;
|
||||
}
|
||||
|
@ -5717,7 +5719,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
curBlockQuote = nullptr;
|
||||
firstBQChild = nullptr;
|
||||
lastBQChild = nullptr;
|
||||
curBlockQuoteIsIndentedWithCSS = false;
|
||||
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
|
||||
}
|
||||
rv = MOZ_KnownLive(HTMLEditorRef())
|
||||
.RemoveBlockContainerWithTransaction(
|
||||
|
@ -5763,8 +5765,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
// this list item.
|
||||
if (curBlockQuote) {
|
||||
SplitRangeOffFromNodeResult outdentResult =
|
||||
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockQuoteIsIndentedWithCSS);
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockIndentedWith);
|
||||
if (NS_WARN_IF(outdentResult.Failed())) {
|
||||
return outdentResult;
|
||||
}
|
||||
|
@ -5774,7 +5777,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
curBlockQuote = nullptr;
|
||||
firstBQChild = nullptr;
|
||||
lastBQChild = nullptr;
|
||||
curBlockQuoteIsIndentedWithCSS = false;
|
||||
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
|
||||
}
|
||||
// XXX `curNode` could become different element since
|
||||
// `OutdentPartOfBlock()` may run mutaiton event listeners.
|
||||
|
@ -5800,8 +5803,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
// let's handle it now. We need to remove the portion of
|
||||
// curBlockQuote that contains [firstBQChild - lastBQChild].
|
||||
SplitRangeOffFromNodeResult outdentResult =
|
||||
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockQuoteIsIndentedWithCSS);
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockIndentedWith);
|
||||
if (NS_WARN_IF(outdentResult.Failed())) {
|
||||
return outdentResult;
|
||||
}
|
||||
|
@ -5811,13 +5815,13 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
curBlockQuote = nullptr;
|
||||
firstBQChild = nullptr;
|
||||
lastBQChild = nullptr;
|
||||
curBlockQuoteIsIndentedWithCSS = false;
|
||||
// curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
|
||||
// Fall out and handle curNode
|
||||
}
|
||||
|
||||
// Are we inside a blockquote?
|
||||
OwningNonNull<nsINode> n = curNode;
|
||||
curBlockQuoteIsIndentedWithCSS = false;
|
||||
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
|
||||
// Keep looking up the hierarchy as long as we don't hit the body or the
|
||||
// active editing host or a table element (other than an entire table)
|
||||
while (!n->IsHTMLElement(nsGkAtoms::body) &&
|
||||
|
@ -5854,7 +5858,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
curBlockQuote = n->AsElement();
|
||||
firstBQChild = curNode;
|
||||
lastBQChild = curNode;
|
||||
curBlockQuoteIsIndentedWithCSS = true;
|
||||
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::CSS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -5961,8 +5965,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
|
|||
|
||||
// We have a <blockquote> we haven't finished handling.
|
||||
SplitRangeOffFromNodeResult outdentResult =
|
||||
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockQuoteIsIndentedWithCSS);
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
|
||||
curBlockIndentedWith);
|
||||
if (NS_WARN_IF(outdentResult.Failed())) {
|
||||
return outdentResult;
|
||||
}
|
||||
|
@ -6028,16 +6033,14 @@ SplitRangeOffFromNodeResult HTMLEditor::SplitRangeOffFromBlock(
|
|||
return SplitRangeOffFromNodeResult(splitAtStartResult, splitAtEndResult);
|
||||
}
|
||||
|
||||
SplitRangeOffFromNodeResult HTMLEditRules::OutdentPartOfBlock(
|
||||
SplitRangeOffFromNodeResult HTMLEditor::OutdentPartOfBlock(
|
||||
Element& aBlockElement, nsIContent& aStartOfOutdent,
|
||||
nsIContent& aEndOfOutdent, bool aIsBlockIndentedWithCSS) {
|
||||
MOZ_ASSERT(IsEditorDataAvailable());
|
||||
nsIContent& aEndOfOutdent, BlockIndentedWith aBlockIndentedWith) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
SplitRangeOffFromNodeResult splitResult =
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.SplitRangeOffFromBlock(aBlockElement, aStartOfOutdent,
|
||||
aEndOfOutdent);
|
||||
if (NS_WARN_IF(splitResult.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
SplitRangeOffFromBlock(aBlockElement, aStartOfOutdent, aEndOfOutdent);
|
||||
if (NS_WARN_IF(splitResult.EditorDestroyed())) {
|
||||
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
|
||||
|
@ -6045,11 +6048,10 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentPartOfBlock(
|
|||
return SplitRangeOffFromNodeResult(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
if (!aIsBlockIndentedWithCSS) {
|
||||
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
|
||||
.RemoveBlockContainerWithTransaction(MOZ_KnownLive(
|
||||
*splitResult.GetMiddleContentAsElement()));
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
if (aBlockIndentedWith == BlockIndentedWith::HTML) {
|
||||
nsresult rv = RemoveBlockContainerWithTransaction(
|
||||
MOZ_KnownLive(*splitResult.GetMiddleContentAsElement()));
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -6060,11 +6062,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentPartOfBlock(
|
|||
}
|
||||
|
||||
if (splitResult.GetMiddleContentAsElement()) {
|
||||
nsresult rv =
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.ChangeMarginStart(
|
||||
MOZ_KnownLive(*splitResult.GetMiddleContentAsElement()),
|
||||
HTMLEditor::ChangeMargin::Decrease);
|
||||
nsresult rv = ChangeMarginStart(
|
||||
MOZ_KnownLive(*splitResult.GetMiddleContentAsElement()),
|
||||
ChangeMargin::Decrease);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return SplitRangeOffFromNodeResult(rv);
|
||||
}
|
||||
|
|
|
@ -310,34 +310,6 @@ class HTMLEditRules : public TextEditRules {
|
|||
MOZ_CAN_RUN_SCRIPT
|
||||
MOZ_MUST_USE SplitRangeOffFromNodeResult OutdentAroundSelection();
|
||||
|
||||
/**
|
||||
* OutdentPartOfBlock() outdents the nodes between aStartOfOutdent and
|
||||
* aEndOfOutdent. This splits the range off from aBlockElement first.
|
||||
* Then, removes the middle element if aIsBlockIndentedWithCSS is false.
|
||||
* Otherwise, decreases the margin of the middle element.
|
||||
*
|
||||
* @param aBlockElement A block element which includes both
|
||||
* aStartOfOutdent and aEndOfOutdent.
|
||||
* @param aStartOfOutdent First node which is descendant of
|
||||
* aBlockElement will be outdented.
|
||||
* @param aEndOfOutdent Last node which is descandant of
|
||||
* aBlockElement will be outdented.
|
||||
* @param aIsBlockIndentedWithCSS true if aBlockElement is indented with
|
||||
* CSS margin property.
|
||||
* false if aBlockElement is <blockquote>
|
||||
* or something.
|
||||
* @return The left content is new created element
|
||||
* splitting before aStartOfOutdent.
|
||||
* The right content is existing element.
|
||||
* The middle content is outdented element
|
||||
* if aIsBlockIndentedWithCSS is true.
|
||||
* Otherwise, nullptr.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
MOZ_MUST_USE SplitRangeOffFromNodeResult
|
||||
OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent,
|
||||
nsIContent& aEndOutdent, bool aIsBlockIndentedWithCSS);
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
nsresult GetParagraphFormatNodes(
|
||||
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes);
|
||||
|
|
|
@ -2348,6 +2348,35 @@ class HTMLEditor final : public TextEditor,
|
|||
*/
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult IndentAroundSelectionWithHTML();
|
||||
|
||||
/**
|
||||
* OutdentPartOfBlock() outdents the nodes between aStartOfOutdent and
|
||||
* aEndOfOutdent. This splits the range off from aBlockElement first.
|
||||
* Then, removes the middle element if aIsBlockIndentedWithCSS is false.
|
||||
* Otherwise, decreases the margin of the middle element.
|
||||
*
|
||||
* @param aBlockElement A block element which includes both
|
||||
* aStartOfOutdent and aEndOfOutdent.
|
||||
* @param aStartOfOutdent First node which is descendant of
|
||||
* aBlockElement will be outdented.
|
||||
* @param aEndOfOutdent Last node which is descandant of
|
||||
* aBlockElement will be outdented.
|
||||
* @param aBlockIndentedWith `CSS` if aBlockElement is indented with
|
||||
* CSS margin property.
|
||||
* `HTML` if aBlockElement is `<blockquote>`
|
||||
* or something.
|
||||
* @return The left content is new created element
|
||||
* splitting before aStartOfOutdent.
|
||||
* The right content is existing element.
|
||||
* The middle content is outdented element
|
||||
* if aBlockIndentedWith is `CSS`.
|
||||
* Otherwise, nullptr.
|
||||
*/
|
||||
enum class BlockIndentedWith { CSS, HTML };
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE SplitRangeOffFromNodeResult
|
||||
OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent,
|
||||
nsIContent& aEndOutdent,
|
||||
BlockIndentedWith aBlockIndentedWith);
|
||||
|
||||
protected: // Called by helper classes.
|
||||
virtual void OnStartToHandleTopLevelEditSubAction(
|
||||
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
||||
|
|
Загрузка…
Ссылка в новой задаче