Bug 1331581: Clean up nsMediaFeatureValueGetter. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 18 Jan 2017 14:33:24 +0100
changeset 375110 52a8ae1e1a82e5f7166001b70d5ab5adb2f26336
parent 375109 2365700d798821589e32c8fbeceefced1ab3da7c
child 375111 80e4fe7ff7cb78b5774caa19f9c340132a06202b
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1331581
milestone53.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 1331581: Clean up nsMediaFeatureValueGetter. r=heycam MozReview-Commit-ID: DlmGk2JSJ1l
layout/style/nsMediaFeatures.cpp
layout/style/nsMediaFeatures.h
layout/style/nsMediaList.cpp
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -85,34 +85,32 @@ GetSize(nsPresContext* aPresContext)
   if (aPresContext->IsRootPaginatedDocument())
     // We want the page size, including unprintable areas and margins.
     size = aPresContext->GetPageSize();
   else
     size = aPresContext->GetVisibleArea().Size();
   return size;
 }
 
-static nsresult
+static void
 GetWidth(nsPresContext* aPresContext, const nsMediaFeature*,
          nsCSSValue& aResult)
 {
   nsSize size = GetSize(aPresContext);
   float pixelWidth = aPresContext->AppUnitsToFloatCSSPixels(size.width);
   aResult.SetFloatValue(pixelWidth, eCSSUnit_Pixel);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetHeight(nsPresContext* aPresContext, const nsMediaFeature*,
           nsCSSValue& aResult)
 {
   nsSize size = GetSize(aPresContext);
   float pixelHeight = aPresContext->AppUnitsToFloatCSSPixels(size.height);
   aResult.SetFloatValue(pixelHeight, eCSSUnit_Pixel);
-  return NS_OK;
 }
 
 inline static nsDeviceContext*
 GetDeviceContextFor(nsPresContext* aPresContext)
 {
   // It would be nice to call
   // nsLayoutUtils::GetDeviceContextForScreenInfo here, except for two
   // things:  (1) it can flush, and flushing is bad here, and (2) it
@@ -142,107 +140,101 @@ GetDeviceSize(nsPresContext* aPresContex
     size = aPresContext->GetPageSize();
   } else {
     GetDeviceContextFor(aPresContext)->
       GetDeviceSurfaceDimensions(size.width, size.height);
   }
   return size;
 }
 
-static nsresult
+static void
 GetDeviceWidth(nsPresContext* aPresContext, const nsMediaFeature*,
                nsCSSValue& aResult)
 {
   nsSize size = GetDeviceSize(aPresContext);
   float pixelWidth = aPresContext->AppUnitsToFloatCSSPixels(size.width);
   aResult.SetFloatValue(pixelWidth, eCSSUnit_Pixel);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetDeviceHeight(nsPresContext* aPresContext, const nsMediaFeature*,
                 nsCSSValue& aResult)
 {
   nsSize size = GetDeviceSize(aPresContext);
   float pixelHeight = aPresContext->AppUnitsToFloatCSSPixels(size.height);
   aResult.SetFloatValue(pixelHeight, eCSSUnit_Pixel);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetOrientation(nsPresContext* aPresContext, const nsMediaFeature*,
                nsCSSValue& aResult)
 {
   nsSize size = GetSize(aPresContext);
   int32_t orientation;
   if (size.width > size.height) {
     orientation = NS_STYLE_ORIENTATION_LANDSCAPE;
   } else {
     // Per spec, square viewports should be 'portrait'
     orientation = NS_STYLE_ORIENTATION_PORTRAIT;
   }
 
   aResult.SetIntValue(orientation, eCSSUnit_Enumerated);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetDeviceOrientation(nsPresContext* aPresContext, const nsMediaFeature*,
                      nsCSSValue& aResult)
 {
   nsSize size = GetDeviceSize(aPresContext);
   int32_t orientation;
   if (size.width > size.height) {
     orientation = NS_STYLE_ORIENTATION_LANDSCAPE;
   } else {
     // Per spec, square viewports should be 'portrait'
     orientation = NS_STYLE_ORIENTATION_PORTRAIT;
   }
 
   aResult.SetIntValue(orientation, eCSSUnit_Enumerated);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetIsResourceDocument(nsPresContext* aPresContext, const nsMediaFeature*,
                       nsCSSValue& aResult)
 {
   nsIDocument* doc = aPresContext->Document();
   aResult.SetIntValue(doc && doc->IsResourceDoc() ? 1 : 0, eCSSUnit_Integer);
-  return NS_OK;
 }
 
 // Helper for two features below
-static nsresult
+static void
 MakeArray(const nsSize& aSize, nsCSSValue& aResult)
 {
   RefPtr<nsCSSValue::Array> a = nsCSSValue::Array::Create(2);
 
   a->Item(0).SetIntValue(aSize.width, eCSSUnit_Integer);
   a->Item(1).SetIntValue(aSize.height, eCSSUnit_Integer);
 
   aResult.SetArrayValue(a, eCSSUnit_Array);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetAspectRatio(nsPresContext* aPresContext, const nsMediaFeature*,
                nsCSSValue& aResult)
 {
-  return MakeArray(GetSize(aPresContext), aResult);
+  MakeArray(GetSize(aPresContext), aResult);
 }
 
-static nsresult
+static void
 GetDeviceAspectRatio(nsPresContext* aPresContext, const nsMediaFeature*,
                      nsCSSValue& aResult)
 {
-  return MakeArray(GetDeviceSize(aPresContext), aResult);
+  MakeArray(GetDeviceSize(aPresContext), aResult);
 }
 
-static nsresult
+static void
 GetColor(nsPresContext* aPresContext, const nsMediaFeature*,
          nsCSSValue& aResult)
 {
   uint32_t depth = 24; // Use depth of 24 when resisting fingerprinting.
 
   if (!ShouldResistFingerprinting(aPresContext)) {
     // FIXME:  This implementation is bogus.  nsDeviceContext
     // doesn't provide reliable information (should be fixed in bug
@@ -252,81 +244,76 @@ GetColor(nsPresContext* aPresContext, co
     dx->GetDepth(depth);
   }
 
   // The spec says to use bits *per color component*, so divide by 3,
   // and round down, since the spec says to use the smallest when the
   // color components differ.
   depth /= 3;
   aResult.SetIntValue(int32_t(depth), eCSSUnit_Integer);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetColorIndex(nsPresContext* aPresContext, const nsMediaFeature*,
               nsCSSValue& aResult)
 {
   // We should return zero if the device does not use a color lookup
   // table.  Stuart says that our handling of displays with 8-bit
   // color is bad enough that we never change the lookup table to
   // match what we're trying to display, so perhaps we should always
   // return zero.  Given that there isn't any better information
   // exposed, we don't have much other choice.
   aResult.SetIntValue(0, eCSSUnit_Integer);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetMonochrome(nsPresContext* aPresContext, const nsMediaFeature*,
               nsCSSValue& aResult)
 {
   // For color devices we should return 0.
   // FIXME: On a monochrome device, return the actual color depth, not
   // 0!
   aResult.SetIntValue(0, eCSSUnit_Integer);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetResolution(nsPresContext* aPresContext, const nsMediaFeature*,
               nsCSSValue& aResult)
 {
   float dpi = 96; // Use 96 when resisting fingerprinting.
 
   if (!ShouldResistFingerprinting(aPresContext)) {
     // Resolution measures device pixels per CSS (inch/cm/pixel).  We
     // return it in device pixels per CSS inches.
     dpi = float(nsPresContext::AppUnitsPerCSSInch()) /
           float(aPresContext->AppUnitsPerDevPixel());
   }
 
   aResult.SetFloatValue(dpi, eCSSUnit_Inch);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetScan(nsPresContext* aPresContext, const nsMediaFeature*,
         nsCSSValue& aResult)
 {
   // Since Gecko doesn't support the 'tv' media type, the 'scan'
   // feature is never present.
   aResult.Reset();
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetDisplayMode(nsPresContext* aPresContext, const nsMediaFeature*,
                nsCSSValue& aResult)
 {
   nsCOMPtr<nsISupports> container = aPresContext->GetRootPresContext()->
     Document()->GetContainer();
   nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container);
   if (!baseWindow) {
     aResult.SetIntValue(NS_STYLE_DISPLAY_MODE_BROWSER, eCSSUnit_Enumerated);
-    return NS_OK;
+    return;
   }
   nsCOMPtr<nsIWidget> mainWidget;
   baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
   int32_t displayMode;
   nsSizeMode mode = mainWidget ? mainWidget->SizeMode() : nsSizeMode_Normal;
   // Background tabs are always in 'browser' mode for now.
   // If new modes are supported, please ensure not cause the regression in
   // Bug 1259641.
@@ -335,131 +322,123 @@ GetDisplayMode(nsPresContext* aPresConte
       displayMode = NS_STYLE_DISPLAY_MODE_FULLSCREEN;
       break;
     default:
       displayMode = NS_STYLE_DISPLAY_MODE_BROWSER;
       break;
   }
 
   aResult.SetIntValue(displayMode, eCSSUnit_Enumerated);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetGrid(nsPresContext* aPresContext, const nsMediaFeature*,
         nsCSSValue& aResult)
 {
   // Gecko doesn't support grid devices (e.g., ttys), so the 'grid'
   // feature is always 0.
   aResult.SetIntValue(0, eCSSUnit_Integer);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetDevicePixelRatio(nsPresContext* aPresContext, const nsMediaFeature*,
                     nsCSSValue& aResult)
 {
   if (!ShouldResistFingerprinting(aPresContext)) {
     float ratio = aPresContext->CSSPixelsToDevPixels(1.0f);
     aResult.SetFloatValue(ratio, eCSSUnit_Number);
   } else {
     aResult.SetFloatValue(1.0, eCSSUnit_Number);
   }
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetTransform3d(nsPresContext* aPresContext, const nsMediaFeature*,
                nsCSSValue& aResult)
 {
   // Gecko supports 3d transforms, so this feature is always 1.
   aResult.SetIntValue(1, eCSSUnit_Integer);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetSystemMetric(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
                 nsCSSValue& aResult)
 {
   aResult.Reset();
   if (ShouldResistFingerprinting(aPresContext)) {
     // If "privacy.resistFingerprinting" is enabled, then we simply don't
     // return any system-backed media feature values. (No spoofed values returned.)
-    return NS_OK;
+    return;
   }
 
   MOZ_ASSERT(aFeature->mValueType == nsMediaFeature::eBoolInteger,
              "unexpected type");
   nsIAtom *metricAtom = *aFeature->mData.mMetric;
   bool hasMetric = nsCSSRuleProcessor::HasSystemMetric(metricAtom);
   aResult.SetIntValue(hasMetric ? 1 : 0, eCSSUnit_Integer);
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetWindowsTheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
                 nsCSSValue& aResult)
 {
   aResult.Reset();
   if (ShouldResistFingerprinting(aPresContext)) {
-    return NS_OK;
+    return;
   }
 
 #ifdef XP_WIN
   uint8_t windowsThemeId =
     nsCSSRuleProcessor::GetWindowsThemeIdentifier();
 
   // Classic mode should fail to match.
   if (windowsThemeId == LookAndFeel::eWindowsTheme_Classic)
-    return NS_OK;
+    return;
 
   // Look up the appropriate theme string
   for (size_t i = 0; i < ArrayLength(themeStrings); ++i) {
     if (windowsThemeId == themeStrings[i].id) {
       aResult.SetStringValue(nsDependentString(themeStrings[i].name),
                              eCSSUnit_Ident);
       break;
     }
   }
 #endif
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetOperatingSystemVersion(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
                          nsCSSValue& aResult)
 {
   aResult.Reset();
   if (ShouldResistFingerprinting(aPresContext)) {
-    return NS_OK;
+    return;
   }
 
 #ifdef XP_WIN
   int32_t metricResult;
   if (NS_SUCCEEDED(
         LookAndFeel::GetInt(LookAndFeel::eIntID_OperatingSystemVersionIdentifier,
                             &metricResult))) {
     for (size_t i = 0; i < ArrayLength(osVersionStrings); ++i) {
       if (metricResult == osVersionStrings[i].id) {
         aResult.SetStringValue(nsDependentString(osVersionStrings[i].name),
                                eCSSUnit_Ident);
         break;
       }
     }
   }
 #endif
-  return NS_OK;
 }
 
-static nsresult
+static void
 GetIsGlyph(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
           nsCSSValue& aResult)
 {
   aResult.SetIntValue(aPresContext->IsGlyph() ? 1 : 0, eCSSUnit_Integer);
-  return NS_OK;
 }
 
 /*
  * Adding new media features requires (1) adding the new feature to this
  * array, with appropriate entries (and potentially any new code needed
  * to support new types in these entries and (2) ensuring that either
  * nsPresContext::MediaFeatureValuesChanged or
  * nsPresContext::PostMediaFeatureValuesChangedEvent is called when the
--- a/layout/style/nsMediaFeatures.h
+++ b/layout/style/nsMediaFeatures.h
@@ -11,20 +11,19 @@
 
 #include "nsCSSProps.h"
 
 class nsIAtom;
 class nsPresContext;
 class nsCSSValue;
 
 struct nsMediaFeature;
-typedef nsresult
-(* nsMediaFeatureValueGetter)(nsPresContext* aPresContext,
-                              const nsMediaFeature* aFeature,
-                              nsCSSValue& aResult);
+typedef void (*nsMediaFeatureValueGetter)(nsPresContext* aPresContext,
+                                          const nsMediaFeature* aFeature,
+                                          nsCSSValue& aResult);
 
 struct nsMediaFeature
 {
   nsIAtom **mName; // extra indirection to point to nsGkAtoms members
 
   enum RangeType { eMinMaxAllowed, eMinMaxNotAllowed };
   RangeType mRangeType;
 
--- a/layout/style/nsMediaList.cpp
+++ b/layout/style/nsMediaList.cpp
@@ -212,19 +212,18 @@ nsMediaQueryResultCacheKey::Matches(nsPr
 {
   if (aPresContext->Medium() != mMedium) {
     return false;
   }
 
   for (uint32_t i = 0; i < mFeatureCache.Length(); ++i) {
     const FeatureEntry *entry = &mFeatureCache[i];
     nsCSSValue actual;
-    nsresult rv =
-      (entry->mFeature->mGetter)(aPresContext, entry->mFeature, actual);
-    NS_ENSURE_SUCCESS(rv, false); // any better ideas?
+
+    entry->mFeature->mGetter(aPresContext, entry->mFeature, actual);
 
     for (uint32_t j = 0; j < entry->mExpressions.Length(); ++j) {
       const ExpressionEntry &eentry = entry->mExpressions[j];
       if (eentry.mExpression.Matches(aPresContext, actual) !=
           eentry.mExpressionMatches) {
         return false;
       }
     }
@@ -474,19 +473,17 @@ nsMediaQuery::Matches(nsPresContext* aPr
   if (mHadUnknownExpression)
     return false;
 
   bool match =
     mMediaType == aPresContext->Medium() || mMediaType == nsGkAtoms::all;
   for (uint32_t i = 0, i_end = mExpressions.Length(); match && i < i_end; ++i) {
     const nsMediaExpression &expr = mExpressions[i];
     nsCSSValue actual;
-    nsresult rv =
-      (expr.mFeature->mGetter)(aPresContext, expr.mFeature, actual);
-    NS_ENSURE_SUCCESS(rv, false); // any better ideas?
+    expr.mFeature->mGetter(aPresContext, expr.mFeature, actual);
 
     match = expr.Matches(aPresContext, actual);
     if (aKey) {
       aKey->AddExpression(&expr, match);
     }
   }
 
   return match == !mNegated;