Bug 810399 - Add new css selectors and media queries for windows os versions. r=bz
authorJim Mathies <jmathies@mozilla.com>
Mon, 01 Jul 2013 11:02:29 -0500
changeset 137033 87b5a0591affd80a7d0eab6e9a3a8cde373d0cdd
parent 137032 31f741b111e0f7f9f1fe5b7e4a40299ca4adf79d
child 137034 b4b9098538cb90ffe9b598db3417add72281d63e
push id24909
push userkhuey@mozilla.com
push dateTue, 02 Jul 2013 16:45:38 +0000
treeherdermozilla-central@23ce4eab8fb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs810399
milestone25.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 810399 - Add new css selectors and media queries for windows os versions. r=bz
content/base/src/nsGkAtomList.h
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsMediaFeatures.cpp
layout/style/test/test_media_queries.html
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -2010,32 +2010,40 @@ 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 version info selector metrics, helpful in removing ambiguity
+// in theme selectors.
+GK_ATOM(windows_version_xp, "windows-version-xp")
+GK_ATOM(windows_version_vista, "windows-version-vista")
+GK_ATOM(windows_version_win7, "windows-version-win7")
+GK_ATOM(windows_version_win8, "windows-version-win8")
+
 // 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_images_in_menus, "-moz-images-in-menus")
 GK_ATOM(_moz_images_in_buttons, "-moz-images-in-buttons")
 GK_ATOM(_moz_overlay_scrollbars, "-moz-overlay-scrollbars")
 GK_ATOM(_moz_windows_default_theme, "-moz-windows-default-theme")
 GK_ATOM(_moz_mac_graphite_theme, "-moz-mac-graphite-theme")
 GK_ATOM(_moz_mac_lion_theme, "-moz-mac-lion-theme")
 GK_ATOM(_moz_windows_compositor, "-moz-windows-compositor")
 GK_ATOM(_moz_windows_classic, "-moz-windows-classic")
 GK_ATOM(_moz_windows_glass, "-moz-windows-glass")
 GK_ATOM(_moz_windows_theme, "-moz-windows-theme")
+GK_ATOM(_moz_os_version, "-moz-os-version")
 GK_ATOM(_moz_touch_enabled, "-moz-touch-enabled")
 GK_ATOM(_moz_maemo_classic, "-moz-maemo-classic")
 GK_ATOM(_moz_menubar_drag, "-moz-menubar-drag")
 GK_ATOM(_moz_device_pixel_ratio, "-moz-device-pixel-ratio")
 GK_ATOM(_moz_device_orientation, "-moz-device-orientation")
 GK_ATOM(_moz_is_resource_document, "-moz-is-resource-document")
 GK_ATOM(_moz_swipe_animation_enabled, "-moz-swipe-animation-enabled")
 GK_ATOM(_moz_physical_home_button, "-moz-physical-home-button")
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -1231,16 +1231,37 @@ InitSystemMetrics()
         break;
       case LookAndFeel::eWindowsTheme_Generic:
         sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_generic);
         break;
     }
   }
 #endif
 
