summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VPanel.java43
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VView.java14
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VWindow.java9
-rw-r--r--src/com/vaadin/ui/Panel.java39
-rw-r--r--src/com/vaadin/ui/Window.java28
5 files changed, 122 insertions, 11 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
index e0ade0c428..7960a74186 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -19,6 +19,7 @@ import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.Container;
+import com.vaadin.terminal.gwt.client.Focusable;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.RenderInformation;
import com.vaadin.terminal.gwt.client.RenderSpace;
@@ -27,7 +28,7 @@ import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
public class VPanel extends SimplePanel implements Container,
- ShortcutActionHandlerOwner {
+ ShortcutActionHandlerOwner, Focusable {
public static final String CLICK_EVENT_IDENTIFIER = "click";
public static final String CLASSNAME = "v-panel";
@@ -100,7 +101,16 @@ public class VPanel extends SimplePanel implements Container,
bottomDecoration.setClassName(CLASSNAME + "-deco");
getElement().appendChild(captionWrap);
+
+ /*
+ * Make contentNode focusable only by using the setFocus() method. This
+ * behaviour can be changed by invoking setTabIndex() in the serverside
+ * implementation
+ */
+ contentNode.setTabIndex(-1);
+
getElement().appendChild(contentNode);
+
getElement().appendChild(bottomDecoration);
setStyleName(CLASSNAME);
DOM.sinkEvents(getElement(), Event.ONKEYDOWN);
@@ -110,6 +120,30 @@ public class VPanel extends SimplePanel implements Container,
}
+ /**
+ * Sets the keyboard focus on the Panel
+ *
+ * @param focus
+ * Should the panel have focus or not.
+ */
+ public void setFocus(boolean focus) {
+ if (focus) {
+ getContainerElement().focus();
+ } else {
+ getContainerElement().blur();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.terminal.gwt.client.Focusable#focus()
+ */
+ public void focus() {
+ setFocus(true);
+
+ }
+
@Override
protected Element getContainerElement() {
return contentNode;
@@ -229,6 +263,11 @@ public class VPanel extends SimplePanel implements Container,
// scrollTop
runHacks(false);
+ // And apply tab index
+ if (uidl.hasVariable("tabindex")) {
+ contentNode.setTabIndex(uidl.getIntVariable("tabindex"));
+ }
+
rendering = false;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VView.java b/src/com/vaadin/terminal/gwt/client/ui/VView.java
index ea43deba9d..5d7cc18945 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VView.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VView.java
@@ -43,7 +43,7 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan
*
*/
public class VView extends SimplePanel implements Container, ResizeHandler,
- Window.ClosingHandler, ShortcutActionHandlerOwner {
+ Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable {
private static final String CLASSNAME = "v-view";
@@ -110,6 +110,10 @@ public class VView extends SimplePanel implements Container, ResizeHandler,
public VView() {
super();
setStyleName(CLASSNAME);
+
+ // Allow focusing the view by using the focus() method, the view
+ // should not be in the document focus flow
+ getElement().setTabIndex(-1);
}
/**
@@ -691,9 +695,9 @@ public class VView extends SimplePanel implements Container, ResizeHandler,
DOM.setStyleAttribute(fElem, "position", "absolute");
DOM.setStyleAttribute(fElem, "opacity", "0.1");
DOM.appendChild(getElement(), fElem);
- Util.focus(fElem);
+ fElem.focus();
} else {
- Util.focus(getElement());
+ getElement().focus();
}
parentFrame = getParentFrame();
@@ -703,4 +707,8 @@ public class VView extends SimplePanel implements Container, ResizeHandler,
return actionHandler;
}
+ public void focus() {
+ getElement().focus();
+ }
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java
index 68501ae082..c564a59423 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -35,6 +35,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.Focusable;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.RenderSpace;
import com.vaadin.terminal.gwt.client.UIDL;
@@ -50,7 +51,7 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan
*/
public class VWindow extends VOverlay implements Container,
ShortcutActionHandlerOwner, ScrollHandler, KeyDownHandler,
- FocusHandler, BlurHandler, BeforeShortcutActionListener {
+ FocusHandler, BlurHandler, BeforeShortcutActionListener, Focusable {
/**
* Minimum allowed height of a window. This refers to the content area, not
@@ -1295,4 +1296,8 @@ public class VWindow extends VOverlay implements Container,
// blur/focus )
}
+ public void focus() {
+ contentPanel.focus();
+ }
+
}
diff --git a/src/com/vaadin/ui/Panel.java b/src/com/vaadin/ui/Panel.java
index 4d00cddfdd..7ffa11a325 100644
--- a/src/com/vaadin/ui/Panel.java
+++ b/src/com/vaadin/ui/Panel.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -17,6 +17,7 @@ import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Scrollable;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VPanel;
+import com.vaadin.ui.Component.Focusable;
import com.vaadin.ui.themes.Reindeer;
import com.vaadin.ui.themes.Runo;
@@ -32,7 +33,7 @@ import com.vaadin.ui.themes.Runo;
@ClientWidget(VPanel.class)
public class Panel extends AbstractComponentContainer implements Scrollable,
ComponentContainer.ComponentAttachListener,
- ComponentContainer.ComponentDetachListener, Action.Notifier {
+ ComponentContainer.ComponentDetachListener, Action.Notifier, Focusable {
private static final String CLICK_EVENT = VPanel.CLICK_EVENT_IDENTIFIER;
@@ -75,6 +76,13 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
protected ActionManager actionManager;
/**
+ * By default the Panel is not in the normal document focus flow and can
+ * only be focused by using the focus()-method. Change this to 0 if you want
+ * to have the Panel in the normal focus flow.
+ */
+ private int tabIndex = -1;
+
+ /**
* Creates a new empty panel. A VerticalLayout is used as content.
*/
public Panel() {
@@ -234,6 +242,8 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
public void paintContent(PaintTarget target) throws PaintException {
content.paint(target);
+ target.addVariable(this, "tabindex", getTabIndex());
+
if (isScrollable()) {
target.addVariable(this, "scrollLeft", getScrollLeft());
target.addVariable(this, "scrollTop", getScrollTop());
@@ -582,4 +592,29 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
fireEvent(new ClickEvent(this, mouseDetails));
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTabIndex() {
+ return tabIndex;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setTabIndex(int tabIndex) {
+ this.tabIndex = tabIndex;
+ requestRepaint();
+ }
+
+ /**
+ * Moves keyboard focus to the component. {@see Focusable#focus()}
+ *
+ */
+ @Override
+ public void focus() {
+ super.focus();
+ }
+
}
diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java
index b31255cb26..5c2769c756 100644
--- a/src/com/vaadin/ui/Window.java
+++ b/src/com/vaadin/ui/Window.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -1120,6 +1120,10 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
if (parent == null) {
fireClose();
} else {
+
+ // focus is restored to the parent window
+ parent.focus();
+
// subwindow is removed from parent
parent.removeWindow(this);
}
@@ -2089,7 +2093,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
* <code>
* // within the window using helper
* subWindow.setCloseShortcut(KeyCode.ESCAPE, null);
- *
+ *
* // or globally
* getWindow().addAction(new Window.CloseShortcut(subWindow, KeyCode.ESCAPE));
* </code>
@@ -2180,4 +2184,24 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
+ /**
+ * {@inheritDoc}
+ *
+ * If the window is a sub-window focusing will cause the sub-window to be
+ * brought on top of other sub-windows on gain keyboard focus.
+ */
+ @Override
+ public void focus() {
+ if (getParent() != null) {
+ /*
+ * When focusing a sub-window it basically means it should be
+ * brought to the front. Instead of just moving the keyboard focus
+ * we focus the window and bring it top-most.
+ */
+ bringToFront();
+ } else {
+ super.focus();
+ }
+ }
+
}