summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--uitest/src/com/vaadin/tests/components/media/AudioTest.html66
-rw-r--r--uitest/src/com/vaadin/tests/components/media/AudioTest.java86
-rw-r--r--uitest/src/com/vaadin/tests/components/media/bip.mp3bin0 -> 13837 bytes
-rw-r--r--uitest/src/com/vaadin/tests/components/media/bip.oggbin0 -> 15137 bytes
-rw-r--r--uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3bin0 -> 80083 bytes
-rw-r--r--uitest/src/com/vaadin/tests/components/media/toyphone_dialling.oggbin0 -> 77861 bytes
9 files changed, 225 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();
+ }
+ }
+ }
+ }
+
}
diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.html b/uitest/src/com/vaadin/tests/components/media/AudioTest.html
new file mode 100644
index 0000000000..8425cad38a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.html
@@ -0,0 +1,66 @@
+<?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>AudioTest</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">AudioTest</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/AudioTest?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td>3000</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>shortAtEndUnmuted</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCheckBox[0]/domChild[0]</td>
+ <td>11,7</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VCheckBox[0]/domChild[0]</td>
+ <td>6,7</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td>5000</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>longerAtEndMuted</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td>
+ <td>69,9</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>controlsHidden</td>
+</tr>
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.java b/uitest/src/com/vaadin/tests/components/media/AudioTest.java
new file mode 100644
index 0000000000..28d1a7716f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2000-2013 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.media;
+
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.server.ClassResource;
+import com.vaadin.server.Resource;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Audio;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.CheckBox;
+
+public class AudioTest extends TestBase {
+
+ @Override
+ protected void setup() {
+
+ // Public domain sounds from pdsounds.org 27.2.2013
+
+ final Resource[] s1 = { new ClassResource(getClass(), "bip.mp3"),
+ new ClassResource(getClass(), "bip.ogg") };
+ final Resource[] s2 = {
+ new ClassResource(getClass(), "toyphone_dialling.mp3"),
+ new ClassResource(getClass(), "toyphone_dialling.ogg") };
+
+ final Audio audio = new Audio();
+
+ audio.setSources(s1);
+ audio.setShowControls(true);
+ audio.setHtmlContentAllowed(true);
+ audio.setAltText("Can't <b>play</b> media");
+ audio.setAutoplay(true);
+
+ addComponent(audio);
+
+ CheckBox checkBox = new CheckBox("Show controls",
+ new MethodProperty<Boolean>(audio, "showControls"));
+ addComponent(checkBox);
+ checkBox = new CheckBox("HtmlContentAllowed",
+ new MethodProperty<Boolean>(audio, "htmlContentAllowed"));
+ addComponent(checkBox);
+ checkBox = new CheckBox("muted", new MethodProperty<Boolean>(audio,
+ "muted"));
+ addComponent(checkBox);
+ checkBox = new CheckBox("autoplay", new MethodProperty<Boolean>(audio,
+ "autoplay"));
+ addComponent(checkBox);
+
+ Button b = new Button("Change", new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ audio.setSources(s2);
+ }
+ });
+ addComponent(b);
+ getLayout().setHeight("400px");
+ getLayout().setExpandRatio(b, 1.0f);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Should autoplay, manipulating checkboxes should do appropriate thing, button changes file.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11160;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/media/bip.mp3 b/uitest/src/com/vaadin/tests/components/media/bip.mp3
new file mode 100644
index 0000000000..2c7e790cf7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/media/bip.mp3
Binary files differ
diff --git a/uitest/src/com/vaadin/tests/components/media/bip.ogg b/uitest/src/com/vaadin/tests/components/media/bip.ogg
new file mode 100644
index 0000000000..4e5014d92f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/media/bip.ogg
Binary files differ
diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3
new file mode 100644
index 0000000000..1788026856
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3
Binary files differ
diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg
new file mode 100644
index 0000000000..a042da5795
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg
Binary files differ