Bug 1445569 - part 3: Make TextEditRules::CheckBidiLevelForDeletion() take |const EditorRawDOMPoint&| instead of |nsINode*| and offset in it r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 15 Mar 2018 18:38:46 +0900
changeset 768342 1fd7ffcc3f5a1e926278ff3e91bef91d6512ad06
parent 768341 f98da05ecfd7aed13427c1607bebd90d75d51a7c
child 768343 8575488ffaa3fc6d292c8975c013a5173ff267db
push id102858
push usermasayuki@d-toybox.com
push dateFri, 16 Mar 2018 03:57:40 +0000
reviewersm_kato
bugs1445569
milestone61.0a1
Bug 1445569 - part 3: Make TextEditRules::CheckBidiLevelForDeletion() take |const EditorRawDOMPoint&| instead of |nsINode*| and offset in it r?m_kato There are 2 callers of TextEditRules::CheckBidiLevelForDeletion(). One of them will start to use EditorRawDOMPoint. Therefore, making it take |const EditorRawDOMPoint&| instead of |nsINode*| and offset in it keeps the caller simpler. MozReview-Commit-ID: DRJXo8gnzba
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
editor/libeditor/TextEditRulesBidi.cpp
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2197,19 +2197,22 @@ HTMLEditRules::WillDeleteSelection(Selec
     NS_ENSURE_TRUE(host, NS_ERROR_FAILURE);
     rv = CheckForEmptyBlock(startNode, host, aSelection, aAction, aHandled);
     NS_ENSURE_SUCCESS(rv, rv);
     if (*aHandled) {
       return NS_OK;
     }
 
     // Test for distance between caret and text that will be deleted
-    rv = CheckBidiLevelForDeletion(aSelection, startNode,
-                                   startOffset, aAction, aCancel);
-    NS_ENSURE_SUCCESS(rv, rv);
+    rv = CheckBidiLevelForDeletion(aSelection,
+                                   EditorRawDOMPoint(startNode, startOffset),
+                                   aAction, aCancel);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
     if (*aCancel) {
       return NS_OK;
     }
 
     NS_ENSURE_STATE(mHTMLEditor);
     rv = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction);
     NS_ENSURE_SUCCESS(rv, rv);
 
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1040,19 +1040,22 @@ TextEditRules::WillDeleteSelection(Selec
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
 
     if (!aSelection->IsCollapsed()) {
       return NS_OK;
     }
 
     // Test for distance between caret and text that will be deleted
-    rv = CheckBidiLevelForDeletion(aSelection, startNode, startOffset,
+    rv = CheckBidiLevelForDeletion(aSelection,
+                                   EditorRawDOMPoint(startNode, startOffset),
                                    aCollapsedAction, aCancel);
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
     if (*aCancel) {
       return NS_OK;
     }
 
     NS_ENSURE_STATE(mTextEditor);
     rv = mTextEditor->ExtendSelectionForDelete(aSelection, &aCollapsedAction);
     NS_ENSURE_SUCCESS(rv, rv);
   }
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -257,18 +257,17 @@ protected:
    */
   already_AddRefed<Element>
   CreateBRInternal(const EditorRawDOMPoint& aPointToInsert,
                    bool aCreateMozBR);
 
   void UndefineCaretBidiLevel(Selection* aSelection);
 
   nsresult CheckBidiLevelForDeletion(Selection* aSelection,
-                                     nsINode* aSelNode,
-                                     int32_t aSelOffset,
+                                     const EditorRawDOMPoint& aSelectionPoint,
                                      nsIEditor::EDirection aAction,
                                      bool* aCancel);
 
   nsresult HideLastPWInput();
 
   nsresult CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection);
 
   bool IsPasswordEditor() const;
--- a/editor/libeditor/TextEditRulesBidi.cpp
+++ b/editor/libeditor/TextEditRulesBidi.cpp
@@ -19,48 +19,48 @@
 #include "nscore.h"
 
 namespace mozilla {
 
 using namespace dom;
 
 // Test for distance between caret and text that will be deleted
 nsresult
-TextEditRules::CheckBidiLevelForDeletion(Selection* aSelection,
-                                         nsINode* aSelNode,
-                                         int32_t aSelOffset,
-                                         nsIEditor::EDirection aAction,
-                                         bool* aCancel)
+TextEditRules::CheckBidiLevelForDeletion(
+                 Selection* aSelection,
+                 const EditorRawDOMPoint& aSelectionPoint,
+                 nsIEditor::EDirection aAction,
+                 bool* aCancel)
 {
   NS_ENSURE_ARG_POINTER(aCancel);
   *aCancel = false;
 
   nsCOMPtr<nsIPresShell> shell = mTextEditor->GetPresShell();
   NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
 
   nsPresContext *context = shell->GetPresContext();
   NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
 
   if (!context->BidiEnabled()) {
     return NS_OK;
   }
 
-  if (!aSelNode || !aSelNode->IsContent()) {
+  if (!aSelectionPoint.GetContainerAsContent()) {
     return NS_ERROR_NULL_POINTER;
   }
-  nsCOMPtr<nsIContent> content = aSelNode->AsContent();
 
   nsBidiLevel levelBefore;
   nsBidiLevel levelAfter;
   RefPtr<nsFrameSelection> frameSelection =
     aSelection->AsSelection()->GetFrameSelection();
   NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
 
   nsPrevNextBidiLevels levels = frameSelection->
-    GetPrevNextBidiLevels(content, aSelOffset, true);
+    GetPrevNextBidiLevels(aSelectionPoint.GetContainerAsContent(),
+                          aSelectionPoint.Offset(), true);
 
   levelBefore = levels.mLevelBefore;
   levelAfter = levels.mLevelAfter;
 
   nsBidiLevel currentCaretLevel = frameSelection->GetCaretBidiLevel();
 
   nsBidiLevel levelOfDeletion;
   levelOfDeletion =