Bug 1404084 - Avoid using nsINode::GetChildAt() in HTMLEditor::GetCSSBackgroundColorState(); r=masayuki
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 28 Sep 2017 16:12:22 -0400
changeset 426355 5cfc116d0e3f815c06faa88a205b1207321361d3
parent 426354 03f60efbf00924e4b73dae414740cfbec6f5ee99
child 426356 d6879c60aa6af236ecb90217f33880dee4f01f26
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersmasayuki
bugs1404084
milestone58.0a1
Bug 1404084 - Avoid using nsINode::GetChildAt() in HTMLEditor::GetCSSBackgroundColorState(); r=masayuki
editor/libeditor/HTMLEditor.cpp
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1723,28 +1723,27 @@ HTMLEditor::GetCSSBackgroundColorState(b
   aOutColor.AssignLiteral("transparent");
 
   // get selection
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_STATE(selection && selection->GetRangeAt(0));
 
   // get selection location
   nsCOMPtr<nsINode> parent = selection->GetRangeAt(0)->GetStartContainer();
-  int32_t offset = selection->GetRangeAt(0)->StartOffset();
   NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
 
   // is the selection collapsed?
   nsCOMPtr<nsINode> nodeToExamine;
   if (selection->Collapsed() || IsTextNode(parent)) {
     // we want to look at the parent and ancestors
     nodeToExamine = parent;
   } else {
     // otherwise we want to look at the first editable node after
     // {parent,offset} and its ancestors for divs with alignment on them
-    nodeToExamine = parent->GetChildAt(offset);
+    nodeToExamine = selection->GetRangeAt(0)->GetChildAtStartOffset();
     //GetNextNode(parent, offset, true, address_of(nodeToExamine));
   }
 
   NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER);
 
   if (aBlockLevel) {
     // we are querying the block background (and not the text background), let's
     // climb to the block container