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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import com.google.gwt.dom.client.Document;
  18. import com.google.gwt.dom.client.Element;
  19. import com.google.gwt.dom.client.Style.Unit;
  20. import com.google.gwt.dom.client.VideoElement;
  21. import com.vaadin.client.Util;
  22. public class VVideo extends VMediaBase {
  23. public static String CLASSNAME = "v-video";
  24. private VideoElement video;
  25. public VVideo() {
  26. video = Document.get().createVideoElement();
  27. setMediaElement(video);
  28. setStyleName(CLASSNAME);
  29. updateDimensionsWhenMetadataLoaded(getElement());
  30. }
  31. /**
  32. * Registers a listener that updates the dimensions of the widget when the
  33. * video metadata has been loaded.
  34. *
  35. * @param el
  36. */
  37. private native void updateDimensionsWhenMetadataLoaded(Element el)
  38. /*-{
  39. var self = this;
  40. el.addEventListener('loadedmetadata', $entry(function(e) {
  41. self.@com.vaadin.client.ui.VVideo::updateElementDynamicSize(II)(el.videoWidth, el.videoHeight);
  42. }), false);
  43. }-*/;
  44. /**
  45. * Updates the dimensions of the widget.
  46. *
  47. * @param w
  48. * @param h
  49. */
  50. private void updateElementDynamicSize(int w, int h) {
  51. video.getStyle().setWidth(w, Unit.PX);
  52. video.getStyle().setHeight(h, Unit.PX);
  53. Util.notifyParentOfSizeChange(this, true);
  54. }
  55. public void setPoster(String poster) {
  56. video.setPoster(poster);
  57. }
  58. }