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;
/**
DOM.appendChild(root, down);
DOM.appendChild(root, status);
DOM.setElementProperty(status, "className", CLASSNAME + "-status");
-
+ DOM.sinkEvents(root, Event.ONMOUSEDOWN);
addCloseHandler(this);
}
*/
@Override
public void onBrowserEvent(Event event) {
- final Element target = DOM.eventGetTarget(event);
- if (DOM.compare(target, up)
- || DOM.compare(target, DOM.getChild(up, 0))) {
- filterOptions(currentPage - 1, lastFilter);
- } else if (DOM.compare(target, down)
- || DOM.compare(target, DOM.getChild(down, 0))) {
- filterOptions(currentPage + 1, lastFilter);
+ if (event.getTypeInt() == Event.ONCLICK) {
+ final Element target = DOM.eventGetTarget(event);
+ if (target == up || target == DOM.getChild(up, 0)) {
+ filterOptions(currentPage - 1, lastFilter);
+ } else if (target == down || target == DOM.getChild(down, 0)) {
+ filterOptions(currentPage + 1, lastFilter);
+ }
}
- tb.setFocus(true);
+
+ /*
+ * Prevent the keyboard focus from leaving the textfield by
+ * preventing the default behaviour of the browser. Fixes #4285.
+ */
+ handleMouseDownEvent(event);
}
/**
left = getPopupLeft();
}
setPopupPosition(left, top);
-
}
/**
* Used when measuring the width of the popup
*/
private final HTML popupOpener = new HTML("") {
+
/*
* (non-Javadoc)
*
if (client != null) {
client.handleTooltipEvent(event, VFilterSelect.this);
}
+
+ /*
+ * Prevent the keyboard focus from leaving the textfield by
+ * preventing the default behaviour of the browser. Fixes #4285.
+ */
+ handleMouseDownEvent(event);
}
};
});
tb.sinkEvents(VTooltip.TOOLTIP_EVENTS);
- popupOpener.sinkEvents(VTooltip.TOOLTIP_EVENTS);
+ popupOpener.sinkEvents(VTooltip.TOOLTIP_EVENTS | Event.ONMOUSEDOWN);
panel.add(tb);
panel.add(popupOpener);
initWidget(panel);
updateRootWidth();
}
+ // Focus dependent style names are lost during the update, so we add
+ // them here back again
+ if (focused) {
+ addStyleDependentName("focus");
+ }
+
initDone = true;
}
prompting = true;
}
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
- tb.setFocus(true);
+ focus();
tb.selectAll();
-
}
}
return w;
}-*/;
+ /**
+ * A flag which prevents a focus event from taking place
+ */
+ boolean iePreventNextFocus = false;
+
/*
* (non-Javadoc)
*
* .dom.client.FocusEvent)
*/
public void onFocus(FocusEvent event) {
+
+ /*
+ * When we disable a blur event in ie we need to refocus the textfield.
+ * This will cause a focus event we do not want to process, so in that
+ * case we just ignore it.
+ */
+ if (BrowserInfo.get().isIE() && iePreventNextFocus) {
+ iePreventNextFocus = false;
+ return;
+ }
+
focused = true;
if (prompting && !readonly) {
setPromptingOff("");
}
}
+ /**
+ * A flag which cancels the blur event and sets the focus back to the
+ * textfield if the Browser is IE
+ */
+ boolean preventNextBlurEventInIE = false;
+
/*
* (non-Javadoc)
*
* com.google.gwt.event.dom.client.BlurHandler#onBlur(com.google.gwt.event
* .dom.client.BlurEvent)
*/
+
public void onBlur(BlurEvent event) {
+
+ if (BrowserInfo.get().isIE() && preventNextBlurEventInIE) {
+ /*
+ * Clicking in the suggestion popup or on the popup button in IE
+ * causes a blur event to be sent for the field. In other browsers
+ * this is prevented by canceling/preventing default behavior for
+ * the focus event, in IE we handle it here by refocusing the text
+ * field and ignoring the resulting focus event for the textfield
+ * (in onFocus).
+ */
+ preventNextBlurEventInIE = false;
+
+ Element focusedElement = Util.getIEFocusedElement();
+ if (getElement().isOrHasChild(focusedElement)
+ || suggestionPopup.getElement()
+ .isOrHasChild(focusedElement)) {
+
+ // IF the suggestion popup or another part of the VFilterSelect
+ // was focused, move the focus back to the textfield and prevent
+ // the triggered focus event (in onFocus).
+ iePreventNextFocus = true;
+ tb.setFocus(true);
+ return;
+ }
+ }
+
focused = false;
if (!readonly) {
// much of the TAB handling takes place here
}
return componentPadding;
}
+
+ /**
+ * Handles special behavior of the mouse down event
+ *
+ * @param event
+ */
+ private void handleMouseDownEvent(Event event) {
+ /*
+ * Prevent the keyboard focus from leaving the textfield by preventing
+ * the default behaviour of the browser. Fixes #4285.
+ */
+ if (event.getTypeInt() == Event.ONMOUSEDOWN) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ /*
+ * In IE the above wont work, the blur event will still trigger. So,
+ * we set a flag here to prevent the next blur event from happening.
+ * This is not needed if do not already have focus, in that case
+ * there will not be any blur event and we should not cancel the
+ * next blur.
+ */
+ if (BrowserInfo.get().isIE() && focused) {
+ preventNextBlurEventInIE = true;
+ }
+ }
+ }
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>ComboFocusBlurEvents</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ComboFocusBlurEvents</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.combobox.ComboFocusBlurEvents?restartApplication</td>
+ <td></td>
+</tr>
+<!--Testing selecting several items, the focus should stay on the combo and only one focus event should trigger-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[1]</td>
+ <td>9,14</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::Root/VFilterSelect$SuggestionPopup[0]/VFilterSelect$SuggestionMenu[0]#item4</td>
+ <td>142,2</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[1]</td>
+ <td>17,12</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::Root/VFilterSelect$SuggestionPopup[0]/VFilterSelect$SuggestionMenu[0]#item7</td>
+ <td>143,6</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[1]</td>
+ <td>13,9</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::Root/VFilterSelect$SuggestionPopup[0]/VFilterSelect$SuggestionMenu[0]#item3</td>
+ <td>147,11</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[1]</td>
+ <td>16,11</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::Root/VFilterSelect$SuggestionPopup[0]/VFilterSelect$SuggestionMenu[0]#item5</td>
+ <td>146,4</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VLabel[0]</td>
+ <td>exact:0: Focus event!</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>OneFocusEvent</td>
+</tr>
+<!--Test ended.-->
+<!--Testing keyboard navigation-->
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]/domChild[0]</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VLabel[0]</td>
+ <td>exact:0: Focus event!</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>StillOneFocusEvent</td>
+</tr>
+<!--Test ended.-->
+<!--Move focus out with mouse-->
+<tr>
+ <td>focus</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentscomboboxComboFocusBlurEvents::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VLabel[0]</td>
+ <td>0: Focus event!<br />1: Blur event!</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>OneFocusOneBlur</td>
+</tr>
+<!--End test.-->
+
+</tbody></table>
+</body>
+</html>
--- /dev/null
+package com.vaadin.tests.components.combobox;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.event.FieldEvents;
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.FocusEvent;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TextField;
+
+public class ComboFocusBlurEvents extends TestBase {
+
+ private int counter = 0;
+
+ @Override
+ protected void setup() {
+
+ List<String> list = new ArrayList<String>();
+ for (int i = 0; i < 100; i++) {
+ list.add("Item " + i);
+ }
+
+ ComboBox cb = new ComboBox("Combobox", list);
+ cb.setImmediate(true);
+ cb.setInputPrompt("Enter text");
+ cb.setDescription("Some Combobox");
+ addComponent(cb);
+
+ final ObjectProperty<String> log = new ObjectProperty<String>("");
+
+ cb.addListener(new FieldEvents.FocusListener() {
+ public void focus(FocusEvent event) {
+ log.setValue(log.getValue().toString() + "<br>" + counter
+ + ": Focus event!");
+ counter++;
+ }
+ });
+
+ cb.addListener(new FieldEvents.BlurListener() {
+ public void blur(BlurEvent event) {
+ log.setValue(log.getValue().toString() + "<br>" + counter
+ + ": Blur event!");
+ counter++;
+ }
+ });
+
+ TextField field = new TextField("Some textfield");
+ field.setImmediate(true);
+ addComponent(field);
+
+ Label output = new Label(log);
+ output.setCaption("Events:");
+
+ output.setContentMode(Label.CONTENT_XHTML);
+ addComponent(output);
+
+ }
+
+ @Override
+ protected String getDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 6536;
+ }
+
+}