Bug 1654406 - Fix Incorrect Ellipsis Offset When Printing Selections r=bobowen
authorErik Nordin <nordzilla@mozilla.com>
Thu, 23 Jul 2020 20:17:03 +0000
changeset 541827 cc83430bf63ad08d3d955d0c43ec9461a9988453
parent 541826 6e556d9c084532ca27fcf30353a88eb82b775595
child 541828 72f036d4f84c3da8b45c27a4d50272d13e880638
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1654406
milestone80.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1654406 - Fix Incorrect Ellipsis Offset When Printing Selections r=bobowen - Fix double-counted ellipsis offset. - Rename unselected to nonselected for consistency. Differential Revision: https://phabricator.services.mozilla.com/D84448
layout/printing/nsPrintJob.cpp
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -2005,17 +2005,17 @@ nsresult nsPrintJob::ReflowPrintObject(c
   NS_ENSURE_SUCCESS(rv, rv);
 
   aPO->mPresShell =
       aPO->mDocument->CreatePresShell(aPO->mPresContext, aPO->mViewManager);
   if (!aPO->mPresShell) {
     return NS_ERROR_FAILURE;
   }
 
-  // If we're printing selection then remove the unselected nodes from our
+  // If we're printing selection then remove the nonselected nodes from our
   // cloned document.
   int16_t printRangeType = nsIPrintSettings::kRangeAllPages;
   printData->mPrintSettings->GetPrintRange(&printRangeType);
   if (printRangeType == nsIPrintSettings::kRangeSelection) {
     DeleteNonSelectedNodes(*aPO->mDocument);
   }
 
   bool doReturn = false;
@@ -2188,61 +2188,49 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY static nsres
   RefPtr<Selection> selection =
       presShell->GetCurrentSelection(SelectionType::eNormal);
   NS_ENSURE_STATE(selection);
 
   MOZ_ASSERT(!selection->RangeCount());
   nsINode* bodyNode = aDoc.GetBodyElement();
   nsINode* startNode = bodyNode;
   uint32_t startOffset = 0;
-  uint32_t ellipsisOffset = 0;
 
   for (nsRange* origRange : *printRanges) {
     // New end is start of original range.
     nsINode* endNode = origRange->GetStartContainer();
-
-    // If we're no longer in the same text node reset the ellipsis offset.
-    if (endNode != startNode) {
-      ellipsisOffset = 0;
-    }
-    uint32_t endOffset = origRange->StartOffset() + ellipsisOffset;
+    uint32_t endOffset = origRange->StartOffset();
 
     // Create the range that we want to remove. Note that if startNode or
     // endNode are null nsRange::Create() will fail and we won't remove
     // that section.
-    RefPtr<nsRange> unselectedRange = nsRange::Create(
+    RefPtr<nsRange> nonselectedRange = nsRange::Create(
         startNode, startOffset, endNode, endOffset, IgnoreErrors());
 
-    if (unselectedRange && !unselectedRange->Collapsed()) {
-      selection->AddRangeAndSelectFramesAndNotifyListeners(*unselectedRange,
+    if (nonselectedRange && !nonselectedRange->Collapsed()) {
+      selection->AddRangeAndSelectFramesAndNotifyListeners(*nonselectedRange,
                                                            IgnoreErrors());
       // Unless we've already added an ellipsis at the start, if we ended mid
       // text node then add ellipsis.
       Text* text = endNode->GetAsText();
-      if (!ellipsisOffset && text && endOffset && endOffset < text->Length()) {
+      if (startNode != endNode && text && endOffset &&
+          endOffset < text->Length()) {
         text->InsertData(endOffset, kEllipsis, IgnoreErrors());
-        ellipsisOffset += kEllipsis.Length();
       }
     }
 
     // Next new start is end of original range.
     startNode = origRange->GetEndContainer();
-
-    // If we're no longer in the same text node reset the ellipsis offset.
-    if (startNode != endNode) {
-      ellipsisOffset = 0;
-    }
-    startOffset = origRange->EndOffset() + ellipsisOffset;
+    startOffset = origRange->EndOffset();
 
     // If the next node will start mid text node then add ellipsis.
     Text* text = startNode ? startNode->GetAsText() : nullptr;
     if (text && startOffset && startOffset < text->Length()) {
       text->InsertData(startOffset, kEllipsis, IgnoreErrors());
       startOffset += kEllipsis.Length();
-      ellipsisOffset += kEllipsis.Length();
     }
   }
 
   // Add in the last range to the end of the body.
   RefPtr<nsRange> lastRange =
       nsRange::Create(startNode, startOffset, bodyNode,
                       bodyNode->GetChildCount(), IgnoreErrors());
   if (lastRange && !lastRange->Collapsed()) {