summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Guerreiro <anthony@vaadin.com>2014-07-07 10:57:17 +0300
committerVaadin Code Review <review@vaadin.com>2014-07-11 07:52:14 +0000
commit6f468c84413ac7d25458dfedc3766665c7d9cd32 (patch)
tree4096bfb94cea56306990ee6792bd301bc348f0ed
parent311411905c0c7c281b63ace5269fb2270369fb68 (diff)
downloadvaadin-framework-6f468c84413ac7d25458dfedc3766665c7d9cd32.tar.gz
vaadin-framework-6f468c84413ac7d25458dfedc3766665c7d9cd32.zip
Fix for drag-and-drop text to TextField in Firefox (#14056)
Couldn't created an automated test in selenium - can't get it to drag text. Change-Id: I1a0beab97840401423e3b446015ff0c729bc2ca2
-rw-r--r--client/src/com/vaadin/client/ui/VTextField.java57
1 files changed, 49 insertions, 8 deletions
diff --git a/client/src/com/vaadin/client/ui/VTextField.java b/client/src/com/vaadin/client/ui/VTextField.java
index c517f8fec0..1968c7e0a6 100644
--- a/client/src/com/vaadin/client/ui/VTextField.java
+++ b/client/src/com/vaadin/client/ui/VTextField.java
@@ -16,6 +16,8 @@
package com.vaadin.client.ui;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
@@ -254,6 +256,48 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler,
el.oncut = null;
}-*/;
+ private void onDrop() {
+ if (focusedTextField == this) {
+ return;
+ }
+ updateText(false);
+ }
+
+ private void updateText(boolean blurred) {
+ String text = getText();
+ setPrompting(inputPrompt != null && (text == null || text.isEmpty()));
+ if (prompting) {
+ setText(isReadOnly() ? "" : inputPrompt);
+ if (blurred) {
+ addStyleDependentName(CLASSNAME_PROMPT);
+ }
+ }
+
+ valueChange(blurred);
+ }
+
+ private void scheduleOnDropEvent() {
+ Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+ @Override
+ public void execute() {
+ onDrop();
+ }
+ });
+ }
+
+ private native void attachDropEventListener(Element el)
+ /*-{
+ var me = this;
+ el.ondrop = $entry(function() {
+ me.@com.vaadin.client.ui.VTextField::scheduleOnDropEvent()();
+ });
+ }-*/;
+
+ private native void detachDropEventListener(Element el)
+ /*-{
+ el.ondrop = null;
+ }-*/;
+
@Override
protected void onDetach() {
super.onDetach();
@@ -263,6 +307,7 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler,
}
if (BrowserInfo.get().isFirefox()) {
removeOnInputListener(getElement());
+ detachDropEventListener(getElement());
}
}
@@ -276,6 +321,9 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler,
// Workaround for FF setting input prompt as the value if esc is
// pressed while the field is focused and empty (#8051).
addOnInputListener(getElement());
+ // Workaround for FF updating component's internal value after
+ // having drag-and-dropped text from another element (#14056)
+ attachDropEventListener(getElement());
}
}
@@ -418,14 +466,7 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler,
}
removeStyleDependentName(CLASSNAME_FOCUS);
focusedTextField = null;
- String text = getText();
- setPrompting(inputPrompt != null && (text == null || "".equals(text)));
- if (prompting) {
- setText(isReadOnly() ? "" : inputPrompt);
- addStyleDependentName(CLASSNAME_PROMPT);
- }
-
- valueChange(true);
+ updateText(true);
}
private void setPrompting(boolean prompting) {