Bug 1360154 - Part 1. DocumentIsBody should return bool, not nsresult. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 11 May 2017 14:03:26 +0900
changeset 575981 b02fa7d40cff4567583c5d4b690be0e41ad85be0
parent 575938 d8762cb967423618ff0a488f14745f60964e5c49
child 575982 f88b3b6e17680a353db38fa9e2d774e6a078514c
child 576052 5e0c4805a56c6fe9825bde08136a67e67069c16a
push id58222
push userm_kato@ga2.so-net.ne.jp
push dateThu, 11 May 2017 05:14:14 +0000
reviewersmasayuki
bugs1360154
milestone55.0a1
Bug 1360154 - Part 1. DocumentIsBody should return bool, not nsresult. r?masayuki nsIEditRules::GetDocumentIsEmpty doesn't return error without null parameter, so we should use bool as return value instead. MozReview-Commit-ID: HIoQmKu6ETF
editor/libeditor/HTMLEditor.cpp
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
editor/libeditor/TextEditor.cpp
editor/libeditor/nsIEditRules.h
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -3571,25 +3571,21 @@ HTMLEditor::SelectEntireDocument(Selecti
 {
   if (!aSelection || !mRules) {
     return NS_ERROR_NULL_POINTER;
   }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
-  // get editor root node
-  nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
-
   // is doc empty?
-  bool bDocIsEmpty;
-  nsresult rv = rules->DocumentIsEmpty(&bDocIsEmpty);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (bDocIsEmpty) {
+  if (rules->DocumentIsEmpty()) {
+    // get editor root node
+    Element* rootElement = GetRoot();
+
     // if its empty dont select entire doc - that would select the bogus node
     return aSelection->Collapse(rootElement, 0);
   }
 
   return EditorBase::SelectEntireDocument(aSelection);
 }
 
 NS_IMETHODIMP
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -321,23 +321,20 @@ TextEditRules::DidDoAction(Selection* aS
     case EditAction::outputText:
       return DidOutputText(aSelection, aResult);
     default:
       // Don't fail on transactions we don't handle here!
       return NS_OK;
   }
 }
 
-NS_IMETHODIMP
-TextEditRules::DocumentIsEmpty(bool* aDocumentIsEmpty)
+NS_IMETHODIMP_(bool)
+TextEditRules::DocumentIsEmpty()
 {
-  NS_ENSURE_TRUE(aDocumentIsEmpty, NS_ERROR_NULL_POINTER);
-
-  *aDocumentIsEmpty = (mBogusNode != nullptr);
-  return NS_OK;
+  return (mBogusNode != nullptr);
 }
 
 void
 TextEditRules::WillInsert(Selection& aSelection, bool* aCancel)
 {
   MOZ_ASSERT(aCancel);
 
   if (IsReadonly() || IsDisabled()) {
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -60,17 +60,17 @@ public:
   NS_IMETHOD BeforeEdit(EditAction action,
                         nsIEditor::EDirection aDirection) override;
   NS_IMETHOD AfterEdit(EditAction action,
                        nsIEditor::EDirection aDirection) override;
   NS_IMETHOD WillDoAction(Selection* aSelection, RulesInfo* aInfo,
                           bool* aCancel, bool* aHandled) override;
   NS_IMETHOD DidDoAction(Selection* aSelection, RulesInfo* aInfo,
                          nsresult aResult) override;
-  NS_IMETHOD DocumentIsEmpty(bool* aDocumentIsEmpty) override;
+  NS_IMETHOD_(bool) DocumentIsEmpty() override;
   NS_IMETHOD DocumentModified() override;
 
 protected:
   virtual ~TextEditRules();
 
 public:
   void ResetIMETextPWBuf();
 
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -857,18 +857,18 @@ NS_IMETHODIMP
 TextEditor::GetDocumentIsEmpty(bool* aDocumentIsEmpty)
 {
   NS_ENSURE_TRUE(aDocumentIsEmpty, NS_ERROR_NULL_POINTER);
 
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
-
-  return rules->DocumentIsEmpty(aDocumentIsEmpty);
+  *aDocumentIsEmpty = rules->DocumentIsEmpty();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditor::GetTextLength(int32_t* aCount)
 {
   NS_ASSERTION(aCount, "null pointer");
 
   // initialize out params
@@ -1544,18 +1544,17 @@ TextEditor::SelectEntireDocument(Selecti
   if (!aSelection || !mRules) {
     return NS_ERROR_NULL_POINTER;
   }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   // is doc empty?
-  bool bDocIsEmpty;
-  if (NS_SUCCEEDED(rules->DocumentIsEmpty(&bDocIsEmpty)) && bDocIsEmpty) {
+  if (rules->DocumentIsEmpty()) {
     // get root node
     nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
     NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
 
     // if it's empty don't select entire doc - that would select the bogus node
     return aSelection->Collapse(rootElement, 0);
   }
 
--- a/editor/libeditor/nsIEditRules.h
+++ b/editor/libeditor/nsIEditRules.h
@@ -54,15 +54,15 @@ public:
                         nsIEditor::EDirection aDirection) = 0;
   NS_IMETHOD AfterEdit(EditAction action,
                        nsIEditor::EDirection aDirection) = 0;
   NS_IMETHOD WillDoAction(mozilla::dom::Selection* aSelection,
                           mozilla::RulesInfo* aInfo, bool* aCancel,
                           bool* aHandled) = 0;
   NS_IMETHOD DidDoAction(mozilla::dom::Selection* aSelection,
                          mozilla::RulesInfo* aInfo, nsresult aResult) = 0;
-  NS_IMETHOD DocumentIsEmpty(bool* aDocumentIsEmpty) = 0;
+  NS_IMETHOD_(bool) DocumentIsEmpty() = 0;
   NS_IMETHOD DocumentModified() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIEditRules, NS_IEDITRULES_IID)
 
 #endif // #ifndef nsIEditRules_h