Browse Source

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
tags/7.3.0.rc1
Anthony Guerreiro 10 years ago
parent
commit
6f468c8441
1 changed files with 49 additions and 8 deletions
  1. 49
    8
      client/src/com/vaadin/client/ui/VTextField.java

+ 49
- 8
client/src/com/vaadin/client/ui/VTextField.java View File

@@ -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) {

Loading…
Cancel
Save