OpenLayers OpenLayers

Ticket #1108 (closed bug: duplicate)

Opened 1 year ago

Last modified 4 months ago

Modify feature example problems with IE. keyboard handler broken in IE

Reported by: openlayers Assigned to: tcoulter
Priority: major Milestone: 2.7 Release
Component: Handler.Keyboard Version: 2.6 RC2
Keywords: Cc: pedrosimonetti@gmail.com
State:

Description (Last modified by euzuro)

In Modify-feature example is not possible to delete a node with IE. According to my investigations in IE keyboard handler is broken and no event is fired on supported types of events (keypress, keydown and keyup).

I found that changing "window" with "document" in the following lines of keyboard.js works with IE6 and Firefox, I don't know if it is correct with other browers types

In noticed also that in IE delete key do not fire keypress event, probably it will be better to use keydown event, tacking into account that in this case we will have a different code (68 for "d" instead of 100). Could be a better solution to use prototype to handle this?

I found that the suggested modifications resolve ticket #864 if we use keydown event instead of keypress (a stated http://www.quirksmode.org/js/keys.html keypress event does not fire in ie for arrow key buttons.

activate: function() {
        if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
            for (var i = 0; i < this.KEY_EVENTS.length; i++) {
                OpenLayers.Event.observe(
                    '''window''', this.KEY_EVENTS[i], this.eventListener);
            }
            return true;
        } else {
            return false;
        }
    }

    deactivate: function() {
        var deactivated = false;
        if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
            for (var i = 0; i < this.KEY_EVENTS.length; i++) {
                OpenLayers.Event.stopObserving(
                    '''window''', this.KEY_EVENTS[i], this.eventListener);
            }
            deactivated = true;
        }
        return deactivated;
    }

Attachments

keyboardDefaultsFix.patch (1.9 kB) - added by openlayers on 04/10/08 12:17:18.

Change History

02/29/08 09:26:10 changed by openlayers

  • state changed.

As the ticket suggests changing "window" to "document" is a step in this process, but there is a bit more involved to get it to work. The following code may not be ideal, but it has gotten around the issue so that my non-firefox users can successfully delete individual points from a polygon.

Handler/Keyboard.js

/**

  • Method: handleKeyEvent */

handleKeyEvent: function (evt) {

if (!evt.charCode) {

evt.charCode = 0;

}

// Non-Firefox Browser Hack for "d" key if ((!evt.charCode) && (evt.keyCode == 68)

&& evt.type == 'keydown' && navigator.appVersion.match(/Konqueror|Safari|KHTML|MSIE/)) { evt.keyCode = 0; evt.charCode = 100;

}

if (this.checkModifiers(evt)) {

// Non-Firefox browsers (Internet Explodinator, Safari, Opera) do not support keypress events if (evt.type == 'keydown'

&& navigator.appVersion.match(/Konqueror|Safari|KHTML|MSIE/)) {

this.callback('keypress', [evt.charCode evt.keyCode]);

} else {

this.callback(evt.type, [evt.charCode evt.keyCode]);

}

}

},

04/10/08 12:17:18 changed by openlayers

  • attachment keyboardDefaultsFix.patch added.

04/10/08 12:20:01 changed by openlayers

  • version changed from 2.5 to 2.6 RC2.

Dear Developers,

I'm doing some investigation about the OL's KeyboardDefaults Control. I've notice that this control isn't working in both IE and Opera, as it was stated here in this thread and in another one: http://www.nabble.com/Opera-and-KeyboardDefaults-tt12141147.html#a12141147

I've checked the tickets for this issue: http://trac.openlayers.org/ticket/864 http://trac.openlayers.org/ticket/1108

There, someone suggest altering the "window" to "document", in two places in the "KeyboardDefaults.js" file. And there was a comment suggesting to change the event handled to "onkeypress" to "onkeydown", considering the problems with "onkeypress" events in IE, as PPK demonstrates at: http://www.quirksmode.org/js/keys.html

I've tested changing from "window" to "document", as the ticket suggets. And I've changed also the "onkeypress" event to "onkeydown" in "Handler/Keyboard.js" file.

This makes IE and Opera catch the keyboard events, but there's another problem. It seems IE catch the "onkeydown" event twice with the "+" and "-" keys used to zoom (I'm using IE6). And there's another problem with Opera. In Opera, the "+" and "-" keys are used to increase the zoom of the page (it changes both font and image sizes). So, pressing the "+" and "-" keys to zoom in a map will also zoom the intire document.

I've noted that changing the event to "onkeyup" seems to fix the problem in IE. But the Opera still has the problem with the "+" and "-" keys. I think the solution will be canceling the event propagation. Does the OL has any function to cancel event propagations? I don't know if Prototype has this feature.

There's a cross-browser solution from Dean Edwards: http://dean.edwards.name/weblog/2005/10/add-event2/

Anyway, I'm seding the patch for the modification of "Control/KeyboardDefaults.js" and "Handler/Keyboard.js" if there's anyone interested in investigate this issue. The patch were created over 2.6-RC2's root.

regards,

Pedro Simonetti.

05/02/08 14:20:07 changed by pedrosimonetti

  • cc set to pedrosimonetti@gmail.com.

I've created a patch based in the considerations of the author of this ticket.

Now I've created a trac account, so I'm posting here to get involved with the development of this feature.

07/04/08 03:05:15 changed by euzuro

  • description changed.

07/04/08 03:05:55 changed by euzuro

  • milestone set to 2.7 Release.

07/28/08 12:24:47 changed by crschmidt

  • owner set to tcoulter.
  • priority changed from minor to major.

07/28/08 13:44:19 changed by pedrosimonetti

Hi Developers,

I'm still tracking the changes on this ticket, and I'm available to help.

07/31/08 13:13:50 changed by crschmidt

  • status changed from new to closed.
  • resolution set to duplicate.

Pedro,

I've worked out that the reason for the double event in IE is simply due to prototype code that we were still using. I'm changing the Keyboard Handler to drop the 'keypress' event registration, registering only keydown/keyup, and this seems to fix the issue.

THank you for your great work on this: I'm going to integrate this into the #1292 patch, and close this ticket as a duplicate of that, since that ticket will entirely subsume this work.

thanks again for your help!

07/31/08 13:45:16 changed by crschmidt

(In [7644]) * Fixes to the Keyboard Handler to make it work better --

  • drop keypress event (not used, registers as keydown in IE< which results in double events)
return evt instead of evt.keyCode evt.charCode, so apps can do

whatever they like best

  • adjust ModifyFeature to new API
  • Adjust KeyboardDefaults to new API, and include a new set of keyCodes

in switch statement to catch more cases

  • Include keyboard defaults test in list-tests.

Patch from tcoulter, work from Pedro Simonetti (See #1108), Paul Spencer, myself. r=pagameba,me (Closes #1292)