summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-03-20 12:24:46 +0000
committerJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-03-20 12:24:46 +0000
commit34ec44230f5b79f860a53a1d10b20a7038646319 (patch)
tree9d2f65a48c4f31b19a98cda1308f00e83ae70781 /src
parent2033fd45c9124ef277e23f9f3a2507a6902e7f70 (diff)
downloadvaadin-framework-34ec44230f5b79f860a53a1d10b20a7038646319.tar.gz
vaadin-framework-34ec44230f5b79f860a53a1d10b20a7038646319.zip
#6085 Allow setting an alternate text for Embedded, for accessibility purposes
svn changeset:23268/svn branch:6.8
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java15
-rw-r--r--src/com/vaadin/ui/Embedded.java33
2 files changed, 46 insertions, 2 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java
index 2c3115c5ed..2783db99d1 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java
@@ -31,6 +31,7 @@ import com.vaadin.terminal.gwt.client.VTooltip;
public class VEmbedded extends HTML implements Paintable {
public static final String CLICK_EVENT_IDENTIFIER = "click";
+ public static final String ALTERNATE_TEXT = "alt";
private static String CLASSNAME = "v-embedded";
@@ -107,6 +108,11 @@ public class VEmbedded extends HTML implements Paintable {
}
DOM.setElementProperty(el, "src", getSrc(uidl, client));
+ if (uidl.hasAttribute(ALTERNATE_TEXT)) {
+ el.setPropertyString(ALTERNATE_TEXT,
+ uidl.getStringAttribute(ALTERNATE_TEXT));
+ }
+
if (created) {
// insert in dom late
getElement().appendChild(el);
@@ -138,7 +144,6 @@ public class VEmbedded extends HTML implements Paintable {
// Handle embedding of Flash
addStyleName(CLASSNAME + "-flash");
setHTML(createFlashEmbed(uidl));
-
} else if (mime.equals("image/svg+xml")) {
addStyleName(CLASSNAME + "-svg");
String data;
@@ -179,7 +184,9 @@ public class VEmbedded extends HTML implements Paintable {
uidl.getStringAttribute("standby"));
}
getElement().appendChild(obj);
-
+ if (uidl.hasAttribute(ALTERNATE_TEXT)) {
+ obj.setInnerText(uidl.getStringAttribute(ALTERNATE_TEXT));
+ }
} else {
VConsole.log("Unknown Embedded mimetype '" + mime + "'");
}
@@ -306,6 +313,10 @@ public class VEmbedded extends HTML implements Paintable {
// End embed tag
html.append("></embed>");
+ if (uidl.hasAttribute(ALTERNATE_TEXT)) {
+ html.append(uidl.getStringAttribute(ALTERNATE_TEXT));
+ }
+
// End object tag
html.append("</object>");
diff --git a/src/com/vaadin/ui/Embedded.java b/src/com/vaadin/ui/Embedded.java
index dc14cc6ef8..181cbbfb96 100644
--- a/src/com/vaadin/ui/Embedded.java
+++ b/src/com/vaadin/ui/Embedded.java
@@ -78,6 +78,8 @@ public class Embedded extends AbstractComponent {
private String archive = null;
+ private String altText;
+
/**
* Creates a new empty Embedded object.
*/
@@ -146,6 +148,9 @@ public class Embedded extends AbstractComponent {
if (archive != null && !"".equals(archive)) {
target.addAttribute("archive", archive);
}
+ if (altText != null && !"".equals(altText)) {
+ target.addAttribute(VEmbedded.ALTERNATE_TEXT, altText);
+ }
// Params
for (final Iterator<String> i = getParameterNames(); i.hasNext();) {
@@ -158,6 +163,34 @@ public class Embedded extends AbstractComponent {
}
/**
+ * Sets this component's "alt-text", that is, an alternate text that can be
+ * presented instead of this component's normal content, for accessibility
+ * purposes. Does not work when {@link #setType(int)} has been called with
+ * {@link #TYPE_BROWSER}.
+ *
+ * @param altText
+ * A short, human-readable description of this component's
+ * content.
+ * @since 6.8
+ */
+ public void setAlternateText(String altText) {
+ if (altText != this.altText
+ || (altText != null && !altText.equals(this.altText))) {
+ this.altText = altText;
+ requestRepaint();
+ }
+ }
+
+ /**
+ * Gets this component's "alt-text".
+ *
+ * @see #setAlternateText(String)
+ */
+ public String getAlternateText() {
+ return altText;
+ }
+
+ /**
* Sets an object parameter. Parameters are optional information, and they
* are passed to the instantiated object. Parameters are are stored as name
* value pairs. This overrides the previous value assigned to this