Bug 1673287 - Draw thumb as part of the range control. r=spohl
authorMarkus Stange <mstange.moz@gmail.com>
Mon, 26 Oct 2020 23:17:57 +0000
changeset 554704 783918e69c25fbb0470d4ea4c431d83392f77616
parent 554703 c586fc967b88780319e11b598db03ff7f7e9b63f
child 554705 8eeb925b28d5539f9550d73af18e05d910b3bd4b
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 thumb as part of the range control. r=spohl This makes the thumb respect the disabled, active and hover state of the range control. Differential Revision: https://phabricator.services.mozilla.com/D94700
widget/nsNativeBasicTheme.cpp
widget/nsNativeBasicTheme.h
--- a/widget/nsNativeBasicTheme.cpp
+++ b/widget/nsNativeBasicTheme.cpp
@@ -640,49 +640,57 @@ void nsNativeBasicTheme::PaintSpinnerBut
     p = center + Point(arrowPolygonX[i] * scale, arrowPolygonY[i] * scale);
     builder->LineTo(p);
   }
   path = builder->Finish();
   aDrawTarget->Fill(path, ColorPattern(ToDeviceColor(borderColor)));
 }
 
 /* static */
-void nsNativeBasicTheme::PaintRangeTrackBackground(
-    nsIFrame* aFrame, DrawTarget* aDrawTarget, const Rect& aRect,
-    const EventStates& aState, uint32_t aDpiRatio, bool aHorizontal) {
+void nsNativeBasicTheme::PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget,
+                                    const Rect& aRect,
+                                    const EventStates& aState,
+                                    uint32_t aDpiRatio, bool aHorizontal) {
   nsRangeFrame* rangeFrame = do_QueryFrame(aFrame);
   if (!rangeFrame) {
     return;
   }
 
+  double progress = rangeFrame->GetValueAsFractionOfRange();
   Rect rect(aRect);
-  const CSSCoord verticalSize = kRangeHeight * aDpiRatio;
-  if (aHorizontal) {
-    rect.y += (rect.height - verticalSize) / 2;
-    rect.height = verticalSize;
-  } else {
-    rect.x += (rect.width - verticalSize) / 2;
-    rect.width = verticalSize;
-  }
-
-  double progress = rangeFrame->GetValueAsFractionOfRange();
+  Rect thumbRect(0, 0, kMinimumRangeThumbSize.value * aDpiRatio,
+                 kMinimumRangeThumbSize.value * aDpiRatio);
   Rect progressClipRect(aRect);
   Rect trackClipRect(aRect);
+  const CSSCoord verticalSize = kRangeHeight * aDpiRatio;
   if (aHorizontal) {
+    rect.height = verticalSize;
+    rect.y = aRect.y + (aRect.height - rect.height) / 2;
+    thumbRect.y = aRect.y + (aRect.height - thumbRect.height) / 2;
+
     progressClipRect.width = aRect.width * progress;
+    trackClipRect.width -= progressClipRect.width;
+
     if (IsFrameRTL(aFrame)) {
-      progressClipRect.x += aRect.width - progressClipRect.width;
+      progressClipRect.x = trackClipRect.XMost();
+      thumbRect.x =
+          aRect.x + (aRect.width - thumbRect.width) * (1.0 - progress);
     } else {
-      trackClipRect.x += progressClipRect.width;
+      trackClipRect.x = progressClipRect.XMost();
+      thumbRect.x = aRect.x + (aRect.width - thumbRect.width) * progress;
     }
-    trackClipRect.width -= progressClipRect.width;
   } else {
+    rect.width = verticalSize;
+    rect.x = aRect.x + (aRect.width - rect.width) / 2;
+    thumbRect.x = aRect.x + (aRect.width - thumbRect.width) / 2;
+
     progressClipRect.height = aRect.height * progress;
-    progressClipRect.y += aRect.height - progressClipRect.height;
     trackClipRect.height -= progressClipRect.height;
+    progressClipRect.y = trackClipRect.YMost();
+    thumbRect.y = aRect.y + (aRect.height - thumbRect.height) * progress;
   }
 
   const CSSCoord borderWidth = 1.0f;
   const CSSCoord radius = 2.0f;
 
   sRGBColor progressColor, progressBorderColor;
   std::tie(progressColor, progressBorderColor) =
       ComputeRangeProgressColors(aState);
@@ -695,16 +703,18 @@ void nsNativeBasicTheme::PaintRangeTrack
                              aDpiRatio);
   aDrawTarget->PopClip();
 
   aDrawTarget->PushClipRect(trackClipRect);
   PaintRoundedRectWithRadius(aDrawTarget, rect, trackColor, trackBorderColor,
                              borderWidth, radius, aDpiRatio);
   aDrawTarget->PopClip();
 
