summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMarc Englund <marc@vaadin.com>2013-03-14 14:21:53 +0200
committerMarc Englund <marc@vaadin.com>2013-03-15 07:57:28 +0200
commitf7b9f9f9afe8b09571d05f1790c9fe0c68a363a9 (patch)
tree3c58e63b7df5657fe8075879286c3f9723465230 /client
parent468438fc0ff41c299e2e015f569f96fbd5e09411 (diff)
downloadvaadin-framework-f7b9f9f9afe8b09571d05f1790c9fe0c68a363a9.tar.gz
vaadin-framework-f7b9f9f9afe8b09571d05f1790c9fe0c68a363a9.zip
Audio/Video fixes, for #11160 but it was much more broken. Also quite a few browser differences.
Ticket: 11160 Change-Id: I1ee228e593eab75d96c285bfa26af9939e058d47
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/MediaBaseConnector.java25
-rw-r--r--client/src/com/vaadin/client/ui/VMediaBase.java26
-rw-r--r--client/src/com/vaadin/client/ui/audio/AudioConnector.java48
3 files changed, 73 insertions, 26 deletions
diff --git a/client/src/com/vaadin/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/client/ui/MediaBaseConnector.java
index 6824caff78..8614977be1 100644
--- a/client/src/com/vaadin/client/ui/MediaBaseConnector.java
+++ b/client/src/com/vaadin/client/ui/MediaBaseConnector.java
@@ -46,15 +46,26 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector {
}
@Override
- public void onStateChanged(StateChangeEvent stateChangeEvent) {
- super.onStateChanged(stateChangeEvent);
+ public void onStateChanged(StateChangeEvent event) {
+ super.onStateChanged(event);
- for (int i = 0; i < getState().sources.size(); i++) {
- URLReference source = getState().sources.get(i);
- String sourceType = getState().sourceTypes.get(i);
- getWidget().addSource(source.getURL(), sourceType);
+ final VMediaBase widget = getWidget();
+ final AbstractMediaState state = getState();
+
+ setAltText(state.altText); // must do before loading sources
+ widget.setAutoplay(state.autoplay);
+ widget.setMuted(state.muted);
+ widget.setControls(state.showControls);
+
+ if (event.hasPropertyChanged("sources")) {
+ widget.removeAllSources();
+ for (int i = 0; i < state.sources.size(); i++) {
+ URLReference source = state.sources.get(i);
+ String sourceType = state.sourceTypes.get(i);
+ widget.addSource(source.getURL(), sourceType);
+ }
+ widget.load();
}
- setAltText(getState().altText);
}
@Override
diff --git a/client/src/com/vaadin/client/ui/VMediaBase.java b/client/src/com/vaadin/client/ui/VMediaBase.java
index 8d40775c8d..b77e8bb161 100644
--- a/client/src/com/vaadin/client/ui/VMediaBase.java
+++ b/client/src/com/vaadin/client/ui/VMediaBase.java
@@ -18,12 +18,16 @@ package com.vaadin.client.ui;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.MediaElement;
+import com.google.gwt.dom.client.NodeList;
+import com.google.gwt.dom.client.SourceElement;
+import com.google.gwt.dom.client.Text;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
public abstract class VMediaBase extends Widget {
private MediaElement media;
+ private Text altText;
/**
* Sets the MediaElement that is to receive all commands and properties.
@@ -44,7 +48,12 @@ public abstract class VMediaBase extends Widget {
}
public void setAltText(String alt) {
- media.appendChild(Document.get().createTextNode(alt));
+ if (altText == null) {
+ altText = Document.get().createTextNode(alt);
+ media.appendChild(altText);
+ } else {
+ altText.setNodeValue(alt);
+ }
}
public void setControls(boolean shouldShowControls) {
@@ -59,8 +68,21 @@ public abstract class VMediaBase extends Widget {
media.setMuted(mediaMuted);
}
+ public void removeAllSources() {
+ NodeList<com.google.gwt.dom.client.Element> l = media
+ .getElementsByTagName(SourceElement.TAG);
+ for (int i = l.getLength() - 1; i >= 0; i--) {
+ media.removeChild(l.getItem(i));
+ }
+
+ }
+
+ public void load() {
+ media.load();
+ }
+
public void addSource(String sourceUrl, String sourceType) {
- Element src = Document.get().createElement("source").cast();
+ Element src = Document.get().createElement(SourceElement.TAG).cast();
src.setAttribute("src", sourceUrl);
src.setAttribute("type", sourceType);
media.appendChild(src);
diff --git a/client/src/com/vaadin/client/ui/audio/AudioConnector.java b/client/src/com/vaadin/client/ui/audio/AudioConnector.java
index c7d20ef585..5a90cab09d 100644
--- a/client/src/com/vaadin/client/ui/audio/AudioConnector.java
+++ b/client/src/com/vaadin/client/ui/audio/AudioConnector.java
@@ -30,23 +30,6 @@ import com.vaadin.ui.Audio;
public class AudioConnector extends MediaBaseConnector {
@Override
- public void onStateChanged(StateChangeEvent stateChangeEvent) {
- super.onStateChanged(stateChangeEvent);
-
- Style style = getWidget().getElement().getStyle();
-
- // Make sure that the controls are not clipped if visible.
- if (getState().showControls
- && (style.getHeight() == null || "".equals(style.getHeight()))) {
- if (BrowserInfo.get().isChrome()) {
- style.setHeight(32, Unit.PX);
- } else {
- style.setHeight(25, Unit.PX);
- }
- }
- }
-
- @Override
protected Widget createWidget() {
return GWT.create(VAudio.class);
}
@@ -55,4 +38,35 @@ public class AudioConnector extends MediaBaseConnector {
protected String getDefaultAltHtml() {
return "Your browser does not support the <code>audio</code> element.";
}
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
+ // Opera (12.14) has a bug where an audio element w/o controls is shown
+ // as 150x300px, which is not usually desired. However, in order to show
+ // the error/alt message, we only do this in the exact situation.
+ if (BrowserInfo.get().isOpera()
+ && stateChangeEvent.hasPropertyChanged("showControls")) {
+ Style style = getWidget().getElement().getStyle();
+ if (!getState().showControls) {
+ if (isUndefinedHeight() && isUndefinedWidth()
+ && getWidget().getOffsetHeight() == 150
+ && getWidget().getOffsetWidth() == 300) {
+ // only if no size set and 150x300
+ style.setWidth(0, Unit.PX);
+ style.setHeight(0, Unit.PX);
+ }
+ } else {
+ // clear sizes if it's supposed to be undefined
+ if (isUndefinedHeight()) {
+ style.clearHeight();
+ }
+ if (isUndefinedWidth()) {
+ style.clearWidth();
+ }
+ }
+ }
+ }
+
}