aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/vaadin/terminal/gwt/client/Util.java35
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTextField.java16
2 files changed, 44 insertions, 7 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java
index e6819efc44..70af13bd4b 100644
--- a/src/com/vaadin/terminal/gwt/client/Util.java
+++ b/src/com/vaadin/terminal/gwt/client/Util.java
@@ -1202,4 +1202,39 @@ public class Util {
return null;
}-*/
;
+
+ /**
+ * Kind of stronger version of isAttached(). In addition to std isAttached,
+ * this method checks that this widget nor any of its parents is hidden. Can
+ * be e.g used to check whether component should react to some events or
+ * not.
+ *
+ * @param widget
+ * @return true if attached and displayed
+ */
+ public static boolean isAttachedAndDisplayed(Widget widget) {
+ if (widget.isAttached()) {
+ /*
+ * Failfast using offset size, then by iterating the widget tree
+ */
+ boolean notZeroSized = widget.getOffsetHeight() > 0
+ || widget.getOffsetWidth() > 0;
+ return notZeroSized || checkVisibilityRecursively(widget);
+ } else {
+ return false;
+ }
+ }
+
+ private static boolean checkVisibilityRecursively(Widget widget) {
+ if (widget.isVisible()) {
+ Widget parent = widget.getParent();
+ if (parent == null) {
+ return true; // root panel
+ } else {
+ return checkVisibilityRecursively(parent);
+ }
+ } else {
+ return false;
+ }
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
index e275d7a9ac..3df2e356d1 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
@@ -24,6 +24,7 @@ import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.VTooltip;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
@@ -419,14 +420,15 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
* @return true iff the value was updated
*/
protected boolean updateCursorPosition() {
- int cursorPos = getCursorPos();
- if (lastCursorPos != cursorPos) {
- client.updateVariable(id, VAR_CURSOR, cursorPos, false);
- lastCursorPos = cursorPos;
- return true;
- } else {
- return false;
+ if (Util.isAttachedAndDisplayed(this)) {
+ int cursorPos = getCursorPos();
+ if (lastCursorPos != cursorPos) {
+ client.updateVariable(id, VAR_CURSOR, cursorPos, false);
+ lastCursorPos = cursorPos;
+ return true;
+ }
}
+ return false;
}
private static VTextField focusedTextField;