+  PaintRangeThumb(aDrawTarget, thumbRect, aState, aDpiRatio);
+
   if (aState.HasState(NS_EVENT_STATE_FOCUS)) {
     PaintRoundedFocusRect(aDrawTarget, aRect, aDpiRatio, radius, 3.0f);
   }
 }
 
 /* static */
 void nsNativeBasicTheme::PaintRangeThumb(DrawTarget* aDrawTarget,
                                          const Rect& aRect,
@@ -1128,21 +1138,21 @@ nsNativeBasicTheme::DrawWidgetBackground
       PaintMenulistArrowButton(aFrame, dt, devPxRect, eventState, dpiRatio);
       break;
     case StyleAppearance::SpinnerUpbutton:
     case StyleAppearance::SpinnerDownbutton:
       PaintSpinnerButton(aFrame, dt, devPxRect, eventState, aAppearance,
                          dpiRatio);
       break;
     case StyleAppearance::Range:
-      PaintRangeTrackBackground(aFrame, dt, devPxRect, eventState, dpiRatio,
-                                IsRangeHorizontal(aFrame));
+      PaintRange(aFrame, dt, devPxRect, eventState, dpiRatio,
+                 IsRangeHorizontal(aFrame));
       break;
     case StyleAppearance::RangeThumb:
-      PaintRangeThumb(dt, devPxRect, eventState, dpiRatio);
+      // Painted as part of StyleAppearance::Range.
       break;
     case StyleAppearance::ProgressBar:
       PaintProgressBar(dt, devPxRect, eventState, dpiRatio);
       break;
     case StyleAppearance::Progresschunk:
       PaintProgresschunk(aFrame, dt, devPxRect, eventState, dpiRatio);
       break;
     case StyleAppearance::Meter:
--- a/widget/nsNativeBasicTheme.h
+++ b/widget/nsNativeBasicTheme.h
@@ -278,21 +278,19 @@ class nsNativeBasicTheme : protected nsN
                                        DrawTarget* aDrawTarget,
                                        const Rect& aRect,
                                        const EventStates& aState,
                                        uint32_t aDpiRatio);
   static void PaintSpinnerButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                                  const Rect& aRect, const EventStates& aState,
                                  StyleAppearance aAppearance,
                                  uint32_t aDpiRatio);
-  static void PaintRangeTrackBackground(nsIFrame* aFrame,
-                                        DrawTarget* aDrawTarget,
-                                        const Rect& aRect,
-                                        const EventStates& aState,
-                                        uint32_t aDpiRatio, bool aHorizontal);
+  static void PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget,
+                         const Rect& aRect, const EventStates& aState,
+                         uint32_t aDpiRatio, bool aHorizontal);
   static void PaintRangeThumb(DrawTarget* aDrawTarget, const Rect& aRect,
                               const EventStates& aState, uint32_t aDpiRatio);
   static void PaintProgressBar(DrawTarget* aDrawTarget, const Rect& aRect,
                                const EventStates& aState, uint32_t aDpiRatio);
   static void PaintProgresschunk(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                                  const Rect& aRect, const EventStates& aState,
                                  uint32_t aDpiRatio);
   static void PaintMeter(DrawTarget* aDrawTarget, const Rect& aRect,