Mercurial > projects > dwt2
comparison org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/browser/Mozilla.d @ 54:70388b0e6dad
[swt lin] compiles
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 27 Mar 2009 23:31:11 +0100 |
parents | 7e78af7adab5 |
children | 536e43f63c81 |
comparison
equal
deleted
inserted
replaced
53:7e78af7adab5 | 54:70388b0e6dad |
---|---|
20 import tango.sys.Environment; | 20 import tango.sys.Environment; |
21 import tango.stdc.string; | 21 import tango.stdc.string; |
22 } else { // Phobos | 22 } else { // Phobos |
23 } | 23 } |
24 | 24 |
25 import org.eclipse.swt.internal.c.gtk; | 25 //import org.eclipse.swt.internal.c.gtk; |
26 | 26 |
27 import org.eclipse.swt.SWT; | 27 import org.eclipse.swt.SWT; |
28 import org.eclipse.swt.SWTError; | 28 import org.eclipse.swt.SWTError; |
29 import org.eclipse.swt.graphics.Device; | 29 import org.eclipse.swt.graphics.Device; |
30 import org.eclipse.swt.graphics.Point; | 30 import org.eclipse.swt.graphics.Point; |
49 import org.eclipse.swt.browser.TitleEvent; | 49 import org.eclipse.swt.browser.TitleEvent; |
50 | 50 |
51 import org.eclipse.swt.internal.Compatibility; | 51 import org.eclipse.swt.internal.Compatibility; |
52 import org.eclipse.swt.internal.LONG; | 52 import org.eclipse.swt.internal.LONG; |
53 import org.eclipse.swt.internal.Library; | 53 import org.eclipse.swt.internal.Library; |
54 import org.eclipse.swt.internal.gtk.OS; | |
54 | 55 |
55 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM; | 56 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM; |
56 import XPCOMInit = org.eclipse.swt.internal.mozilla.XPCOMInit; | 57 import XPCOMInit = org.eclipse.swt.internal.mozilla.XPCOMInit; |
57 | 58 |
58 import org.eclipse.swt.internal.mozilla.Common; | 59 import org.eclipse.swt.internal.mozilla.Common; |
296 rc = XPCOMInit.GRE_GetGREPathWithProperties (&range, 1, null, 0, greBuffer.ptr, greBuffer.length); | 297 rc = XPCOMInit.GRE_GetGREPathWithProperties (&range, 1, null, 0, greBuffer.ptr, greBuffer.length); |
297 } | 298 } |
298 | 299 |
299 if (rc is XPCOM.NS_OK) { | 300 if (rc is XPCOM.NS_OK) { |
300 /* indicates that a XULRunner was found */ | 301 /* indicates that a XULRunner was found */ |
301 mozillaPath = greBuffer; | 302 mozillaPath = cast(String)greBuffer; |
302 IsXULRunner = mozillaPath.length > 0; | 303 IsXULRunner = mozillaPath.length > 0; |
303 | 304 |
304 /* | 305 /* |
305 * Test whether the detected XULRunner can be used as the GRE before loading swt's | 306 * Test whether the detected XULRunner can be used as the GRE before loading swt's |
306 * XULRunner library. If it cannot be used then fall back to attempting to use | 307 * XULRunner library. If it cannot be used then fall back to attempting to use |
315 if (rc !is XPCOM.NS_OK) { | 316 if (rc !is XPCOM.NS_OK) { |
316 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS)); | 317 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS)); |
317 if (Device.DEBUG) getDwtLogger().error (__FILE__, __LINE__, "cannot use detected XULRunner: {}", mozillaPath); //$NON-NLS-1$ | 318 if (Device.DEBUG) getDwtLogger().error (__FILE__, __LINE__, "cannot use detected XULRunner: {}", mozillaPath); //$NON-NLS-1$ |
318 | 319 |
319 /* attempt to XPCOMGlueStartup the GRE pointed at by MOZILLA_FIVE_HOME */ | 320 /* attempt to XPCOMGlueStartup the GRE pointed at by MOZILLA_FIVE_HOME */ |
320 auto ptr = Environment.get(XPCOM.MOZILLA_FIVE_HOME); | 321 version(Tango){ |
322 auto ptr = Environment.get(XPCOM.MOZILLA_FIVE_HOME); | |
323 } else { // Phobos | |
324 implMissing(__FILE__, __LINE__); | |
325 String ptr; | |
326 } | |
321 | 327 |
322 if (ptr is null) { | 328 if (ptr is null) { |
323 IsXULRunner = false; | 329 IsXULRunner = false; |
324 } else { | 330 } else { |
325 mozillaPath = ptr; | 331 mozillaPath = ptr; |
366 " [Could not detect registered XULRunner to use]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | 372 " [Could not detect registered XULRunner to use]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
367 SWT.error (SWT.ERROR_NO_HANDLES, null, errorString); | 373 SWT.error (SWT.ERROR_NO_HANDLES, null, errorString); |
368 } | 374 } |
369 | 375 |
370 /* attempt to use the GRE pointed at by MOZILLA_FIVE_HOME */ | 376 /* attempt to use the GRE pointed at by MOZILLA_FIVE_HOME */ |
371 auto mozFiveHome = Environment.get(XPCOM.MOZILLA_FIVE_HOME); | 377 version(Tango){ |
378 auto mozFiveHome = Environment.get(XPCOM.MOZILLA_FIVE_HOME); | |
379 } else { // Phobos | |
380 implMissing(__FILE__, __LINE__); | |
381 String mozFiveHome; | |
382 } | |
372 if (mozFiveHome !is null) { | 383 if (mozFiveHome !is null) { |
373 mozillaPath = mozFiveHome; | 384 mozillaPath = mozFiveHome; |
374 } else { | 385 } else { |
375 browser.dispose (); | 386 browser.dispose (); |
376 SWT.error (SWT.ERROR_NO_HANDLES, null, " [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]"); //$NON-NLS-1$ | 387 SWT.error (SWT.ERROR_NO_HANDLES, null, " [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]"); //$NON-NLS-1$ |
627 if (tmpChars is null) { | 638 if (tmpChars is null) { |
628 browser.dispose (); | 639 browser.dispose (); |
629 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__); | 640 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__); |
630 } | 641 } |
631 int span = XPCOM.strlen_PRUnichar (tmpChars); | 642 int span = XPCOM.strlen_PRUnichar (tmpChars); |
632 prefLocales = Utf.toString(tmpChars[0 .. span]) ~ TOKENIZER_LOCALE; | 643 prefLocales = String_valueOf(tmpChars[0 .. span]) ~ TOKENIZER_LOCALE; |
633 } | 644 } |
634 | 645 |
635 /* | 646 /* |
636 * construct the new locale preference value by prepending the | 647 * construct the new locale preference value by prepending the |
637 * user's current locale and language to the original value | 648 * user's current locale and language to the original value |
638 */ | 649 */ |
639 | 650 |
640 String language = Culture.current.twoLetterLanguageName (); | 651 version(Tango){ |
641 String country = Region.current.twoLetterRegionName (); | 652 String language = Culture.current.twoLetterLanguageName (); |
642 String stringBuffer = language.dup; | 653 String country = Region.current.twoLetterRegionName (); |
654 } else { // Phobos | |
655 implMissing(__FILE__, __LINE__); | |
656 String language = "en"; | |
657 String country = "us"; | |
658 } | |
659 String stringBuffer = language._idup(); | |
643 | 660 |
644 stringBuffer ~= SEPARATOR_LOCALE; | 661 stringBuffer ~= SEPARATOR_LOCALE; |
645 stringBuffer ~= country.toLowerCase (); | 662 stringBuffer ~= country.toLowerCase (); |
646 stringBuffer ~= TOKENIZER_LOCALE; | 663 stringBuffer ~= TOKENIZER_LOCALE; |
647 stringBuffer ~= language; | 664 stringBuffer ~= language; |
648 stringBuffer ~= TOKENIZER_LOCALE; | 665 stringBuffer ~= TOKENIZER_LOCALE; |
649 String newLocales = stringBuffer.dup; | 666 String newLocales = stringBuffer._idup(); |
650 | 667 |
651 int start, end = -1; | 668 int start, end = -1; |
652 do { | 669 do { |
653 start = end + 1; | 670 start = end + 1; |
654 end = prefLocales.indexOf (TOKENIZER_LOCALE, start); | 671 end = prefLocales.indexOf (TOKENIZER_LOCALE, start); |
664 if (newLocales.indexOf (token) is -1) { | 681 if (newLocales.indexOf (token) is -1) { |
665 stringBuffer ~= token; | 682 stringBuffer ~= token; |
666 } | 683 } |
667 } | 684 } |
668 } while (end !is -1); | 685 } while (end !is -1); |
669 newLocales[] = stringBuffer[]; | 686 (cast(char[])newLocales)[] = stringBuffer[]; |
670 if (!newLocales.equals (prefLocales)) { | 687 if (!newLocales.equals (prefLocales)) { |
671 /* write the new locale value */ | 688 /* write the new locale value */ |
672 newLocales = newLocales.substring (0, newLocales.length () - TOKENIZER_LOCALE.length ()); /* remove trailing tokenizer */ | 689 newLocales = newLocales.substring (0, newLocales.length () - TOKENIZER_LOCALE.length ()); /* remove trailing tokenizer */ |
673 if (localizedString is null) { | 690 if (localizedString is null) { |
674 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID.ptr, null, &nsIPrefLocalizedString.IID, cast(void**)&localizedString); | 691 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID.ptr, null, &nsIPrefLocalizedString.IID, cast(void**)&localizedString); |
714 if (tmpChar is null) { | 731 if (tmpChar is null) { |
715 browser.dispose (); | 732 browser.dispose (); |
716 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__); | 733 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__); |
717 } | 734 } |
718 int span = XPCOM.strlen_PRUnichar (tmpChar); | 735 int span = XPCOM.strlen_PRUnichar (tmpChar); |
719 prefCharset = Utf.toString(tmpChar[0 .. span]); | 736 prefCharset = String_valueOf(tmpChar[0 .. span]); |
720 } | 737 } |
721 | 738 |
722 String newCharset = System.getProperty ("file.encoding"); // $NON-NLS-1$ | 739 String newCharset = System.getProperty ("file.encoding"); // $NON-NLS-1$ |
723 if (!newCharset.equals (prefCharset)) { | 740 if (!newCharset.equals (prefCharset)) { |
724 /* write the new charset value */ | 741 /* write the new charset value */ |
1325 serializer.Release (); | 1342 serializer.Release (); |
1326 | 1343 |
1327 //int length = XPCOM.strlen_PRUnichar (string); | 1344 //int length = XPCOM.strlen_PRUnichar (string); |
1328 //chars = new char[length]; | 1345 //chars = new char[length]; |
1329 //XPCOM.memmove (chars, result[0], length * 2); | 1346 //XPCOM.memmove (chars, result[0], length * 2); |
1330 chars = Utf.toString(fromString16z(string)); | 1347 chars = String_valueOf(fromString16z(string)); |
1331 } | 1348 } |
1332 | 1349 |
1333 componentManager.Release (); | 1350 componentManager.Release (); |
1334 document.Release (); | 1351 document.Release (); |
1335 return chars.dup; | 1352 return chars._idup(); |
1336 } | 1353 } |
1337 | 1354 |
1338 extern(D) | 1355 extern(D) |
1339 public String getUrl () { | 1356 public String getUrl () { |
1340 if (awaitingNavigate) return ""; //$NON-NLS-1$ | 1357 if (awaitingNavigate) return ""; //$NON-NLS-1$ |
1883 } | 1900 } |
1884 | 1901 |
1885 /* nsISupports */ | 1902 /* nsISupports */ |
1886 | 1903 |
1887 extern(System) | 1904 extern(System) |
1888 nsresult QueryInterface (cnsID* riid, void** ppvObject) { | 1905 nsresult QueryInterface (in nsID* riid, void** ppvObject) { |
1889 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; | 1906 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
1890 | 1907 |
1891 if (*riid == nsISupports.IID) { | 1908 if (*riid == nsISupports.IID) { |
1892 *ppvObject = cast(void*)cast(nsISupports)this; | 1909 *ppvObject = cast(void*)cast(nsISupports)this; |
1893 AddRef (); | 1910 AddRef (); |
1968 } | 1985 } |
1969 | 1986 |
1970 /* nsIInterfaceRequestor */ | 1987 /* nsIInterfaceRequestor */ |
1971 | 1988 |
1972 extern(System) | 1989 extern(System) |
1973 nsresult GetInterface ( nsID* riid, void** ppvObject) { | 1990 nsresult GetInterface ( in nsID* riid, void** ppvObject) { |
1974 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; | 1991 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
1975 //nsID guid = new nsID (); | 1992 //nsID guid = new nsID (); |
1976 //XPCOM.memmove (guid, riid, nsID.sizeof); | 1993 //XPCOM.memmove (guid, riid, nsID.sizeof); |
1977 if (*riid == nsIDOMWindow.IID) { | 1994 if (*riid == nsIDOMWindow.IID) { |
1978 nsIDOMWindow aContentDOMWindow; | 1995 nsIDOMWindow aContentDOMWindow; |
2228 event.display = browser.getDisplay (); | 2245 event.display = browser.getDisplay (); |
2229 event.widget = browser; | 2246 event.widget = browser; |
2230 //int length = XPCOM.strlen_PRUnichar (aMessage); | 2247 //int length = XPCOM.strlen_PRUnichar (aMessage); |
2231 //char[] dest = new char[length]; | 2248 //char[] dest = new char[length]; |
2232 //XPCOM.memmove (dest, aMessage, length * 2); | 2249 //XPCOM.memmove (dest, aMessage, length * 2); |
2233 event.text = Utf.toString(fromString16z(aMessage)); | 2250 event.text = String_valueOf(fromString16z(aMessage)); |
2234 for (int i = 0; i < statusTextListeners.length; i++) { | 2251 for (int i = 0; i < statusTextListeners.length; i++) { |
2235 statusTextListeners[i].changed (event); | 2252 statusTextListeners[i].changed (event); |
2236 } | 2253 } |
2237 return XPCOM.NS_OK; | 2254 return XPCOM.NS_OK; |
2238 } | 2255 } |
2252 event.widget = browser; | 2269 event.widget = browser; |
2253 //int length = XPCOM.strlen_PRUnichar (status); | 2270 //int length = XPCOM.strlen_PRUnichar (status); |
2254 //char[] dest = new char[length]; | 2271 //char[] dest = new char[length]; |
2255 //XPCOM.memmove (dest, status, length * 2); | 2272 //XPCOM.memmove (dest, status, length * 2); |
2256 //String string = new String (dest); | 2273 //String string = new String (dest); |
2257 event.text = Utf.toString(fromString16z(status)); | 2274 event.text = String_valueOf(fromString16z(status)); |
2258 for (int i = 0; i < statusTextListeners.length; i++) { | 2275 for (int i = 0; i < statusTextListeners.length; i++) { |
2259 statusTextListeners[i].changed (event); | 2276 statusTextListeners[i].changed (event); |
2260 } | 2277 } |
2261 return XPCOM.NS_OK; | 2278 return XPCOM.NS_OK; |
2262 } | 2279 } |
2490 */ | 2507 */ |
2491 int length = XPCOM.strlen_PRUnichar (aTitle); | 2508 int length = XPCOM.strlen_PRUnichar (aTitle); |
2492 if (length > 0) { | 2509 if (length > 0) { |
2493 //char[] dest = new char[length]; | 2510 //char[] dest = new char[length]; |
2494 //XPCOM.memmove (dest, aTitle, length * 2); | 2511 //XPCOM.memmove (dest, aTitle, length * 2); |
2495 event.title = Utf.toString(fromString16z(aTitle)); | 2512 event.title = String_valueOf(fromString16z(aTitle)); |
2496 } else { | 2513 } else { |
2497 event.title = getUrl (); | 2514 event.title = getUrl (); |
2498 } | 2515 } |
2499 for (int i = 0; i < titleListeners.length; i++) { | 2516 for (int i = 0; i < titleListeners.length; i++) { |
2500 titleListeners[i].changed (event); | 2517 titleListeners[i].changed (event); |
2640 } | 2657 } |
2641 | 2658 |
2642 extern(System) | 2659 extern(System) |
2643 nsresult IsPreferred (char* aContentType, char** aDesiredContentType, PRBool* retval) { | 2660 nsresult IsPreferred (char* aContentType, char** aDesiredContentType, PRBool* retval) { |
2644 bool preferred = false; | 2661 bool preferred = false; |
2645 auto size = strlen (aContentType); | 2662 auto size = OS.strlen (aContentType); |
2646 if (size > 0) { | 2663 if (size > 0) { |
2647 //byte[] typeBytes = new byte[size + 1]; | 2664 //byte[] typeBytes = new byte[size + 1]; |
2648 //XPCOM.memmove (typeBytes, aContentType, size); | 2665 //XPCOM.memmove (typeBytes, aContentType, size); |
2649 String contentType = fromStringz(aContentType); | 2666 String contentType = fromStringz(aContentType)._idup(); |
2650 | 2667 |
2651 /* do not attempt to handle known problematic content types */ | 2668 /* do not attempt to handle known problematic content types */ |
2652 if (!contentType.equals (XPCOM.CONTENT_MAYBETEXT) && !contentType.equals (XPCOM.CONTENT_MULTIPART)) { | 2669 if (!contentType.equals (XPCOM.CONTENT_MAYBETEXT) && !contentType.equals (XPCOM.CONTENT_MULTIPART)) { |
2653 /* determine whether browser can handle the content type */ | 2670 /* determine whether browser can handle the content type */ |
2654 // int /*long*/[] result = new int /*long*/[1]; | 2671 // int /*long*/[] result = new int /*long*/[1]; |
2682 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__); | 2699 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__); |
2683 if (categoryManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__); | 2700 if (categoryManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__); |
2684 | 2701 |
2685 //nsICategoryManager categoryManager = new nsICategoryManager (result[0]); | 2702 //nsICategoryManager categoryManager = new nsICategoryManager (result[0]); |
2686 //result[0] = 0; | 2703 //result[0] = 0; |
2687 char* categoryBytes = "Gecko-Content-Viewers"; //$NON-NLS-1$ | 2704 CCharPtr categoryBytes = "Gecko-Content-Viewers"; //$NON-NLS-1$ |
2688 char* result; | 2705 char* result; |
2689 rc = categoryManager.GetCategoryEntry (categoryBytes, aContentType, &result); | 2706 rc = categoryManager.GetCategoryEntry (categoryBytes, aContentType, &result); |
2690 categoryManager.Release (); | 2707 categoryManager.Release (); |
2691 /* if no viewer for the content type is registered then rc is XPCOM.NS_ERROR_NOT_AVAILABLE */ | 2708 /* if no viewer for the content type is registered then rc is XPCOM.NS_ERROR_NOT_AVAILABLE */ |
2692 preferred = rc is XPCOM.NS_OK; | 2709 preferred = rc is XPCOM.NS_OK; |
2734 if (awaitingNavigate) return XPCOM.NS_OK; | 2751 if (awaitingNavigate) return XPCOM.NS_OK; |
2735 | 2752 |
2736 //int length = XPCOM.strlen_PRUnichar (aTipText); | 2753 //int length = XPCOM.strlen_PRUnichar (aTipText); |
2737 //char[] dest = new char[length]; | 2754 //char[] dest = new char[length]; |
2738 //XPCOM.memmove (dest, aTipText, length * 2); | 2755 //XPCOM.memmove (dest, aTipText, length * 2); |
2739 String text = Utf.toString(fromString16z(aTipText)); | 2756 String text = String_valueOf(fromString16z(aTipText)); |
2740 if (tip !is null && !tip.isDisposed ()) tip.dispose (); | 2757 if (tip !is null && !tip.isDisposed ()) tip.dispose (); |
2741 Display display = browser.getDisplay (); | 2758 Display display = browser.getDisplay (); |
2742 Shell parent = browser.getShell (); | 2759 Shell parent = browser.getShell (); |
2743 tip = new Shell (parent, SWT.ON_TOP); | 2760 tip = new Shell (parent, SWT.ON_TOP); |
2744 tip.setLayout (new FillLayout()); | 2761 tip.setLayout (new FillLayout()); |