Skip to content

Commit 16ee714

Browse files
lak-proddevLakshminarayana Nekkanti
authored andcommitted
Allow customization of the browser style in the "BrowserViewer"
class. #3035
1 parent a9213eb commit 16ee714

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserViewer.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void mouseDown(MouseEvent e) {
234234
// we can use it in this environment
235235
//if (WebBrowserUtil.canUseInternalWebBrowser())
236236
try {
237-
this.browser = new Browser(this, SWT.NONE);
237+
this.browser = new Browser(this, getBrowserStyle());
238238
this.browser.addLocationListener(LocationListener.changingAdapter(event -> {
239239
URI uri = URI.create(event.location);
240240
if (!(uri.getScheme().equals("http") || uri.getScheme().equals("https") //$NON-NLS-1$ //$NON-NLS-2$
@@ -275,6 +275,17 @@ public void mouseDown(MouseEvent e) {
275275
addDisposeListener(this::dispose);
276276
}
277277

278+
/**
279+
* Returns the style flags to be used for the Browser object. Subclasses can
280+
* override this method to provide custom styles for the Browser. By default,
281+
* this method returns the SWT.NONE style.
282+
*
283+
* @return an integer representing the style flags for the Browser object.
284+
*/
285+
protected int getBrowserStyle() {
286+
return SWT.NONE; // Default style
287+
}
288+
278289
/**
279290
* Returns the underlying SWT browser widget.
280291
*

tests/org.eclipse.ui.tests.browser/src/org/eclipse/ui/tests/browser/internal/InternalBrowserViewTestCase.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.browser.internal;
1515

16+
import static org.junit.Assert.assertEquals;
17+
1618
import java.net.URL;
1719

20+
import org.eclipse.swt.SWT;
21+
import org.eclipse.swt.widgets.Composite;
1822
import org.eclipse.swt.widgets.Display;
1923
import org.eclipse.swt.widgets.Shell;
2024
import org.eclipse.ui.PlatformUI;
2125
import org.eclipse.ui.browser.IWebBrowser;
2226
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
27+
import org.eclipse.ui.internal.browser.BrowserViewer;
2328
import org.eclipse.ui.internal.browser.WebBrowserPreference;
2429
import org.junit.Test;
2530

@@ -68,4 +73,42 @@ public void run() {
6873
Display display = Display.getCurrent();
6974
while (!exit[0] && !shell.isDisposed()) if (!display.readAndDispatch()) display.sleep();
7075
}
76+
77+
@Test
78+
public void testDefaultBrowserStyle() {
79+
class TestBrowserViewer extends BrowserViewer {
80+
public TestBrowserViewer(Composite parent, int style) {
81+
super(parent, style);
82+
}
83+
84+
@Override
85+
protected int getBrowserStyle() {
86+
return super.getBrowserStyle();
87+
}
88+
}
89+
90+
TestBrowserViewer browserViewer = new TestBrowserViewer(shell, SWT.NONE);
91+
int browserStyle = browserViewer.getBrowserStyle();
92+
// Assert: Verify the returned style is SWT.NONE
93+
assertEquals("The default browser style should be SWT.NONE", SWT.NONE, browserStyle);
94+
}
95+
96+
@Test
97+
public void testCustomBrowserStyle() {
98+
class CustomBrowserViewer extends BrowserViewer {
99+
public CustomBrowserViewer(Composite parent, int style) {
100+
super(parent, style);
101+
}
102+
103+
@Override
104+
protected int getBrowserStyle() {
105+
return SWT.EDGE; // Custom style
106+
}
107+
}
108+
109+
CustomBrowserViewer customBrowserViewer = new CustomBrowserViewer(shell, SWT.NONE);
110+
int browserStyle = customBrowserViewer.getBrowserStyle();
111+
// Assert: Verify the returned style is SWT.EDGE
112+
assertEquals("The custom browser style should be SWT.EDGE", SWT.EDGE, browserStyle);
113+
}
71114
}

0 commit comments

Comments
 (0)