#include "ui/ozone/platform/wayland/host/wayland_input_method_context.h"
#include <optional>
#include <string>
#include <string_view>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/debug/dump_without_crashing.h"
#include "base/environment.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/i18n/char_iterator.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/nix/xdg_util.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_offset_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/chromeos_buildflags.h"
#include "ui/base/ime/composition_text.h"
#include "ui/base/ime/ime_text_span.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/ozone/events_ozone.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/range/range.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_seat.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v1.h"
#include "ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v3.h"
#include "ui/ozone/public/ozone_switches.h"
#if BUILDFLAG(USE_XKBCOMMON)
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "base/check.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "chromeos/startup/browser_params_proxy.h"
#endif
namespace ui {
namespace {
constexpr CharacterComposer::PreeditStringMode kPreeditStringMode = …;
#else
CharacterComposer::PreeditStringMode::kHexModeOnly;
#endif
std::optional<size_t> OffsetFromUTF8Offset(std::string_view text,
uint32_t offset) { … }
bool IsImeEnabled() { … }
gfx::Range AdjustUtf8Alignment(std::string_view text_utf8, gfx::Range range) { … }
struct OffsetText { … };
std::optional<OffsetText> TrimSurroundingTextForStandard(
std::string_view text_utf8,
gfx::Range selection_utf8) { … }
std::optional<OffsetText> TrimSurroundingTextForExtension(
std::string_view text_utf8,
const base::span<size_t> offsets) { … }
}
WaylandInputMethodContext::WaylandInputMethodContext(
WaylandConnection* connection,
WaylandKeyboard::Delegate* key_delegate,
LinuxInputMethodContextDelegate* ime_delegate)
: … { … }
WaylandInputMethodContext::~WaylandInputMethodContext() { … }
void WaylandInputMethodContext::CreateTextInputWrapper() { … }
void WaylandInputMethodContext::Init(
bool initialize_for_testing,
std::unique_ptr<ZWPTextInputWrapper> wrapper_for_testing,
std::optional<base::nix::DesktopEnvironment> desktop_for_testing) { … }
bool WaylandInputMethodContext::DispatchKeyEvent(const KeyEvent& key_event) { … }
bool WaylandInputMethodContext::IsPeekKeyEvent(const KeyEvent& key_event) { … }
void WaylandInputMethodContext::UpdatePreeditText(
const std::u16string& preedit_text) { … }
void WaylandInputMethodContext::Reset() { … }
void WaylandInputMethodContext::WillUpdateFocus(TextInputClient* old_client,
TextInputClient* new_client) { … }
void WaylandInputMethodContext::UpdateFocus(
bool has_client,
TextInputType old_type,
const TextInputClientAttributes& new_client_attributes,
TextInputClient::FocusReason reason) { … }
void WaylandInputMethodContext::Focus(bool skip_virtual_keyboard_update,
TextInputClient::FocusReason reason) { … }
void WaylandInputMethodContext::Blur(bool skip_virtual_keyboard_update) { … }
void WaylandInputMethodContext::SetCursorLocation(const gfx::Rect& rect) { … }
void WaylandInputMethodContext::SetSurroundingText(
const std::u16string& text,
const gfx::Range& text_range,
const gfx::Range& composition_range,
const gfx::Range& selection_range,
const std::optional<GrammarFragment>& fragment,
const std::optional<AutocorrectInfo>& autocorrect) { … }
VirtualKeyboardController*
WaylandInputMethodContext::GetVirtualKeyboardController() { … }
bool WaylandInputMethodContext::DisplayVirtualKeyboard() { … }
void WaylandInputMethodContext::DismissVirtualKeyboard() { … }
void WaylandInputMethodContext::AddObserver(
VirtualKeyboardControllerObserver* observer) { … }
void WaylandInputMethodContext::RemoveObserver(
VirtualKeyboardControllerObserver* observer) { … }
bool WaylandInputMethodContext::IsKeyboardVisible() { … }
void WaylandInputMethodContext::OnPreeditString(
std::string_view text,
const std::vector<SpanStyle>& spans,
const gfx::Range& preedit_cursor) { … }
void WaylandInputMethodContext::OnCommitString(std::string_view text) { … }
void WaylandInputMethodContext::OnCursorPosition(int32_t index,
int32_t anchor) { … }
void WaylandInputMethodContext::OnDeleteSurroundingText(int32_t index,
uint32_t length) { … }
void WaylandInputMethodContext::OnKeysym(uint32_t keysym,
uint32_t state,
uint32_t modifiers_bits,
uint32_t time) { … }
void WaylandInputMethodContext::OnSetPreeditRegion(
int32_t index,
uint32_t length,
const std::vector<SpanStyle>& spans) { … }
void WaylandInputMethodContext::OnClearGrammarFragments(
const gfx::Range& range) { … }
void WaylandInputMethodContext::OnAddGrammarFragment(
const GrammarFragment& fragment) { … }
void WaylandInputMethodContext::OnSetAutocorrectRange(const gfx::Range& range) { … }
void WaylandInputMethodContext::OnSetVirtualKeyboardOccludedBounds(
const gfx::Rect& screen_bounds) { … }
void WaylandInputMethodContext::OnConfirmPreedit(bool keep_selection) { … }
void WaylandInputMethodContext::OnInputPanelState(uint32_t state) { … }
void WaylandInputMethodContext::OnModifiersMap(
std::vector<std::string> modifiers_map) { … }
void WaylandInputMethodContext::OnInsertImage(const GURL& src) { … }
void WaylandInputMethodContext::OnKeyboardFocusedWindowChanged() { … }
void WaylandInputMethodContext::MaybeUpdateActivated(
bool skip_virtual_keyboard_update,
TextInputClient::FocusReason reason) { … }
}