|
25 | 25 | import java.util.function.*; |
26 | 26 |
|
27 | 27 | import org.eclipse.swt.*; |
| 28 | +import org.eclipse.swt.events.*; |
28 | 29 | import org.eclipse.swt.graphics.*; |
29 | 30 | import org.eclipse.swt.internal.*; |
30 | 31 | import org.eclipse.swt.internal.gtk.*; |
@@ -96,7 +97,10 @@ class WebKit extends WebBrowser { |
96 | 97 | URI tlsErrorUri; |
97 | 98 | String tlsErrorType; |
98 | 99 |
|
| 100 | + private Shell searchShell; |
| 101 | + |
99 | 102 | boolean firstLoad = true; |
| 103 | + |
100 | 104 | static boolean FirstCreate = true; |
101 | 105 |
|
102 | 106 | /** |
@@ -784,6 +788,12 @@ public void create (Composite parent, int style) { |
784 | 788 | onResize (event); |
785 | 789 | break; |
786 | 790 | } |
| 791 | + case SWT.KeyDown: { |
| 792 | + if (event.keyCode == 'f' && (event.stateMask & SWT.CTRL) == SWT.CTRL) { |
| 793 | + openSearchDialog(); |
| 794 | + } |
| 795 | + break; |
| 796 | + } |
787 | 797 | } |
788 | 798 | }; |
789 | 799 | browser.addListener (SWT.Dispose, listener); |
@@ -2665,6 +2675,74 @@ private void webkit_settings_set(byte [] property, int value) { |
2665 | 2675 | OS.g_object_set(settings, property, value, 0); |
2666 | 2676 | } |
2667 | 2677 |
|
| 2678 | +private void openSearchDialog() { |
| 2679 | + if (searchShell != null && !searchShell.isDisposed()) { |
| 2680 | + return; |
| 2681 | + } |
| 2682 | + /* |
| 2683 | + * TODO: |
| 2684 | + * how to set no max count here? 65535 should be the value of UINT_MAX, |
| 2685 | + * which should be G_MAXUINT, which should be the maximum count here |
| 2686 | + */ |
| 2687 | + int maxMatchesCount = 65535; |
| 2688 | + int searchOptions = 0; |
| 2689 | + Shell shell = new Shell(browser.getShell(), SWT.TOOL | SWT.ON_TOP | SWT.RESIZE); |
| 2690 | + shell.setText("Search for text"); |
| 2691 | + shell.setLayout(new FillLayout()); |
| 2692 | + Point browserLocation = browser.getLocation(); |
| 2693 | + Rectangle browserArea = browser.getClientArea(); |
| 2694 | + Point location = browser.getShell().getLocation(); |
| 2695 | + location.x += browserLocation.x; |
| 2696 | + location.y += browserLocation.y + browserArea.height; |
| 2697 | + shell.setLocation(location); |
| 2698 | + Composite composite = new Composite(shell, SWT.NONE); |
| 2699 | + GridLayout l = new GridLayout(); |
| 2700 | + l.numColumns = 3; |
| 2701 | + composite.setLayout(l); |
| 2702 | + Text text = new Text(composite, SWT.BORDER); |
| 2703 | + Button next = new Button(composite, SWT.FLAT | SWT.ARROW | SWT.DOWN); |
| 2704 | + Button previous = new Button(composite, SWT.FLAT | SWT.ARROW | SWT.UP); |
| 2705 | + |
| 2706 | + AtomicBoolean searched = new AtomicBoolean(false); |
| 2707 | + long findController = WebKitGTK.webkit_web_view_get_find_controller(webView); |
| 2708 | + Runnable searchNext = () -> { |
| 2709 | + if (!searched.getAndSet(true)) { |
| 2710 | + System.out.println("search"); |
| 2711 | + String searchText = text.getText(); |
| 2712 | + WebKitGTK.webkit_find_controller_search(findController, searchText.getBytes(), searchOptions, maxMatchesCount); |
| 2713 | + } else { |
| 2714 | + WebKitGTK.webkit_find_controller_search_next(findController); |
| 2715 | + System.out.println("next"); |
| 2716 | + } |
| 2717 | + }; |
| 2718 | + Runnable searchPrevious = () -> { |
| 2719 | + if (!searched.getAndSet(true)) { |
| 2720 | + String searchText = text.getText(); |
| 2721 | + WebKitGTK.webkit_find_controller_search(findController, searchText.getBytes(), searchOptions, maxMatchesCount); |
| 2722 | + } else { |
| 2723 | + WebKitGTK.webkit_find_controller_search_previous(findController); |
| 2724 | + } |
| 2725 | + }; |
| 2726 | + next.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> searchNext.run())); |
| 2727 | + previous.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> searchPrevious.run())); |
| 2728 | + text.addKeyListener(KeyListener.keyPressedAdapter(e -> { |
| 2729 | + if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { |
| 2730 | + searchNext.run(); |
| 2731 | + } |
| 2732 | + })); |
| 2733 | + text.addModifyListener(e -> { |
| 2734 | + WebKitGTK.webkit_find_controller_search_finish(findController); |
| 2735 | + searched.getAndSet(false); |
| 2736 | + }); |
| 2737 | + shell.addDisposeListener(e -> { |
| 2738 | + WebKitGTK.webkit_find_controller_search_finish(findController); |
| 2739 | + searchShell = null; |
| 2740 | + }); |
| 2741 | + shell.pack(); |
| 2742 | + shell.open(); |
| 2743 | + searchShell = shell; |
| 2744 | +} |
| 2745 | + |
2668 | 2746 | static Object convertToJava (long ctx, long value) { |
2669 | 2747 | int type = WebKitGTK.JSValueGetType (ctx, value); |
2670 | 2748 | switch (type) { |
|
0 commit comments