1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.dom.svg.utils;
19
20 import org.vectomatic.dom.svg.utils.DOMHelper;
21
22 import com.google.gwt.dom.client.Document;
23 import com.google.gwt.dom.client.Element;
24 import com.google.gwt.dom.client.IFrameElement;
25 import com.google.gwt.dom.client.NativeEvent;
26 import com.google.gwt.user.client.ui.RootPanel;
27
28
29
30
31 public class IFrameXmlLoader implements AsyncXmlLoader {
32
33 public IFrameXmlLoader() {
34 }
35
36 public void loadResource(String resourceName, AsyncXmlLoaderCallback callback) {
37 IFrameElement iframe = Document.get().createIFrameElement();
38 iframe.setAttribute("tabIndex", "-1");
39 iframe.setAttribute("style", "position: absolute; width: 0; height: 0; border: 0");
40 iframe.setAttribute("src", "javascript:''");
41 Element body = RootPanel.get().getElement();
42 body.appendChild(iframe);
43 setFrameLocation(resourceName, iframe, callback);
44 }
45
46 @SuppressWarnings("unused")
47 private void dispatch(NativeEvent event, AsyncXmlLoaderCallback callback) {
48 IFrameElement iframe = event.getCurrentEventTarget().cast();
49 if (iframe != null) {
50 String href = getHref(iframe);
51 if (!"about:blank".equals(href)) {
52 Element root = iframe.getContentDocument().getDocumentElement();
53 Element localRoot = DOMHelper.importNode(DOMHelper.getCurrentDocument(), root, true).cast();
54 callback.onSuccess(href, localRoot);
55 }
56 Element body = RootPanel.get().getElement();
57 body.removeChild(iframe);
58 }
59 }
60
61 private native String getHref(IFrameElement iframe)
62
63 ;
64
65 private native void setFrameLocation(String resourceName, IFrameElement iframe, AsyncXmlLoaderCallback callback)
66
67
68
69
70
71 ;
72 }