chromium/ui/views/test/ui_controls_factory_desktop_aura_ozone.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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

namespace ui_controls {

void EnableUIControls() {}

void ResetUIControlsIfEnabled() {}

// An interface to provide Aura implementation of UI control.
// static
bool SendKeyPress(gfx::NativeWindow window,
                  ui::KeyboardCode key,
                  bool control,
                  bool shift,
                  bool alt,
                  bool command) {}

// static
bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
                                ui::KeyboardCode key,
                                bool control,
                                bool shift,
                                bool alt,
                                bool command,
                                base::OnceClosure closure,
                                KeyEventType wait_for) {}

// static
bool SendKeyEvents(gfx::NativeWindow window,
                   ui::KeyboardCode key,
                   int key_event_types,
                   int accelerator_state) {}

// static
bool SendKeyEventsNotifyWhenDone(gfx::NativeWindow window,
                                 ui::KeyboardCode key,
                                 int key_event_types,
                                 base::OnceClosure closure,
                                 int accelerator_state) {}

// static
bool SendMouseMove(int screen_x, int screen_y, gfx::NativeWindow window_hint) {}

// static
bool SendMouseMoveNotifyWhenDone(int screen_x,
                                 int screen_y,
                                 base::OnceClosure task,
                                 gfx::NativeWindow window_hint) {}

// static
bool SendMouseEvents(MouseButton type,
                     int button_state,
                     int accelerator_state,
                     gfx::NativeWindow window_hint) {}

// static
bool SendMouseEventsNotifyWhenDone(MouseButton type,
                                   int button_state,
                                   base::OnceClosure task,
                                   int accelerator_state,
                                   gfx::NativeWindow window_hint) {}

// static
bool SendMouseClick(MouseButton type, gfx::NativeWindow window_hint) {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
// static
bool SendTouchEvents(int action, int id, int x, int y) {
  return SendTouchEventsNotifyWhenDone(action, id, x, y, base::OnceClosure());
}

// static
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;

  // Touch release events might not have coordinates that match any window, so
  // just use whichever window is on top.
  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;
}

// static
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)
// static
void ForceUseScreenCoordinatesOnce() {}
#endif

}  // namespace ui_controls