diff options
author | Artur Signell <artur@vaadin.com> | 2012-01-30 10:00:11 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-01-30 10:00:11 +0200 |
commit | 47e5c9da79f9d945c1b5bfaaf044a7ac4a05f302 (patch) | |
tree | 0f404ad104340d1cee460a29dc70e8a8f7047812 /src | |
parent | f2d8308279f03e6b445eb722ddcc9b4a3a6d1ca3 (diff) | |
download | vaadin-framework-47e5c9da79f9d945c1b5bfaaf044a7ac4a05f302.tar.gz vaadin-framework-47e5c9da79f9d945c1b5bfaaf044a7ac4a05f302.zip |
Split VAudio and VVideo into widget + paintable
Diffstat (limited to 'src')
6 files changed, 209 insertions, 144 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAudio.java b/src/com/vaadin/terminal/gwt/client/ui/VAudio.java index 7fc061184d..f6df827237 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAudio.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAudio.java @@ -6,12 +6,6 @@ package com.vaadin.terminal.gwt.client.ui; import com.google.gwt.dom.client.AudioElement; import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Style; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.UIDL; public class VAudio extends VMediaBase { private static String CLASSNAME = "v-audio"; @@ -25,31 +19,8 @@ public class VAudio extends VMediaBase { } @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - super.updateFromUIDL(uidl, client); - Style style = audio.getStyle(); - - // Make sure that the controls are not clipped if visible. - if (shouldShowControls(uidl) - && (style.getHeight() == null || "".equals(style.getHeight()))) { - if (BrowserInfo.get().isChrome()) { - style.setHeight(32, Unit.PX); - } else { - style.setHeight(25, Unit.PX); - } - } - } - - @Override protected String getDefaultAltHtml() { return "Your browser does not support the <code>audio</code> element."; } - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAudioPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAudioPaintable.java new file mode 100644 index 0000000000..e949d95104 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAudioPaintable.java @@ -0,0 +1,37 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VAudioPaintable extends VMediaBasePaintable {
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+ super.updateFromUIDL(uidl, client);
+ Style style = getWidgetForPaintable().getElement().getStyle();
+
+ // Make sure that the controls are not clipped if visible.
+ if (shouldShowControls(uidl)
+ && (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);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java b/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java index df76b6d878..6c5fbc2ef0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java @@ -8,25 +8,10 @@ import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.MediaElement; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.Util; -public abstract class VMediaBase extends Widget implements VPaintableWidget { - public static final String ATTR_PAUSE = "pause"; - public static final String ATTR_PLAY = "play"; - public static final String ATTR_MUTED = "muted"; - public static final String ATTR_CONTROLS = "ctrl"; - public static final String ATTR_AUTOPLAY = "auto"; - public static final String TAG_SOURCE = "src"; - public static final String ATTR_RESOURCE = "res"; - public static final String ATTR_RESOURCE_TYPE = "type"; - public static final String ATTR_HTML = "html"; - public static final String ATTR_ALT_TEXT = "alt"; +public abstract class VMediaBase extends Widget { private MediaElement media; - protected ApplicationConnection client; /** * Sets the MediaElement that is to receive all commands and properties. @@ -38,96 +23,40 @@ public abstract class VMediaBase extends Widget implements VPaintableWidget { media = element; } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - - this.client = client; - - media.setControls(shouldShowControls(uidl)); - media.setAutoplay(shouldAutoplay(uidl)); - media.setMuted(isMediaMuted(uidl)); - - // Add all sources - for (int ix = 0; ix < uidl.getChildCount(); ix++) { - UIDL child = uidl.getChildUIDL(ix); - if (TAG_SOURCE.equals(child.getTag())) { - Element src = Document.get().createElement("source").cast(); - src.setAttribute("src", getSourceUrl(child)); - src.setAttribute("type", getSourceType(child)); - media.appendChild(src); - } - } - setAltText(uidl); - - evalPauseCommand(uidl); - evalPlayCommand(uidl); - } - - protected boolean shouldShowControls(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_CONTROLS); - } - - private boolean shouldAutoplay(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_AUTOPLAY); - } - - private boolean isMediaMuted(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_MUTED); - } - /** - * @param uidl - * @return the URL of a resource to be used as a source for the media + * @return the default HTML to show users with browsers that do not support + * HTML5 media markup. */ - private String getSourceUrl(UIDL uidl) { - String url = client.translateVaadinUri(uidl - .getStringAttribute(ATTR_RESOURCE)); - if (url == null) { - return ""; - } - return url; - } + protected abstract String getDefaultAltHtml(); - /** - * @param uidl - * @return the mime type of the media - */ - private String getSourceType(UIDL uidl) { - return uidl.getStringAttribute(ATTR_RESOURCE_TYPE); + public void play() { + media.play(); } - private void setAltText(UIDL uidl) { - String alt = uidl.getStringAttribute(ATTR_ALT_TEXT); + public void pause() { + media.pause(); + } - if (alt == null || "".equals(alt)) { - alt = getDefaultAltHtml(); - } else if (!allowHtmlContent(uidl)) { - alt = Util.escapeHTML(alt); - } + public void setAltText(String alt) { media.appendChild(Document.get().createTextNode(alt)); } - private boolean allowHtmlContent(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_HTML); + public void setControls(boolean shouldShowControls) { + media.setControls(shouldShowControls); } - private void evalPlayCommand(UIDL uidl) { - if (uidl.hasAttribute(ATTR_PLAY)) { - media.play(); - } + public void setAutoplay(boolean shouldAutoplay) { + media.setAutoplay(shouldAutoplay); } - private void evalPauseCommand(UIDL uidl) { - if (uidl.hasAttribute(ATTR_PAUSE)) { - media.pause(); - } + public void setMuted(boolean mediaMuted) { + media.setMuted(mediaMuted); } - /** - * @return the default HTML to show users with browsers that do not support - * HTML5 media markup. - */ - protected abstract String getDefaultAltHtml(); + public void addSource(String sourceUrl, String sourceType) { + Element src = Document.get().createElement("source").cast(); + src.setAttribute("src", sourceUrl); + src.setAttribute("type", sourceType); + media.appendChild(src); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMediaBasePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VMediaBasePaintable.java new file mode 100644 index 0000000000..fc709d56b3 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VMediaBasePaintable.java @@ -0,0 +1,109 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.Util;
+
+public abstract class VMediaBasePaintable extends VAbstractPaintableWidget {
+
+ public static final String TAG_SOURCE = "src";
+
+ public static final String ATTR_PAUSE = "pause";
+ public static final String ATTR_PLAY = "play";
+ public static final String ATTR_MUTED = "muted";
+ public static final String ATTR_CONTROLS = "ctrl";
+ public static final String ATTR_AUTOPLAY = "auto";
+ public static final String ATTR_RESOURCE = "res";
+ public static final String ATTR_RESOURCE_TYPE = "type";
+ public static final String ATTR_HTML = "html";
+ public static final String ATTR_ALT_TEXT = "alt";
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+
+ getWidgetForPaintable().setControls(shouldShowControls(uidl));
+ getWidgetForPaintable().setAutoplay(shouldAutoplay(uidl));
+ getWidgetForPaintable().setMuted(isMediaMuted(uidl));
+
+ // Add all sources
+ for (int ix = 0; ix < uidl.getChildCount(); ix++) {
+ UIDL child = uidl.getChildUIDL(ix);
+ if (TAG_SOURCE.equals(child.getTag())) {
+ getWidgetForPaintable().addSource(getSourceUrl(child),
+ getSourceType(child));
+ }
+ }
+ setAltText(uidl);
+
+ evalPauseCommand(uidl);
+ evalPlayCommand(uidl);
+ }
+
+ protected boolean shouldShowControls(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_CONTROLS);
+ }
+
+ private boolean shouldAutoplay(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_AUTOPLAY);
+ }
+
+ private boolean isMediaMuted(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_MUTED);
+ }
+
+ private boolean allowHtmlContent(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_HTML);
+ }
+
+ private void evalPlayCommand(UIDL uidl) {
+ if (uidl.hasAttribute(ATTR_PLAY)) {
+ getWidgetForPaintable().play();
+ }
+ }
+
+ private void evalPauseCommand(UIDL uidl) {
+ if (uidl.hasAttribute(ATTR_PAUSE)) {
+ getWidgetForPaintable().pause();
+ }
+ }
+
+ @Override
+ public VMediaBase getWidgetForPaintable() {
+ return (VMediaBase) super.getWidgetForPaintable();
+ }
+
+ /**
+ * @param uidl
+ * @return the URL of a resource to be used as a source for the media
+ */
+ private String getSourceUrl(UIDL uidl) {
+ String url = getConnection().translateVaadinUri(
+ uidl.getStringAttribute(VMediaBasePaintable.ATTR_RESOURCE));
+ if (url == null) {
+ return "";
+ }
+ return url;
+ }
+
+ /**
+ * @param uidl
+ * @return the mime type of the media
+ */
+ private String getSourceType(UIDL uidl) {
+ return uidl.getStringAttribute(VMediaBasePaintable.ATTR_RESOURCE_TYPE);
+ }
+
+ private void setAltText(UIDL uidl) {
+ String alt = uidl.getStringAttribute(VMediaBasePaintable.ATTR_ALT_TEXT);
+
+ if (alt == null || "".equals(alt)) {
+ alt = getWidgetForPaintable().getDefaultAltHtml();
+ } else if (!allowHtmlContent(uidl)) {
+ alt = Util.escapeHTML(alt);
+ }
+ getWidgetForPaintable().setAltText(alt);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVideo.java b/src/com/vaadin/terminal/gwt/client/ui/VVideo.java index 71be059319..36f17e1436 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VVideo.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VVideo.java @@ -8,13 +8,9 @@ import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.VideoElement; import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; public class VVideo extends VMediaBase { - public static final String ATTR_POSTER = "poster"; private static String CLASSNAME = "v-video"; @@ -28,22 +24,6 @@ public class VVideo extends VMediaBase { updateDimensionsWhenMetadataLoaded(getElement()); } - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - super.updateFromUIDL(uidl, client); - setPosterFromUIDL(uidl); - } - - private void setPosterFromUIDL(UIDL uidl) { - if (uidl.hasAttribute(ATTR_POSTER)) { - video.setPoster(client.translateVaadinUri(uidl - .getStringAttribute(ATTR_POSTER))); - } - } - /** * Registers a listener that updates the dimensions of the widget when the * video metadata has been loaded. @@ -76,7 +56,8 @@ public class VVideo extends VMediaBase { return "Your browser does not support the <code>video</code> element."; } - public Widget getWidgetForPaintable() { - return this; + public void setPoster(String poster) { + video.setPoster(poster); } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVideoPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VVideoPaintable.java new file mode 100644 index 0000000000..a9a46671be --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VVideoPaintable.java @@ -0,0 +1,38 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VVideoPaintable extends VMediaBasePaintable {
+ public static final String ATTR_POSTER = "poster";
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+ super.updateFromUIDL(uidl, client);
+ setPosterFromUIDL(uidl);
+ }
+
+ private void setPosterFromUIDL(UIDL uidl) {
+ if (uidl.hasAttribute(ATTR_POSTER)) {
+ getWidgetForPaintable().setPoster(
+ getConnection().translateVaadinUri(
+ uidl.getStringAttribute(ATTR_POSTER)));
+ }
+ }
+
+ @Override
+ public VVideo getWidgetForPaintable() {
+ return (VVideo) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VVideo.class);
+ }
+
+}
|