diff options
author | Anna Koskinen <anna@vaadin.com> | 2014-11-12 16:13:01 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-01-20 09:14:03 +0000 |
commit | 0651b9aa3b8880110eeac9a220e267daa04c9b4f (patch) | |
tree | 30fa6b537495e35ec0db8e9277003a7e9b1aa58c /client | |
parent | 3be687e39f4f6ec25383c090d8badfacf380fec9 (diff) | |
download | vaadin-framework-0651b9aa3b8880110eeac9a220e267daa04c9b4f.tar.gz vaadin-framework-0651b9aa3b8880110eeac9a220e267daa04c9b4f.zip |
Embedded ThemeResource should react to theme change (#15194)
Change-Id: Ied78a8c999e592a944c27138e179c37a31a0af54
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java b/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java index cd4c79ccc6..38995cf800 100644 --- a/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java +++ b/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java @@ -32,6 +32,7 @@ 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; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.ClickEventHandler; import com.vaadin.client.ui.VEmbedded; @@ -46,12 +47,45 @@ import com.vaadin.ui.Embedded; public class EmbeddedConnector extends AbstractComponentConnector implements Paintable { + private Element resourceElement; + private ObjectElement objectElement; + private String resourceUrl; + @Override protected void init() { super.init(); } @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + 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; @@ -102,8 +136,9 @@ public class EmbeddedConnector extends AbstractComponentConnector implements style.setProperty("width", getState().width); style.setProperty("height", getState().height); - DOM.setElementProperty(el, "src", - getWidget().getSrc(uidl, client)); + resourceElement = el; + objectElement = null; + setResourceUrl(getResourceUrl("src")); if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) { el.setPropertyString( @@ -133,8 +168,9 @@ public class EmbeddedConnector extends AbstractComponentConnector implements getWidget().browserElement = DOM.getFirstChild(getWidget() .getElement()); } - DOM.setElementAttribute(getWidget().browserElement, "src", - getWidget().getSrc(uidl, client)); + resourceElement = getWidget().browserElement; + objectElement = null; + setResourceUrl(getResourceUrl("src")); clearBrowserElement = false; } else { VConsole.error("Unknown Embedded type '" + getWidget().type @@ -163,15 +199,19 @@ public class EmbeddedConnector extends AbstractComponentConnector implements getWidget().addStyleName(VEmbedded.CLASSNAME + "-svg"); String data; Map<String, String> parameters = VEmbedded.getParameters(uidl); + ObjectElement obj = Document.get().createObjectElement(); + resourceElement = null; if (parameters.get("data") == null) { - data = getWidget().getSrc(uidl, client); + objectElement = obj; + data = getResourceUrl("src"); + setResourceUrl(data); } else { + objectElement = null; data = "data:image/svg+xml," + parameters.get("data"); + obj.setData(data); } getWidget().setHTML(""); - ObjectElement obj = Document.get().createObjectElement(); obj.setType(mime); - obj.setData(data); if (!isUndefinedWidth()) { obj.getStyle().setProperty("width", "100%"); } |