#include "ui/ozone/platform/wayland/host/wayland_event_source.h"
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <tuple>
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/time/time.h"
#include "build/chromeos_buildflags.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/ozone/events_ozone.h"
#include "ui/events/ozone/layout/keyboard_layout_engine.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/platform/wayland/wayland_event_watcher.h"
#include "ui/events/pointer_details.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/ozone/platform/wayland/host/dump_util.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_cursor_position.h"
#include "ui/ozone/platform/wayland/host/wayland_keyboard.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/host/wayland_window_drag_controller.h"
#include "ui/ozone/platform/wayland/host/wayland_window_manager.h"
namespace ui {
namespace {
constexpr auto kMouseButtonToStringMap = …;
constexpr auto kModifierToStringMap = …;
std::string ToPointerFlagsString(int flags) { … }
std::string ToKeyboardModifierStrings(int modifiers) { … }
bool HasAnyPointerButtonFlag(int flags) { … }
std::vector<uint8_t> ToLittleEndianByteVector(uint32_t value) { … }
EventTarget* GetRootTarget(EventTarget* target) { … }
gfx::Point GetOriginInScreen(WaylandWindow* target) { … }
gfx::Point GetLocationInScreen(LocatedEvent* event) { … }
void SetRootLocation(LocatedEvent* event) { … }
constexpr int kGestureScrollFingerCount = …;
constexpr int kPointerScrollDataSetMaxSize = …;
constexpr int kFlingStartTimeoutMs = …;
}
struct WaylandEventSource::TouchPoint { … };
WaylandEventSource::TouchPoint::TouchPoint(gfx::PointF location,
WaylandWindow* current_window)
: … { … }
WaylandEventSource::PointerScrollData::PointerScrollData() = default;
WaylandEventSource::PointerScrollData::PointerScrollData(
const PointerScrollData&) = default;
WaylandEventSource::PointerScrollData::PointerScrollData(PointerScrollData&&) =
default;
WaylandEventSource::PointerScrollData::~PointerScrollData() = default;
WaylandEventSource::PointerScrollData&
WaylandEventSource::PointerScrollData::operator=(const PointerScrollData&) =
default;
WaylandEventSource::PointerScrollData&
WaylandEventSource::PointerScrollData::operator=(PointerScrollData&&) = default;
void WaylandEventSource::PointerScrollData::DumpState(std::ostream& out) const { … }
WaylandEventSource::FrameData::FrameData(const Event& e,
base::OnceCallback<void()> cb)
: … { … }
WaylandEventSource::FrameData::~FrameData() = default;
void WaylandEventSource::FrameData::DumpState(std::ostream& out) const { … }
void WaylandEventSource::ConvertEventToTarget(const EventTarget* new_target,
LocatedEvent* event) { … }
WaylandEventSource::WaylandEventSource(wl_display* display,
wl_event_queue* event_queue,
WaylandWindowManager* window_manager,
WaylandConnection* connection,
bool use_threaded_polling)
: … { … }
WaylandEventSource::~WaylandEventSource() = default;
void WaylandEventSource::SetShutdownCb(base::OnceCallback<void()> shutdown_cb) { … }
void WaylandEventSource::StartProcessingEvents() { … }
void WaylandEventSource::OnKeyboardFocusChanged(WaylandWindow* window,
bool focused) { … }
void WaylandEventSource::OnKeyboardModifiersChanged(int modifiers) { … }
uint32_t WaylandEventSource::OnKeyboardKeyEvent(
EventType type,
DomCode dom_code,
bool repeat,
std::optional<uint32_t> serial,
base::TimeTicks timestamp,
int device_id,
WaylandKeyboard::KeyEventKind kind) { … }
void WaylandEventSource::OnSynthesizedKeyPressEvent(DomCode dom_code,
base::TimeTicks timestamp) { … }
void WaylandEventSource::OnPointerFocusChanged(
WaylandWindow* window,
const gfx::PointF& location,
base::TimeTicks timestamp,
wl::EventDispatchPolicy dispatch_policy) { … }
void WaylandEventSource::OnPointerButtonEvent(
EventType type,
int changed_button,
base::TimeTicks timestamp,
WaylandWindow* window,
wl::EventDispatchPolicy dispatch_policy,
bool allow_release_of_unpressed_button,
bool is_synthesized) { … }
void WaylandEventSource::OnPointerButtonEventInternal(WaylandWindow* window,
EventType type) { … }
void WaylandEventSource::OnPointerMotionEvent(
const gfx::PointF& location,
base::TimeTicks timestamp,
wl::EventDispatchPolicy dispatch_policy,
bool is_synthesized) { … }
void WaylandEventSource::OnPointerAxisEvent(const gfx::Vector2dF& offset,
base::TimeTicks timestamp) { … }
void WaylandEventSource::RoundTripQueue() { … }
void WaylandEventSource::DumpState(std::ostream& out) const { … }
void WaylandEventSource::ResetStateForTesting() { … }
const gfx::PointF& WaylandEventSource::GetPointerLocation() const { … }
void WaylandEventSource::OnPointerFrameEvent() { … }
void WaylandEventSource::OnPointerAxisSourceEvent(uint32_t axis_source) { … }
void WaylandEventSource::OnPointerAxisStopEvent(uint32_t axis,
base::TimeTicks timestamp) { … }
void WaylandEventSource::OnTouchPressEvent(
WaylandWindow* window,
const gfx::PointF& location,
base::TimeTicks timestamp,
PointerId id,
wl::EventDispatchPolicy dispatch_policy) { … }
void WaylandEventSource::OnTouchReleaseEvent(
base::TimeTicks timestamp,
PointerId id,
wl::EventDispatchPolicy dispatch_policy,
bool is_synthesized) { … }
void WaylandEventSource::OnTouchReleaseInternal(PointerId id) { … }
void WaylandEventSource::SetTargetAndDispatchEvent(Event* event,
EventTarget* target) { … }
void WaylandEventSource::SetTouchTargetAndDispatchTouchEvent(
TouchEvent* event) { … }
void WaylandEventSource::OnTouchMotionEvent(
const gfx::PointF& location,
base::TimeTicks timestamp,
PointerId id,
wl::EventDispatchPolicy dispatch_policy,
bool is_synthesized) { … }
void WaylandEventSource::OnTouchCancelEvent() { … }
void WaylandEventSource::OnTouchFrame() { … }
void WaylandEventSource::OnTouchFocusChanged(WaylandWindow* window) { … }
std::vector<PointerId> WaylandEventSource::GetActiveTouchPointIds() { … }
void WaylandEventSource::OnTouchStylusToolChanged(
PointerId pointer_id,
EventPointerType pointer_type) { … }
void WaylandEventSource::OnTouchStylusForceChanged(PointerId pointer_id,
float force) { … }
void WaylandEventSource::OnTouchStylusTiltChanged(PointerId pointer_id,
const gfx::Vector2dF& tilt) { … }
const WaylandWindow* WaylandEventSource::GetTouchTarget(PointerId id) const { … }
void WaylandEventSource::OnPinchEvent(EventType event_type,
const gfx::Vector2dF& delta,
base::TimeTicks timestamp,
int device_id,
std::optional<float> scale_delta) { … }
void WaylandEventSource::OnHoldEvent(EventType event_type,
uint32_t finger_count,
base::TimeTicks timestamp,
int device_id,
wl::EventDispatchPolicy dispatch_policy) { … }
void WaylandEventSource::SetRelativePointerMotionEnabled(bool enabled) { … }
void WaylandEventSource::OnRelativePointerMotion(const gfx::Vector2dF& delta,
base::TimeTicks timestamp) { … }
bool WaylandEventSource::IsPointerButtonPressed(EventFlags button) const { … }
void WaylandEventSource::ReleasePressedPointerButtons(
WaylandWindow* window,
base::TimeTicks timestamp) { … }
void WaylandEventSource::OnPointerStylusToolChanged(
EventPointerType pointer_type) { … }
void WaylandEventSource::OnPointerStylusForceChanged(float force) { … }
void WaylandEventSource::OnPointerStylusTiltChanged(
const gfx::Vector2dF& tilt) { … }
const WaylandWindow* WaylandEventSource::GetPointerTarget() const { … }
void WaylandEventSource::OnDispatcherListChanged() { … }
void WaylandEventSource::OnWindowRemoved(WaylandWindow* window) { … }
void WaylandEventSource::HandleTouchFocusChange(WaylandWindow* window,
bool focused,
std::optional<PointerId> id) { … }
bool WaylandEventSource::ShouldUnsetTouchFocus(WaylandWindow* win,
PointerId id) { … }
gfx::Vector2dF WaylandEventSource::ComputeFlingVelocity() { … }
std::optional<PointerDetails> WaylandEventSource::AmendStylusData() const { … }
std::optional<PointerDetails> WaylandEventSource::AmendStylusData(
PointerId pointer_id) const { … }
void WaylandEventSource::EnsurePointerScrollData(
const std::optional<base::TimeTicks>& timestamp) { … }
void WaylandEventSource::ProcessPointerScrollData() { … }
}