Bug 1435944 part 2 - Use atom for identifier media features. r=emilio
authorXidorn Quan <me@upsuper.org>
Thu, 08 Feb 2018 13:50:42 +1100
changeset 402902 332427963060bac736d5ab3ee0332f95ddee1b63
parent 402901 43a1e6e51a52fffbad6b7442857681ddc0bd2606
child 402903 c6843800cfc79ce9c0b3f72e6e457b2848678298
push id33406
push usercbrindusan@mozilla.com
push dateThu, 08 Feb 2018 18:59:51 +0000
treeherdermozilla-central@992a8e2e042b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1435944
milestone60.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 1435944 part 2 - Use atom for identifier media features. r=emilio MozReview-Commit-ID: 8NHLNySwcSf
dom/base/nsGkAtomList.h
layout/style/nsCSSParser.cpp
layout/style/nsMediaFeatures.cpp
layout/style/nsMediaList.cpp
--- a/dom/base/nsGkAtomList.h
+++ b/dom/base/nsGkAtomList.h
@@ -2280,16 +2280,28 @@ GK_ATOM(windows_theme_aero, "windows-the
 GK_ATOM(windows_theme_aero_lite, "windows-theme-aero-lite")
 GK_ATOM(windows_theme_luna_blue, "windows-theme-luna-blue")
 GK_ATOM(windows_theme_luna_olive, "windows-theme-luna-olive")
 GK_ATOM(windows_theme_luna_silver, "windows-theme-luna-silver")
 GK_ATOM(windows_theme_royale, "windows-theme-royale")
 GK_ATOM(windows_theme_zune, "windows-theme-zune")
 GK_ATOM(windows_theme_generic, "windows-theme-generic")
 
+// windows media query names
+GK_ATOM(aero, "aero")
+GK_ATOM(aero_lite, "aero-lite")
+GK_ATOM(luna_blue, "luna-blue")
+GK_ATOM(luna_olive, "luna-olive")
+GK_ATOM(luna_silver, "luna-silver")
+GK_ATOM(royale, "royale")
+GK_ATOM(zune, "zune")
+GK_ATOM(windows_win7, "windows-win7")
+GK_ATOM(windows_win8, "windows-win8")
+GK_ATOM(windows_win10, "windows-win10")
+
 // And the same again, as media query keywords.
 GK_ATOM(_moz_scrollbar_start_backward, "-moz-scrollbar-start-backward")
 GK_ATOM(_moz_scrollbar_start_forward, "-moz-scrollbar-start-forward")
 GK_ATOM(_moz_scrollbar_end_backward, "-moz-scrollbar-end-backward")
 GK_ATOM(_moz_scrollbar_end_forward, "-moz-scrollbar-end-forward")
 GK_ATOM(_moz_scrollbar_thumb_proportional, "-moz-scrollbar-thumb-proportional")
 GK_ATOM(_moz_overlay_scrollbars, "-moz-overlay-scrollbars")
 GK_ATOM(_moz_windows_accent_color_in_titlebar, "-moz-windows-accent-color-in-titlebar")
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -3621,16 +3621,19 @@ CSSParserImpl::ParseMediaQueryExpression
       }
       break;
     case nsMediaFeature::eEnumerated:
       rv = ParseSingleTokenVariant(expr->mValue, VARIANT_KEYWORD,
                                    feature->mData.mKeywordTable);
       break;
     case nsMediaFeature::eIdent:
       rv = ParseSingleTokenVariant(expr->mValue, VARIANT_IDENTIFIER, nullptr);
+      if (rv) {
+        expr->mValue.AtomizeIdentValue();
+      }
       break;
   }
   if (!rv || !ExpectSymbol(')', true)) {
     REPORT_UNEXPECTED(PEMQExpectedFeatureValue);
     SkipUntil(')');
     return false;
   }
 
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -53,42 +53,42 @@ static const nsCSSProps::KTableEntry kDi
   { eCSSKeyword_minimal_ui,              NS_STYLE_DISPLAY_MODE_MINIMAL_UI },
   { eCSSKeyword_standalone,              NS_STYLE_DISPLAY_MODE_STANDALONE },
   { eCSSKeyword_fullscreen,              NS_STYLE_DISPLAY_MODE_FULLSCREEN },
   { eCSSKeyword_UNKNOWN,                 -1 }
 };
 
 #ifdef XP_WIN
 struct WindowsThemeName {
-  LookAndFeel::WindowsTheme id;
-  const wchar_t* name;
+  LookAndFeel::WindowsTheme mId;
+  nsStaticAtom** mName;
 };
 
 // Windows theme identities used in the -moz-windows-theme media query.
-const WindowsThemeName themeStrings[] = {
-  { LookAndFeel::eWindowsTheme_Aero,       L"aero" },
-  { LookAndFeel::eWindowsTheme_AeroLite,   L"aero-lite" },
-  { LookAndFeel::eWindowsTheme_LunaBlue,   L"luna-blue" },
-  { LookAndFeel::eWindowsTheme_LunaOlive,  L"luna-olive" },
-  { LookAndFeel::eWindowsTheme_LunaSilver, L"luna-silver" },
-  { LookAndFeel::eWindowsTheme_Royale,     L"royale" },
-  { LookAndFeel::eWindowsTheme_Zune,       L"zune" },
-  { LookAndFeel::eWindowsTheme_Generic,    L"generic" }
+const WindowsThemeName kThemeStrings[] = {
+  { LookAndFeel::eWindowsTheme_Aero,       &nsGkAtoms::aero },
+  { LookAndFeel::eWindowsTheme_AeroLite,   &nsGkAtoms::aero_lite },
+  { LookAndFeel::eWindowsTheme_LunaBlue,   &nsGkAtoms::luna_blue },
+  { LookAndFeel::eWindowsTheme_LunaOlive,  &nsGkAtoms::luna_olive },
+  { LookAndFeel::eWindowsTheme_LunaSilver, &nsGkAtoms::luna_silver },
+  { LookAndFeel::eWindowsTheme_Royale,     &nsGkAtoms::royale },
+  { LookAndFeel::eWindowsTheme_Zune,       &nsGkAtoms::zune },
+  { LookAndFeel::eWindowsTheme_Generic,    &nsGkAtoms::generic_ }
 };
 
 struct OperatingSystemVersionInfo {
-  LookAndFeel::OperatingSystemVersion id;
-  const wchar_t* name;
+  LookAndFeel::OperatingSystemVersion mId;
+  nsStaticAtom** mName;
 };
 
 // Os version identities used in the -moz-os-version media query.
-const OperatingSystemVersionInfo osVersionStrings[] = {
-  { LookAndFeel::eOperatingSystemVersion_Windows7,      L"windows-win7" },
-  { LookAndFeel::eOperatingSystemVersion_Windows8,      L"windows-win8" },
-  { LookAndFeel::eOperatingSystemVersion_Windows10,     L"windows-win10" }
+const OperatingSystemVersionInfo kOsVersionStrings[] = {
+  { LookAndFeel::eOperatingSystemVersion_Windows7,  &nsGkAtoms::windows_win7 },
+  { LookAndFeel::eOperatingSystemVersion_Windows8,  &nsGkAtoms::windows_win8 },
+  { LookAndFeel::eOperatingSystemVersion_Windows10, &nsGkAtoms::windows_win10 }
 };
 #endif
 
 static nsPresContext*
 GetPresContext(nsIDocument* aDocument)
 {
   nsIPresShell* presShell = aDocument->GetShell();
   if (!presShell) {
@@ -481,20 +481,19 @@ GetWindowsTheme(nsIDocument* aDocument, 
 #ifdef XP_WIN
   uint8_t windowsThemeId = GetWindowsThemeIdentifier();
 
   // Classic mode should fail to match.
   if (windowsThemeId == LookAndFeel::eWindowsTheme_Classic)
     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);
+  for (const auto& theme : kThemeStrings) {
+    if (windowsThemeId == theme.mId) {
+      aResult.SetAtomIdentValue((*theme.mName)->ToAddRefed());
       break;
     }
   }
 #endif
 }
 
 static void
 GetOperatingSystemVersion(nsIDocument* aDocument, const nsMediaFeature* aFeature,
@@ -507,20 +506,19 @@ GetOperatingSystemVersion(nsIDocument* a
     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);
+    for (const auto& osVersion : kOsVersionStrings) {
+      if (metricResult == osVersion.mId) {
+        aResult.SetAtomIdentValue((*osVersion.mName)->ToAddRefed());
         break;
       }
     }
   }
 #endif
 }
 
 static void
--- a/layout/style/nsMediaList.cpp
+++ b/layout/style/nsMediaList.cpp
@@ -159,19 +159,19 @@ nsMediaExpression::Matches(nsPresContext
                      "bad range"); // we asserted above about mRange
         // We don't really need DoCompare, but it doesn't hurt (and
         // maybe the compiler will condense this case with eInteger).
         cmp = DoCompare(actual.GetIntValue(), required.GetIntValue());
       }
       break;
     case nsMediaFeature::eIdent:
       {
-        NS_ASSERTION(actual.GetUnit() == eCSSUnit_Ident,
+        NS_ASSERTION(actual.GetUnit() == eCSSUnit_AtomIdent,
                      "bad actual value");
-        NS_ASSERTION(required.GetUnit() == eCSSUnit_Ident,
+        NS_ASSERTION(required.GetUnit() == eCSSUnit_AtomIdent,
                      "bad required value");
         NS_ASSERTION(mFeature->mRangeType == nsMediaFeature::eMinMaxNotAllowed,
                      "bad range");
         cmp = !(actual == required); // string comparison
       }
       break;
   }
   switch (mRange) {
@@ -442,19 +442,17 @@ nsMediaQuery::AppendToString(nsAString& 
           NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Enumerated,
                        "bad unit");
           AppendASCIItoUTF16(
               nsCSSProps::ValueToKeyword(expr.mValue.GetIntValue(),
                                          feature->mData.mKeywordTable),
               aString);
           break;
         case nsMediaFeature::eIdent:
-          NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Ident,
-                       "bad unit");
-          aString.Append(expr.mValue.GetStringBufferValue());
+          expr.mValue.AppendToString(eCSSProperty_DOM, aString);
           break;
       }
     }
 
     aString.Append(')');
   }
 }