Skip to content

Commit c5c9707

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents caf551e + e2cbda9 commit c5c9707

5 files changed

Lines changed: 180 additions & 19 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.function.*;
2626

2727
import org.eclipse.swt.*;
28+
import org.eclipse.swt.events.*;
2829
import org.eclipse.swt.graphics.*;
2930
import org.eclipse.swt.internal.*;
3031
import org.eclipse.swt.internal.gtk.*;
@@ -96,6 +97,11 @@ class WebKit extends WebBrowser {
9697
URI tlsErrorUri;
9798
String tlsErrorType;
9899

100+
private final ControlListener browserMoveListener = ControlListener.controlMovedAdapter(this::browserShellMoved);
101+
private Point searchShellLocation;
102+
private Shell searchShell;
103+
private String searchText;
104+
99105
boolean firstLoad = true;
100106
static boolean FirstCreate = true;
101107

@@ -201,6 +207,9 @@ class WebKit extends WebBrowser {
201207
/** Flag indicating whether TLS errors (like self-signed certificates) are to be ignored. */
202208
static final boolean ignoreTls;
203209

210+
/** Flag that disables browser searching added on top of the WebKit browser. */
211+
static final boolean disableBrowserSearch;
212+
204213
static {
205214
Proc2 = new Callback (WebKit.class, "Proc", 2); //$NON-NLS-1$
206215
Proc3 = new Callback (WebKit.class, "Proc", 3); //$NON-NLS-1$
@@ -248,6 +257,7 @@ class WebKit extends WebBrowser {
248257
NativePendingCookies = null;
249258
}
250259
ignoreTls = "true".equals(System.getProperty("org.eclipse.swt.internal.webkitgtk.ignoretlserrors"));
260+
disableBrowserSearch = "true".equals(System.getProperty("org.eclipse.swt.internal.webkitgtk.disableBrowserSearch"));
251261
}
252262

253263
@Override
@@ -784,13 +794,24 @@ public void create (Composite parent, int style) {
784794
onResize (event);
785795
break;
786796
}
797+
case SWT.KeyDown: {
798+
if (!disableBrowserSearch && event.keyCode == 'f' && (event.stateMask & SWT.CTRL) == SWT.CTRL) {
799+
openSearchDialog();
800+
}
801+
break;
802+
}
787803
}
788804
};
789805
browser.addListener (SWT.Dispose, listener);
790806
browser.addListener (SWT.FocusIn, listener);
791807
browser.addListener (SWT.KeyDown, listener);
792808
browser.addListener (SWT.Resize, listener);
793809

