chromium/ui/views/interaction/interaction_test_util_mouse.cc

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

#include "ui/views/interaction/interaction_test_util_mouse.h"

#include <memory>
#include <utility>
#include <variant>

#include "base/auto_reset.h"
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "ui/base/test/ui_controls.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/widget/widget.h"

#if defined(USE_AURA)
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/drag_drop_client_observer.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#endif  // defined(USE_AURA)

// Currently, touch is only supported on ChromeOS Ash.
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define TOUCH_INPUT_SUPPORTED
#else
#define TOUCH_INPUT_SUPPORTED
#endif

namespace views::test {

namespace {
raw_ptr<InteractionTestUtilMouse> g_current_mouse_util =;

void PostTask(base::OnceClosure task) {}

#if TOUCH_INPUT_SUPPORTED

ui_controls::TouchType GetTouchAction(ui_controls::MouseButtonState state) {
  switch (state) {
    case ui_controls::DOWN:
      return ui_controls::kTouchPress;
    case ui_controls::UP:
      return ui_controls::kTouchRelease;
  }
}

int GetTouchCount(ui_controls::MouseButton button) {
  switch (button) {
    case ui_controls::LEFT:
      return 1;
    case ui_controls::MIDDLE:
      return 3;
    case ui_controls::RIGHT:
      return 2;
  }
}

#endif  // TOUCH_INPUT_SUPPORTED

}  // namespace

#if defined(USE_AURA)

// Ends any drag currently in progress or that starts during this object's
// lifetime. This is needed because the drag controller can get out of sync with
// mouse event handling - especially when running ChromeOS-on-Linux. This can
// result in weird test hangs/timeouts during mouse-up after a drag, or (more
// insidiously) during test shutdown.
//
// Once started, the DragEnder will kill any drags that start until:
//  - Stop() is called.
//  - The Aura window it is watching goes away.
//  - The DragEnder is destroyed (which should happen no earlier than the end of
//    ShutDownOnMainThread()).
class InteractionTestUtilMouse::DragEnder
    : public aura::client::DragDropClientObserver,
      public aura::WindowObserver {};

#endif  // defined(USE_AURA)

InteractionTestUtilMouse::InteractionTestUtilMouse(views::Widget* widget)
    :{}

InteractionTestUtilMouse::~InteractionTestUtilMouse() {}

// static
InteractionTestUtilMouse::MouseGesture InteractionTestUtilMouse::MoveTo(
    gfx::Point point) {}

// static
InteractionTestUtilMouse::MouseGesture InteractionTestUtilMouse::MouseDown(
    ui_controls::MouseButton button) {}

// static
InteractionTestUtilMouse::MouseGesture InteractionTestUtilMouse::MouseUp(
    ui_controls::MouseButton button) {}

// static
InteractionTestUtilMouse::MouseGestures InteractionTestUtilMouse::Click(
    ui_controls::MouseButton button) {}

// static
InteractionTestUtilMouse::MouseGestures InteractionTestUtilMouse::DragAndHold(
    gfx::Point destination) {}

// static
InteractionTestUtilMouse::MouseGestures
InteractionTestUtilMouse::DragAndRelease(gfx::Point destination) {}

bool InteractionTestUtilMouse::ShouldCancelDrag() const {}

void InteractionTestUtilMouse::CancelFutureDrag() {}

void InteractionTestUtilMouse::CancelDragNow() {}

bool InteractionTestUtilMouse::SendButtonPress(
    const MouseButtonGesture& gesture,
    gfx::NativeWindow window_hint,
    bool sync,
    base::OnceClosure on_complete) {}

bool InteractionTestUtilMouse::SendMove(const MouseMoveGesture& gesture,
                                        gfx::NativeWindow window_hint,
                                        bool sync,
                                        base::OnceClosure on_complete) {}

bool InteractionTestUtilMouse::SetTouchMode(bool touch_mode) {}

bool InteractionTestUtilMouse::GetTouchMode() const {}

bool InteractionTestUtilMouse::PerformGesturesImpl(
    MouseGestures gestures,
    gfx::NativeWindow window_hint) {}

void InteractionTestUtilMouse::CancelAllGestures() {}

InteractionTestUtilMouse::InteractionTestUtilMouse(gfx::NativeWindow window)
#if defined(USE_AURA)
    :{}

// static
void InteractionTestUtilMouse::AddGestures(MouseGestures& gestures,
                                           MouseGesture to_add) {}

// static
void InteractionTestUtilMouse::AddGestures(MouseGestures& gestures,
                                           MouseGestures to_add) {}

}  // namespace views::test