diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2021-04-29 14:17:23 +0200 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2021-05-12 15:11:56 +0200 |
commit | 33e08cdfdfcb6ed759d5ba529db7e7b31484ee16 (patch) | |
tree | 7cbf66909b8fe5e66213b0084fa46dec47833c31 | |
parent | e7d56d6c0a942a89bd9d497b57cbb0f70e39bb27 (diff) | |
download | qtwebengine-33e08cdfdfcb6ed759d5ba529db7e7b31484ee16.tar.gz |
Add support for Keyboard.getLayoutMap()
Pulls in the following changes:
Submodule src/3rdparty 6c7b4ffb..1d3b13e9
> 1d3b13e9634 Make clang to inline load/store atomic calls for YieldSortKey struct
> f6730fe81a0 Enable XkbKeyboardLayoutEngine::SetCurrentLayoutByName for Qt
Fixes: QTBUG-92971
Change-Id: I0c0cddfe4d3e25fd6d3f7e0764b302c300303172
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
m--------- | src/3rdparty | 0 | ||||
-rw-r--r-- | src/buildtools/configure.json | 17 | ||||
-rw-r--r-- | src/core/ozone/BUILD.gn | 5 | ||||
-rw-r--r-- | src/core/ozone/ozone_platform_qt.cpp | 71 | ||||
-rw-r--r-- | src/core/render_widget_host_view_qt.cpp | 6 | ||||
-rw-r--r-- | src/core/render_widget_host_view_qt.h | 1 |
6 files changed, 98 insertions, 2 deletions
diff --git a/src/3rdparty b/src/3rdparty -Subproject 6c7b4ffb3fe19e7c6a2db60ce2d05c3b50c16ff +Subproject 1d3b13e963467a19ebdd515431464771f513f6e diff --git a/src/buildtools/configure.json b/src/buildtools/configure.json index 812a91f9c..88d1790c1 100644 --- a/src/buildtools/configure.json +++ b/src/buildtools/configure.json @@ -56,6 +56,12 @@ { "type": "pkgConfig", "args": "xtst" } ] }, + "webengine-xkbfile": { + "label": "xkbfile", + "sources": [ + { "type": "pkgConfig", "args": "xkbfile" } + ] + }, "webengine-nss": { "label": "nss >= 3.26", "sources": [ @@ -490,6 +496,11 @@ "condition": "libs.webengine-xtst", "output": [ "privateFeature" ] }, + "webengine-system-xkbfile": { + "label": "xkbfile", + "condition": "libs.webengine-xkbfile", + "output": [ "privateFeature" ] + }, "webengine-system-gn": { "label": "Use System Gn", "autoDetect": "false", @@ -538,7 +549,8 @@ && features.webengine-system-xcursor && features.webengine-system-xi && features.webengine-system-xproto-gl - && features.webengine-system-xtst", + && features.webengine-system-xtst + && features.webengine-system-xkbfile", "output": [ "privateFeature" ] }, "webengine-jumbo-build": { @@ -784,7 +796,8 @@ "webengine-system-xcursor", "webengine-system-xi", "webengine-system-xproto-gl", - "webengine-system-xtst" + "webengine-system-xtst", + "webengine-system-xkbfile" ] }, { diff --git a/src/core/ozone/BUILD.gn b/src/core/ozone/BUILD.gn index 4d27f8877..a01728842 100644 --- a/src/core/ozone/BUILD.gn +++ b/src/core/ozone/BUILD.gn @@ -1,6 +1,7 @@ # Copyright 2016 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//ui/base/ui_features.gni") source_set("qt") { sources = [ @@ -18,4 +19,8 @@ source_set("qt") { ] defines = [ "OZONE_IMPLEMENTATION" ] + + if (use_xkbcommon && use_x11) { + libs = [ "xkbfile" ] + } } diff --git a/src/core/ozone/ozone_platform_qt.cpp b/src/core/ozone/ozone_platform_qt.cpp index 9db5b9986..c547cf783 100644 --- a/src/core/ozone/ozone_platform_qt.cpp +++ b/src/core/ozone/ozone_platform_qt.cpp @@ -40,9 +40,12 @@ #include "ozone_platform_qt.h" #if defined(USE_OZONE) +#include "ui/base/buildflags.h" #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" #include "ui/base/ime/input_method.h" #include "ui/display/types/native_display_delegate.h" +#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" +#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" #include "ui/ozone/common/stub_client_native_pixmap_factory.h" #include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/public/gpu_platform_support_host.h" @@ -56,6 +59,16 @@ #include "surface_factory_qt.h" #include "platform_window_qt.h" +#if BUILDFLAG(USE_XKBCOMMON) && defined(USE_X11) +#include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h" +#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" + +#include <X11/XKBlib.h> +#include <X11/extensions/XKBrules.h> + +extern void *GetQtXDisplay(); +#endif // BUILDFLAG(USE_XKBCOMMON) && defined(USE_X11) + namespace ui { namespace { @@ -86,6 +99,11 @@ private: std::unique_ptr<InputController> input_controller_; std::unique_ptr<OverlayManagerOzone> overlay_manager_; +#if BUILDFLAG(USE_XKBCOMMON) && defined(USE_X11) + XkbEvdevCodes m_xkbEvdevCodeConverter; +#endif + std::unique_ptr<KeyboardLayoutEngine> m_keyboardLayoutEngine; + DISALLOW_COPY_AND_ASSIGN(OzonePlatformQt); }; @@ -135,12 +153,65 @@ std::unique_ptr<display::NativeDisplayDelegate> OzonePlatformQt::CreateNativeDis return nullptr; } +#if BUILDFLAG(USE_XKBCOMMON) && defined(USE_X11) +static std::string getCurrentKeyboardLayout() +{ + Display *dpy = static_cast<Display *>(GetQtXDisplay()); + if (dpy == nullptr) + return std::string(); + + XkbStateRec state; + if (XkbGetState(dpy, XkbUseCoreKbd, &state) != 0) + return std::string(); + + XkbRF_VarDefsRec vdr; + if (XkbRF_GetNamesProp(dpy, nullptr, &vdr) == 0) + return std::string(); + + char *layout = strtok(vdr.layout, ","); + for (int i = 0; i < state.group; i++) { + layout = strtok(nullptr, ","); + if (layout == nullptr) + return std::string(); + } + + char *variant = strtok(vdr.variant, ","); + if (!variant) + return layout; + + for (int i = 0; i < state.group; i++) { + variant = strtok(nullptr, ","); + if (variant == nullptr) + return layout; + } + + std::string layoutWithVariant = layout; + layoutWithVariant = layoutWithVariant.append("-"); + layoutWithVariant = layoutWithVariant.append(variant); + return layoutWithVariant; +} +#endif // BUILDFLAG(USE_XKBCOMMON) && defined(USE_X11) + void OzonePlatformQt::InitializeUI(const ui::OzonePlatform::InitParams &) { overlay_manager_.reset(new StubOverlayManager()); cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone()); gpu_platform_support_host_.reset(ui::CreateStubGpuPlatformSupportHost()); input_controller_ = CreateStubInputController(); + +#if BUILDFLAG(USE_XKBCOMMON) && defined(USE_X11) + std::string layout = getCurrentKeyboardLayout(); + if (layout.empty()) { + m_keyboardLayoutEngine = std::make_unique<StubKeyboardLayoutEngine>(); + } else { + m_keyboardLayoutEngine = std::make_unique<XkbKeyboardLayoutEngine>(m_xkbEvdevCodeConverter); + m_keyboardLayoutEngine->SetCurrentLayoutByName(layout); + } +#else + m_keyboardLayoutEngine = std::make_unique<StubKeyboardLayoutEngine>(); +#endif // BUILDFLAG(USE_XKBCOMMON) && defined(USE_X11) + + KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(m_keyboardLayoutEngine.get()); } void OzonePlatformQt::InitializeGPU(const ui::OzonePlatform::InitParams &) diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index e98c69c66..bee3c4ca4 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -80,6 +80,7 @@ #include "ui/events/gesture_detection/gesture_configuration.h" #include "ui/events/gesture_detection/gesture_provider_config_helper.h" #include "ui/events/gesture_detection/motion_event.h" +#include "ui/events/keycodes/dom/dom_keyboard_layout_map.h" #include "ui/gfx/image/image_skia.h" #include "ui/touch_selection/touch_selection_controller.h" @@ -1968,6 +1969,11 @@ void RenderWidgetHostViewQt::FocusedNodeChanged(bool is_editable_node, const gfx } } +base::flat_map<std::string, std::string> RenderWidgetHostViewQt::GetKeyboardLayoutMap() +{ + return ui::GenerateDomKeyboardLayoutMap(); +} + void RenderWidgetHostViewQt::TakeFallbackContentFrom(content::RenderWidgetHostView *view) { DCHECK(!static_cast<RenderWidgetHostViewBase*>(view)->IsRenderWidgetHostViewChildFrame()); diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index 9c843e2a9..46c2547da 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -175,6 +175,7 @@ public: const viz::FrameSinkId &GetFrameSinkId() const override; const viz::LocalSurfaceId &GetLocalSurfaceId() const override; void FocusedNodeChanged(bool is_editable_node, const gfx::Rect& node_bounds_in_screen) override; + base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override; void TakeFallbackContentFrom(content::RenderWidgetHostView *view) override; void EnsureSurfaceSynchronizedForWebTest() override; |