Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit a322625

Browse files
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
1 parent d64c656 commit a322625

4 files changed

Lines changed: 61 additions & 59 deletions

File tree

editor/libeditor/EditorUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ class MOZ_STACK_CLASS SplitRangeOffFromNodeResult final {
467467
bool Succeeded() const { return NS_SUCCEEDED(mRv); }
468468
bool Failed() const { return NS_FAILED(mRv); }
469469
nsresult Rv() const { return mRv; }
470+
bool EditorDestroyed() const { return mRv == NS_ERROR_EDITOR_DESTROYED; }
470471

471472
/**
472473
* GetLeftContent() returns new created node before the part of quarried out.

editor/libeditor/HTMLEditRules.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5686,7 +5686,8 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
56865686
nsCOMPtr<nsIContent> rightContentOfLastOutdented;
56875687
nsCOMPtr<Element> curBlockQuote;
56885688
nsCOMPtr<nsIContent> firstBQChild, lastBQChild;
5689-
bool curBlockQuoteIsIndentedWithCSS = false;
5689+
HTMLEditor::BlockIndentedWith curBlockIndentedWith =
5690+
HTMLEditor::BlockIndentedWith::HTML;
56905691
for (uint32_t i = 0; i < arrayOfNodes.Length(); i++) {
56915692
if (!arrayOfNodes[i]->IsContent()) {
56925693
continue;
@@ -5706,8 +5707,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
57065707
// with any curBlockQuote first.
57075708
if (curBlockQuote) {
57085709
SplitRangeOffFromNodeResult outdentResult =
5709-
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5710-
curBlockQuoteIsIndentedWithCSS);
5710+
MOZ_KnownLive(HTMLEditorRef())
5711+
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5712+
curBlockIndentedWith);
57115713
if (NS_WARN_IF(outdentResult.Failed())) {
57125714
return outdentResult;
57135715
}
@@ -5717,7 +5719,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
57175719
curBlockQuote = nullptr;
57185720
firstBQChild = nullptr;
57195721
lastBQChild = nullptr;
5720-
curBlockQuoteIsIndentedWithCSS = false;
5722+
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
57215723
}
57225724
rv = MOZ_KnownLive(HTMLEditorRef())
57235725
.RemoveBlockContainerWithTransaction(
@@ -5763,8 +5765,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
57635765
// this list item.
57645766
if (curBlockQuote) {
57655767
SplitRangeOffFromNodeResult outdentResult =
5766-
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5767-
curBlockQuoteIsIndentedWithCSS);
5768+
MOZ_KnownLive(HTMLEditorRef())
5769+
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5770+
curBlockIndentedWith);
57685771
if (NS_WARN_IF(outdentResult.Failed())) {
57695772
return outdentResult;
57705773
}
@@ -5774,7 +5777,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
57745777
curBlockQuote = nullptr;
57755778
firstBQChild = nullptr;
57765779
lastBQChild = nullptr;
5777-
curBlockQuoteIsIndentedWithCSS = false;
5780+
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
57785781
}
57795782
// XXX `curNode` could become different element since
57805783
// `OutdentPartOfBlock()` may run mutaiton event listeners.
@@ -5800,8 +5803,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
58005803
// let's handle it now. We need to remove the portion of
58015804
// curBlockQuote that contains [firstBQChild - lastBQChild].
58025805
SplitRangeOffFromNodeResult outdentResult =
5803-
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5804-
curBlockQuoteIsIndentedWithCSS);
5806+
MOZ_KnownLive(HTMLEditorRef())
5807+
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5808+
curBlockIndentedWith);
58055809
if (NS_WARN_IF(outdentResult.Failed())) {
58065810
return outdentResult;
58075811
}
@@ -5811,13 +5815,13 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
58115815
curBlockQuote = nullptr;
58125816
firstBQChild = nullptr;
58135817
lastBQChild = nullptr;
5814-
curBlockQuoteIsIndentedWithCSS = false;
5818+
// curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
58155819
// Fall out and handle curNode
58165820
}
58175821

58185822
// Are we inside a blockquote?
58195823
OwningNonNull<nsINode> n = curNode;
5820-
curBlockQuoteIsIndentedWithCSS = false;
5824+
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::HTML;
58215825
// Keep looking up the hierarchy as long as we don't hit the body or the
58225826
// active editing host or a table element (other than an entire table)
58235827
while (!n->IsHTMLElement(nsGkAtoms::body) &&
@@ -5854,7 +5858,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
58545858
curBlockQuote = n->AsElement();
58555859
firstBQChild = curNode;
58565860
lastBQChild = curNode;
5857-
curBlockQuoteIsIndentedWithCSS = true;
5861+
curBlockIndentedWith = HTMLEditor::BlockIndentedWith::CSS;
58585862
break;
58595863
}
58605864
}
@@ -5961,8 +5965,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
59615965

59625966
// We have a <blockquote> we haven't finished handling.
59635967
SplitRangeOffFromNodeResult outdentResult =
5964-
OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5965-
curBlockQuoteIsIndentedWithCSS);
5968+
MOZ_KnownLive(HTMLEditorRef())
5969+
.OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
5970+
curBlockIndentedWith);
59665971
if (NS_WARN_IF(outdentResult.Failed())) {
59675972
return outdentResult;
59685973
}
@@ -6028,28 +6033,25 @@ SplitRangeOffFromNodeResult HTMLEditor::SplitRangeOffFromBlock(
60286033
return SplitRangeOffFromNodeResult(splitAtStartResult, splitAtEndResult);
60296034
}
60306035

6031-
SplitRangeOffFromNodeResult HTMLEditRules::OutdentPartOfBlock(
6036+
SplitRangeOffFromNodeResult HTMLEditor::OutdentPartOfBlock(
60326037
Element& aBlockElement, nsIContent& aStartOfOutdent,
6033-
nsIContent& aEndOfOutdent, bool aIsBlockIndentedWithCSS) {
6034-
MOZ_ASSERT(IsEditorDataAvailable());
6038+
nsIContent& aEndOfOutdent, BlockIndentedWith aBlockIndentedWith) {
6039+
MOZ_ASSERT(IsEditActionDataAvailable());
60356040

60366041
SplitRangeOffFromNodeResult splitResult =
6037-
MOZ_KnownLive(HTMLEditorRef())
6038-
.SplitRangeOffFromBlock(aBlockElement, aStartOfOutdent,
6039-
aEndOfOutdent);
6040-
if (NS_WARN_IF(splitResult.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
6042+
SplitRangeOffFromBlock(aBlockElement, aStartOfOutdent, aEndOfOutdent);
6043+
if (NS_WARN_IF(splitResult.EditorDestroyed())) {
60416044
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
60426045
}
60436046

60446047
if (NS_WARN_IF(!splitResult.GetMiddleContentAsElement())) {
60456048
return SplitRangeOffFromNodeResult(NS_ERROR_FAILURE);
60466049
}
60476050

6048-
if (!aIsBlockIndentedWithCSS) {
6049-
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
6050-
.RemoveBlockContainerWithTransaction(MOZ_KnownLive(
6051-
*splitResult.GetMiddleContentAsElement()));
6052-
if (NS_WARN_IF(!CanHandleEditAction())) {
6051+
if (aBlockIndentedWith == BlockIndentedWith::HTML) {
6052+
nsresult rv = RemoveBlockContainerWithTransaction(
6053+
MOZ_KnownLive(*splitResult.GetMiddleContentAsElement()));
6054+
if (NS_WARN_IF(Destroyed())) {
60536055
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
60546056
}
60556057
if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -6060,11 +6062,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentPartOfBlock(
60606062
}
60616063

60626064
if (splitResult.GetMiddleContentAsElement()) {
6063-
nsresult rv =
6064-
MOZ_KnownLive(HTMLEditorRef())
6065-
.ChangeMarginStart(
6066-
MOZ_KnownLive(*splitResult.GetMiddleContentAsElement()),
6067-
HTMLEditor::ChangeMargin::Decrease);
6065+
nsresult rv = ChangeMarginStart(
6066+
MOZ_KnownLive(*splitResult.GetMiddleContentAsElement()),
6067+
ChangeMargin::Decrease);
60686068
if (NS_WARN_IF(NS_FAILED(rv))) {
60696069
return SplitRangeOffFromNodeResult(rv);
60706070
}

editor/libeditor/HTMLEditRules.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -310,34 +310,6 @@ class HTMLEditRules : public TextEditRules {
310310
MOZ_CAN_RUN_SCRIPT
311311
MOZ_MUST_USE SplitRangeOffFromNodeResult OutdentAroundSelection();
312312

313-
/**
314-
* OutdentPartOfBlock() outdents the nodes between aStartOfOutdent and
315-
* aEndOfOutdent. This splits the range off from aBlockElement first.
316-
* Then, removes the middle element if aIsBlockIndentedWithCSS is false.
317-
* Otherwise, decreases the margin of the middle element.
318-
*
319-
* @param aBlockElement A block element which includes both
320-
* aStartOfOutdent and aEndOfOutdent.
321-
* @param aStartOfOutdent First node which is descendant of
322-
* aBlockElement will be outdented.
323-
* @param aEndOfOutdent Last node which is descandant of
324-
* aBlockElement will be outdented.
325-
* @param aIsBlockIndentedWithCSS true if aBlockElement is indented with
326-
* CSS margin property.
327-
* false if aBlockElement is <blockquote>
328-
* or something.
329-
* @return The left content is new created element
330-
* splitting before aStartOfOutdent.
331-
* The right content is existing element.
332-
* The middle content is outdented element
333-
* if aIsBlockIndentedWithCSS is true.
334-
* Otherwise, nullptr.
335-
*/
336-
MOZ_CAN_RUN_SCRIPT
337-
MOZ_MUST_USE SplitRangeOffFromNodeResult
338-
OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent,
339-
nsIContent& aEndOutdent, bool aIsBlockIndentedWithCSS);
340-
341313
MOZ_CAN_RUN_SCRIPT
342314
nsresult GetParagraphFormatNodes(
343315
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes);

