Bug 862518 - Make sure the thumb of <input type=range> with fractional values is drawn at the correct position with Cocoa native theming. r=roc
authorJonathan Watt <jwatt@jwatt.org>
Wed, 17 Apr 2013 00:50:26 +0100
changeset 139961 9bef1ecd7ed3ce399a038dbf83b157223c8602cc
parent 139960 e1939f325abb3f11ff70374a0a4c675e9cb39d20
child 139962 cad82c3b69bceb547a2627fdfb54d4ce14128a8b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs862518
milestone23.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 862518 - Make sure the thumb of <input type=range> with fractional values is drawn at the correct position with Cocoa native theming. r=roc
layout/forms/nsRangeFrame.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/layout/forms/nsRangeFrame.h
+++ b/layout/forms/nsRangeFrame.h
@@ -88,16 +88,24 @@ public:
    *   stored in its mRect.
    */
   bool IsHorizontal(const nsSize *aFrameSizeOverride = nullptr) const;
 
   double GetMin() const;
   double GetMax() const;
   double GetValue() const;
 
+  /** 
+   * Returns the input element's value as a fraction of the difference between
+   * the input's minimum and its maximum (i.e. returns 0.0 when the value is
+   * the same as the minimum, and returns 1.0 when the value is the same as the 
+   * maximum).
+   */  
+  double GetValueAsFractionOfRange();
+
   /**
    * Returns whether the frame and its child should use the native style.
    */
   bool ShouldUseNativeStyle() const;
 
   double GetValueAtEventPoint(nsGUIEvent* aEvent);
 
   /**
@@ -122,24 +130,16 @@ private:
 
   void DoUpdateThumbPosition(nsIFrame* aThumbFrame,
                              const nsSize& aRangeSize);
 
   void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
                                   const nsSize& aRangeSize);
 
   /**
-   * Returns the input element's value as a fraction of the difference between
-   * the input's minimum and its maximum (i.e. returns 0.0 when the value is
-   * the same as the minimum, and returns 1.0 when the value is the same as the
-   * maximum).
-   */
-  double GetValueAsFractionOfRange();
-
-  /**
    * The div used to show the ::-moz-range-track pseudo-element.
    * @see nsRangeFrame::CreateAnonymousContent
    */
   nsCOMPtr<nsIContent> mTrackDiv;
 
   /**
    * The div used to show the ::-moz-range-progress pseudo-element, which is
    * used to (optionally) style the specific chunk of track leading up to the
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2264,31 +2264,21 @@ nsNativeThemeCocoa::DrawWidgetBackground
       // do nothing, drawn by scale
       break;
 
     case NS_THEME_RANGE: {
       nsRangeFrame *rangeFrame = do_QueryFrame(aFrame);
       if (!rangeFrame) {
         break;
       }
-      int32_t value = rangeFrame->GetValue();
-      int32_t min = rangeFrame->GetMin();
-      int32_t max = rangeFrame->GetMax();
-      if (max < min) {
-        // The spec says that the only valid value is the minimum. For the
-        // purposes of drawing the range, we need to have a max that's greater
-        // than min though (it doesn't really matter what the value is, as long
-        // as the thumb is painted at the min.
-        max = min + 1;
-        value = min;
-      }
-      MOZ_ASSERT(MOZ_DOUBLE_IS_FINITE(value) &&
-                 MOZ_DOUBLE_IS_FINITE(min) &&
-                 MOZ_DOUBLE_IS_FINITE(max) &&
-                 value >= min && value <= max);
+      // DrawScale requires integer min, max and value. This is purely for
+      // drawing, so we normalize to a range 0-1000 here.
+      int32_t value = int32_t(rangeFrame->GetValueAsFractionOfRange() * 1000);
+      int32_t min = 0;
+      int32_t max = 1000;
       bool isVertical = !IsRangeHorizontal(aFrame);
       bool reverseDir =
         isVertical ||
         rangeFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
       DrawScale(cgContext, macRect, eventState, isVertical, reverseDir,
                 value, min, max, aFrame);
       break;
     }