Bug 1391978 - Part 8. Replace nsISelection::GetAnchorOffset with Selection::AnchorOffset. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 25 Aug 2017 16:12:39 +0900
changeset 654199 7d3d869f21669486e9dd3bb925451e5bd20fa3b0
parent 654198 3171ed5808d9045b268cc76989c7d06ea220d393
child 654200 a739151e75d8920dd76b9729fd0d698f574218ed
push id76495
push userbmo:m_kato@ga2.so-net.ne.jp
push dateMon, 28 Aug 2017 10:39:27 +0000
reviewersmasayuki
bugs1391978
milestone57.0a1
Bug 1391978 - Part 8. Replace nsISelection::GetAnchorOffset with Selection::AnchorOffset. r?masayuki MozReview-Commit-ID: GgxyRsVXHwl
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLTableEditor.cpp
editor/libeditor/TextEditRules.cpp
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1579,22 +1579,19 @@ HTMLEditor::InsertElementAtSelection(nsI
       if (HTMLEditUtils::IsNamedAnchor(node)) {
         selection->CollapseToStart();
       } else {
         selection->CollapseToEnd();
       }
     }
 
     nsCOMPtr<nsIDOMNode> parentSelectedNode;
-    int32_t offsetForInsert;
     rv = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode));
-    // XXX: ERROR_HANDLING bad XPCOM usage
-    if (NS_SUCCEEDED(rv) &&
-        NS_SUCCEEDED(selection->GetAnchorOffset(&offsetForInsert)) &&
-        parentSelectedNode) {
+    if (parentSelectedNode) {
+      int32_t offsetForInsert = selection->AnchorOffset();
       // Adjust position based on the node we are going to insert.
       NormalizeEOLInsertPosition(element, address_of(parentSelectedNode),
                                  &offsetForInsert);
 
       rv = InsertNodeAtPoint(node, address_of(parentSelectedNode),
                              &offsetForInsert, false);
       NS_ENSURE_SUCCESS(rv, rv);
       // Set caret after element, but check for special case
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -3210,19 +3210,17 @@ HTMLEditor::GetSelectedOrParentTableElem
 
     nsCOMPtr<nsIDOMNode> selectedNode;
 
     // Get child of anchor node, if exists
     bool hasChildren;
     anchorNode->HasChildNodes(&hasChildren);
 
     if (hasChildren) {
-      int32_t anchorOffset;
-      rv = selection->GetAnchorOffset(&anchorOffset);
-      NS_ENSURE_SUCCESS(rv, rv);
+      int32_t anchorOffset = selection->AnchorOffset();
       selectedNode = GetChildAt(anchorNode, anchorOffset);
       if (!selectedNode) {
         selectedNode = anchorNode;
         // If anchor doesn't have a child, we can't be selecting a table element,
         //  so don't do the following:
       } else {
         nsCOMPtr<nsIAtom> atom = EditorBase::GetTag(selectedNode);
 
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -196,17 +196,17 @@ TextEditRules::BeforeEdit(EditAction act
     // setText replaces all text, so mCachedSelectionNode might be invalid on
     // AfterEdit.
     // Since this will be used as start position of spellchecker, we should
     // use root instead.
     mCachedSelectionNode = textEditor->GetRoot();
     mCachedSelectionOffset = 0;
   } else {
     mCachedSelectionNode = selection->GetAnchorNode();
-    selection->GetAnchorOffset(&mCachedSelectionOffset);
+    mCachedSelectionOffset = selection->AnchorOffset();
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditRules::AfterEdit(EditAction action,
                          nsIEditor::EDirection aDirection)