From 565a2172805f90bcb531e0b25fe1b64857f9f1da Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 6 Dec 2024 10:28:33 +0100 Subject: [PATCH] Use Edge/WebView2 as the default browser on Windows #1466 - Introduce SWT flag SWT.IE to be used for Browser to create an Internet Explorer instance - Adapt mapping of existing VM argument for default browser to map "ie" to new Internet Explorer flag and use Edge as default - Make SWT Browser instantiate Edge on Windows by default, i.e., unless the flag SWT.IE is specified - Adapt the SWT ControlExample to represent the SWT.IE flag and properly switch between Edge, Internet Explorer and default - Adapt Browser tests to consider to new default configuration Contributes to https://github.com/eclipse-platform/eclipse.platform.swt/issues/1466 --- .../.settings/.api_filters | 8 ++++++++ .../common/org/eclipse/swt/browser/Browser.java | 6 +++--- .../org/eclipse/swt/browser/BrowserFactory.java | 6 +++--- .../Eclipse SWT/common/org/eclipse/swt/SWT.java | 14 ++++++++++++-- .../swt/examples/controlexample/BrowserTab.java | 5 +++++ .../Test_org_eclipse_swt_browser_Browser.java | 4 +++- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters b/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters index 8e9f80c10d2..70b018a8894 100644 --- a/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters @@ -375,6 +375,14 @@ + + + + + + + + diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/Browser.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/Browser.java index 0bcc46d6cc6..a266af150c1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/Browser.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/Browser.java @@ -182,9 +182,9 @@ static int checkStyle(int style) { if (current.equalsIgnoreCase ("webkit")) { //$NON-NLS-1$ DefaultType = SWT.WEBKIT; break; - } else if (current.equalsIgnoreCase ("edge") && "win32".equals (platform)) { //$NON-NLS-1$ //$NON-NLS-2$ - DefaultType = SWT.EDGE; } else if (current.equalsIgnoreCase ("ie") && "win32".equals (platform)) { //$NON-NLS-1$ //$NON-NLS-2$ + DefaultType = SWT.IE; + } else if (current.equalsIgnoreCase ("edge") && "win32".equals (platform)) { //$NON-NLS-1$ //$NON-NLS-2$ DefaultType = SWT.NONE; break; } @@ -196,7 +196,7 @@ static int checkStyle(int style) { } } /* If particular backend isn't specified, use the value from the system property. */ - if ((style & (SWT.WEBKIT | SWT.EDGE)) == 0) { + if ((style & (SWT.WEBKIT | SWT.IE)) == 0) { style |= DefaultType; } if ("win32".equals (platform) && (style & SWT.EDGE) != 0) { //$NON-NLS-1$ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/BrowserFactory.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/BrowserFactory.java index ebfe06a1f6a..0936f7d958e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/BrowserFactory.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/BrowserFactory.java @@ -19,13 +19,13 @@ class BrowserFactory { WebBrowser createWebBrowser (int style) { // This function can't throw, otherwise the Browser will be left in inconsistent state. - if ((style & SWT.EDGE) != 0) { + if ((style & SWT.IE) != 0) { try { - return new Edge(); + return new IE(); } catch (SWTError e) { System.err.println(e); } } - return new IE (); + return new Edge (); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java index c5d5e345c8b..ecc0aef99b5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java @@ -2564,8 +2564,6 @@ public class SWT { /** * Style constant specifying that a Browser should use Edge (WebView2) * for rendering its content (value is 1<<18). - *

NOTE: Edge integration is experimental, it isn't a drop-in replacement - * for Internet Explorer.

*

Used By:

*
    *
  • Browser
  • @@ -2575,6 +2573,18 @@ public class SWT { */ public static final int EDGE = 1 << 18; + /** + * Style constant specifying that a Browser should use Internet Explorer + * for rendering its content (value is 1<<19). + *

    Used By:

    + *
      + *
    • Browser
    • + *
    + * + * @since 3.129 + */ + public static final int IE = 1 << 19; + /** * Style constant for balloon behavior (value is 1<<12). *

    Used By:

    diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java index 25ea624e395..a46f1693e96 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java @@ -49,6 +49,7 @@ class BrowserTab extends Tab { /* Style widgets added to the "Style" group */ Button webKitButton; Button edgeButton; + Button ieButton; String errorMessage, lastText, lastUrl; @@ -94,6 +95,7 @@ void createExampleWidgets () { if (borderButton.getSelection ()) style |= SWT.BORDER; if (webKitButton.getSelection ()) style |= SWT.WEBKIT; if (edgeButton.getSelection ()) style |= SWT.EDGE; + if (ieButton.getSelection ()) style |= SWT.IE; /* Create the example widgets */ try { @@ -168,6 +170,8 @@ void createStyleGroup () { webKitButton.setText ("SWT.WEBKIT"); edgeButton = new Button (styleGroup, SWT.RADIO); edgeButton.setText ("SWT.EDGE"); + ieButton = new Button (styleGroup, SWT.RADIO); + ieButton.setText ("SWT.IE"); borderButton = new Button (styleGroup, SWT.CHECK); borderButton.setText ("SWT.BORDER"); } @@ -345,6 +349,7 @@ void setExampleWidgetState () { super.setExampleWidgetState (); webKitButton.setSelection (browser == null ? false : (browser.getStyle () & SWT.WEBKIT) != 0); edgeButton.setSelection (browser == null ? false : (browser.getStyle () & SWT.EDGE) != 0); + ieButton.setSelection (browser == null ? false : (browser.getStyle () & SWT.IE) != 0); borderButton.setSelection (browser == null ? false : (browser.getStyle () & SWT.BORDER) != 0); } } diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java index 90972844618..d12cdf3a7f3 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java @@ -146,8 +146,10 @@ public static Collection browserFlagsToTest() { // NOTE: This is currently disabled due to test issues in the CI // Execute Edge tests first, because IE starts some OS timer that conflicts with Edge event handling // browserFlags.add(0, new Object[] {SWT.EDGE}); + browserFlags.add(new Object[] {SWT.IE}); + } else { + browserFlags.add(new Object[] {SWT.NONE}); } - browserFlags.add(new Object[] {SWT.NONE}); return browserFlags; }