You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VVideo.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.google.gwt.dom.client.Document;
  6. import com.google.gwt.dom.client.Style.Unit;
  7. import com.google.gwt.dom.client.VideoElement;
  8. import com.google.gwt.user.client.Element;
  9. import com.google.gwt.user.client.ui.Widget;
  10. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  11. import com.vaadin.terminal.gwt.client.UIDL;
  12. import com.vaadin.terminal.gwt.client.Util;
  13. public class VVideo extends VMediaBase {
  14. public static final String ATTR_POSTER = "poster";
  15. private static String CLASSNAME = "v-video";
  16. private VideoElement video;
  17. public VVideo() {
  18. video = Document.get().createVideoElement();
  19. setMediaElement(video);
  20. setStyleName(CLASSNAME);
  21. updateDimensionsWhenMetadataLoaded(getElement());
  22. }
  23. @Override
  24. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  25. if (client.updateComponent(this, uidl, true)) {
  26. return;
  27. }
  28. super.updateFromUIDL(uidl, client);
  29. setPosterFromUIDL(uidl);
  30. }
  31. private void setPosterFromUIDL(UIDL uidl) {
  32. if (uidl.hasAttribute(ATTR_POSTER)) {
  33. video.setPoster(client.translateVaadinUri(uidl
  34. .getStringAttribute(ATTR_POSTER)));
  35. }
  36. }
  37. /**
  38. * Registers a listener that updates the dimensions of the widget when the
  39. * video metadata has been loaded.
  40. *
  41. * @param el
  42. */
  43. private native void updateDimensionsWhenMetadataLoaded(Element el)
  44. /*-{
  45. var self = this;
  46. el.addEventListener('loadedmetadata', function(e) {
  47. $entry(self.@com.vaadin.terminal.gwt.client.ui.VVideo::updateElementDynamicSize(II)(el.videoWidth, el.videoHeight));
  48. }, false);
  49. }-*/;
  50. /**
  51. * Updates the dimensions of the widget.
  52. *
  53. * @param w
  54. * @param h
  55. */
  56. private void updateElementDynamicSize(int w, int h) {
  57. video.getStyle().setWidth(w, Unit.PX);
  58. video.getStyle().setHeight(h, Unit.PX);
  59. Util.notifyParentOfSizeChange(this, true);
  60. }
  61. @Override
  62. protected String getDefaultAltHtml() {
  63. return "Your browser does not support the <code>video</code> element.";
  64. }
  65. public Widget getWidgetForPaintable() {
  66. return this;
  67. }
  68. }