#include <memory>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/aura_test_utils.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/test/ui_controls.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ozone_ui_controls_test_helper.h"
#include "ui/views/test/test_desktop_screen_ozone.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h"
namespace {
ui::OzoneUIControlsTestHelper* g_ozone_ui_controls_test_helper = …;
DOWN;
LEFT;
MIDDLE;
MouseButton;
RIGHT;
UP;
aura::Window* RootWindowForPoint(const gfx::Point& point,
aura::Window* window_hint = nullptr) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
aura::Window* TopRootWindow() {
std::vector<aura::Window*> windows =
views::DesktopWindowTreeHostPlatform::GetAllOpenWindows();
DCHECK(!windows.empty());
return windows[0]->GetRootWindow();
}
#endif
}
namespace ui_controls {
void EnableUIControls() { … }
void ResetUIControlsIfEnabled() { … }
bool SendKeyPress(gfx::NativeWindow window,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
bool command) { … }
bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
bool command,
base::OnceClosure closure,
KeyEventType wait_for) { … }
bool SendKeyEvents(gfx::NativeWindow window,
ui::KeyboardCode key,
int key_event_types,
int accelerator_state) { … }
bool SendKeyEventsNotifyWhenDone(gfx::NativeWindow window,
ui::KeyboardCode key,
int key_event_types,
base::OnceClosure closure,
int accelerator_state) { … }
bool SendMouseMove(int screen_x, int screen_y, gfx::NativeWindow window_hint) { … }
bool SendMouseMoveNotifyWhenDone(int screen_x,
int screen_y,
base::OnceClosure task,
gfx::NativeWindow window_hint) { … }
bool SendMouseEvents(MouseButton type,
int button_state,
int accelerator_state,
gfx::NativeWindow window_hint) { … }
bool SendMouseEventsNotifyWhenDone(MouseButton type,
int button_state,
base::OnceClosure task,
int accelerator_state,
gfx::NativeWindow window_hint) { … }
bool SendMouseClick(MouseButton type, gfx::NativeWindow window_hint) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool SendTouchEvents(int action, int id, int x, int y) {
return SendTouchEventsNotifyWhenDone(action, id, x, y, base::OnceClosure());
}
bool SendTouchEventsNotifyWhenDone(int action,
int id,
int x,
int y,
base::OnceClosure task) {
DCHECK(g_ozone_ui_controls_test_helper);
gfx::Point screen_location(x, y);
aura::Window* root_window;
if (action & ui_controls::kTouchRelease) {
root_window = TopRootWindow();
} else {
root_window = RootWindowForPoint(screen_location);
}
if (root_window == nullptr) {
return true;
}
g_ozone_ui_controls_test_helper->SendTouchEvent(
root_window->GetHost()->GetAcceleratedWidget(), action, id,
screen_location, std::move(task));
return true;
}
void UpdateDisplaySync(const std::string& display_specs) {
DCHECK(g_ozone_ui_controls_test_helper);
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
g_ozone_ui_controls_test_helper->UpdateDisplay(display_specs,
run_loop.QuitClosure());
run_loop.Run();
}
#endif
#if BUILDFLAG(IS_LINUX)
void ForceUseScreenCoordinatesOnce() { … }
#endif
}