Bug 1673287 - Draw range progress and track pieces with the same rounded rect but different rectangular clips. r=spohl
authorMarkus Stange <mstange.moz@gmail.com>
Mon, 26 Oct 2020 23:17:50 +0000
changeset 554703 c586fc967b88780319e11b598db03ff7f7e9b63f
parent 554702 d00aefbdfbd767da9c085aba3d5991bdaef71d14
child 554704 783918e69c25fbb0470d4ea4c431d83392f77616
push id37898
push userabutkovits@mozilla.com
push dateWed, 28 Oct 2020 09:24:21 +0000
treeherdermozilla-central@83bf4fd3b1fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1673287
milestone84.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 1673287 - Draw range progress and track pieces with the same rounded rect but different rectangular clips. r=spohl This feels a bit nicer but the difference isn't visible to the user. But it demonstrates how we can fix progress bars. Differential Revision: https://phabricator.services.mozilla.com/D94699
widget/nsNativeBasicTheme.cpp
--- a/widget/nsNativeBasicTheme.cpp
+++ b/widget/nsNativeBasicTheme.cpp
@@ -659,54 +659,51 @@ void nsNativeBasicTheme::PaintRangeTrack
     rect.y += (rect.height - verticalSize) / 2;
     rect.height = verticalSize;
   } else {
     rect.x += (rect.width - verticalSize) / 2;
     rect.width = verticalSize;
   }
 
   double progress = rangeFrame->GetValueAsFractionOfRange();
-  Rect progressRect(rect);
-  Rect trackRect(rect);
+  Rect progressClipRect(aRect);
+  Rect trackClipRect(aRect);
   if (aHorizontal) {
-    progressRect.width = rect.width * progress;
+    progressClipRect.width = aRect.width * progress;
     if (IsFrameRTL(aFrame)) {
-      progressRect.x += rect.width - progressRect.width;
+      progressClipRect.x += aRect.width - progressClipRect.width;
     } else {
-      trackRect.x += progressRect.width;
+      trackClipRect.x += progressClipRect.width;
     }
-    trackRect.width -= progressRect.width;
+    trackClipRect.width -= progressClipRect.width;
   } else {
-    progressRect.height = rect.height * progress;
-    progressRect.y += rect.height - progressRect.height;
-    trackRect.height -= progressRect.height;
+    progressClipRect.height = aRect.height * progress;
+    progressClipRect.y += aRect.height - progressClipRect.height;
+    trackClipRect.height -= progressClipRect.height;
   }
 
   const CSSCoord borderWidth = 1.0f;
   const CSSCoord radius = 2.0f;
 
-  // Avoid artifacts between thumb and track when progress is approaching
-  // 0.0f or 1.0f.
-  if ((aHorizontal && ((progressRect.width > (radius * 2.0f)))) ||
-      (!aHorizontal && ((progressRect.height > radius * 2.0f)))) {
-    sRGBColor progressColor, progressBorderColor;
-    std::tie(progressColor, progressBorderColor) =
-        ComputeRangeProgressColors(aState);
-    PaintRoundedRectWithRadius(aDrawTarget, progressRect, progressColor,
-                               progressBorderColor, borderWidth, radius,
-                               aDpiRatio);
-  }
-  if ((aHorizontal && ((trackRect.width > (radius * 2.0f)))) ||
-      (!aHorizontal && (trackRect.height > (radius * 2.0f)))) {
-    sRGBColor trackColor, trackBorderColor;
-    std::tie(trackColor, trackBorderColor) = ComputeRangeTrackColors(aState);
-    PaintRoundedRectWithRadius(aDrawTarget, trackRect, trackColor,
-                               trackBorderColor, borderWidth, radius,
-                               aDpiRatio);
-  }
+  sRGBColor progressColor, progressBorderColor;
+  std::tie(progressColor, progressBorderColor) =
+      ComputeRangeProgressColors(aState);
+  sRGBColor trackColor, trackBorderColor;
+  std::tie(trackColor, trackBorderColor) = ComputeRangeTrackColors(aState);
+
+  aDrawTarget->PushClipRect(progressClipRect);
+  PaintRoundedRectWithRadius(aDrawTarget, rect, progressColor,
+                             progressBorderColor, borderWidth, radius,
+                             aDpiRatio);
+  aDrawTarget->PopClip();
+
+  aDrawTarget->PushClipRect(trackClipRect);
+  PaintRoundedRectWithRadius(aDrawTarget, rect, trackColor, trackBorderColor,
+                             borderWidth, radius, aDpiRatio);
+  aDrawTarget->PopClip();
 
   if (aState.HasState(NS_EVENT_STATE_FOCUS)) {
     PaintRoundedFocusRect(aDrawTarget, aRect, aDpiRatio, radius, 3.0f);
   }
 }
 
 /* static */
 void nsNativeBasicTheme::PaintRangeThumb(DrawTarget* aDrawTarget,