---
# System prepended metadata

title: Cursor in Chromium
tags: [Chromium-Graphics, elkurin-daily-note]

---

# Cursor in Chromium
Cursor is a mouse pointer.  
Let's see its representation in Chromium.

## ui::Cursor
[ui::Cursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/cursor.h;l=44;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf) is a representation of cursor.  
It holds [PlatformCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/cursor.h;l=86;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf) as scoped refptr. [PlatformCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/platform_cursor.h;l=24;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf) is a wrapper of platform specific cursor class such as WinCursor or X11Cursor.  
For wayland, there are 2 extended class of PlatformCursor. [BitmapCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/common/bitmap_cursor.h;l=21;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf) and [WaylndAyncCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_async_cursor.h;l=17;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf). WaylandAsyncCursor holds BitmapCursor as its representation.  
The cursor in wayland is created by [WaylandCursorFactory](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_cursor_factory.h;l=54;drc=9a83f678256228495b701428ee57a42f4ca678a3). There are [CreateImageCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_cursor_factory.cc;l=77;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf), [CreateAnimatedCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_cursor_factory.cc;l=105;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf) and [GetDefaultCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_cursor_factory.cc;l=162;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf) which are the methods to create cursor.

These wrappers are used [WaylandCursor](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_cursor.h;l=49;drc=e98d214c48dd94a2b4363b384e952a32258b9487). Let's look at this class later.

## CursorData
[CursorData](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/cursor.h;l=23;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf) is a container of cursor data.  
There are only 3 members here, bitmap, hotspot and scale factor.  
On construction of Cursor, [NewCustom](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/cursor.h;l=48;drc=e77d8705ea2d252a74e0fbd7778e653c010f5c53) is called and it specifies these 3 parameters.

`bitmap` as `std::vector<SkBitmap>` is a cursor image. This is kept as a vector because animated cursors have several images to show one by one.  
[`hotspot`](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/cursor.h;l=36;drc=e77d8705ea2d252a74e0fbd7778e653c010f5c53) is usually a center position of the cursor. It is a representation position kept as gfx::Point.  
[`scale_factor`](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/cursor.h;l=40;drc=e77d8705ea2d252a74e0fbd7778e653c010f5c53) is a scale of the cursor.

## CursorType
The cursor image changes depending on where the cursor is focusing on.  
The different types are listed in [CursorType](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/cursor/mojom/cursor_type.mojom;l=8;drc=2d0a33ccdfa8ac1a9bdf1d86d3b9138f99484bdf).

The images are in [ui/resources](https://source.chromium.org/chromium/chromium/src/+/main:ui/resources/default_100_percent/).  
Here are examples:  
![](https://hackmd.io/_uploads/B1KnxHpza.png)  
![](https://hackmd.io/_uploads/BkU1-rTMa.png)  
![](https://hackmd.io/_uploads/ByE6lBTf6.png)  
![](https://hackmd.io/_uploads/r17Cgr6GT.png)  
![](https://hackmd.io/_uploads/HkfgbSpzp.png)




