Skip to content

Commit

Permalink
Bug 1754547 - Generalize moz-os-version into moz-platform. r=dao,pref…
Browse files Browse the repository at this point in the history
…erences-reviewers,Gijs

Allow differentiating non-windows platforms on it.

Differential Revision: https://phabricator.services.mozilla.com/D138431
  • Loading branch information
emilio committed Feb 10, 2022
1 parent 8b8708f commit 5fed8de
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 182 deletions.
8 changes: 4 additions & 4 deletions browser/base/content/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ body {
with the ruleset above. We must set background properties on :root and not
#navigator-toolbox on Windows 7/8 due to a WebRender bug that hides the
minimize/maximize/close buttons. */
@media not (-moz-os-version: windows-win7) {
@media not (-moz-os-version: windows-win8) {
@media not (-moz-platform: windows-win7) {
@media not (-moz-platform: windows-win8) {
#navigator-toolbox:-moz-lwtheme {
background-color: var(--lwt-accent-color);
}
Expand All @@ -74,8 +74,8 @@ body {
}
}
/* TODO bug 1695280: Remove this block. */
@media (-moz-os-version: windows-win7),
(-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win7),
(-moz-platform: windows-win8) {
:root:-moz-lwtheme {
background-color: var(--lwt-accent-color);
background-image: var(--lwt-additional-images);
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ var gBrowserInit = {

if (AppConstants.platform == "win") {
if (
window.matchMedia("(-moz-os-version: windows-win8)").matches &&
window.matchMedia("(-moz-platform: windows-win8)").matches &&
window.matchMedia("(-moz-windows-default-theme)").matches
) {
let windowFrameColor = new Color(
Expand Down
4 changes: 2 additions & 2 deletions browser/themes/shared/preferences/preferences.inc.css
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ richlistitem[selected] .actionsMenu:focus-visible {
margin-inline-start: 0;
}

@media (-moz-os-version: windows-win7),
(-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win7),
(-moz-platform: windows-win8) {
#windows-sso,
#windows-sso-caption {
display: none;
Expand Down
14 changes: 7 additions & 7 deletions browser/themes/windows/browser-aero.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
--glass-shadow-color: hsla(240,5%,5%,0.3);
}

@media (-moz-os-version: windows-win7),
(-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win7),
(-moz-platform: windows-win8) {
@media (-moz-windows-classic: 0) {
:root[sizemode="normal"] #toolbar-menubar:not([autohide="true"]) > #menubar-items,
:root[sizemode="normal"] #toolbar-menubar[autohide="true"][inactive] + #TabsToolbar > .toolbar-items {
Expand Down Expand Up @@ -43,8 +43,8 @@
}

@media (-moz-windows-compositor) {
@media not (-moz-os-version: windows-win7) {
@media not (-moz-os-version: windows-win8) {
@media not (-moz-platform: windows-win7) {
@media not (-moz-platform: windows-win8) {
@media (-moz-windows-default-theme) {
@media (-moz-windows-accent-color-in-titlebar) {
:root[sizemode=normal][tabsintitlebar] #navigator-toolbox {
Expand Down Expand Up @@ -241,8 +241,8 @@
}
}

@media (-moz-os-version: windows-win7),
(-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win7),
(-moz-platform: windows-win8) {
:root {
background-color: transparent;
appearance: auto;
Expand All @@ -267,7 +267,7 @@
}
}

@media (-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win8) {
/* Artificially draw window borders that are covered by lwtheme, see bug 591930.
* Borders for win7 are below, win10 only needs something like this when
* drawing in the titlebar (-moz-windows-accent-color-in-titlebar). */
Expand Down
16 changes: 8 additions & 8 deletions browser/themes/windows/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
* illegible.
*/
@media (-moz-windows-default-theme) {
@media not (-moz-os-version: windows-win7) {
@media not (-moz-platform: windows-win7) {
#toolbar-menubar:not(:-moz-lwtheme):-moz-window-inactive {
color: ThreeDShadow;
}
}
}

@media not (-moz-os-version: windows-win7) {
@media not (-moz-os-version: windows-win8) {
@media not (-moz-platform: windows-win7) {
@media not (-moz-platform: windows-win8) {
/* On Windows 10, when temporarily showing the menu bar, make it at least as
* tall as the tab bar such that the window controls don't appear to move up. */
:root[tabsintitlebar] #toolbar-menubar[autohide="true"] {
Expand All @@ -79,7 +79,7 @@
}

/* Add 4px extra margin on top of the tabs toolbar on Windows 7. */
@media (-moz-os-version: windows-win7) {
@media (-moz-platform: windows-win7) {
:root[sizemode="normal"][chromehidden~="menubar"] #TabsToolbar > .toolbar-items,
:root[sizemode="normal"] #toolbar-menubar[autohide="true"][inactive] + #TabsToolbar > .toolbar-items {
padding-top: 4px;
Expand All @@ -99,7 +99,7 @@
}

/* Add a fog for background tabs to be visible on Windows 7 glass window background */
@media (-moz-os-version: windows-win7) {
@media (-moz-platform: windows-win7) {
@media (-moz-windows-default-theme) {
#TabsToolbar:not(:-moz-lwtheme) {
background-image: radial-gradient(ellipse at bottom, rgba(255,255,255,0.8), rgba(255,255,255,0.5) 80%, transparent);
Expand All @@ -109,7 +109,7 @@

@media (-moz-windows-compositor: 0),
(-moz-windows-default-theme: 0),
(-moz-os-version: windows-win8) {
(-moz-platform: windows-win8) {
/* Please keep the menu text colors in this media block in sync with
* compacttheme.css, minus the :not(:-moz-lwtheme) condition - see Bug 1165718.
*/
Expand Down Expand Up @@ -234,8 +234,8 @@
-moz-box-align: stretch;
}

@media (-moz-os-version: windows-win7),
(-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win7),
(-moz-platform: windows-win8) {
/* Preserve window control buttons position at the top of the button box. */
.titlebar-buttonbox-container {
-moz-box-align: start;
Expand Down
10 changes: 5 additions & 5 deletions browser/themes/windows/compacttheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}

/* Add a fog for background tabs to be visible on Windows 7 glass window background */
@media (-moz-os-version: windows-win7) {
@media (-moz-platform: windows-win7) {
@media (-moz-windows-default-theme) {
#TabsToolbar {
background-image: radial-gradient(ellipse at bottom, rgba(255,255,255,0.8), rgba(255,255,255,0.5) 80%, transparent);
Expand All @@ -50,8 +50,8 @@
}
}

@media (-moz-os-version: windows-win7),
(-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win7),
(-moz-platform: windows-win8) {
@media (-moz-windows-compositor) {
:root {
background: transparent !important;
Expand All @@ -69,7 +69,7 @@
These colors are copied from browser.css. */
@media (-moz-windows-compositor: 0),
(-moz-windows-default-theme: 0),
(-moz-os-version: windows-win8) {
(-moz-platform: windows-win8) {
:root[tabsintitlebar] {
color: CaptionText;
}
Expand Down Expand Up @@ -97,7 +97,7 @@
padding-top: 0 !important;
}
}
@media (-moz-os-version: windows-win8) {
@media (-moz-platform: windows-win8) {
#navigator-toolbox {
border-top: none !important;
}
Expand Down
2 changes: 1 addition & 1 deletion browser/themes/windows/customizableui/panelUI.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}

/* Add border-radius on Windows 7 */
@media (-moz-os-version: windows-win7) {
@media (-moz-platform: windows-win7) {
#BMB_bookmarksPopup menupopup::part(content) {
border-radius: 3.5px;
}
Expand Down
2 changes: 1 addition & 1 deletion browser/themes/windows/searchbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
outline: none;
}

@media (-moz-os-version: windows-win10) {
@media (-moz-platform: windows-win10) {
#PopupSearchAutoComplete {
/* A border is necessary because the shadow is bottom-right */
border-color: var(--menu-border-color);
Expand Down
2 changes: 1 addition & 1 deletion editor/reftests/xul/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ html|input.empty {
color: graytext;
}

@media (-moz-windows-default-theme) and (-moz-os-version: windows-win7) {
@media (-moz-windows-default-theme) and (-moz-platform: windows-win7) {
:root:not(.winxp) html|input.empty {
font-style: italic;
}
Expand Down
3 changes: 1 addition & 2 deletions layout/style/GeckoBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,7 @@ mozilla::PointerCapabilities Gecko_MediaFeatures_AllPointerCapabilities(
float Gecko_MediaFeatures_GetDevicePixelRatio(const mozilla::dom::Document*);

bool Gecko_MediaFeatures_IsResourceDocument(const mozilla::dom::Document*);
nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(
const mozilla::dom::Document*);
bool Gecko_MediaFeatures_MatchesPlatform(mozilla::StylePlatform);

void Gecko_GetSafeAreaInsets(const nsPresContext*, float*, float*, float*,
float*);
Expand Down
1 change: 1 addition & 0 deletions layout/style/ServoBindings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ cbindgen-types = [
{ gecko = "StyleCursorKind", servo = "crate::values::computed::ui::CursorKind" },
{ gecko = "StyleDisplay", servo = "crate::values::specified::Display" },
{ gecko = "StyleDisplayMode", servo = "crate::gecko::media_features::DisplayMode" },
{ gecko = "StylePlatform", servo = "crate::gecko::media_features::Platform" },
{ gecko = "StylePrefersColorScheme", servo = "crate::gecko::media_features::PrefersColorScheme" },
{ gecko = "StyleFillRule", servo = "crate::values::generics::basic_shape::FillRule" },
{ gecko = "StyleFontDisplay", servo = "crate::font_face::FontDisplay" },
Expand Down
55 changes: 32 additions & 23 deletions layout/style/nsMediaFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "mozilla/GeckoBindings.h"
#include "PreferenceSheet.h"
#include "nsGlobalWindowOuter.h"
#ifdef XP_WIN
# include "mozilla/WindowsVersion.h"
#endif

using namespace mozilla;
using mozilla::dom::DisplayMode;
Expand Down Expand Up @@ -223,30 +226,36 @@ StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(const Document* aDocument) {
return static_cast<StyleDisplayMode>(browsingContext->DisplayMode());
}

nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(
const Document* aDocument) {
using OperatingSystemVersion = LookAndFeel::OperatingSystemVersion;

if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
return nullptr;
}

int32_t metricResult;
if (NS_FAILED(LookAndFeel::GetInt(
LookAndFeel::IntID::OperatingSystemVersionIdentifier,
&metricResult))) {
return nullptr;
}

switch (OperatingSystemVersion(metricResult)) {
case OperatingSystemVersion::Windows7:
return nsGkAtoms::windows_win7;
case OperatingSystemVersion::Windows8:
return nsGkAtoms::windows_win8;
case OperatingSystemVersion::Windows10:
return nsGkAtoms::windows_win10;
bool Gecko_MediaFeatures_MatchesPlatform(StylePlatform aPlatform) {
switch (aPlatform) {
#if defined(XP_WIN)
case StylePlatform::Windows:
return true;
case StylePlatform::WindowsWin10:
case StylePlatform::WindowsWin7:
case StylePlatform::WindowsWin8: {
if (IsWin10OrLater()) {
return aPlatform == StylePlatform::WindowsWin10;
}
if (IsWin8OrLater()) {
return aPlatform == StylePlatform::WindowsWin8;
}
return aPlatform == StylePlatform::WindowsWin7;
}
#elif defined(ANDROID)
case StylePlatform::Android:
return true;
#elif defined(MOZ_WIDGET_GTK)
case StylePlatform::Linux:
return true;
#elif defined(XP_MACOSX)
case StylePlatform::Macos:
return true;
#else
# error "Unknown platform?"
#endif
default:
return nullptr;
return false;
}
}

Expand Down
43 changes: 0 additions & 43 deletions layout/style/test/chrome/bug418986-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ var suppressed_toggles = [

var toggles_enabled_in_content = [];

// Possible values for '-moz-os-version'
var windows_versions = ["windows-win7", "windows-win8", "windows-win10"];

// Read the current OS.
var OS = SpecialPowers.Services.appinfo.OS;

Expand Down Expand Up @@ -123,27 +120,6 @@ var testToggles = function(resisting) {
});
};

// __testWindowsSpecific__.
// Runs a media query on the queryName with the given possible matching values.
var testWindowsSpecific = function(resisting, queryName, possibleValues) {
let foundValue = null;
possibleValues.forEach(function(val) {
if (keyValMatches(queryName, val)) {
foundValue = val;
}
});
if (resisting || !is_chrome_window) {
ok(!foundValue, queryName + " should have no match");
} else {
ok(
foundValue,
foundValue
? "Match found: '" + queryName + ":" + foundValue + "'"
: "Should have a match for '" + queryName + "'"
);
}
};

// __generateHtmlLines(resisting)__.
// Create a series of div elements that look like:
// `<div class='spoof' id='resolution'>resolution</div>`,
Expand All @@ -167,13 +143,6 @@ var generateHtmlLines = function(resisting) {
div.textContent = key;
fragment.appendChild(div);
});
if (OS === "WINNT") {
let div = document.createElementNS(HTML_NS, "div");
div.setAttribute("class", "windows");
div.setAttribute("id", "-moz-os-version");
div.textContent = "-moz-os-version";
fragment.appendChild(div);
}
return fragment;
};

Expand Down Expand Up @@ -242,15 +211,6 @@ var generateCSSLines = function(resisting) {
lines += suppressedMediaQueryCSSLine(key, "green");
}
});
if (OS === "WINNT") {
lines +=
".windows { background-color: " + (resisting ? "green" : "red") + ";}\n";
lines +=
windows_versions.map(val => "(-moz-os-version: " + val + ")").join(", ") +
" { #-moz-os-version { background-color: " +
(resisting ? "red" : "green") +
";} }\n";
}
return lines;
};

Expand Down Expand Up @@ -361,9 +321,6 @@ var test = async function(isContent) {
testMatch(key, resisting ? onVal : offVal);
});
testToggles(resisting);
if (OS === "WINNT") {
testWindowsSpecific(resisting, "-moz-os-version", windows_versions);
}
testCSS(resisting);
if (OS === "Darwin") {
testOSXFontSmoothing(resisting);
Expand Down
10 changes: 7 additions & 3 deletions layout/style/test/chrome/chrome-only-media-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ const CHROME_ONLY_TOGGLES = [
// Non-parseable queries can be tested directly in
// `test_chrome_only_media_queries.html`.
const CHROME_ONLY_QUERIES = [
"(-moz-os-version: windows-win7)",
"(-moz-os-version: windows-win8)",
"(-moz-os-version: windows-win10)",
"(-moz-platform: linux)",
"(-moz-platform: windows)",
"(-moz-platform: macos)",
"(-moz-platform: android)",
"(-moz-platform: windows-win7)",
"(-moz-platform: windows-win8)",
"(-moz-platform: windows-win10)",
"(-moz-content-prefers-color-scheme: dark)",
"(-moz-content-prefers-color-scheme: light)",
];
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
expectParseable("(forced-colors: active)");
expectParseable("(forced-colors)");

expectNonParseable("(-moz-os-version: )");
expectNonParseable("(-moz-platform: )");

testWithPref();
</script>
Loading

0 comments on commit 5fed8de

Please sign in to comment.