From e3a322b8102d68bf56c072ae208f4a6c0c3db2d0 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 19 Apr 2015 15:28:49 +0300 Subject: [PATCH] Bug 1153649 part 2 - Use some OwningNonNull in editor; r=ehsan --- editor/libeditor/nsHTMLEditRules.cpp | 35 ++++++++++++++-------------- editor/libeditor/nsWSRunObject.cpp | 7 +++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/editor/libeditor/nsHTMLEditRules.cpp b/editor/libeditor/nsHTMLEditRules.cpp index 93b005352452..b4f232b659aa 100644 --- a/editor/libeditor/nsHTMLEditRules.cpp +++ b/editor/libeditor/nsHTMLEditRules.cpp @@ -958,9 +958,8 @@ nsHTMLEditRules::GetIndentState(bool *aCanIndent, bool *aCanOutdent) *aCanOutdent = false; // get selection - NS_ENSURE_STATE(mHTMLEditor); - nsRefPtr selection = mHTMLEditor->GetSelection(); - NS_ENSURE_STATE(selection); + NS_ENSURE_STATE(mHTMLEditor && mHTMLEditor->GetSelection()); + OwningNonNull selection = *mHTMLEditor->GetSelection(); // contruct a list of nodes to act on. nsCOMArray arrayOfNodes; @@ -2006,7 +2005,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection, if (wsType == WSType::text) { // Found normal text to delete. - nsRefPtr nodeAsText = visNode->GetAsText(); + OwningNonNull nodeAsText = *visNode->GetAsText(); int32_t so = visOffset; int32_t eo = visOffset + 1; if (aAction == nsIEditor::ePrevious) { @@ -2040,7 +2039,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection, address_of(visNode), &so, address_of(visNode), &eo); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->DeleteText(*nodeAsText, std::min(so, eo), + res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo), DeprecatedAbs(eo - so)); *aHandled = true; NS_ENSURE_SUCCESS(res, res); @@ -2429,7 +2428,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection, uint32_t rangeCount = aSelection->RangeCount(); for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) { - nsRefPtr range = aSelection->GetRangeAt(rangeIdx); + OwningNonNull range = *aSelection->GetRangeAt(rangeIdx); // Build a list of nodes in the range nsTArray> arrayOfNodes; @@ -2474,19 +2473,19 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection, if (startNode->GetAsText() && startNode->Length() > uint32_t(startOffset)) { // Delete to last character - nsRefPtr dataNode = - static_cast(startNode.get()); + OwningNonNull dataNode = + *static_cast(startNode.get()); NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->DeleteText(*dataNode, startOffset, + res = mHTMLEditor->DeleteText(dataNode, startOffset, startNode->Length() - startOffset); NS_ENSURE_SUCCESS(res, res); } if (endNode->GetAsText() && endOffset) { // Delete to first character NS_ENSURE_STATE(mHTMLEditor); - nsRefPtr dataNode = - static_cast(endNode.get()); - res = mHTMLEditor->DeleteText(*dataNode, 0, endOffset); + OwningNonNull dataNode = + *static_cast(endNode.get()); + res = mHTMLEditor->DeleteText(dataNode, 0, endOffset); NS_ENSURE_SUCCESS(res, res); } @@ -3056,7 +3055,7 @@ nsHTMLEditRules::WillMakeList(Selection* aSelection, if (!aSelection || !aListType || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr listType = do_GetAtom(*aListType); + OwningNonNull listType = do_GetAtom(*aListType); nsresult res = WillInsert(aSelection, aCancel); NS_ENSURE_SUCCESS(res, res); @@ -3126,11 +3125,11 @@ nsHTMLEditRules::WillMakeList(Selection* aSelection, // make sure we can put a list here NS_ENSURE_STATE(mHTMLEditor); - if (!mHTMLEditor->CanContainTag(*parent, *listType)) { + if (!mHTMLEditor->CanContainTag(*parent, listType)) { *aCancel = true; return NS_OK; } - res = SplitAsNeeded(*listType, parent, offset); + res = SplitAsNeeded(listType, parent, offset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr theList = @@ -3300,7 +3299,7 @@ nsHTMLEditRules::WillMakeList(Selection* aSelection, // need to make a list to put things in if we haven't already, if (!curList) { - res = SplitAsNeeded(*listType, curParent, offset); + res = SplitAsNeeded(listType, curParent, offset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); curList = mHTMLEditor->CreateNode(listType, curParent, offset); @@ -3442,7 +3441,7 @@ nsHTMLEditRules::WillMakeBasicBlock(Selection* aSelection, bool *aCancel, bool *aHandled) { - nsCOMPtr blockType = do_GetAtom(*aBlockType); + OwningNonNull blockType = do_GetAtom(*aBlockType); if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } // initialize out param *aCancel = false; @@ -3553,7 +3552,7 @@ nsHTMLEditRules::WillMakeBasicBlock(Selection* aSelection, arrayOfNodes.RemoveObject(brNode); } // make sure we can put a block here - res = SplitAsNeeded(*blockType, parent, offset); + res = SplitAsNeeded(blockType, parent, offset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); theBlock = dont_AddRef(GetAsDOMNode( diff --git a/editor/libeditor/nsWSRunObject.cpp b/editor/libeditor/nsWSRunObject.cpp index f80d5bec7699..2a8d20af86ed 100644 --- a/editor/libeditor/nsWSRunObject.cpp +++ b/editor/libeditor/nsWSRunObject.cpp @@ -5,6 +5,7 @@ #include "nsWSRunObject.h" +#include "mozilla/dom/OwningNonNull.h" #include "mozilla/Assertions.h" #include "mozilla/Casting.h" #include "mozilla/mozalloc.h" @@ -605,13 +606,13 @@ already_AddRefed nsWSRunObject::GetWSBoundingParent() { NS_ENSURE_TRUE(mNode, nullptr); - nsCOMPtr wsBoundingParent = mNode; + OwningNonNull wsBoundingParent = *mNode; while (!IsBlockNode(wsBoundingParent)) { nsCOMPtr parent = wsBoundingParent->GetParentNode(); if (!parent || !mHTMLEditor->IsEditable(parent)) { break; } - wsBoundingParent.swap(parent); + wsBoundingParent = parent; } return wsBoundingParent.forget(); } @@ -1013,7 +1014,7 @@ nsWSRunObject::GetPreviousWSNodeInner(nsINode* aStartNode, MOZ_ASSERT(aStartNode && aBlockParent); nsCOMPtr priorNode = aStartNode->GetPreviousSibling(); - nsCOMPtr curNode = aStartNode; + OwningNonNull curNode = *aStartNode; while (!priorNode) { // We have exhausted nodes in parent of aStartNode. nsCOMPtr curParent = curNode->GetParentNode();