Skip to content

avm2: Implement flash.ui.Mouse.cursor - #24150

Open
falpi wants to merge 1 commit into
ruffle-rs:masterfrom
falpi:add-mouse-cursor-property
Open

avm2: Implement flash.ui.Mouse.cursor#24150
falpi wants to merge 1 commit into
ruffle-rs:masterfrom
falpi:add-mouse-cursor-property

Conversation

@falpi

@falpi falpi commented Jul 7, 2026

Copy link
Copy Markdown

Summary

flash.ui.Mouse was missing the cursor property entirely, so assignments to
Mouse.cursor had no effect. The Text Layout Framework sets
Mouse.cursor = MouseCursor.IBEAM when the pointer moves over editable text, so
Spark TextInput / TextArea (and any TLF-based content) never displayed the
I-beam cursor — the pointer stayed an arrow.

This implements flash.ui.Mouse.cursor (getter and setter), letting content
force a specific cursor and matching Flash Player.

Root cause

flash.ui.Mouse only exposed hide/show/supportsCursor/registerCursor.
There was no cursor property, so:

  • Mouse.cursor = MouseCursor.IBEAM (used by flashx.textLayout.edit.SelectionManager.setMouseCursor) was a no-op / illegal write, and
  • reading Mouse.cursor was unsupported.

Ruffle already picks a cursor automatically from the object under the pointer
(arrow, button, I-beam over a TextField, …), but nothing let ActionScript
force one.

Reproduction

Minimal AS3: a grey rectangle that requests the I-beam while hovered. Without
this patch the cursor stays an arrow (and the assignment does not take effect);
with it, the pointer becomes an I-beam over the rectangle.

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.ui.MouseCursor;

var box:Sprite = new Sprite();
box.graphics.beginFill(0xCCCCCC);
box.graphics.drawRect(0, 0, 200, 100);
addChild(box);

box.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent):void {
    Mouse.cursor = MouseCursor.IBEAM;
});
box.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent):void {
    Mouse.cursor = MouseCursor.AUTO;
});

The same path is exercised implicitly by any Flex Spark editable text control.

Fix

  • Add a forced_cursor: Option<MouseCursor> field to the persistent MouseData.
  • The native Mouse.cursor setter stores it; the getter reads it back.
    MouseCursor.AUTO maps to None — the automatic per-object cursor is kept —
    and any other value overrides that choice. Invalid strings throw
    ArgumentError avm1: Color.setTransform/setRGB sets transformed-by-script flag (fix #1906) #2008, as in Flash Player.
  • In the player's cursor update, a non-None forced_cursor replaces the
    automatically-computed cursor before it is applied.

The AS3 constant ↔ internal enum mapping: AUTO→None, ARROW→Arrow,
BUTTON→Hand, IBEAM→IBeam, HAND→Grab.

Notes

  • The forced cursor takes effect on the next mouse activity (the cursor is
    recomputed while processing pointer events); TLF sets it during
    rollOver/mouseMove, so it applies immediately in practice.
  • Automatic cursor selection (e.g. the hand over buttons) is unchanged when
    Mouse.cursor is left at its default "auto".

Checklist

  • I, a human, have self-reviewed this PR and fully understand the changes within.
  • I have made or updated tests where possible.
  • All of my commits are properly scoped, compile successfully, and pass all tests.
  • This PR does not make sense to split up into smaller PRs.
  • An LLM was involved in the authoring of this code.

@evilpie evilpie added the needs-tests This PR needs regression tests to be added before it can be merged label Jul 7, 2026
@falpi
falpi force-pushed the add-mouse-cursor-property branch from 9fe540d to 3462e65 Compare July 7, 2026 21:01
flash.ui.Mouse had no `cursor` property, so assignments to it were lost.
The Text Layout Framework sets `Mouse.cursor = MouseCursor.IBEAM` when the
pointer enters editable text, so Spark TextInput/TextArea (and any TLF
content) never showed the I-beam cursor.

Add the native `cursor` getter/setter, backed by a `forced_cursor` field on
MouseData. `MouseCursor.AUTO` maps to `None` (the cursor is still chosen
automatically from the object under the pointer); any other value overrides
that automatic choice in the player's cursor update. Invalid values throw
ArgumentError ruffle-rs#2008, matching Flash Player.
@falpi
falpi force-pushed the add-mouse-cursor-property branch from 3462e65 to 02d39d6 Compare July 7, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-tests This PR needs regression tests to be added before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants