From: michaelvogt Date: Wed, 20 Mar 2013 16:09:49 +0000 (+0200) Subject: WAI-ARIA button (#11380) X-Git-Tag: 7.1.0.beta1~199 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=833b117b967e3466b37bf95d3f801e927e0e5c45;p=vaadin-framework.git WAI-ARIA button (#11380) Accessibility functions for Button Change-Id: I12ddfd8232d4d35135add1cb4406bfdc20b758f2 --- diff --git a/client/src/com/vaadin/client/ui/VButton.java b/client/src/com/vaadin/client/ui/VButton.java index decfb7c0cc..28a2221380 100644 --- a/client/src/com/vaadin/client/ui/VButton.java +++ b/client/src/com/vaadin/client/ui/VButton.java @@ -16,6 +16,7 @@ package com.vaadin.client.ui; +import com.google.gwt.aria.client.Roles; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; @@ -25,7 +26,6 @@ import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.ui.Accessibility; import com.google.gwt.user.client.ui.FocusWidget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; @@ -103,7 +103,7 @@ public class VButton extends FocusWidget implements ClickHandler { | Event.KEYEVENTS); // Add a11y role "button" - Accessibility.setRole(getElement(), Accessibility.ROLE_BUTTON); + Roles.getButtonRole().set(getElement()); getElement().appendChild(wrapper); wrapper.appendChild(captionElement); @@ -357,14 +357,12 @@ public class VButton extends FocusWidget implements ClickHandler { this.enabled = enabled; if (!enabled) { cleanupCaptureState(); - Accessibility.removeState(getElement(), - Accessibility.STATE_PRESSED); super.setTabIndex(-1); } else { - Accessibility.setState(getElement(), - Accessibility.STATE_PRESSED, "false"); super.setTabIndex(tabIndex); } + + Roles.getButtonRole().setAriaDisabledState(getElement(), !enabled); } } diff --git a/client/src/com/vaadin/client/ui/button/ButtonConnector.java b/client/src/com/vaadin/client/ui/button/ButtonConnector.java index 9733d206c7..fff983c168 100644 --- a/client/src/com/vaadin/client/ui/button/ButtonConnector.java +++ b/client/src/com/vaadin/client/ui/button/ButtonConnector.java @@ -24,6 +24,7 @@ import com.google.gwt.event.dom.client.FocusEvent; import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Element; import com.vaadin.client.EventHelper; import com.vaadin.client.MouseEventDetailsBuilder; import com.vaadin.client.communication.StateChangeEvent; @@ -83,8 +84,10 @@ public class ButtonConnector extends AbstractComponentConnector implements if (getIcon() != null) { if (getWidget().icon == null) { getWidget().icon = new Icon(getConnection()); - getWidget().wrapper.insertBefore( - getWidget().icon.getElement(), + Element iconElement = getWidget().icon.getElement(); + iconElement.setAttribute("alt", getState().iconAltText); + + getWidget().wrapper.insertBefore(iconElement, getWidget().captionElement); } getWidget().icon.setUri(getIcon()); diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java index fcfc55aadc..1bcf802f12 100644 --- a/server/src/com/vaadin/ui/Button.java +++ b/server/src/com/vaadin/ui/Button.java @@ -32,6 +32,7 @@ import com.vaadin.event.ShortcutAction; import com.vaadin.event.ShortcutAction.KeyCode; import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.event.ShortcutListener; +import com.vaadin.server.Resource; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.button.ButtonServerRpc; import com.vaadin.shared.ui.button.ButtonState; @@ -580,6 +581,35 @@ public class Button extends AbstractComponent implements return (ButtonState) super.getState(); } + /** + * Sets the component's icon and alt text. + * + * An alt text is shown when an image could not be loaded, and read by + * assisitve devices. + * + * @param icon + * the icon to be shown with the component's caption. + * @param iconAltText + * String to use as alt text + */ + public void setIcon(Resource icon, String iconAltText) { + super.setIcon(icon); + getState().iconAltText = iconAltText == null ? "" : iconAltText; + } + + /** + * Returns the icon's alt text. + * + * @return String with the alt text + */ + public String getIconAlternateText() { + return getState().iconAltText; + } + + public void setIconAlternateText(String iconAltText) { + getState().iconAltText = iconAltText; + } + /** * Set whether the caption text is rendered as HTML or not. You might need * to retheme button to allow higher content than the original text style. diff --git a/shared/src/com/vaadin/shared/ui/button/ButtonState.java b/shared/src/com/vaadin/shared/ui/button/ButtonState.java index a33a9f78db..7e1fd52ed7 100644 --- a/shared/src/com/vaadin/shared/ui/button/ButtonState.java +++ b/shared/src/com/vaadin/shared/ui/button/ButtonState.java @@ -37,4 +37,5 @@ public class ButtonState extends TabIndexState { * If caption should be rendered in HTML */ public boolean htmlContentAllowed = false; + public String iconAltText = ""; }