Commit 9893e293 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone/wayland: Handle preedit string in WaylandInputMethodContext

As of [1], UTF characteres are correctly composed on Ozone/wayland,
taking as input raw key events from InputMethod classes. That is
possible thanks to previously ChromeOS-only CharacterComposer component.
This patch fixes the preedit text handling in WaylandInputMethodContext,
which basically properly support HEX_MODE in CharacterComposer.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1448136

R=rjkroege@chromium.org, shuchen@chromium.org

Bug: 921947
Change-Id: I7cf750df2bf43273464f52a726719d50d74075f8
Reviewed-on: https://chromium-review.googlesource.com/c/1454297Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#630679}
parent 7ae8ccc9
......@@ -4,6 +4,7 @@ include_rules = [
"+ui/base/ui_base_features.h",
"+ui/base/ime/character_composer.h",
"+ui/base/ime/composition_text.h",
"+ui/base/ime/ime_text_span.h",
"+ui/base/ime/linux/linux_input_method_context.h",
"+ui/base/ime/linux/linux_input_method_context_factory.h",
"+mojo/public",
......
......@@ -10,6 +10,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/ime/composition_text.h"
#include "ui/base/ime/ime_text_span.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
......@@ -74,13 +75,27 @@ bool WaylandInputMethodContext::DispatchKeyEvent(
!character_composer_.FilterKeyPress(key_event))
return false;
// TODO(nickdiego): Handle preedit string
// CharacterComposer consumed the key event. Update the composition text.
UpdatePreeditText(character_composer_.preedit_string());
auto composed = character_composer_.composed_character();
if (!composed.empty())
delegate_->OnCommit(composed);
return true;
}
void WaylandInputMethodContext::UpdatePreeditText(
const base::string16& preedit_text) {
CompositionText preedit;
preedit.text = preedit_text;
auto length = preedit.text.size();
preedit.selection = gfx::Range(length);
preedit.ime_text_spans.push_back(
ImeTextSpan(ImeTextSpan::Type::kComposition, 0, length,
ImeTextSpan::Thickness::kThin, SK_ColorTRANSPARENT));
delegate_->OnPreeditChanged(preedit);
}
void WaylandInputMethodContext::Reset() {
character_composer_.Reset();
if (text_input_)
......
......@@ -5,6 +5,9 @@
#ifndef UI_OZONE_PLATFORM_WAYLAND_WAYLAND_INPUT_METHOD_CONTEXT_H_
#define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_INPUT_METHOD_CONTEXT_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "ui/base/ime/character_composer.h"
#include "ui/base/ime/linux/linux_input_method_context.h"
......@@ -43,6 +46,8 @@ class WaylandInputMethodContext : public LinuxInputMethodContext,
void OnKeysym(uint32_t key, uint32_t state, uint32_t modifiers) override;
private:
void UpdatePreeditText(const base::string16& preedit_text);
WaylandConnection* connection_ = nullptr; // TODO(jani) Handle this better
// Delegate interface back to IME code in ui.
......
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