+  // os version metrics, currently only defined for Windows.
+  if (NS_SUCCEEDED(
+        LookAndFeel::GetInt(LookAndFeel::eIntID_OperatingSystemVersionIdentifier,
+                            &metricResult))) {
+    switch(metricResult) {
+      case LookAndFeel::eOperatingSystemVersion_WindowsXP:
+        sSystemMetrics->AppendElement(nsGkAtoms::windows_version_xp);
+        break;
+      case LookAndFeel::eOperatingSystemVersion_WindowsVista:
+        sSystemMetrics->AppendElement(nsGkAtoms::windows_version_vista);
+        break;
+      case LookAndFeel::eOperatingSystemVersion_Windows7:
+        sSystemMetrics->AppendElement(nsGkAtoms::windows_version_win7);
+        break;
+      case LookAndFeel::eOperatingSystemVersion_Windows8:
+        sSystemMetrics->AppendElement(nsGkAtoms::windows_version_win8);
+        break;
+      // don't add anything for future versions
+    }
+  }
+
   return true;
 }
 
 /* static */ void
 nsCSSRuleProcessor::FreeSystemMetrics()
 {
   delete sSystemMetrics;
   sSystemMetrics = nullptr;
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -40,16 +40,29 @@ const WindowsThemeName themeStrings[] = 
     { 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" }
 };
+
+struct OperatingSystemVersionInfo {
+    LookAndFeel::OperatingSystemVersion id;
+    const wchar_t* name;
+};
+
+// Os version identities used in the -moz-os-version media query.
+const OperatingSystemVersionInfo osVersionStrings[] = {
+    { LookAndFeel::eOperatingSystemVersion_WindowsXP,     L"windows-xp" },
+    { LookAndFeel::eOperatingSystemVersion_WindowsVista,  L"windows-vista" },
+    { LookAndFeel::eOperatingSystemVersion_Windows7,      L"windows-win7" },
+    { LookAndFeel::eOperatingSystemVersion_Windows8,      L"windows-win8" },
+};
 #endif
 
 // A helper for four features below
 static nsSize
 GetSize(nsPresContext* aPresContext)
 {
     nsSize size;
     if (aPresContext->IsRootPaginatedDocument())
@@ -323,16 +336,38 @@ GetWindowsTheme(nsPresContext* aPresCont
             break;
         }
     }
 #endif
     return NS_OK;
 }
 
 static nsresult
+GetOperatinSystemVersion(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
+                         nsCSSValue& aResult)
+{
+    aResult.Reset();
+#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
 GetIsGlyph(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
           nsCSSValue& aResult)
 {
     aResult.SetIntValue(aPresContext->IsGlyph() ? 1 : 0, eCSSUnit_Integer);
     return NS_OK;
 }
 
 /*
@@ -581,16 +616,23 @@ nsMediaFeatures::features[] = {
     },
     {
         &nsGkAtoms::_moz_windows_theme,
         nsMediaFeature::eMinMaxNotAllowed,
         nsMediaFeature::eIdent,
         { nullptr },
         GetWindowsTheme
     },
+    {
+        &nsGkAtoms::_moz_os_version,
+        nsMediaFeature::eMinMaxNotAllowed,
+        nsMediaFeature::eIdent,
+        { nullptr },
+        GetOperatinSystemVersion
+    },
 
     {
         &nsGkAtoms::_moz_swipe_animation_enabled,
         nsMediaFeature::eMinMaxNotAllowed,
         nsMediaFeature::eBoolInteger,
         { &nsGkAtoms::swipe_animation_enabled },
         GetSystemMetric
     },
--- a/layout/style/test/test_media_queries.html
+++ b/layout/style/test/test_media_queries.html
@@ -685,16 +685,23 @@ function run() {
   expression_should_be_parseable("-moz-windows-theme: luna-silver");
   expression_should_be_parseable("-moz-windows-theme: royale");
   expression_should_be_parseable("-moz-windows-theme: generic");
   expression_should_be_parseable("-moz-windows-theme: zune");
   expression_should_be_parseable("-moz-windows-theme: garbage");
   expression_should_not_be_parseable("-moz-windows-theme: ''");
   expression_should_not_be_parseable("-moz-windows-theme: ");
 
+  // os version media queries (currently windows only)
+  expression_should_be_parseable("-moz-os-version: windows-xp");
+  expression_should_be_parseable("-moz-os-version: windows-vista");
+  expression_should_be_parseable("-moz-os-version: windows-win7");
+  expression_should_be_parseable("-moz-os-version: windows-win8");
+  expression_should_not_be_parseable("-moz-os-version: ");
+
   // OpenType SVG media features
   query_should_be_parseable("(-moz-is-glyph)");
   query_should_not_be_parseable("not (-moz-is-glyph)");
   query_should_not_be_parseable("only (-moz-is-glyph)");
   query_should_be_parseable("all and (-moz-is-glyph)");
   query_should_be_parseable("not all and (-moz-is-glyph)");
   query_should_be_parseable("only all and (-moz-is-glyph)");