import com.google.gwt.aria.client.RelevantValue;
import com.google.gwt.aria.client.Roles;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
VErrorMessage em = new VErrorMessage();
Element description = DOM.createDiv();
+ private TooltipInfo currentTooltipInfo = new TooltipInfo(" ");
+
private boolean closing = false;
private boolean opening = false;
*/
public void showAssistive(TooltipInfo info) {
updatePosition(null, true);
- show(info);
+ setTooltipText(info);
+ showTooltip();
}
- /**
- * Show a popup containing the information in the "info" tooltip
- *
- * @param info
- */
- private void show(TooltipInfo info) {
- boolean hasContent = false;
+ private void setTooltipText(TooltipInfo info) {
if (info.getErrorMessage() != null) {
em.setVisible(true);
em.updateMessage(info.getErrorMessage());
- hasContent = true;
} else {
em.setVisible(false);
}
if (info.getTitle() != null && !"".equals(info.getTitle())) {
- DOM.setInnerHTML(description, info.getTitle());
- description.getStyle().clearDisplay();
- hasContent = true;
+ description.setInnerHTML(info.getTitle());
} else {
- DOM.setInnerHTML(description, "");
- description.getStyle().setDisplay(Display.NONE);
+ description.setInnerHTML("");
+ }
+ currentTooltipInfo = info;
+ }
+
+ /**
+ * Show a popup containing the currentTooltipInfo
+ *
+ */
+ private void showTooltip() {
+ boolean hasContent = false;
+ if (currentTooltipInfo.getErrorMessage() != null
+ || (currentTooltipInfo.getTitle() != null && !""
+ .equals(currentTooltipInfo.getTitle()))) {
+ hasContent = true;
}
if (hasContent) {
// Issue #8454: With IE7 the tooltips size is calculated based on
y = Window.getScrollTop();
}
}
-
setPopupPosition(x, y);
sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT);
}
}
}
- private void showTooltip() {
-
- // Close current tooltip
- if (isShowing()) {
- closeNow();
- }
-
- // Schedule timer for showing the tooltip according to if it was
- // recently closed or not.
- int timeout = justClosed ? getQuickOpenDelay() : getOpenDelay();
- showTimer.schedule(timeout);
- opening = true;
+ /**
+ * For assistive tooltips to work correctly we must have the tooltip visible
+ * and attached to the DOM well in advance.
+ *
+ * @return
+ */
+ public boolean isActuallyVisible() {
+ return super.isShowing() && getPopupLeft() > 0 && getPopupTop() > 0;
}
private void closeNow() {
private Timer showTimer = new Timer() {
@Override
public void run() {
- TooltipInfo info = tooltipEventHandler.getTooltipInfo();
- if (null != info) {
- show(info);
- }
opening = false;
+ showTooltip();
}
};
@Override
public void run() {
closeNow();
- justClosedTimer.schedule(2000);
+ justClosedTimer.schedule(getQuickOpenTimeout());
justClosed = true;
}
};
}
closeTimer.schedule(getCloseTimeout());
closing = true;
- justClosed = true;
- justClosedTimer.schedule(getQuickOpenTimeout());
}
@Override
private int tooltipEventMouseY;
public void updatePosition(Event event, boolean isFocused) {
- if (isFocused) {
- tooltipEventMouseX = -1000;
- tooltipEventMouseY = -1000;
- } else {
- tooltipEventMouseX = DOM.eventGetClientX(event);
- tooltipEventMouseY = DOM.eventGetClientY(event);
- }
+ tooltipEventMouseX = getEventX(event, isFocused);
+ tooltipEventMouseY = getEventY(event, isFocused);
+ }
+
+ private int getEventX(Event event, boolean isFocused) {
+ return isFocused ? -5000 : DOM.eventGetClientX(event);
+ }
+
+ private int getEventY(Event event, boolean isFocused) {
+ return isFocused ? -5000 : DOM.eventGetClientY(event);
}
@Override
closeNow();
}
- TooltipInfo info = tooltipEventHandler.getTooltipInfo();
- if (null != info) {
- show(info);
- }
+ showTooltip();
opening = false;
}
private boolean handledByFocus;
/**
- * Current tooltip active
- */
- private TooltipInfo currentTooltipInfo = null;
-
- /**
- * Get current active tooltip information
- *
- * @return Current active tooltip information or null
- */
- public TooltipInfo getTooltipInfo() {
- return currentTooltipInfo;
- }
-
- /**
- * Locate connector and it's tooltip for given element
+ * Locate the tooltip for given element
*
* @param element
* Element used in search
- * @return true if connector and tooltip found
+ * @return TooltipInfo if connector and tooltip found, null if not
*/
- private boolean resolveConnector(Element element) {
+ private TooltipInfo getTooltipFor(Element element) {
ApplicationConnection ac = getApplicationConnection();
ComponentConnector connector = Util.getConnectorForElement(ac,
assert connector.hasTooltip() : "getTooltipInfo for "
+ Util.getConnectorString(connector)
+ " returned a tooltip even though hasTooltip claims there are no tooltips for the connector.";
- currentTooltipInfo = info;
- return true;
+ return info;
+
}
- return false;
+ return null;
}
/**
*/
private void handleHideEvent() {
hideTooltip();
- currentTooltipInfo = null;
}
@Override
return;
}
- boolean connectorAndTooltipFound = resolveConnector(element);
- if (!connectorAndTooltipFound) {
- if (isShowing()) {
+ TooltipInfo info = getTooltipFor(element);
+ if (info == null) {
+ if (isActuallyVisible()) {
handleHideEvent();
- } else {
- currentTooltipInfo = null;
}
} else {
+ setTooltipText(info);
updatePosition(event, isFocused);
-
- if (isShowing() && !isFocused) {
- replaceCurrentTooltip();
- } else {
+ if (isActuallyVisible() && !isFocused) {
showTooltip();
+ } else {
+ if (isActuallyVisible()) {
+ closeNow();
+ }
+ // Schedule timer for showing the tooltip according to if it
+ // was
+ // recently closed or not.
+ int timeout = justClosed ? getQuickOpenDelay()
+ : getOpenDelay();
+ if (timeout == 0) {
+ showTooltip();
+ } else {
+ showTimer.schedule(timeout);
+ opening = true;
+ }
}
}
handledByFocus = isFocused;
currentElement = element;
}
+
}
private final TooltipEventHandler tooltipEventHandler = new TooltipEventHandler();
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+
+/**
+ * Test to see if tooltip delay is working properly.
+ *
+ * @author Vaadin Ltd
+ */
+public class TooltipDelay extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest vaadinRequest) {
+
+ Button button = new Button("Expand");
+ button.setDescription("Expand");
+ addComponent(button);
+
+ getTooltipConfiguration().setOpenDelay(5000);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
+ */
+ @Override
+ protected String getTestDescription() {
+ return "Tooltips should appear with a five second delay.";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
+ */
+ @Override
+ protected Integer getTicketNumber() {
+ return 13695;
+ }
+
+}
\ No newline at end of file