summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2012-08-23 18:58:00 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2012-08-24 16:09:47 +0300
commitf2cb4a9d9b3d5e89e38446906e7b556946f0a82a (patch)
tree227ae56d856e0744da2abe63671dfc0d4ef11424 /client
parente362dec1811c9872419c5ea627c9e157a7abf8a0 (diff)
downloadvaadin-framework-f2cb4a9d9b3d5e89e38446906e7b556946f0a82a.tar.gz
vaadin-framework-f2cb4a9d9b3d5e89e38446906e7b556946f0a82a.zip
Split Embedded into several components, migrate them to Vaadin 7 (#9087)
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java38
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java120
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java44
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java228
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java67
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java10
6 files changed, 507 insertions, 0 deletions
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java
new file mode 100644
index 0000000000..61231c4fba
--- /dev/null
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java
@@ -0,0 +1,38 @@
+package com.vaadin.terminal.gwt.client.ui.embeddedbrowser;
+
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.embeddedbrowser.EmbeddedBrowserState;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
+
+@Connect(com.vaadin.ui.EmbeddedBrowser.class)
+public class EmbeddedBrowserConnector extends AbstractComponentConnector {
+
+ @Override
+ protected void init() {
+ super.init();
+ }
+
+ @Override
+ public VEmbeddedBrowser getWidget() {
+ return (VEmbeddedBrowser) super.getWidget();
+ }
+
+ @Override
+ public EmbeddedBrowserState getState() {
+ return (EmbeddedBrowserState) super.getState();
+ }
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+
+ super.onStateChanged(stateChangeEvent);
+
+ getWidget().setAlternateText(getState().getAlternateText());
+ getWidget().setSource(
+ getState().getSource() != null ? getState().getSource()
+ .getURL() : null);
+ getWidget().setName(getConnectorId());
+ }
+
+}
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java
new file mode 100644
index 0000000000..fffbff049e
--- /dev/null
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java
@@ -0,0 +1,120 @@
+package com.vaadin.terminal.gwt.client.ui.embeddedbrowser;
+
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.IFrameElement;
+import com.google.gwt.user.client.ui.Widget;
+
+public class VEmbeddedBrowser extends Widget {
+
+ protected IFrameElement iframe;
+ protected Element altElement;
+ protected String altText;
+
+ public VEmbeddedBrowser() {
+ Element root = Document.get().createDivElement();
+ setElement(root);
+
+ setStylePrimaryName("v-embeddedbrowser");
+
+ createAltTextElement();
+ }
+
+ /**
+ * Always creates new iframe inside widget. Will replace previous iframe.
+ *
+ * @return
+ */
+ protected IFrameElement createIFrameElement(String src) {
+ String name = null;
+
+ // Remove alt text
+ if (altElement != null) {
+ getElement().removeChild(altElement);
+ altElement = null;
+ }
+
+ // Remove old iframe
+ if (iframe != null) {
+ name = iframe.getAttribute("name");
+ getElement().removeChild(iframe);
+ iframe = null;
+ }
+
+ iframe = Document.get().createIFrameElement();
+ iframe.setSrc(src);
+ iframe.setFrameBorder(0);
+ iframe.setAttribute("width", "100%");
+ iframe.setAttribute("height", "100%");
+ iframe.setAttribute("allowTransparency", "true");
+
+ getElement().appendChild(iframe);
+
+ // Reset old attributes (except src)
+ if (name != null) {
+ iframe.setName(name);
+ }
+
+ return iframe;
+ }
+
+ protected void createAltTextElement() {
+ if (iframe != null) {
+ return;
+ }
+
+ if (altElement == null) {
+ altElement = Document.get().createSpanElement();
+ getElement().appendChild(altElement);
+ }
+
+ if (altText != null) {
+ altElement.setInnerText(altText);
+ } else {
+ altElement.setInnerText("");
+ }
+ }
+
+ public void setAlternateText(String altText) {
+ if (this.altText != altText) {
+ this.altText = altText;
+ if (altElement != null) {
+ if (altText != null) {
+ altElement.setInnerText(altText);
+ } else {
+ altElement.setInnerText("");
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the source (the "src" attribute) of iframe. Will replace old iframe
+ * with new.
+ *
+ * @param source
+ * Source of iframe.
+ */
+ public void setSource(String source) {
+
+ if (source == null) {
+ if (iframe != null) {
+ getElement().removeChild(iframe);
+ iframe = null;
+ }
+ createAltTextElement();
+ setAlternateText(altText);
+ return;
+ }
+
+ if (iframe == null || iframe.getSrc() != source) {
+ createIFrameElement(source);
+ }
+ }
+
+ public void setName(String name) {
+ if (iframe != null) {
+ iframe.setName(name);
+ }
+ }
+}
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java
new file mode 100644
index 0000000000..a9e7a71013
--- /dev/null
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java
@@ -0,0 +1,44 @@
+package com.vaadin.terminal.gwt.client.ui.flash;
+
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.flash.FlashState;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
+
+@Connect(com.vaadin.ui.Flash.class)
+public class FlashConnector extends AbstractComponentConnector {
+
+ @Override
+ protected void init() {
+ super.init();
+ }
+
+ @Override
+ public VFlash getWidget() {
+ return (VFlash) super.getWidget();
+ }
+
+ @Override
+ public FlashState getState() {
+ return (FlashState) super.getState();
+ }
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+
+ super.onStateChanged(stateChangeEvent);
+
+ getWidget().setSource(
+ getState().getSource() != null ? getState().getSource()
+ .getURL() : null);
+ getWidget().setArchive(getState().getArchive());
+ getWidget().setClassId(getState().getClassId());
+ getWidget().setCodebase(getState().getCodebase());
+ getWidget().setCodetype(getState().getCodetype());
+ getWidget().setStandby(getState().getStandby());
+ getWidget().setAlternateText(getState().getAlternateText());
+ getWidget().setEmbedParams(getState().getEmbedParams());
+
+ getWidget().rebuildIfNeeded();
+ }
+}
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java b/client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java
new file mode 100644
index 0000000000..5d60dc66aa
--- /dev/null
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java
@@ -0,0 +1,228 @@
+package com.vaadin.terminal.gwt.client.ui.flash;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gwt.user.client.ui.HTML;
+import com.vaadin.terminal.gwt.client.Util;
+
+public class VFlash extends HTML {
+
+ protected String source;
+ protected String altText;
+ protected String classId;
+ protected String codebase;
+ protected String codetype;
+ protected String standby;
+ protected String archive;
+ protected Map<String, String> embedParams = new HashMap<String, String>();
+ protected boolean needsRebuild = false;
+ protected String width;
+ protected String height;
+
+ public VFlash() {
+ setStylePrimaryName("v-flash");
+ }
+
+ public void setSource(String source) {
+ if (this.source != source) {
+ this.source = source;
+ needsRebuild = true;
+ }
+ }
+
+ public void setAlternateText(String altText) {
+ if (this.altText != altText) {
+ this.altText = altText;
+ needsRebuild = true;
+ }
+ }
+
+ public void setClassId(String classId) {
+ if (this.classId != classId) {
+ this.classId = classId;
+ needsRebuild = true;
+ }
+ }
+
+ public void setCodebase(String codebase) {
+ if (this.codebase != codebase) {
+ this.codebase = codebase;
+ needsRebuild = true;
+ }
+ }
+
+ public void setCodetype(String codetype) {
+ if (this.codetype != codetype) {
+ this.codetype = codetype;
+ needsRebuild = true;
+ }
+ }
+
+ public void setStandby(String standby) {
+ if (this.standby != standby) {
+ this.standby = standby;
+ needsRebuild = true;
+ }
+ }
+
+ public void setArchive(String archive) {
+ if (this.archive != archive) {
+ this.archive = archive;
+ needsRebuild = true;
+ }
+ }
+
+ /**
+ * Call this after changing values of widget. It will rebuild embedding
+ * structure if needed.
+ */
+ public void rebuildIfNeeded() {
+ if (needsRebuild) {
+ needsRebuild = false;
+ this.setHTML(createFlashEmbed());
+ }
+ }
+
+ @Override
+ public void setWidth(String width) {
+ // super.setWidth(height);
+
+ if (this.width != width) {
+ this.width = width;
+ needsRebuild = true;
+ }
+ }
+
+ @Override
+ public void setHeight(String height) {
+ // super.setHeight(height);
+
+ if (this.height != height) {
+ this.height = height;
+ needsRebuild = true;
+ }
+ }
+
+ public void setEmbedParams(Map<String, String> params) {
+ if (params == null) {
+ if (!embedParams.isEmpty()) {
+ embedParams.clear();
+ needsRebuild = true;
+ }
+ return;
+ }
+
+ if (!embedParams.equals(params)) {
+ embedParams = new HashMap<String, String>(params);
+ needsRebuild = true;
+ }
+ }
+
+ protected String createFlashEmbed() {
+ /*
+ * To ensure cross-browser compatibility we are using the twice-cooked
+ * method to embed flash i.e. we add a OBJECT tag for IE ActiveX and
+ * inside it a EMBED for all other browsers.
+ */
+
+ StringBuilder html = new StringBuilder();
+
+ // Start the object tag
+ html.append("<object ");
+
+ /*
+ * Add classid required for ActiveX to recognize the flash. This is a
+ * predefined value which ActiveX recognizes and must be the given
+ * value. More info can be found on
+ * http://kb2.adobe.com/cps/415/tn_4150.html. Allow user to override
+ * this by setting his own classid.
+ */
+ if (classId != null) {
+ html.append("classid=\"" + Util.escapeAttribute(classId) + "\" ");
+ } else {
+ html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
+ }
+
+ /*
+ * Add codebase required for ActiveX and must be exactly this according
+ * to http://kb2.adobe.com/cps/415/tn_4150.html to work with the above
+ * given classid. Again, see more info on
+ * http://kb2.adobe.com/cps/415/tn_4150.html. Limiting Flash version to
+ * 6.0.0.0 and above. Allow user to override this by setting his own
+ * codebase
+ */
+ if (codebase != null) {
+ html.append("codebase=\"" + Util.escapeAttribute(codebase) + "\" ");
+ } else {
+ html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
+ }
+
+ // Add width and height
+ html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
+ html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
+ html.append("type=\"application/x-shockwave-flash\" ");
+
+ // Codetype
+ if (codetype != null) {
+ html.append("codetype=\"" + Util.escapeAttribute(codetype) + "\" ");
+ }
+
+ // Standby
+ if (standby != null) {
+ html.append("standby=\"" + Util.escapeAttribute(standby) + "\" ");
+ }
+
+ // Archive
+ if (archive != null) {
+ html.append("archive=\"" + Util.escapeAttribute(archive) + "\" ");
+ }
+
+ // End object tag
+ html.append(">");
+
+ // Ensure we have an movie parameter
+ if (embedParams.get("movie") == null) {
+ embedParams.put("movie", source);
+ }
+
+ // Add parameters to OBJECT
+ for (String name : embedParams.keySet()) {
+ html.append("<param ");
+ html.append("name=\"" + Util.escapeAttribute(name) + "\" ");
+ html.append("value=\""
+ + Util.escapeAttribute(embedParams.get(name)) + "\" ");
+ html.append("/>");
+ }
+
+ // Build inner EMBED tag
+ html.append("<embed ");
+ html.append("src=\"" + Util.escapeAttribute(source) + "\" ");
+ html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
+ html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
+ html.append("type=\"application/x-shockwave-flash\" ");
+
+ // Add the parameters to the Embed
+ for (String name : embedParams.keySet()) {
+ html.append(Util.escapeAttribute(name));
+ html.append("=");
+ html.append("\"" + Util.escapeAttribute(embedParams.get(name))
+ + "\"");
+ }
+
+ // End embed tag
+ html.append("></embed>");
+
+ if (altText != null) {
+ html.append("<noembed>");
+ html.append(altText);
+ html.append("</noembed>");
+ }
+
+ // End object tag
+ html.append("</object>");
+
+ return html.toString();
+ }
+
+}
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java
new file mode 100644
index 0000000000..d36e224a03
--- /dev/null
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java
@@ -0,0 +1,67 @@
+package com.vaadin.terminal.gwt.client.ui.image;
+
+import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.event.dom.client.LoadEvent;
+import com.google.gwt.event.dom.client.LoadHandler;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.image.ImageServerRpc;
+import com.vaadin.shared.ui.image.ImageState;
+import com.vaadin.terminal.gwt.client.communication.RpcProxy;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
+import com.vaadin.terminal.gwt.client.ui.ClickEventHandler;
+
+@Connect(com.vaadin.ui.Image.class)
+public class ImageConnector extends AbstractComponentConnector {
+
+ ImageServerRpc rpc;
+
+ @Override
+ protected void init() {
+ super.init();
+ rpc = RpcProxy.create(ImageServerRpc.class, this);
+ getWidget().addHandler(new LoadHandler() {
+
+ @Override
+ public void onLoad(LoadEvent event) {
+ getLayoutManager().setNeedsMeasure(ImageConnector.this);
+ }
+
+ }, LoadEvent.getType());
+ }
+
+ @Override
+ public VImage getWidget() {
+ return (VImage) super.getWidget();
+ }
+
+ @Override
+ public ImageState getState() {
+ return (ImageState) super.getState();
+ }
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
+ clickEventHandler.handleEventHandlerRegistration();
+
+ getWidget().setUrl(
+ getState().getSource() != null ? getState().getSource()
+ .getURL() : null);
+ getWidget().setAltText(getState().getAlternateText());
+ }
+
+ protected final ClickEventHandler clickEventHandler = new ClickEventHandler(
+ this) {
+
+ @Override
+ protected void fireClick(NativeEvent event,
+ MouseEventDetails mouseDetails) {
+ rpc.click(mouseDetails);
+ }
+
+ };
+
+}
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java b/client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java
new file mode 100644
index 0000000000..7e6b77ed4a
--- /dev/null
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java
@@ -0,0 +1,10 @@
+package com.vaadin.terminal.gwt.client.ui.image;
+
+import com.google.gwt.user.client.ui.Image;
+
+public class VImage extends Image {
+
+ public VImage() {
+ setStylePrimaryName("v-image");
+ }
+}