Hit Testing Proposal

The “sub dom” concept can quickly become unwieldy for anyone who has tried to do anything more intricate than a simple Canvas animation. Why? Because associating fallback elements with Canvas interaction is not always an easy task, and it is complicated by screen readers that need to know the exact position of an element on the Canvas so that they can interpret it.

To help solve this issue, the Canvas needs some way to associate sub dom elements with an area on the bitmapped Canvas. The new W3C Canvas Hit Testing proposal outlines why this type of functionality should be added to the Canvas specification:

In the current HTML5 specification, authors are advised to create a fallback DOM under the canvas element to enable screen readers to interact with canvas user interfaces. The size and position of those elements are not defined, which causes problems for accessibility tools—for example, what size/position should they report for these elements?

Because canvas elements usually respond to user input, it seems prudent to solve the hit testing and accessibility issues with the same mechanism.

So what kind of mechanism are they suggesting?

The idea appears to be to create two new methods, setElementPath(element) and clearElementPath(element), that will allow programmers to define (and delete) an area of the Canvas to use as a hit area, provided that it is associated with the fallback DOM element of the Canvas. It appears that you must have an accessible fallback DOM element ...

Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.