chromium/ui/ozone/platform/wayland/host/wayland_cursor_factory.h

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

#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_CURSOR_FACTORY_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_CURSOR_FACTORY_H_

#include <string>
#include <vector>

#include "base/containers/flat_map.h"
#include "base/functional/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/scoped_observation.h"
#include "ui/linux/cursor_theme_manager_observer.h"
#include "ui/ozone/common/bitmap_cursor_factory.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h"
#include "ui/ozone/platform/wayland/host/wayland_async_cursor.h"
#include "ui/ozone/platform/wayland/host/wayland_cursor.h"

struct wl_cursor_theme;

namespace ui {

class BitmapCursor;
class LinuxUi;
class WaylandConnection;

// CursorFactory implementation for Wayland.
//
// This CursorFactory implementation generates WaylandAsyncCursor objects, which
// are wrappers for BitmapCursor that allows cursor images to be asynchronously
// loaded.
//
// During normal operation, and assuming an empty cache, the sequence of
// functions that are called to actually get the cursor image where it needs to
// be goes as follows:
//
// - wl_cursor_theme_load is invoked to load the theme by the IO thread, which
// then invokes...
// - FinishThemeLoad on the UI thread, which invokes ThemeData::SetLoadedTheme,
// which then invokes its registered callbacks, the only one currently being...
// - FinishCursorLoad, which obtains the appropriate cursor image from the
// cursor theme and calls WaylandAsyncCursor::SetLoadedCursor on the cursor
// object that was returned earlier by GetDefaultCursor with the actual
// BitmapCursor.
//
// This will invoke all callbacks registered on the WaylandAsyncCursor object
// using WaylandAsyncCursor::OnCursorLoaded, with the only one currently being
// WaylandWindow::OnCursorLoaded which uses the obtained BitmapCursor object to
// set the cursor image on the window.
class WaylandCursorFactory : public BitmapCursorFactory,
                             public CursorThemeManagerObserver,
                             public WaylandCursorBufferListener {};

}  // namespace ui

#endif  // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_CURSOR_FACTORY_H_