UI/AppKit: Support image cursors

This commit is contained in:
Sam Atkins 2025-02-21 12:47:53 +00:00 committed by Andreas Kling
commit fc4a2eeba8
Notes: github-actions[bot] 2025-02-28 12:51:08 +00:00

View file

@ -450,90 +450,91 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
if (self == nil) { if (self == nil) {
return; return;
} }
if (!cursor.template has<Gfx::StandardCursor>()) { cursor.template visit(
// FIXME: Implement image cursors in AppKit. [](Gfx::ImageCursor const& image_cursor) {
[[NSCursor arrowCursor] set]; auto* cursor_image = Ladybird::gfx_bitmap_to_ns_image(*image_cursor.bitmap.bitmap());
return; auto hotspot = Ladybird::gfx_point_to_ns_point(image_cursor.hotspot);
}
auto standard_cursor = cursor.template get<Gfx::StandardCursor>(); [[[NSCursor alloc] initWithImage:cursor_image hotSpot:hotspot] set];
},
[&self](Gfx::StandardCursor standard_cursor) {
if (standard_cursor == Gfx::StandardCursor::Hidden) {
if (!m_hidden_cursor.has_value()) {
m_hidden_cursor.emplace();
}
if (standard_cursor == Gfx::StandardCursor::Hidden) { return;
if (!m_hidden_cursor.has_value()) { }
m_hidden_cursor.emplace();
}
return; m_hidden_cursor.clear();
}
m_hidden_cursor.clear(); switch (standard_cursor) {
case Gfx::StandardCursor::Arrow:
switch (standard_cursor) { [[NSCursor arrowCursor] set];
case Gfx::StandardCursor::Arrow: break;
[[NSCursor arrowCursor] set]; case Gfx::StandardCursor::Crosshair:
break; [[NSCursor crosshairCursor] set];
case Gfx::StandardCursor::Crosshair: break;
[[NSCursor crosshairCursor] set]; case Gfx::StandardCursor::IBeam:
break; [[NSCursor IBeamCursor] set];
case Gfx::StandardCursor::IBeam: break;
[[NSCursor IBeamCursor] set]; case Gfx::StandardCursor::ResizeHorizontal:
break; [[NSCursor resizeLeftRightCursor] set];
case Gfx::StandardCursor::ResizeHorizontal: break;
[[NSCursor resizeLeftRightCursor] set]; case Gfx::StandardCursor::ResizeVertical:
break; [[NSCursor resizeUpDownCursor] set];
case Gfx::StandardCursor::ResizeVertical: break;
[[NSCursor resizeUpDownCursor] set]; case Gfx::StandardCursor::ResizeDiagonalTLBR:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::ResizeDiagonalTLBR: [[NSCursor arrowCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor arrowCursor] set]; case Gfx::StandardCursor::ResizeDiagonalBLTR:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::ResizeDiagonalBLTR: [[NSCursor arrowCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor arrowCursor] set]; case Gfx::StandardCursor::ResizeColumn:
break; [[NSCursor resizeLeftRightCursor] set];
case Gfx::StandardCursor::ResizeColumn: break;
[[NSCursor resizeLeftRightCursor] set]; case Gfx::StandardCursor::ResizeRow:
break; [[NSCursor resizeUpDownCursor] set];
case Gfx::StandardCursor::ResizeRow: break;
[[NSCursor resizeUpDownCursor] set]; case Gfx::StandardCursor::Hand:
break; [[NSCursor pointingHandCursor] set];
case Gfx::StandardCursor::Hand: break;
[[NSCursor pointingHandCursor] set]; case Gfx::StandardCursor::Help:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::Help: [[NSCursor arrowCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor arrowCursor] set]; case Gfx::StandardCursor::Drag:
break; [[NSCursor closedHandCursor] set];
case Gfx::StandardCursor::Drag: break;
[[NSCursor closedHandCursor] set]; case Gfx::StandardCursor::DragCopy:
break; [[NSCursor dragCopyCursor] set];
case Gfx::StandardCursor::DragCopy: break;
[[NSCursor dragCopyCursor] set]; case Gfx::StandardCursor::Move:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::Move: [[NSCursor dragCopyCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor dragCopyCursor] set]; case Gfx::StandardCursor::Wait:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::Wait: [[NSCursor arrowCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor arrowCursor] set]; case Gfx::StandardCursor::Disallowed:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::Disallowed: [[NSCursor arrowCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor arrowCursor] set]; case Gfx::StandardCursor::Eyedropper:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::Eyedropper: [[NSCursor arrowCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor arrowCursor] set]; case Gfx::StandardCursor::Zoom:
break; // FIXME: AppKit does not have a corresponding cursor, so we should make one.
case Gfx::StandardCursor::Zoom: [[NSCursor arrowCursor] set];
// FIXME: AppKit does not have a corresponding cursor, so we should make one. break;
[[NSCursor arrowCursor] set]; default:
break; break;
default: }
break; });
}
}; };
m_web_view_bridge->on_zoom_level_changed = [weak_self]() { m_web_view_bridge->on_zoom_level_changed = [weak_self]() {