From 81d03b3b1d407d6405d27d5e11a567ffed20cac5 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Wed, 20 Apr 2016 20:44:56 +0300 Subject: [PATCH] Bug 1156062 - Back out for now, requested by Masayuki at bug 1191356 comment 23 --- editor/libeditor/nsHTMLEditRules.cpp | 87 +++++++++++++--------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/editor/libeditor/nsHTMLEditRules.cpp b/editor/libeditor/nsHTMLEditRules.cpp index 997af22e9df6..4a16a5af8f8b 100644 --- a/editor/libeditor/nsHTMLEditRules.cpp +++ b/editor/libeditor/nsHTMLEditRules.cpp @@ -312,28 +312,23 @@ NS_IMETHODIMP nsHTMLEditRules::BeforeEdit(EditAction action, nsIEditor::EDirection aDirection) { - if (mLockRulesSniffing) { - return NS_OK; - } + if (mLockRulesSniffing) return NS_OK; - NS_ENSURE_STATE(mHTMLEditor); - nsCOMPtr kungFuDeathGrip(mHTMLEditor); - - nsAutoLockRulesSniffing lockIt(this); + nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this); mDidExplicitlySetInterline = false; - if (!mActionNesting) { - mActionNesting++; - - // Clear our flag about if just deleted a range + if (!mActionNesting++) + { + // clear our flag about if just deleted a range mDidRangedDelete = false; - // Remember where our selection was before edit action took place: + // remember where our selection was before edit action took place: - // Get selection + // get selection + NS_ENSURE_STATE(mHTMLEditor); RefPtr selection = mHTMLEditor->GetSelection(); - // Get the selection location + // get the selection location if (!selection->RangeCount()) { return NS_ERROR_UNEXPECTED; } @@ -341,37 +336,42 @@ nsHTMLEditRules::BeforeEdit(EditAction action, mRangeItem->startOffset = selection->GetRangeAt(0)->StartOffset(); mRangeItem->endNode = selection->GetRangeAt(0)->GetEndParent(); mRangeItem->endOffset = selection->GetRangeAt(0)->EndOffset(); - nsCOMPtr selStartNode = mRangeItem->startNode; - nsCOMPtr selEndNode = mRangeItem->endNode; + nsCOMPtr selStartNode = GetAsDOMNode(mRangeItem->startNode); + nsCOMPtr selEndNode = GetAsDOMNode(mRangeItem->endNode); - // Register with range updater to track this as we perturb the doc + // register this range with range updater to track this as we perturb the doc + NS_ENSURE_STATE(mHTMLEditor); (mHTMLEditor->mRangeUpdater).RegisterRangeItem(mRangeItem); - // Clear deletion state bool + // clear deletion state bool mDidDeleteSelection = false; - // Clear out mDocChangeRange and mUtilRange - if (mDocChangeRange) { - // Clear out our accounting of what changed + // clear out mDocChangeRange and mUtilRange + if(mDocChangeRange) + { + // clear out our accounting of what changed mDocChangeRange->Reset(); } - if (mUtilRange) { - // Ditto for mUtilRange. + if(mUtilRange) + { + // ditto for mUtilRange. mUtilRange->Reset(); } - // Remember current inline styles for deletion and normal insertion ops + // remember current inline styles for deletion and normal insertion operations if (action == EditAction::insertText || action == EditAction::insertIMEText || action == EditAction::deleteSelection || IsStyleCachePreservingAction(action)) { - nsCOMPtr selNode = - aDirection == nsIEditor::eNext ? selEndNode : selStartNode; - nsresult rv = CacheInlineStyles(GetAsDOMNode(selNode)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr selNode = selStartNode; + if (aDirection == nsIEditor::eNext) + selNode = selEndNode; + nsresult res = CacheInlineStyles(selNode); + NS_ENSURE_SUCCESS(res, res); } // Stabilize the document against contenteditable count changes + NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr doc = mHTMLEditor->GetDOMDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED); nsCOMPtr htmlDoc = do_QueryInterface(doc); @@ -381,9 +381,9 @@ nsHTMLEditRules::BeforeEdit(EditAction action, mRestoreContentEditableCount = true; } - // Check that selection is in subtree defined by body node + // check that selection is in subtree defined by body node ConfirmSelectionInBody(); - // Let rules remember the top level action + // let rules remember the top level action mTheAction = action; } return NS_OK; @@ -394,27 +394,24 @@ NS_IMETHODIMP nsHTMLEditRules::AfterEdit(EditAction action, nsIEditor::EDirection aDirection) { - if (mLockRulesSniffing) { - return NS_OK; - } - - NS_ENSURE_STATE(mHTMLEditor); - nsCOMPtr kungFuDeathGrip(mHTMLEditor); + if (mLockRulesSniffing) return NS_OK; nsAutoLockRulesSniffing lockIt(this); - MOZ_ASSERT(mActionNesting > 0); - nsresult rv = NS_OK; - mActionNesting--; - if (!mActionNesting) { - // Do all the tricky stuff - rv = AfterEditInner(action, aDirection); + NS_PRECONDITION(mActionNesting>0, "bad action nesting!"); + nsresult res = NS_OK; + if (!--mActionNesting) + { + // do all the tricky stuff + res = AfterEditInner(action, aDirection); - // Free up selectionState range item + // free up selectionState range item + NS_ENSURE_STATE(mHTMLEditor); (mHTMLEditor->mRangeUpdater).DropRangeItem(mRangeItem); // Reset the contenteditable count to its previous value if (mRestoreContentEditableCount) { + NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr doc = mHTMLEditor->GetDOMDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED); nsCOMPtr htmlDoc = do_QueryInterface(doc); @@ -426,9 +423,7 @@ nsHTMLEditRules::AfterEdit(EditAction action, } } - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; + return res; }