Commit c2dd34b0 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

ozone/wayland: set input method factory only upon CreateInputMethod

When tests are initialized, some of them try to set a test input
method factory. However, they fail to do so, because
OzonePlatform::InitializeUi is called earlier. That method does
various initialization and also sets the input method factory.

Previously, we used to set the factory in CreateInputMethod method
if that hasn't been set yet. (see https://crrev.com/c/1531600),
but after https://crrev.com/c/1798263, that functionality was
moved back to InitializeUi. We didn't run any tests with Wayland
and couldn't spot this problem. However, now, I'm enabling
views_unittests, and that problem was hit.

Thus, to fix the issue, let the GtkUi call CreateInputMethod to
give an OzonePlatform chance to set an input method. If it is
not set, then use gtkui provided one.

Bug: 578890
Change-Id: Ic09de5a18a1ff969e1a96977a987f09cac1129f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062974Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#742691}
parent 5d92ceeb
......@@ -75,6 +75,7 @@
#include "ui/gfx/x/x11.h" // nogncheck
#include "ui/gfx/x/x11_types.h" // nogncheck
#elif defined(USE_OZONE)
#include "ui/base/ime/input_method.h"
#include "ui/ozone/public/ozone_platform.h"
#endif
......@@ -420,13 +421,15 @@ GtkUi::~GtkUi() {
void GtkUi::Initialize() {
#if defined(USE_OZONE)
// Linux ozone platforms may set LinuxInputMethodContextFactory instance at
// InitializeUI step (which is called in Toolkit initialization step), so
// at this point if it's not set LinuxUI (i.e: GtkUi) implementation is
// used. For example, ozone/x11 uses GtkUi context factory, but
// ozone/wayland uses it's own implementation.
if (!ui::LinuxInputMethodContextFactory::instance())
// Linux ozone platforms may want to set LinuxInputMethodContextFactory
// instance instead of using GtkUi context factory. This step is made upon
// CreateInputMethod call. If the factory is not set, use the GtkUi context
// factory.
if (!ui::OzonePlatform::GetInstance()->CreateInputMethod(
nullptr, gfx::kNullAcceleratedWidget)) {
DCHECK(!ui::LinuxInputMethodContextFactory::instance());
ui::LinuxInputMethodContextFactory::SetInstance(this);
}
#endif
GtkSettings* settings = gtk_settings_get_default();
......
......@@ -132,7 +132,17 @@ class OzonePlatformWayland : public OzonePlatform {
std::unique_ptr<InputMethod> CreateInputMethod(
internal::InputMethodDelegate* delegate,
gfx::AcceleratedWidget) override {
gfx::AcceleratedWidget widget) override {
// Instantiate and set LinuxInputMethodContextFactory unless it is already
// set (e.g: tests may have already set it).
if (!LinuxInputMethodContextFactory::instance() &&
!input_method_context_factory_) {
input_method_context_factory_ =
std::make_unique<WaylandInputMethodContextFactory>(connection_.get());
LinuxInputMethodContextFactory::SetInstance(
input_method_context_factory_.get());
}
return std::make_unique<InputMethodAuraLinux>(delegate);
}
......@@ -174,16 +184,6 @@ class OzonePlatformWayland : public OzonePlatform {
supported_buffer_formats_ =
connection_->buffer_manager_host()->GetSupportedBufferFormats();
// Instantiate and set LinuxInputMethodContextFactory unless it is already
// set (e.g: tests may have already set it).
if (!LinuxInputMethodContextFactory::instance() &&
!input_method_context_factory_) {
input_method_context_factory_ =
std::make_unique<WaylandInputMethodContextFactory>(connection_.get());
LinuxInputMethodContextFactory::SetInstance(
input_method_context_factory_.get());
}
}
void InitializeGPU(const InitParams& args) override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment