Backed out 5 changesets (bug 1903508) for causing bustage on nsLookAndFeel.mm CLOSED TREE

Backed out changeset fdb7a3ddb14d (bug 1903508)
Backed out changeset 16ddc594a932 (bug 1903508)
Backed out changeset 0c9dba12e2c8 (bug 1903508)
Backed out changeset e3871cddc8ec (bug 1903508)
Backed out changeset dc4af9abfa96 (bug 1903508)
This commit is contained in:
Norisz Fay 2024-07-03 19:28:48 +03:00
parent d1e2f35dfd
commit 306a996c14
11 changed files with 89 additions and 96 deletions

View File

@ -59,6 +59,14 @@ XPIDL_SOURCES += [
include("/ipc/chromium/chromium-config.mozbuild")
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
CFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
if CONFIG["MOZ_WAYLAND"]:
CFLAGS += CONFIG["MOZ_WAYLAND_CFLAGS"]
CXXFLAGS += CONFIG["MOZ_WAYLAND_CFLAGS"]
GeneratedFile(
"RFPTargetConstants.sys.mjs",
script="extract_rfp_targets.py",

View File

@ -56,11 +56,22 @@
# include "WinUtils.h"
# include "mozilla/gfx/DisplayConfigWindows.h"
# include "gfxWindowsPlatform.h"
# include <winuser.h>
#elif defined(MOZ_WIDGET_ANDROID)
# include "mozilla/java/GeckoAppShellWrappers.h"
#elif defined(XP_MACOSX)
# include <Carbon/Carbon.h>
# include "nsMacUtilsImpl.h"
# include <CoreFoundation/CoreFoundation.h>
#elif defined(XP_LINUX)
# include "mozilla/WidgetUtilsGtk.h"
# include <gtk/gtk.h>
# ifdef MOZ_X11
# include <X11/XKBlib.h>
# endif
# ifdef MOZ_WAYLAND
# include <xkbcommon/xkbcommon.h>
# endif
#endif
using namespace mozilla;
@ -295,10 +306,78 @@ void PopulatePrefs() {
void PopulateKeyboardLayout() {
nsAutoCString layoutName;
#if defined(XP_WIN)
char layout[KL_NAMELENGTH];
if (!::GetKeyboardLayoutNameA(layout)) {
return;
}
layoutName.Assign(layout);
nsresult rv = LookAndFeel::GetKeyboardLayout(layoutName);
#elif defined(XP_MACOSX)
TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
char layout[128];
if (NS_FAILED(rv) || layoutName.IsEmpty()) {
CFStringRef layoutID = static_cast<CFStringRef>(
TISGetInputSourceProperty(source, kTISPropertyInputSourceID));
CFStringGetCString(layoutID, layout, sizeof(layout), kCFStringEncodingUTF8);
layoutName.Assign(layout);
#elif defined(XP_LINUX) && !defined(ANDROID)
if (mozilla::widget::GdkIsX11Display()) {
# if defined(MOZ_X11)
Display* display = XOpenDisplay(nullptr);
if (!display) {
return;
}
XkbDescRec* kbdDesc = XkbAllocKeyboard();
if (!kbdDesc) {
XCloseDisplay(display);
return;
}
XkbStateRec state;
XkbGetState(display, XkbUseCoreKbd, &state);
uint32_t group = state.group;
XkbGetNames(display, XkbGroupNamesMask, kbdDesc);
if (!kbdDesc->names || !kbdDesc->names->groups[group]) {
return;
}
char* layout = XGetAtomName(display, kbdDesc->names->groups[group]);
XkbFreeKeyboard(kbdDesc, 0, True);
XCloseDisplay(display);
layoutName.Assign(layout);
# endif
} else {
# if defined(MOZ_WAYLAND)
struct xkb_context* context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) {
return;
}
struct xkb_keymap* keymap = xkb_keymap_new_from_names(
context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) {
xkb_context_unref(context);
return;
}
const char* layout = xkb_keymap_layout_get_name(keymap, 0);
if (layout) {
layoutName.Assign(layout);
}
xkb_keymap_unref(keymap);
xkb_context_unref(context);
# endif
}
#endif
if (layoutName.IsEmpty()) {
return;
}

View File

@ -555,8 +555,6 @@ class LookAndFeel {
}
}
static nsresult GetKeyboardLayout(nsACString& aLayout);
protected:
static void DoHandleGlobalThemeChange();
// Set to true when ThemeChanged needs to be called on mTheme (and other

View File

@ -31,8 +31,6 @@ 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.

View File

@ -18,7 +18,6 @@
#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>
@ -582,19 +581,6 @@ 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 {

View File

@ -2295,59 +2295,6 @@ bool nsLookAndFeel::WidgetUsesImage(WidgetNodeType aNodeType) {
return false;
}
nsresult nsLookAndFeel::GetKeyboardLayoutImpl(nsACString& aLayout) {
if (mozilla::widget::GdkIsX11Display()) {
#if defined(MOZ_X11)
Display* display = gdk_x11_get_default_xdisplay();
if (!display) {
return NS_ERROR_NOT_AVAILABLE;
}
XkbDescRec* kbdDesc = XkbAllocKeyboard();
if (!kbdDesc) {
return NS_ERROR_NOT_AVAILABLE;
}
auto cleanup = MakeScopeExit([&] { XkbFreeKeyboard(kbdDesc, 0, true); });
XkbStateRec state;
XkbGetState(display, XkbUseCoreKbd, &state);
uint32_t group = state.group;
XkbGetNames(display, XkbGroupNamesMask, kbdDesc);
if (!kbdDesc->names || !kbdDesc->names->groups[group]) {
return NS_ERROR_NOT_AVAILABLE;
}
char* layout = XGetAtomName(display, kbdDesc->names->groups[group]);
aLayout.Assign(layout);
#endif
} else {
#if defined(MOZ_WAYLAND)
struct xkb_context* context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) {
return NS_ERROR_NOT_AVAILABLE;
}
auto cleanupContext = MakeScopeExit([&] { xkb_context_unref(context); });
struct xkb_keymap* keymap = xkb_keymap_new_from_names(
context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) {
return NS_ERROR_NOT_AVAILABLE;
}
auto cleanupKeymap = MakeScopeExit([&] { xkb_keymap_unref(keymap); });
const char* layout = xkb_keymap_layout_get_name(keymap, 0);
if (layout) {
aLayout.Assign(layout);
}
#endif
}
return NS_OK;
}
void nsLookAndFeel::RecordLookAndFeelSpecificTelemetry() {
// Gtk version we're on.
nsString version;

View File

@ -47,8 +47,6 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
void GetThemeInfo(nsACString&) override;
nsresult GetKeyboardLayoutImpl(nsACString& aLayout) override;
static const nscolor kBlack = NS_RGB(0, 0, 0);
static const nscolor kWhite = NS_RGB(255, 255, 255);
void OnColorSchemeSettingChanged();

View File

@ -1550,9 +1550,4 @@ void LookAndFeel::SetData(widget::FullLookAndFeel&& aTables) {
nsLookAndFeel::GetInstance()->SetDataImpl(std::move(aTables));
}
// static
nsresult LookAndFeel::GetKeyboardLayout(nsACString& aLayout) {
return nsLookAndFeel::GetInstance()->GetKeyboardLayoutImpl(aLayout);
}
} // namespace mozilla

View File

@ -72,10 +72,6 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
virtual void GetThemeInfo(nsACString&) {}
virtual nsresult GetKeyboardLayoutImpl(nsACString& aLayout) {
return NS_ERROR_NOT_IMPLEMENTED;
}
protected:
nsXPLookAndFeel() = default;

View File

@ -878,16 +878,6 @@ auto nsLookAndFeel::ComputeTitlebarColors() -> TitlebarColors {
return result;
}
nsresult nsLookAndFeel::GetKeyboardLayoutImpl(nsACString& aLayout) {
char layout[KL_NAMELENGTH];
if (!::GetKeyboardLayoutNameA(layout)) {
return NS_ERROR_NOT_AVAILABLE;
}
aLayout.Assign(layout);
return NS_OK;
}
void nsLookAndFeel::EnsureInit() {
if (mInitialized) {
return;

View File

@ -62,8 +62,6 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
gfxFontStyle& aFontStyle) override;
char16_t GetPasswordCharacterImpl() override;
nsresult GetKeyboardLayoutImpl(nsACString& aLayout) override;
private:
struct TitlebarColors {
// NOTE: These are the DWM accent colors, which might not match the