#include "ui/ozone/platform/wayland/emulate/wayland_input_emulate.h"
#include <ui-controls-unstable-v1-client-protocol.h>
#include <wayland-client-protocol.h>
#include <cstdint>
#include <string>
#include "base/logging.h"
#include "ui/base/test/ui_controls.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/types/display_constants.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/ozone/platform/wayland/host/shell_toplevel_wrapper.h"
#include "ui/ozone/platform/wayland/host/wayland_popup.h"
#include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.h"
#include "ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h"
#include "ui/ozone/platform/wayland/host/xdg_toplevel_wrapper_impl.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "ui/base/wayland/wayland_display_util.h"
#include "ui/display/manager/managed_display_info.h"
#include "ui/display/test/display_test_util.h"
#endif
namespace {
constexpr uint32_t kMinVersion = …;
}
namespace wl {
WaylandInputEmulate::PendingRequest::PendingRequest(
PendingRequestType request_type,
uint32_t request_id)
: … { … }
WaylandInputEmulate::PendingRequest::~PendingRequest() = default;
WaylandInputEmulate::TestWindow::TestWindow() = default;
WaylandInputEmulate::TestWindow::~TestWindow() = default;
WaylandInputEmulate::WaylandInputEmulate(
base::RepeatingCallback<void(uint32_t)> request_processed)
: … { … }
WaylandInputEmulate::~WaylandInputEmulate() { … }
void WaylandInputEmulate::EmulateKeyboardKey(ui::DomCode dom_code,
int key_state,
int accelerator_state,
uint32_t request_id) { … }
void WaylandInputEmulate::EmulatePointerMotion(
gfx::AcceleratedWidget widget,
const gfx::Point& mouse_surface_location,
const gfx::Point& mouse_screen_location,
uint32_t request_id) { … }
void WaylandInputEmulate::EmulatePointerButton(ui_controls::MouseButton button,
int button_state,
int accelerator_state,
uint32_t request_id) { … }
void WaylandInputEmulate::EmulateTouch(int action,
const gfx::Point& touch_screen_location,
int touch_id,
uint32_t request_id) { … }
#if BUILDFLAG(IS_CHROMEOS)
void WaylandInputEmulate::EmulateUpdateDisplay(const std::string& display_specs,
uint32_t request_id) {
VLOG(1) << "Updating display specs to: " << display_specs;
if (zcr_ui_controls_v1_get_version(ui_controls_) >=
ZCR_UI_CONTROLS_V1_DISPLAY_INFO_LIST_DONE_SINCE_VERSION) {
const std::vector<display::Display>& existing_displays =
display::Screen::GetScreen()->GetAllDisplays();
auto info_list = display::CreateDisplayInfoListFromSpecs(
display_specs, std::vector<display::Display>(), false);
size_t existing_display_index = 0;
for (const auto& pending_display : info_list) {
if (existing_display_index < existing_displays.size()) {
auto id_pair = ui::wayland::ToWaylandDisplayIdPair(
existing_displays[existing_display_index].id());
zcr_ui_controls_v1_set_display_info_id(ui_controls_, id_pair.high,
id_pair.low);
++existing_display_index;
}
zcr_ui_controls_v1_set_display_info_size(
ui_controls_, pending_display.bounds_in_native().width(),
pending_display.bounds_in_native().height());
float device_scale_factor = pending_display.device_scale_factor();
uint32_t scale_factor_value =
*reinterpret_cast<const uint32_t*>(&device_scale_factor);
zcr_ui_controls_v1_set_display_info_device_scale_factor(
ui_controls_, scale_factor_value);
zcr_ui_controls_v1_display_info_done(ui_controls_);
}
zcr_ui_controls_v1_display_info_list_done(ui_controls_, request_id);
auto* wayland_proxy = wl::WaylandProxy::GetInstance();
wayland_proxy->FlushForTesting();
}
}
#endif
#if BUILDFLAG(IS_LINUX)
void WaylandInputEmulate::ForceUseScreenCoordinatesOnce() { … }
#endif
void WaylandInputEmulate::OnWindowConfigured(gfx::AcceleratedWidget widget,
bool is_configured) { … }
void WaylandInputEmulate::OnWindowRoleAssigned(gfx::AcceleratedWidget widget) { … }
void WaylandInputEmulate::OnWindowRemoved(gfx::AcceleratedWidget widget) { … }
void WaylandInputEmulate::OnWindowAdded(gfx::AcceleratedWidget widget) { … }
void WaylandInputEmulate::OnRequestProcessed(void* data,
zcr_ui_controls_v1* ui_controls,
uint32_t id) { … }
void WaylandInputEmulate::OnGlobal(void* data,
wl_registry* registry,
uint32_t name,
const char* interface,
uint32_t version) { … }
void WaylandInputEmulate::OnGlobalRemove(void* data,
wl_registry* registry,
uint32_t name) { … }
void WaylandInputEmulate::OnFrameDone(void* data,
wl_callback* callback,
uint32_t time) { … }
bool WaylandInputEmulate::AnyWindowWaitingForBufferCommit() { … }
void WaylandInputEmulate::DispatchPendingRequests() { … }
}