2020-10-28 17:30:54 +01:00
|
|
|
// Copyright 2020 The Chromium Embedded Framework Authors. Portions copyright
|
|
|
|
// 2012 The Chromium Authors. All rights reserved. Use of this source code is
|
|
|
|
// governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/native/cursor_util.h"
|
2020-10-28 17:30:54 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_client.h"
|
2020-10-28 17:30:54 +01:00
|
|
|
#include "ui/base/cursor/mojom/cursor_type.mojom.h"
|
|
|
|
|
|
|
|
namespace cursor_util {
|
|
|
|
|
2022-04-15 00:04:40 +02:00
|
|
|
bool OnCursorChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
const ui::Cursor& ui_cursor) {
|
2022-04-08 22:48:56 +02:00
|
|
|
auto client = browser->GetHost()->GetClient();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!client) {
|
2020-10-28 17:30:54 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-10-28 17:30:54 +01:00
|
|
|
auto handler = client->GetDisplayHandler();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!handler) {
|
2020-10-28 17:30:54 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-10-28 17:30:54 +01:00
|
|
|
|
|
|
|
const cef_cursor_type_t cursor_type =
|
|
|
|
static_cast<cef_cursor_type_t>(ui_cursor.type());
|
|
|
|
CefCursorInfo custom_cursor_info;
|
|
|
|
if (ui_cursor.type() == ui::mojom::CursorType::kCustom) {
|
|
|
|
custom_cursor_info.hotspot.x = ui_cursor.custom_hotspot().x();
|
|
|
|
custom_cursor_info.hotspot.y = ui_cursor.custom_hotspot().y();
|
|
|
|
custom_cursor_info.image_scale_factor = ui_cursor.image_scale_factor();
|
|
|
|
custom_cursor_info.buffer = ui_cursor.custom_bitmap().getPixels();
|
|
|
|
custom_cursor_info.size.width = ui_cursor.custom_bitmap().width();
|
|
|
|
custom_cursor_info.size.height = ui_cursor.custom_bitmap().height();
|
|
|
|
}
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
auto scoped_cursor_handle(ScopedCursorHandle::Create(browser, ui_cursor));
|
|
|
|
return handler->OnCursorChange(browser,
|
|
|
|
scoped_cursor_handle->GetCursorHandle(),
|
|
|
|
cursor_type, custom_cursor_info);
|
2020-10-28 17:30:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cursor_util
|