810+
browser.addDisposeListener(e -> closeSearchDialog());
811+
browser.addControlListener(ControlListener.controlResizedAdapter(this::browserShellMoved));
812+
browser.addControlListener(ControlListener.controlMovedAdapter(this::browserShellMoved));
813+
browser.getShell().addControlListener(browserMoveListener);
814+
794815
/*
795816
* Bug in WebKitGTK. MouseOver/MouseLeave events are not consistently sent from
796817
* the DOM when the mouse enters and exits the browser control, see
@@ -835,6 +856,9 @@ public boolean close () {
835856
// false = blocks disposal. In Browser.java, user is told widget was not disposed.
836857
// See Snippet326.
837858
boolean close (boolean showPrompters) {
859+
if (browser != null && !browser.isDisposed()) {
860+
browser.getShell().removeControlListener(browserMoveListener);
861+
}
838862
// don't execute any JavaScript if it's disabled or requested to get disabled
839863
// we need to check jsEnabledOnNextPage here because jsEnabled is updated asynchronously
840864
// and may not reflect the proper state (bug 571746 and bug 567881)
@@ -2665,6 +2689,115 @@ private void webkit_settings_set(byte [] property, int value) {
26652689
OS.g_object_set(settings, property, value, 0);
26662690
}
26672691

2692+
private void browserShellMoved(ControlEvent e) {
2693+
closeSearchDialog();
2694+
searchShellLocation = null;
2695+
}
2696+
2697+
private void closeSearchDialog() {
2698+
if (searchShell != null && !searchShell.isDisposed()) {
2699+
searchShellLocation = searchShell.getLocation();
2700+
searchShell.close();
2701+
if (searchText != null && webView != 0) {
2702+
long findController = WebKitGTK.webkit_web_view_get_find_controller(webView);
2703+
WebKitGTK.webkit_find_controller_search_finish(findController);
2704+
}
2705+
searchText = null;
2706+
}
2707+
}
2708+
2709+
private void openSearchDialog() {
2710+
if (webView == 0 || (searchShell != null && !searchShell.isDisposed())) {
2711+
return;
2712+
}
2713+
Shell browserShell = browser.getShell();
2714+
if (browserShell == null || browserShell.isDisposed() || (browserShell.getStyle() & SWT.TOOL) == SWT.TOOL) {
2715+
/*
2716+
* We don't provide search capabilities for browsers in a pop-up.
2717+
* We could cause issues with pop-up focus handling when the search shell is opened.
2718+
*/
2719+
return;
2720+
}
2721+
Shell shell = new Shell(browserShell, SWT.TOOL | SWT.MODELESS);
2722+
Rectangle browserArea = browser.getClientArea();
2723+
int height = 45;
2724+
Point location;
2725+
if (searchShellLocation != null) {
2726+
location = searchShellLocation;
2727+
} else {
2728+
location = browser.toDisplay(0, 0);
2729+
location.y += Math.max(0, browserArea.height - height);
2730+
}
2731+
shell.setLocation(location);
2732+
shell.setSize(250, height);
2733+
GridLayout l = new GridLayout();
2734+
l.marginWidth = 8;
2735+
l.marginHeight = 8;
2736+
l.numColumns = 4;
2737+
shell.setLayout(l);
2738+
Text text = new Text(shell, SWT.BORDER);
2739+
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
2740+
Cursor defaultCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_ARROW);
2741+
Button next = new Button(shell, SWT.FLAT | SWT.ARROW | SWT.DOWN);
2742+
next.setCursor(defaultCursor);
2743+
Button previous = new Button(shell, SWT.FLAT | SWT.ARROW | SWT.UP);
2744+
previous.setCursor(defaultCursor);
2745+
shell.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZEALL));
2746+
boolean[] mouseDown = new boolean[1];
2747+
int[] xPos = new int[1];
2748+
int[] yPos = new int[1];
2749+
shell.addMouseListener(new MouseAdapter() {
2750+
@Override
2751+
public void mouseUp(MouseEvent arg0) {
2752+
mouseDown[0] = false;
2753+
}
2754+
@Override
2755+
public void mouseDown(MouseEvent e) {
2756+
mouseDown[0] = true;
2757+
xPos[0] = e.x;
2758+
yPos[0] = e.y;
2759+
}
2760+
});
2761+
shell.addMouseMoveListener(e -> {
2762+
if (mouseDown[0]) {
2763+
shell.setLocation(shell.getLocation().x + (e.x - xPos[0]), shell.getLocation().y + (e.y - yPos[0]));
2764+
}
2765+
});
2766+
long findController = WebKitGTK.webkit_web_view_get_find_controller(webView);
2767+
Runnable searchNext = () -> search(findController, text::getText, WebKitGTK::webkit_find_controller_search_next);
2768+
Runnable searchPrevious = () -> search(findController, text::getText, WebKitGTK::webkit_find_controller_search_previous);
2769+
next.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> searchNext.run()));
2770+
previous.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> searchPrevious.run()));
2771+
text.addKeyListener(KeyListener.keyPressedAdapter(e -> {
2772+
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
2773+
searchNext.run();
2774+
}
2775+
}));
2776+
shell.addDisposeListener(e -> {
2777+
searchShellLocation = searchShell.getLocation();
2778+
WebKitGTK.webkit_find_controller_search_finish(findController);
2779+
searchShell = null;
2780+
});
2781+
shell.open();
2782+
searchShell = shell;
2783+
}
2784+
2785+
private void search(long findController, Supplier<String> currentText, Consumer<Long> incrementSearch) {
2786+
int maxMatchesCount = WebKitGTK.G_MAXUINT; // TODO: how to set no max count here?
2787+
int searchOptions = WebKitGTK.WEBKIT_FIND_OPTIONS_WRAP_AROUND;
2788+
String text = currentText.get();
2789+
if (!text.equals(searchText)) {
2790+
if (searchText != null) {
2791+
WebKitGTK.webkit_find_controller_search_finish(findController);
2792+
}
2793+
searchText = text;
2794+
byte[] textToSearch = Converter.wcsToMbcs(searchText, true);
2795+
WebKitGTK.webkit_find_controller_search(findController, textToSearch, searchOptions, maxMatchesCount);
2796+
} else {
2797+
incrementSearch.accept(Long.valueOf(findController));
2798+
}
2799+
}
2800+
26682801
static Object convertToJava (long ctx, long value) {
26692802
int type = WebKitGTK.JSValueGetType (ctx, value);
26702803
switch (type) {

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public class WebKitGTK extends C {
9090
public static final int WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START = 0;
9191
public static final int WEBKIT_USER_CONTENT_INJECT_TOP_FRAME = 1;
9292

93+
public static final int G_MAXUINT = 65535;
94+
public static final int WEBKIT_FIND_OPTIONS_WRAP_AROUND = 1 << 4;
95+
9396
/** Signals */
9497

9598
// Authentication.

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,10 @@ long gtk_switch_page(long notebook, long page, int page_num) {
589589

590590
if (GTK.GTK4) {
591591
Control control = item.getControl();
592-
control.setBoundsInPixels(getClientAreaInPixels());
592+
if (control != null && !control.isDisposed()) {
593+
control.setBoundsInPixels(getClientAreaInPixels());
594+
control.setVisible(true);
595+
}
593596
} else {
594597
int index = GTK.gtk_notebook_get_current_page(handle);
595598
if (index != -1) {

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -762,20 +762,30 @@ long gtk_enter_notify_event (long widget, long event) {
762762
if (imageList != null) {
763763
int index = imageList.indexOf(hotImage);
764764
if (index != -1 && imageHandle != 0) {
765-
if (GTK.GTK4) {
766-
long pixbuf = ImageList.createPixbuf(hotImage);
767-
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
768-
OS.g_object_unref(pixbuf);
769-
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
770-
} else {
771-
GTK3.gtk_image_set_from_surface(imageHandle, imageList.getSurface(index));
772-
}
765+
GTK3.gtk_image_set_from_surface(imageHandle, imageList.getSurface(index));
773766
}
774767
}
775768
}
776769
return 0;
777770
}
778771

772+
@Override
773+
void gtk4_enter_event(long controller, double x, double y, long event) {
774+
drawHotImage = (parent.style & SWT.FLAT) != 0 && hotImage != null;
775+
if (drawHotImage) {
776+
ImageList imageList = parent.imageList;
777+
if (imageList != null) {
778+
int index = imageList.indexOf(hotImage);
779+
if (index != -1 && imageHandle != 0) {
780+
long pixbuf = ImageList.createPixbuf(hotImage);
781+
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
782+
OS.g_object_unref(pixbuf);
783+
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
784+
}
785+
}
786+
}
787+
}
788+
779789
@Override
780790
long gtk_event_after (long widget, long gdkEvent) {
781791
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
@@ -826,21 +836,33 @@ long gtk_leave_notify_event (long widget, long event) {
826836
if (imageList != null) {
827837
int index = imageList.indexOf(image);
828838
if (index != -1 && imageHandle != 0) {
829-
if (GTK.GTK4) {
830-
long pixbuf = ImageList.createPixbuf(image);
831-
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
832-
OS.g_object_unref(pixbuf);
833-
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
834-
} else {
835-
GTK3.gtk_image_set_from_surface(imageHandle, imageList.getSurface(index));
836-
}
839+
GTK3.gtk_image_set_from_surface(imageHandle, imageList.getSurface(index));
837840
}
838841
}
839842
}
840843
}
841844
return 0;
842845
}
843846

847+
@Override
848+
void gtk4_leave_event(long controller, long event) {
849+
if (drawHotImage) {
850+
drawHotImage = false;
851+
if (image != null) {
852+
ImageList imageList = parent.imageList;
853+
if (imageList != null) {
854+
int index = imageList.indexOf(image);
855+
if (index != -1 && imageHandle != 0) {
856+
long pixbuf = ImageList.createPixbuf(image);
857+
long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf);
858+
OS.g_object_unref(pixbuf);
859+
GTK4.gtk_image_set_from_paintable(imageHandle, texture);
860+
}
861+
}
862+
}
863+
}
864+
}
865+
844866
@Override
845867
long gtk_map (long widget) {
846868
parent.fixZOrder ();

tests/org.eclipse.swt.tests/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@
7878
<dependency>
7979
<groupId>org.junit.vintage</groupId>
8080
<artifactId>junit-vintage-engine</artifactId>
81-
<version>5.13.1</version>
81+
<version>5.13.2</version>
8282
</dependency>
8383
<dependency>
8484
<groupId>org.junit.platform</groupId>
8585
<artifactId>junit-platform-suite-engine</artifactId>
86-
<version>1.13.1</version>
86+
<version>1.13.2</version>
8787
</dependency>
8888
</dependencies>
8989
</plugin>

0 commit comments

Comments
 (0)