OMSVGSVGElement.addDomHandler(handler, MouseWheelEvent.getType()); won't work

101 views
Skip to first unread message

arno....@gmail.com

unread,
Mar 14, 2013, 7:39:06 PM3/14/13
to lib-g...@googlegroups.com
Hello.

Why is it not possible to add a MouseWheelHandler to my SVGSVGElement?

OMSVGSVGElement.addDomHandler(handler, com.google.gwt.event.dom.client.MouseWheelEvent.getType());

- Won't work?
- Is it possible?
- Have anyone an example?

Regards!

Lukas Laag

unread,
Mar 15, 2013, 5:04:30 AM3/15/13
to lib-g...@googlegroups.com
Hi,

It would be theoretically possible, however, given the present support
for this event in current browsers, it would not be very useful (ie:
browsers either do not support the event because it has not been
standardized, or do not fire it for svg elements).
See:
http://developer.mozilla.org/en-US/docs/DOM/DOM_event_reference/mousewheel
http://www.quirksmode.org/dom/events/scroll.html
If you absolutely need this feature, your best bet is to wrap your
root svg element in a div and add handlers on this div. If you do that
you can 'emulate' the behavior but it will be only on webkit based
browsers (no FF, no IE)

Lukas
> --
> You received this message because you are subscribed to the Google Groups
> "lib-gwt-svg" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to lib-gwt-svg...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

arno....@gmail.com

unread,
Mar 15, 2013, 11:38:37 AM3/15/13
to lib-g...@googlegroups.com
Thank you Lukas, for your fast answer (and your SVG-Framework).


> "It would be theoretically possible,"
and practically too! :)

For Chrome i use addDomHandler (works fine with libgwt-svg).
For IE i install malicious code on cliendsite. ;)
For FF i use JSNI:
  
    public native void addNativeMouseWheelListener(
            GWTDialogueMapZoomHandler handler) /*-{

        function onMouseWheel(e) {

            if ($wnd.event || $wnd.Event) {
                if (!e)
                    e = $wnd.event;
                   
                var x = e.clientX;
                var y = e.clientY;
                var delta = e.detail * (-1);
               
                // For bug fixing only:   
                // alert("x: " + x + " y: " + y + " delta: " + delta);
                   
                handler.@example.your.project.and.class.name::onMouseWheel(IID)(x, y, delta);
            }

        }
        var svg=$doc.getElementById("DialogueMap");
        svg.addEventListener("DOMMouseScroll", onMouseWheel, false);
    }-*/;


Regards!

[1] https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI?hl=de
Reply all
Reply to author
Forward
0 new messages