Skip to content

Allow customization of the browser style in the "BrowserViewer" class. #3035 #3036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.eclipse.ui.browser/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.browser; singleton:=true
Bundle-Version: 3.8.500.qualifier
Bundle-Version: 3.8.600.qualifier
Bundle-Activator: org.eclipse.ui.internal.browser.WebBrowserUIPlugin
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void mouseDown(MouseEvent e) {
// we can use it in this environment
//if (WebBrowserUtil.canUseInternalWebBrowser())
try {
this.browser = new Browser(this, SWT.NONE);
this.browser = new Browser(this, getBrowserStyle());
this.browser.addLocationListener(LocationListener.changingAdapter(event -> {
URI uri = URI.create(event.location);
if (!(uri.getScheme().equals("http") || uri.getScheme().equals("https") //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -275,6 +275,17 @@ public void mouseDown(MouseEvent e) {
addDisposeListener(this::dispose);
}

/**
* Returns the style flags to be used for the Browser object. Subclasses can
* override this method to provide custom styles for the Browser. By default,
* this method returns the SWT.NONE style.
*
* @return an integer representing the style flags for the Browser object.
*/
protected int getBrowserStyle() {
return SWT.NONE; // Default style
}

/**
* Returns the underlying SWT browser widget.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
*******************************************************************************/
package org.eclipse.ui.tests.browser.internal;

import static org.junit.Assert.assertEquals;

import java.net.URL;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.internal.browser.BrowserViewer;
import org.eclipse.ui.internal.browser.WebBrowserPreference;
import org.junit.Test;

Expand Down Expand Up @@ -68,4 +73,42 @@ public void run() {
Display display = Display.getCurrent();
while (!exit[0] && !shell.isDisposed()) if (!display.readAndDispatch()) display.sleep();
}

@Test
public void testDefaultBrowserStyle() {
class TestBrowserViewer extends BrowserViewer {
public TestBrowserViewer(Composite parent, int style) {
super(parent, style);
}

@Override
protected int getBrowserStyle() {
return super.getBrowserStyle();
}
}

TestBrowserViewer browserViewer = new TestBrowserViewer(shell, SWT.NONE);
int browserStyle = browserViewer.getBrowserStyle();
// Assert: Verify the returned style is SWT.NONE
assertEquals("The default browser style should be SWT.NONE", SWT.NONE, browserStyle);
}

@Test
public void testCustomBrowserStyle() {
class CustomBrowserViewer extends BrowserViewer {
public CustomBrowserViewer(Composite parent, int style) {
super(parent, style);
}

@Override
protected int getBrowserStyle() {
return SWT.EDGE; // Custom style
}
}

CustomBrowserViewer customBrowserViewer = new CustomBrowserViewer(shell, SWT.NONE);
int browserStyle = customBrowserViewer.getBrowserStyle();
// Assert: Verify the returned style is SWT.EDGE
assertEquals("The custom browser style should be SWT.EDGE", SWT.EDGE, browserStyle);
}
}
Loading