]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #1412
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 6 May 2008 11:47:49 +0000 (11:47 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 6 May 2008 11:47:49 +0000 (11:47 +0000)
svn changeset:4345/svn branch:trunk

src/com/itmill/toolkit/demo/KeyboardShortcut.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java

index 3dd157ea8c9f1e03e041750b465c541b2ffb8bad..0c13f4d6c38f66864815def9d4126c61f4006bc0 100644 (file)
@@ -35,9 +35,8 @@ public class KeyboardShortcut extends Application implements Handler {
                     + "applications. (see our article on <a href=\"http://www.itmill"
                     + ".com/articles/Keybindings_in_Web_Browsers.htm\">"
                     + "www.itmill.com)</a></p>"
-                    + "Events are attached to Window in this application, so a "
-                    + "component inside window must be focused to fire event on"
-                    + " keyboard shortcut.</p>"
+                    + "<p>Focus must be inside web application (eg. not in address "
+                    + "bar) for shortcuts to work. By default app element is focused.</p>"
                     + "<strong>Shortcuts used in this example:</strong> "
                     + "<br/>ESC restarts program, ctrl-shift-a (Button A), "
                     + "ctrl-shift-z (Button Z), ctrl-shift-x (Button X)",
@@ -104,7 +103,6 @@ public class KeyboardShortcut extends Application implements Handler {
 
         w.addActionHandler(this);
 
-        f.focus();
     }
 
     public Action[] getActions(Object target, Object sender) {
index fe849a6bb28c42a3526be9c1b9d849b43571faa7..128c9160cfab2385c76f20945d67d44d70c00e2e 100644 (file)
@@ -8,6 +8,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 
 import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.Window;
@@ -55,13 +56,30 @@ public class IView extends SimplePanel implements Paintable,
     public IView(String elementId) {
         super();
         setStyleName(CLASSNAME);
+
         DOM.sinkEvents(getElement(), Event.ONKEYDOWN);
 
+        DOM.setElementPropertyInt(getElement(), "tabIndex", 0);
+
         RootPanel.get(elementId).add(this);
 
         Window.addWindowResizeListener(this);
+
+        // set focus to iview element by default to listen possible keyboard
+        // shortcuts
+        focus(getElement());
+
     }
 
+    private static native void focus(Element el)
+    /*-{
+        try {
+            el.focus();
+        } catch (e) {
+        
+        }
+    }-*/;
+
     public String getTheme() {
         return theme;
     }