diff options
author | John Ahlroos <john@vaadin.com> | 2013-03-27 09:57:40 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-04-03 07:55:39 +0000 |
commit | bde44c29bdec4647dbec94b1ed2482baaf00cddf (patch) | |
tree | a8c2e855bbda0ad1180bf2ba72fe2cae28b7d83b /client | |
parent | d7bfb3a99cf2dee5a7622645357bfd606585b283 (diff) | |
download | vaadin-framework-bde44c29bdec4647dbec94b1ed2482baaf00cddf.tar.gz vaadin-framework-bde44c29bdec4647dbec94b1ed2482baaf00cddf.zip |
Implemented changes to CSS injection based on API review #5500
Change-Id: I2bed5f5a5c3cfc6b97e94cbd218bb06f446c7325
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/ui/UIConnector.java | 64 |
1 files changed, 10 insertions, 54 deletions
diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index f4524882fa..69296b537c 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -17,7 +17,6 @@ package com.vaadin.client.ui.ui; import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import com.google.gwt.core.client.Scheduler; @@ -26,7 +25,6 @@ import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.HeadElement; import com.google.gwt.dom.client.LinkElement; import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Position; import com.google.gwt.dom.client.StyleInjector; @@ -62,7 +60,7 @@ import com.vaadin.client.ui.VNotification; import com.vaadin.client.ui.VUI; import com.vaadin.client.ui.layout.MayScrollChildren; import com.vaadin.client.ui.window.WindowConnector; -import com.vaadin.server.Page.StyleSheet; +import com.vaadin.server.Page.Styles; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; @@ -340,7 +338,7 @@ public class UIConnector extends AbstractSingleComponentContainerConnector } /** - * Reads CSS strings and resources injected by {@link StyleSheet#inject} + * Reads CSS strings and resources injected by {@link Styles#inject} * from the UIDL stream. * * @param uidl @@ -354,8 +352,6 @@ public class UIConnector extends AbstractSingleComponentContainerConnector /* * Search the UIDL stream for CSS resources and strings to be injected. */ - final List<String> resourcesToInject = new LinkedList<String>(); - final StringBuilder cssToInject = new StringBuilder(); for (Iterator<?> it = uidl.getChildIterator(); it.hasNext();) { UIDL cssInjectionsUidl = (UIDL) it.next(); @@ -364,62 +360,22 @@ public class UIConnector extends AbstractSingleComponentContainerConnector String url = getWidget().connection .translateVaadinUri(cssInjectionsUidl .getStringAttribute("url")); - - // Check if url already has been injected - boolean injected = false; - NodeList<com.google.gwt.dom.client.Element> links = head - .getElementsByTagName(LinkElement.TAG); - for (int i = 0; i < links.getLength(); i++) { - LinkElement link = LinkElement.as(links.getItem(i)); - if (link.getHref().equals(url)) { - injected = true; - break; - } - } - - if (!injected) { - // Ensure duplicates do not get injected - resourcesToInject.add(url); - } + LinkElement link = LinkElement.as(DOM + .createElement(LinkElement.TAG)); + link.setRel("stylesheet"); + link.setHref(url); + link.setType("text/css"); + head.appendChild(link); // Check if we have CSS string to inject } else if (cssInjectionsUidl.getTag().equals("css-string")) { for (Iterator<?> it2 = cssInjectionsUidl.getChildIterator(); it2 .hasNext();) { - cssToInject.append((String) it2.next()); + StyleInjector.injectAtEnd((String) it2.next()); + StyleInjector.flush(); } } } - - /* - * Inject resources as deferred to ensure other Vaadin resources that - * are located before in the DOM get applied first so the injected ones - * can override them. - */ - if (!resourcesToInject.isEmpty()) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - for (String url : resourcesToInject) { - LinkElement link = LinkElement.as(DOM - .createElement(LinkElement.TAG)); - link.setRel("stylesheet"); - link.setHref(url); - link.setType("text/css"); - head.appendChild(link); - } - } - }); - } - - /* - * Inject the string CSS injections as a combined style tag. Not - * injected as deferred since StyleInjector will do it for us. - */ - if (cssToInject.length() > 0) { - StyleInjector.injectAtEnd(cssToInject.toString()); - } } public void init(String rootPanelId, |