W3C home > Mailing lists > Public > public-fx@w3.org > January to March 2013

Re: Transformed Pointer Coordinates?

From: Hans Muller <hmuller@adobe.com>
Date: Wed, 13 Feb 2013 19:31:15 -0800
To: "robert@ocallahan.org" <robert@ocallahan.org>, Jacob Rossi <Jacob.Rossi@microsoft.com>
CC: "Tab Atkins Jr." <jackalmage@gmail.com>, Simon Fraser <smfr@me.com>, Doug Schepers <schepers@w3.org>, "public-pointer-events@w3.org" <public-pointer-events@w3.org>, "public-fx@w3.org" <public-fx@w3.org>, www-style list <www-style@w3.org>
Message-ID: <CD419924.1F4EA%hmuller@adobe.com>

From: Robert O'Callahan <robert@ocallahan.org<mailto:robert@ocallahan.org>>
Reply-To: "robert@ocallahan.org<mailto:robert@ocallahan.org>" <robert@ocallahan.org<mailto:robert@ocallahan.org>>
Date: Monday, February 11, 2013 4:56 PM
To: Jacob Rossi <Jacob.Rossi@microsoft.com<mailto:Jacob.Rossi@microsoft.com>>
Cc: "Tab Atkins Jr." <jackalmage@gmail.com<mailto:jackalmage@gmail.com>>, Simon Fraser <smfr@me.com<mailto:smfr@me.com>>, Doug Schepers <schepers@w3.org<mailto:schepers@w3.org>>, "public-pointer-events@w3.org<mailto:public-pointer-events@w3.org>" <public-pointer-events@w3.org<mailto:public-pointer-events@w3.org>>, "public-fx@w3.org<mailto:public-fx@w3.org>" <public-fx@w3.org<mailto:public-fx@w3.org>>, www-style list <www-style@w3.org<mailto:www-style@w3.org>>
Subject: Re: Transformed Pointer Coordinates?
Resent-From: <public-pointer-events@w3.org<mailto:public-pointer-events@w3.org>>
Resent-Date: Monday, February 11, 2013 4:56 PM

partial interface Node {
  DOMPoint convertPointFromNode(Node from, DOMPoint pt);

'pt' is in CSS pixels relative to the top-left of "from"'s first border-box. Returns a point in CSS pixels relative to the top-left of the destination node's first border-box.

Havng convertPointFromNode() return a border-box  location sounds inconvenient to me, at least in the case of a canvas. Handling canvas pointer events seems like a common use case that should be simple. Returning coordinates relative to the border box means that most canvas-based applications will have to craft conversion code that does something like:

function myCanvasEventLocation(event)
    var style = document.defaultView.getComputedStyle(myCanvas, null);

    function styleValue(property) {
        return parseInt(style.getPropertyValue(property), 10) || 0;

    var borderBoxXY = myCanvas.convertPointFromNode(document, new DOMPoint(event.clientX, event.clientY));
    var canvasX = borderBoxXY.x - myCanvas.clientLeft - styleValue("padding-left");
    var canvasY = borderBoxXY.y - myCanvas.clientTop - styleValue("padding-top");

    return new DOMPoint(canvasX, canvasY);

I think that something simpler, like a PointerEvent method that returned a content-box relative location, would be helpful.

- Hans
Received on Thursday, 14 February 2013 03:31:55 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:49:44 UTC