Bug 813532 - Part a: Some cleanup for GetPriorHTMLNode; r=ehsan
authorMs2ger <ms2ger@gmail.com>
Sat, 22 Dec 2012 09:17:05 +0100
changeset 116675 663a6aa70ffd24d6356e47f49e6fc5dda2b9705a
parent 116674 8ca4011a1250c4548eb00323511171b54139c428
child 116676 d78fba69a62b5c4883df89fdf317aa8d81ba15ab
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs813532
milestone20.0a1
Bug 813532 - Part a: Some cleanup for GetPriorHTMLNode; r=ehsan
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/html/nsHTMLEditor.h
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -4057,69 +4057,72 @@ nsHTMLEditor::GetNextHTMLSibling(nsIDOMN
 }
 
 
 
 ///////////////////////////////////////////////////////////////////////////
 // GetPriorHTMLNode: returns the previous editable leaf node, if there is
 //                   one within the <body>
 //
-nsresult
-nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing)
+nsIContent*
+nsHTMLEditor::GetPriorHTMLNode(nsINode* aNode, bool aNoBlockCrossing)
 {
-  NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
-
-  nsIContent* activeEditingHost = GetActiveEditingHost();
-  if (!activeEditingHost) {
-    *outNode = nullptr;
-    return NS_OK;
+  MOZ_ASSERT(aNode);
+
+  if (!GetActiveEditingHost()) {
+    return nullptr;
   }
 
-  nsresult res = GetPriorNode(inNode, true, address_of(*outNode),
-                              bNoBlockCrossing);
-  NS_ENSURE_SUCCESS(res, res);
-  
-  NS_ASSERTION(!*outNode || IsDescendantOfEditorRoot(*outNode),
-               "GetPriorNode screwed up");
-  return res;
+  return GetPriorNode(aNode, true, aNoBlockCrossing);
+}
+
+nsresult
+nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode* aNode,
+                               nsCOMPtr<nsIDOMNode>* aResultNode,
+                               bool aNoBlockCrossing)
+{
+  NS_ENSURE_TRUE(aResultNode, NS_ERROR_NULL_POINTER);
+
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+  NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
+
+  *aResultNode = do_QueryInterface(GetPriorHTMLNode(node, aNoBlockCrossing));
+  return NS_OK;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////
 // GetPriorHTMLNode: same as above but takes {parent,offset} instead of node
-//                       
+//
 nsIContent*
 nsHTMLEditor::GetPriorHTMLNode(nsINode* aParent, int32_t aOffset,
                                bool aNoBlockCrossing)
 {
+  MOZ_ASSERT(aParent);
+
   if (!GetActiveEditingHost()) {
     return nullptr;
   }
 
   return GetPriorNode(aParent, aOffset, true, aNoBlockCrossing);
 }
 
 nsresult
-nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode *inParent, int32_t inOffset, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing)
+nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode* aNode, int32_t aOffset,
+                               nsCOMPtr<nsIDOMNode>* aResultNode,
+                               bool aNoBlockCrossing)
 {
-  NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
-
-  nsIContent* activeEditingHost = GetActiveEditingHost();
-  if (!activeEditingHost) {
-    *outNode = nullptr;
-    return NS_OK;
-  }
-
-  nsresult res = GetPriorNode(inParent, inOffset, true, address_of(*outNode),
-                              bNoBlockCrossing);
-  NS_ENSURE_SUCCESS(res, res);
-
-  NS_ASSERTION(!*outNode || IsDescendantOfEditorRoot(*outNode),
-               "GetPriorNode screwed up");
-  return res;
+  NS_ENSURE_TRUE(aResultNode, NS_ERROR_NULL_POINTER);
+
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+  NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
+
+  *aResultNode = do_QueryInterface(GetPriorHTMLNode(node, aOffset,
+                                                    aNoBlockCrossing));
+  return NS_OK;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////
 // GetNextHTMLNode: returns the next editable leaf node, if there is
 //                   one within the <body>
 //                       
 nsresult
--- a/editor/libeditor/html/nsHTMLEditor.h
+++ b/editor/libeditor/html/nsHTMLEditor.h
@@ -671,28 +671,33 @@ protected:
   bool NodeIsProperty(nsIDOMNode *aNode);
   bool HasAttr(nsIDOMNode *aNode, const nsAString *aAttribute);
   bool IsAtFrontOfNode(nsIDOMNode *aNode, int32_t aOffset);
   bool IsAtEndOfNode(nsIDOMNode *aNode, int32_t aOffset);
   bool IsOnlyAttribute(nsIDOMNode *aElement, const nsAString *aAttribute);
   bool IsOnlyAttribute(const nsIContent* aElement, const nsAString& aAttribute);
 
   nsresult RemoveBlockContainer(nsIDOMNode *inNode);
+
   nsIContent* GetPriorHTMLSibling(nsINode* aNode);
   nsresult GetPriorHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode);
   nsIContent* GetPriorHTMLSibling(nsINode* aParent, int32_t aOffset);
   nsresult GetPriorHTMLSibling(nsIDOMNode *inParent, int32_t inOffset, nsCOMPtr<nsIDOMNode> *outNode);
+
   nsIContent* GetNextHTMLSibling(nsINode* aNode);
   nsresult GetNextHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode);
   nsIContent* GetNextHTMLSibling(nsINode* aParent, int32_t aOffset);
   nsresult GetNextHTMLSibling(nsIDOMNode *inParent, int32_t inOffset, nsCOMPtr<nsIDOMNode> *outNode);
+
+  nsIContent* GetPriorHTMLNode(nsINode* aNode, bool aNoBlockCrossing = false);
   nsresult GetPriorHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing = false);
-  nsresult GetPriorHTMLNode(nsIDOMNode *inParent, int32_t inOffset, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing = false);
   nsIContent* GetPriorHTMLNode(nsINode* aParent, int32_t aOffset,
                                bool aNoBlockCrossing = false);
+  nsresult GetPriorHTMLNode(nsIDOMNode *inParent, int32_t inOffset, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing = false);
+
   nsresult GetNextHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing = false);
   nsIContent* GetNextHTMLNode(nsINode* aParent, int32_t aOffset,
                               bool aNoBlockCrossing = false);
   nsresult GetNextHTMLNode(nsIDOMNode *inParent, int32_t inOffset, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing = false);
 
   nsresult IsFirstEditableChild( nsIDOMNode *aNode, bool *aOutIsFirst);
   nsresult IsLastEditableChild( nsIDOMNode *aNode, bool *aOutIsLast);
   nsresult GetFirstEditableChild( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutFirstChild);