Bug 1903508 - Part 4: Implement nsLookAndFeel::GetKeyboardLayoutImpl() for the MAC platform. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D215073
This commit is contained in:
Tim Huang 2024-07-03 14:28:13 +00:00
Родитель 613527b683
Коммит 1c5d2407d6
2 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -31,6 +31,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
RecordAccessibilityTelemetry();
}
nsresult GetKeyboardLayoutImpl(nsACString& aLayout) override;
// 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.

Просмотреть файл

@ -18,6 +18,7 @@
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/Telemetry.h"
#include "mozilla/widget/WidgetMessageUtils.h"
#include "mozilla/MacStringHelpers.h"
#import <Cocoa/Cocoa.h>
#import <AppKit/NSColor.h>
@ -581,6 +582,19 @@ void nsLookAndFeel::RecordAccessibilityTelemetry() {
}
}
nsresult nsLookAndFeel::GetKeyboardLayoutImpl(nsACString& aLayout) {
TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
nsAutoString layout;
CFStringRef layoutName = static_cast<CFStringRef>(
TISGetInputSourceProperty(source, kTISPropertyLocalizedName));
CopyNSStringToXPCOMString((const NSString*)layoutName, layout);
aLayout.Assign(NS_ConvertUTF16toUTF8(layout));
CFRelease(source);
return NS_OK;
}
@implementation MOZLookAndFeelDynamicChangeObserver
+ (void)startObserving {