editor/libeditor/HTMLEditor.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,35 @@ class HTMLEditor final : public TextEditor,
23482348
*/
23492349
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult IndentAroundSelectionWithHTML();
23502350

2351+
/**
2352+
* OutdentPartOfBlock() outdents the nodes between aStartOfOutdent and
2353+
* aEndOfOutdent. This splits the range off from aBlockElement first.
2354+
* Then, removes the middle element if aIsBlockIndentedWithCSS is false.
2355+
* Otherwise, decreases the margin of the middle element.
2356+
*
2357+
* @param aBlockElement A block element which includes both
2358+
* aStartOfOutdent and aEndOfOutdent.
2359+
* @param aStartOfOutdent First node which is descendant of
2360+
* aBlockElement will be outdented.
2361+
* @param aEndOfOutdent Last node which is descandant of
2362+
* aBlockElement will be outdented.
2363+
* @param aBlockIndentedWith `CSS` if aBlockElement is indented with
2364+
* CSS margin property.
2365+
* `HTML` if aBlockElement is `<blockquote>`
2366+
* or something.
2367+
* @return The left content is new created element
2368+
* splitting before aStartOfOutdent.
2369+
* The right content is existing element.
2370+
* The middle content is outdented element
2371+
* if aBlockIndentedWith is `CSS`.
2372+
* Otherwise, nullptr.
2373+
*/
2374+
enum class BlockIndentedWith { CSS, HTML };
2375+
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE SplitRangeOffFromNodeResult
2376+
OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent,
2377+
nsIContent& aEndOutdent,
2378+
BlockIndentedWith aBlockIndentedWith);
2379+
23512380
protected: // Called by helper classes.
23522381
virtual void OnStartToHandleTopLevelEditSubAction(
23532382
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;

0 commit comments

Comments
 (0)