summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAhmed Ashour <asashour@yahoo.com>2017-09-27 12:03:18 +0200
committerHenri Sara <henri.sara@gmail.com>2017-09-27 13:03:18 +0300
commit22566d5d9d3794edc1bad59a709f3a78b3a3ba28 (patch)
treeea1ac7cdb9e40d0f1b8b3f438f3e1d6dcbc3fb57 /client
parent367c7751a6ff9234fd47bc5a48e6ef9a4117a7a2 (diff)
downloadvaadin-framework-22566d5d9d3794edc1bad59a709f3a78b3a3ba28.tar.gz
vaadin-framework-22566d5d9d3794edc1bad59a709f3a78b3a3ba28.zip
Convert Embedded not to be a LegacyComponent (#10088)
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VEmbedded.java74
-rw-r--r--client/src/main/java/com/vaadin/client/ui/embedded/EmbeddedConnector.java117
2 files changed, 81 insertions, 110 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VEmbedded.java b/client/src/main/java/com/vaadin/client/ui/VEmbedded.java
index 45037f72a8..5f4e801a44 100644
--- a/client/src/main/java/com/vaadin/client/ui/VEmbedded.java
+++ b/client/src/main/java/com/vaadin/client/ui/VEmbedded.java
@@ -32,7 +32,7 @@ import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
import com.vaadin.client.VConsole;
import com.vaadin.client.WidgetUtil;
-import com.vaadin.shared.ui.embedded.EmbeddedConstants;
+import com.vaadin.shared.ui.embedded.EmbeddedState;
public class VEmbedded extends HTML {
public static String CLASSNAME = "v-embedded";
@@ -59,11 +59,14 @@ public class VEmbedded extends HTML {
* <p>
* For internal use only. May be removed or replaced in the future.
*
- * @param uidl
- * The UIDL
+ * @param state
+ * The EmbeddedState
+ * @param src
+ * The src attribute
* @return Tags concatenated into a string
+ * @since
*/
- public String createFlashEmbed(UIDL uidl) {
+ public String createFlashEmbed(EmbeddedState state, String src) {
/*
* 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
@@ -82,12 +85,9 @@ public class VEmbedded extends HTML {
* http://kb2.adobe.com/cps/415/tn_4150.html. Allow user to override
* this by setting his own classid.
*/
- if (uidl.hasAttribute("classid")) {
- html.append(
- "classid=\""
- + WidgetUtil.escapeAttribute(
- uidl.getStringAttribute("classid"))
- + "\" ");
+ if (state.classId != null) {
+ html.append("classid=\"" + WidgetUtil.escapeAttribute(state.classId)
+ + "\" ");
} else {
html.append(
"classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
@@ -101,12 +101,9 @@ public class VEmbedded extends HTML {
* 6.0.0.0 and above. Allow user to override this by setting his own
* codebase
*/
- if (uidl.hasAttribute("codebase")) {
- html.append(
- "codebase=\""
- + WidgetUtil.escapeAttribute(
- uidl.getStringAttribute("codebase"))
- + "\" ");
+ if (state.codebase != null) {
+ html.append("codebase=\""
+ + WidgetUtil.escapeAttribute(state.codebase) + "\" ");
} else {
html.append(
"codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
@@ -123,39 +120,30 @@ public class VEmbedded extends HTML {
html.append("type=\"application/x-shockwave-flash\" ");
// Codetype
- if (uidl.hasAttribute("codetype")) {
- html.append(
- "codetype=\""
- + WidgetUtil.escapeAttribute(
- uidl.getStringAttribute("codetype"))
- + "\" ");
+ if (state.codetype != null) {
+ html.append("codetype=\""
+ + WidgetUtil.escapeAttribute(state.codetype) + "\" ");
}
// Standby
- if (uidl.hasAttribute("standby")) {
- html.append(
- "standby=\""
- + WidgetUtil.escapeAttribute(
- uidl.getStringAttribute("standby"))
- + "\" ");
+ if (state.standby != null) {
+ html.append("standby=\"" + WidgetUtil.escapeAttribute(state.standby)
+ + "\" ");
}
// Archive
- if (uidl.hasAttribute("archive")) {
- html.append(
- "archive=\""
- + WidgetUtil.escapeAttribute(
- uidl.getStringAttribute("archive"))
- + "\" ");
+ if (state.archive != null) {
+ html.append("archive=\"" + WidgetUtil.escapeAttribute(state.archive)
+ + "\" ");
}
// End object tag
html.append(">");
// Ensure we have an movie parameter
- Map<String, String> parameters = getParameters(uidl);
+ Map<String, String> parameters = state.parameters;
if (parameters.get("movie") == null) {
- parameters.put("movie", getSrc(uidl, client));
+ parameters.put("movie", getSrc(src, client));
}
// Add parameters to OBJECT
@@ -169,7 +157,7 @@ public class VEmbedded extends HTML {
// Build inner EMBED tag
html.append("<embed ");
- html.append("src=\"" + WidgetUtil.escapeAttribute(getSrc(uidl, client))
+ html.append("src=\"" + WidgetUtil.escapeAttribute(getSrc(src, client))
+ "\" ");
html.append("width=\"" + WidgetUtil.escapeAttribute(width) + "\" ");
html.append("height=\"" + WidgetUtil.escapeAttribute(height) + "\" ");
@@ -186,9 +174,8 @@ public class VEmbedded extends HTML {
// End embed tag
html.append("></embed>");
- if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) {
- html.append(
- uidl.getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT));
+ if (state.altText != null) {
+ html.append(state.altText);
}
// End object tag
@@ -232,12 +219,13 @@ public class VEmbedded extends HTML {
* <p>
* For internal use only. May be removed or replaced in the future.
*
- * @param uidl
+ * @param src
+ * the src attribute
* @param client
* @return
*/
- public String getSrc(UIDL uidl, ApplicationConnection client) {
- String url = client.translateVaadinUri(uidl.getStringAttribute("src"));
+ public String getSrc(String src, ApplicationConnection client) {
+ String url = client.translateVaadinUri(src);
if (url == null) {
return "";
}
diff --git a/client/src/main/java/com/vaadin/client/ui/embedded/EmbeddedConnector.java b/client/src/main/java/com/vaadin/client/ui/embedded/EmbeddedConnector.java
index 3564c1e058..dbc04941ba 100644
--- a/client/src/main/java/com/vaadin/client/ui/embedded/EmbeddedConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/embedded/EmbeddedConnector.java
@@ -27,9 +27,6 @@ import com.google.gwt.dom.client.ObjectElement;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
-import com.vaadin.client.ApplicationConnection;
-import com.vaadin.client.Paintable;
-import com.vaadin.client.UIDL;
import com.vaadin.client.VConsole;
import com.vaadin.client.VTooltip;
import com.vaadin.client.communication.StateChangeEvent;
@@ -38,14 +35,12 @@ import com.vaadin.client.ui.ClickEventHandler;
import com.vaadin.client.ui.VEmbedded;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
-import com.vaadin.shared.ui.embedded.EmbeddedConstants;
import com.vaadin.shared.ui.embedded.EmbeddedServerRpc;
import com.vaadin.shared.ui.embedded.EmbeddedState;
import com.vaadin.ui.Embedded;
@Connect(Embedded.class)
-public class EmbeddedConnector extends AbstractComponentConnector
- implements Paintable {
+public class EmbeddedConnector extends AbstractComponentConnector {
private Element resourceElement;
private ObjectElement objectElement;
@@ -56,44 +51,16 @@ public class EmbeddedConnector extends AbstractComponentConnector
super.onStateChanged(stateChangeEvent);
// if theme has changed the resourceUrl may need to be updated
updateResourceIfNecessary();
- }
-
- private void updateResourceIfNecessary() {
- if (resourceElement != null || objectElement != null) {
- String src = getResourceUrl("src");
- if (src != null && !src.isEmpty()) {
- if (!src.equals(resourceUrl)) {
- setResourceUrl(src);
- }
- } else if (resourceUrl != null && !resourceUrl.isEmpty()) {
- setResourceUrl("");
- }
- }
- }
-
- private void setResourceUrl(String src) {
- resourceUrl = src;
- if (resourceElement != null) {
- resourceElement.setAttribute("src", src);
- } else if (objectElement != null) {
- objectElement.setData(src);
- }
- }
-
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (!isRealUpdate(uidl)) {
- return;
- }
// Save details
- getWidget().client = client;
+ getWidget().client = getConnection();
boolean clearBrowserElement = true;
clickEventHandler.handleEventHandlerRegistration();
- if (uidl.hasAttribute("type")) {
+ final EmbeddedState state = getState();
+ if (state.type != Embedded.TYPE_OBJECT) {
// remove old style name related to type
if (getWidget().type != null) {
getWidget().removeStyleName(
@@ -104,7 +71,8 @@ public class EmbeddedConnector extends AbstractComponentConnector
getWidget().removeStyleName(
VEmbedded.CLASSNAME + "-" + getWidget().mimetype);
}
- getWidget().type = uidl.getStringAttribute("type");
+ getWidget().type = state.type == Embedded.TYPE_IMAGE ? "image"
+ : "browser";
if (getWidget().type.equals("image")) {
getWidget().addStyleName(VEmbedded.CLASSNAME + "-image");
Element el = null;
@@ -128,17 +96,15 @@ public class EmbeddedConnector extends AbstractComponentConnector
// Set attributes
Style style = el.getStyle();
- style.setProperty("width", getState().width);
- style.setProperty("height", getState().height);
+ style.setProperty("width", state.width);
+ style.setProperty("height", state.height);
resourceElement = el;
objectElement = null;
setResourceUrl(getResourceUrl("src"));
- if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) {
- el.setPropertyString(EmbeddedConstants.ALTERNATE_TEXT,
- uidl.getStringAttribute(
- EmbeddedConstants.ALTERNATE_TEXT));
+ if (state.altText != null) {
+ el.setPropertyString("alt", state.altText);
}
if (created) {
@@ -158,7 +124,7 @@ public class EmbeddedConnector extends AbstractComponentConnector
getWidget().setHTML(
"<iframe width=\"100%\" height=\"100%\" frameborder=\"0\""
+ " allowTransparency=\"true\" src=\"\""
- + " name=\"" + uidl.getId()
+ + " name=\"" + getConnectorId()
+ "\"></iframe>");
getWidget().browserElement = DOM
.getFirstChild(getWidget().getElement());
@@ -171,7 +137,7 @@ public class EmbeddedConnector extends AbstractComponentConnector
VConsole.error(
"Unknown Embedded type '" + getWidget().type + "'");
}
- } else if (uidl.hasAttribute("mimetype")) {
+ } else if (state.mimeType != null) {
// remove old style name related to type
if (getWidget().type != null) {
getWidget().removeStyleName(
@@ -182,18 +148,19 @@ public class EmbeddedConnector extends AbstractComponentConnector
getWidget().removeStyleName(
VEmbedded.CLASSNAME + "-" + getWidget().mimetype);
}
- final String mime = uidl.getStringAttribute("mimetype");
+ final String mime = state.mimeType;
if (mime.equals("application/x-shockwave-flash")) {
getWidget().mimetype = "flash";
// Handle embedding of Flash
getWidget().addStyleName(VEmbedded.CLASSNAME + "-flash");
- getWidget().setHTML(getWidget().createFlashEmbed(uidl));
+ getWidget().setHTML(getWidget().createFlashEmbed(state,
+ getResourceUrl("src")));
} else if (mime.equals("image/svg+xml")) {
getWidget().mimetype = "svg";
getWidget().addStyleName(VEmbedded.CLASSNAME + "-svg");
String data;
- Map<String, String> parameters = VEmbedded.getParameters(uidl);
+ Map<String, String> parameters = state.parameters;
ObjectElement obj = Document.get().createObjectElement();
resourceElement = null;
if (parameters.get("data") == null) {
@@ -213,30 +180,24 @@ public class EmbeddedConnector extends AbstractComponentConnector
if (!isUndefinedHeight()) {
obj.getStyle().setProperty("height", "100%");
}
- if (uidl.hasAttribute("classid")) {
- obj.setAttribute("classid",
- uidl.getStringAttribute("classid"));
+ if (state.classId != null) {
+ obj.setAttribute("classid", state.classId);
}
- if (uidl.hasAttribute("codebase")) {
- obj.setAttribute("codebase",
- uidl.getStringAttribute("codebase"));
+ if (state.codebase != null) {
+ obj.setAttribute("codebase", state.codebase);
}
- if (uidl.hasAttribute("codetype")) {
- obj.setAttribute("codetype",
- uidl.getStringAttribute("codetype"));
+ if (state.codetype != null) {
+ obj.setAttribute("codetype", state.codetype);
}
- if (uidl.hasAttribute("archive")) {
- obj.setAttribute("archive",
- uidl.getStringAttribute("archive"));
+ if (state.archive != null) {
+ obj.setAttribute("archive", state.archive);
}
- if (uidl.hasAttribute("standby")) {
- obj.setAttribute("standby",
- uidl.getStringAttribute("standby"));
+ if (state.standby != null) {
+ obj.setAttribute("standby", state.standby);
}
getWidget().getElement().appendChild(obj);
- if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) {
- obj.setInnerText(uidl.getStringAttribute(
- EmbeddedConstants.ALTERNATE_TEXT));
+ if (state.altText != null) {
+ obj.setInnerText(state.altText);
}
} else {
VConsole.error("Unknown Embedded mimetype '" + mime + "'");
@@ -250,6 +211,28 @@ public class EmbeddedConnector extends AbstractComponentConnector
}
}
+ private void updateResourceIfNecessary() {
+ if (resourceElement != null || objectElement != null) {
+ String src = getResourceUrl("src");
+ if (src != null && !src.isEmpty()) {
+ if (!src.equals(resourceUrl)) {
+ setResourceUrl(src);
+ }
+ } else if (resourceUrl != null && !resourceUrl.isEmpty()) {
+ setResourceUrl("");
+ }
+ }
+ }
+
+ private void setResourceUrl(String src) {
+ resourceUrl = src;
+ if (resourceElement != null) {
+ resourceElement.setAttribute("src", src);
+ } else if (objectElement != null) {
+ objectElement.setData(src);
+ }
+ }
+
@Override
public VEmbedded getWidget() {
return (VEmbedded) super.getWidget();