On 24 mar, 09:40, "nicanor.babula" <[email protected]> wrote:
>
> I don't understand..
> 1) Is there any relationship between FocusListener and
> KeyboardListener? I mean if a widget must have fired first onFocus
> before could receive keyboard events.
Yes, a widget must have the focus (and thus be focusable; which does
not mean it has to *fire* focus events at the GWT level) to receive
keyboard events. That's how it works in browsers (firstly so that
keyboard events are directed to e.g. a single text box at a time ;-) )
and it's unrelated to GWT (i.e. you just cannot change it, you'll have
to live with that).
Eventually, you could use DOM.addEventPreview to get all keyboard
events (including ones that are directed to a text box), but the "add"
in DOM.addEventPreview is misleading as it rather pushes the preview
EventPreviewer on an internal stack and effectively *replaces* it in
previewing events.
> 2) The FocusListener rely totally on onFocus/onBlur DOM events or is
> some custom cross-browser implementation?
I believe it's based only on onfocus and onblur DOM events, but I
might be wrong (have a look at the code if you really want to know).
But in your case (receiving keyboard events), you don't have to play
with FocusListener; the need for having focus to receive keyboard
events is handled at the browser level.
> 3) I have a class declare like this:
>
> public class ResizableDraggablePanel extends AbsolutePanel implements
> SourcesMouseEvents
>
> and the events it sinks are:
> DOM.sinkEvents(getElement(), DOM.getEventsSunk(getElement()) |
> Event.MOUSEEVENTS);
You should use this.sinkEvents(Event.MOUSEEVENTS), which does just
that but is far more readable and less error-prone.
http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/UIObject.html#sinkEvents(int)
> And I have another class that extends the first like this:
> public class Evento extends ResizableDraggablePanel implements
> SourcesKeyboardEvents, HasFocus{
>
> sinking the events like this:
> sinkEvents(DOM.getEventsSunk(getElement()) | Event.MOUSEEVENTS |
> Event.ONDBLCLICK | Event.KEYEVENTS | Event.FOCUSEVENTS);
>
> The problem is that the second class responds to focus/keyboard events
> only in firefox. It could have anything to do with the first class?
No, I think it's a problem with your DOM element not being
"focusable" (in Firefox, Opera and IE it's just a matter of giving it
a tabindex, but in Safari 3 and Chrome 1.0 you have to do a tricky
thing with a hidden text box; it'll be fixed in Safari 4 and Chrome
2.0 though).
If I were you, I'd extend FocusPanel which handles all this for you;
but in your case this means that either Evento doesn't extend
ResizableDraggablePanel (and you'll have to refactor your code within
a helper class and duplicate a bit of code in the two classes) or
ResizableDraggablePanel extends FocusPanel (even if it doesn't need to
handle focus events and be focusable). If you feel plucky, you can
also copy some bits from FocusPanel (the bits that use FocusImpl) to
make your Evento be focusable without having to break inheritance or
make the base class a FocusPanel itself.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---