1 11 package org.eclipse.swt.browser; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.graphics.*; 15 import org.eclipse.swt.internal.mozilla.*; 16 import org.eclipse.swt.layout.*; 17 import org.eclipse.swt.widgets.*; 18 19 class WindowCreator { 20 XPCOMObject supports; 21 XPCOMObject windowCreator; 22 int refCount = 0; 23 24 public WindowCreator() { 25 createCOMInterfaces(); 26 } 27 28 int AddRef() { 29 refCount++; 30 return refCount; 31 } 32 33 void createCOMInterfaces() { 34 35 supports = new XPCOMObject(new int[]{2, 0, 0}){ 36 public int method0(int[] args) {return queryInterface(args[0], args[1]);} 37 public int method1(int[] args) {return AddRef();} 38 public int method2(int[] args) {return Release();} 39 }; 40 41 windowCreator = new XPCOMObject(new int[]{2, 0, 0, 3}){ 42 public int method0(int[] args) {return queryInterface(args[0], args[1]);} 43 public int method1(int[] args) {return AddRef();} 44 public int method2(int[] args) {return Release();} 45 public int method3(int[] args) {return CreateChromeWindow(args[0], args[1], args[2]);} 46 }; 47 } 48 49 void disposeCOMInterfaces() { 50 if (supports != null) { 51 supports.dispose(); 52 supports = null; 53 } 54 if (windowCreator != null) { 55 windowCreator.dispose(); 56 windowCreator = null; 57 } 58 } 59 60 int getAddress() { 61 return windowCreator.getAddress(); 62 } 63 64 int queryInterface(int riid, int ppvObject) { 65 if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE; 66 nsID guid = new nsID(); 67 XPCOM.memmove(guid, riid, nsID.sizeof); 68 69 if (guid.Equals(nsISupports.NS_ISUPPORTS_IID)) { 70 XPCOM.memmove(ppvObject, new int[] {supports.getAddress()}, 4); 71 AddRef(); 72 return XPCOM.NS_OK; 73 } 74 if (guid.Equals(nsIWindowCreator.NS_IWINDOWCREATOR_IID)) { 75 XPCOM.memmove(ppvObject, new int[] {windowCreator.getAddress()}, 4); 76 AddRef(); 77 return XPCOM.NS_OK; 78 } 79 80 XPCOM.memmove(ppvObject, new int[] {0}, 4); 81 return XPCOM.NS_ERROR_NO_INTERFACE; 82 } 83 84 int Release() { 85 refCount--; 86 if (refCount == 0) disposeCOMInterfaces(); 87 return refCount; 88 } 89 90 91 92 int CreateChromeWindow(int parent, int chromeFlags, int _retval) { 93 if (parent == 0) return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 94 nsIWebBrowserChrome browserChromeParent = new nsIWebBrowserChrome(parent); 95 int[] aWebBrowser = new int[1]; 96 int rc = browserChromeParent.GetWebBrowser(aWebBrowser); 97 if (rc != XPCOM.NS_OK) Browser.error(rc); 98 if (aWebBrowser[0] == 0) Browser.error(XPCOM.NS_ERROR_NO_INTERFACE); 99 100 nsIWebBrowser webBrowser = new nsIWebBrowser(aWebBrowser[0]); 101 int[] result = new int[1]; 102 rc = webBrowser.QueryInterface(nsIBaseWindow.NS_IBASEWINDOW_IID, result); 103 if (rc != XPCOM.NS_OK) Browser.error(rc); 104 if (result[0] == 0) Browser.error(XPCOM.NS_ERROR_NO_INTERFACE); 105 webBrowser.Release(); 106 107 nsIBaseWindow baseWindow = new nsIBaseWindow(result[0]); 108 result[0] = 0; 109 int[] aParentNativeWindow = new int[1]; 110 rc = baseWindow.GetParentNativeWindow(aParentNativeWindow); 111 if (rc != XPCOM.NS_OK) Browser.error(rc); 112 if (aParentNativeWindow[0] == 0) Browser.error(XPCOM.NS_ERROR_NO_INTERFACE); 113 baseWindow.Release(); 114 115 Display display = Display.getCurrent(); 116 Browser src = Browser.findBrowser(aParentNativeWindow[0]); 117 final Browser browser; 118 boolean doit = false; 119 if ((chromeFlags & nsIWebBrowserChrome.CHROME_MODAL) != 0) { 120 128 final Shell shell = new Shell(src.getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 129 shell.setLayout(new FillLayout()); 130 browser = new Browser(shell, SWT.NONE); 131 browser.addVisibilityWindowListener(new VisibilityWindowListener() { 132 public void hide(WindowEvent event) { 133 } 134 public void show(WindowEvent event) { 135 if (event.location != null) shell.setLocation(event.location); 136 if (event.size != null) { 137 Point size = event.size; 138 shell.setSize(shell.computeSize(size.x, size.y)); 139 } 140 shell.open(); 141 } 142 }); 143 browser.addCloseWindowListener(new CloseWindowListener() { 144 public void close(WindowEvent event) { 145 shell.close(); 146 } 147 }); 148 doit = true; 149 } else { 150 WindowEvent event = new WindowEvent(src); 151 event.display = display; 152 event.widget = src; 153 event.required = true; 154 for (int i = 0; i < src.openWindowListeners.length; i++) 155 src.openWindowListeners[i].open(event); 156 browser = event.browser; 157 doit = browser != null && !browser.isDisposed(); 158 if (doit) { 159 browser.addressBar = (chromeFlags & nsIWebBrowserChrome.CHROME_LOCATIONBAR) != 0; 160 browser.menuBar = (chromeFlags & nsIWebBrowserChrome.CHROME_MENUBAR) != 0; 161 browser.statusBar = (chromeFlags & nsIWebBrowserChrome.CHROME_STATUSBAR) != 0; 162 browser.toolBar = (chromeFlags & nsIWebBrowserChrome.CHROME_TOOLBAR) != 0; 163 } 164 } 165 if (doit) { 166 int address = browser.webBrowserChrome.getAddress(); 167 nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome(address); 168 webBrowserChrome.AddRef(); 169 XPCOM.memmove(_retval, new int[] {address}, 4); 170 } 171 return doit ? XPCOM.NS_OK : XPCOM.NS_ERROR_NOT_IMPLEMENTED; 172 } 173 } 174 | Popular Tags |