Bug 1153649 part 2 - Use some OwningNonNull in editor; r=ehsan

This commit is contained in:
Aryeh Gregor 2015-04-19 15:28:49 +03:00
parent 27ec7e6c45
commit e3a322b810
2 changed files with 21 additions and 21 deletions

View File

@ -958,9 +958,8 @@ nsHTMLEditRules::GetIndentState(bool *aCanIndent, bool *aCanOutdent)
*aCanOutdent = false;
// get selection
NS_ENSURE_STATE(mHTMLEditor);
nsRefPtr<Selection> selection = mHTMLEditor->GetSelection();
NS_ENSURE_STATE(selection);
NS_ENSURE_STATE(mHTMLEditor && mHTMLEditor->GetSelection());
OwningNonNull<Selection> selection = *mHTMLEditor->GetSelection();
// contruct a list of nodes to act on.
nsCOMArray<nsIDOMNode> arrayOfNodes;
@ -2006,7 +2005,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
if (wsType == WSType::text) {
// Found normal text to delete.
nsRefPtr<Text> nodeAsText = visNode->GetAsText();
OwningNonNull<Text> 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<nsRange> range = aSelection->GetRangeAt(rangeIdx);
OwningNonNull<nsRange> range = *aSelection->GetRangeAt(rangeIdx);
// Build a list of nodes in the range
nsTArray<nsCOMPtr<nsINode>> arrayOfNodes;
@ -2474,19 +2473,19 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
if (startNode->GetAsText() &&
startNode->Length() > uint32_t(startOffset)) {
// Delete to last character
nsRefPtr<nsGenericDOMDataNode> dataNode =
static_cast<nsGenericDOMDataNode*>(startNode.get());
OwningNonNull<nsGenericDOMDataNode> dataNode =
*static_cast<nsGenericDOMDataNode*>(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<nsGenericDOMDataNode> dataNode =
static_cast<nsGenericDOMDataNode*>(endNode.get());
res = mHTMLEditor->DeleteText(*dataNode, 0, endOffset);
OwningNonNull<nsGenericDOMDataNode> dataNode =
*static_cast<nsGenericDOMDataNode*>(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<nsIAtom> listType = do_GetAtom(*aListType);
OwningNonNull<nsIAtom> 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<Element> 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<nsIAtom> blockType = do_GetAtom(*aBlockType);
OwningNonNull<nsIAtom> 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(

View File

@ -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<nsINode>
nsWSRunObject::GetWSBoundingParent()
{
NS_ENSURE_TRUE(mNode, nullptr);
nsCOMPtr<nsINode> wsBoundingParent = mNode;
OwningNonNull<nsINode> wsBoundingParent = *mNode;
while (!IsBlockNode(wsBoundingParent)) {
nsCOMPtr<nsINode> 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<nsIContent> priorNode = aStartNode->GetPreviousSibling();
nsCOMPtr<nsINode> curNode = aStartNode;
OwningNonNull<nsINode> curNode = *aStartNode;
while (!priorNode) {
// We have exhausted nodes in parent of aStartNode.
nsCOMPtr<nsINode> curParent = curNode->GetParentNode();