Bug 1067345 - Part 1.1 - Move ResponsiveImageSelector selection into GetSelectedImage instead of GetBestCandidateIndex
authorJohn Schoenick <jschoenick@mozilla.com>
Wed, 10 Dec 2014 18:52:00 -0500
changeset 229462 afeff812b5dda8dcbf3628fab5a53fbd0d5be564
parent 229461 51c2796056eab4b61a33e719c603e0602451f0a1
child 229463 4cc6d580cda6eb3d8f9e908cd0dfe0deb8b2560b
push id11352
push userryanvm@gmail.com
push dateTue, 17 Feb 2015 19:29:37 +0000
treeherderfx-team@b6c56fab513d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1067345
milestone38.0a1
Bug 1067345 - Part 1.1 - Move ResponsiveImageSelector selection into GetSelectedImage instead of GetBestCandidateIndex
dom/base/ResponsiveImageSelector.cpp
--- a/dom/base/ResponsiveImageSelector.cpp
+++ b/dom/base/ResponsiveImageSelector.cpp
@@ -280,38 +280,29 @@ ResponsiveImageSelector::SelectImage(boo
 {
   if (!aReselect && mBestCandidateIndex != -1) {
     // Already have selection
     return false;
   }
 
   int oldBest = mBestCandidateIndex;
   mBestCandidateIndex = -1;
-  return GetBestCandidateIndex() != oldBest;
-}
-
-int
-ResponsiveImageSelector::GetBestCandidateIndex()
-{
-  if (mBestCandidateIndex != -1) {
-    return mBestCandidateIndex;
-  }
 
   int numCandidates = mCandidates.Length();
   if (!numCandidates) {
-    return -1;
+    return oldBest != -1;
   }
 
   nsIDocument* doc = mContent ? mContent->OwnerDoc() : nullptr;
   nsIPresShell *shell = doc ? doc->GetShell() : nullptr;
   nsPresContext *pctx = shell ? shell->GetPresContext() : nullptr;
 
   if (!pctx) {
     MOZ_ASSERT(false, "Unable to find document prescontext");
-    return -1;
+    return oldBest != -1;
   }
 
   double displayDensity = pctx->CSSPixelsToDevPixels(1.0f);
 
   // Per spec, "In a UA-specific manner, choose one image source"
   // - For now, select the lowest density greater than displayDensity, otherwise
   //   the greatest density available
 
@@ -349,17 +340,26 @@ ResponsiveImageSelector::GetBestCandidat
         (candidateDensity >= displayDensity && candidateDensity < bestDensity)) {
       bestIndex = i;
       bestDensity = candidateDensity;
     }
   }
 
   MOZ_ASSERT(bestIndex >= 0 && bestIndex < numCandidates);
   mBestCandidateIndex = bestIndex;
-  return bestIndex;
+
+  return mBestCandidateIndex != oldBest;
+}
+
+int
+ResponsiveImageSelector::GetBestCandidateIndex()
+{
+  SelectImage();
+
+  return mBestCandidateIndex;
 }
 
 bool
 ResponsiveImageSelector::ComputeFinalWidthForCurrentViewport(int32_t *aWidth)
 {
   unsigned int numSizes = mSizeQueries.Length();
   nsIDocument* doc = mContent ? mContent->OwnerDoc() : nullptr;
   nsIPresShell *presShell = doc ? doc->GetShell() : nullptr;