diff --git a/toolkit/components/telemetry/Scalars.yaml b/toolkit/components/telemetry/Scalars.yaml index 9b8829028492..da087843bcf9 100644 --- a/toolkit/components/telemetry/Scalars.yaml +++ b/toolkit/components/telemetry/Scalars.yaml @@ -83,6 +83,24 @@ a11y: release_channel_collection: opt-out keyed: false + invert_colors: + bug_numbers: + - 1794626 + description: > + Boolean tracking if the user has an invert colors OS + setting enabled. + expires: never + kind: boolean + notification_emails: + - accessibility@mozilla.com + - mreschenberg@mozilla.com + products: + - 'firefox' + record_in_processes: + - 'main' + release_channel_collection: opt-out + keyed: false + theme: bug_numbers: - 1022528 diff --git a/widget/cocoa/nsLookAndFeel.h b/widget/cocoa/nsLookAndFeel.h index 7cbcaecc6977..adce685a4ef9 100644 --- a/widget/cocoa/nsLookAndFeel.h +++ b/widget/cocoa/nsLookAndFeel.h @@ -24,6 +24,15 @@ class nsLookAndFeel final : public nsXPLookAndFeel { return 0x2022; } + void RecordLookAndFeelSpecificTelemetry() override { + RecordAccessibilityTelemetry(); + } + + // Having a separate, static method allows us to rely on the same + // chunk of telemetry logging code at initialization and when we + // recieve an event that changes the value of our telemetry probe. + static void RecordAccessibilityTelemetry(); + protected: static bool SystemWantsDarkTheme(); static bool IsSystemOrientationRTL(); diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index aac6fc8376ca..6deaea82307b 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -18,6 +18,7 @@ #include "mozilla/FontPropertyTypes.h" #include "mozilla/gfx/2D.h" #include "mozilla/StaticPrefs_widget.h" +#include "mozilla/Telemetry.h" #include "mozilla/widget/WidgetMessageUtils.h" #include "SDKDeclarations.h" @@ -576,6 +577,14 @@ bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName, gfxFontStyle& NS_OBJC_END_TRY_BLOCK_RETURN(false); } +void nsLookAndFeel::RecordAccessibilityTelemetry() { + if ([[NSWorkspace sharedWorkspace] + respondsToSelector:@selector(accessibilityDisplayShouldInvertColors)]) { + bool val = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldInvertColors]; + Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_INVERT_COLORS, val); + } +} + @implementation MOZLookAndFeelDynamicChangeObserver + (void)startObserving { @@ -663,6 +672,10 @@ bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName, gfxFontStyle& } - (void)mediaQueriesChanged { + // Changing`Invert Colors` sends AccessibilityDisplayOptionsDidChangeNotifications. + // We monitor that setting via telemetry, so call into that + // recording method here. + nsLookAndFeel::RecordAccessibilityTelemetry(); LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind::MediaQueriesOnly); }