forked from jcefmaven/jcefbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a7.patch
2307 lines (2215 loc) · 92.1 KB
/
a7.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9d3db08..8bab7e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -130,7 +130,7 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON)
# Specify the CEF distribution version.
if(NOT DEFINED CEF_VERSION)
- set(CEF_VERSION "116.0.19+gc6a20bc+chromium-116.0.5845.141")
+ set(CEF_VERSION "116.0.27+gd8c85ac+chromium-116.0.5845.190")
endif()
# Determine the platform.
diff --git a/java/org/cef/CefClient.java b/java/org/cef/CefClient.java
index 7f87bc5..740dd25 100644
--- a/java/org/cef/CefClient.java
+++ b/java/org/cef/CefClient.java
@@ -85,20 +85,6 @@ public class CefClient extends CefClientHandler
private CefPrintHandler printHandler_ = null;
private CefRequestHandler requestHandler_ = null;
private boolean isDisposed_ = false;
- private volatile CefBrowser focusedBrowser_ = null;
- private final PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- if (focusedBrowser_ != null) {
- Component browserUI = focusedBrowser_.getUIComponent();
- Object oldUI = evt.getOldValue();
- if (isPartOf(oldUI, browserUI)) {
- focusedBrowser_.setFocus(false);
- focusedBrowser_ = null;
- }
- }
- }
- };
/**
* The CTOR is only accessible within this package.
@@ -108,20 +94,6 @@ public class CefClient extends CefClientHandler
*/
CefClient() throws UnsatisfiedLinkError {
super();
-
- KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(
- propertyChangeListener);
- }
-
- private boolean isPartOf(Object obj, Component browserUI) {
- if (obj == browserUI) return true;
- if (obj instanceof Container) {
- Component childs[] = ((Container) obj).getComponents();
- for (Component child : childs) {
- return isPartOf(child, browserUI);
- }
- }
- return false;
}
@Override
@@ -133,15 +105,15 @@ public class CefClient extends CefClientHandler
// CefClientHandler
public CefBrowser createBrowser(
- String url, boolean isOffscreenRendered, boolean isTransparent) {
- return createBrowser(url, isOffscreenRendered, isTransparent, null);
+ String url, boolean isTransparent) {
+ return createBrowser(url, isTransparent, null);
}
- public CefBrowser createBrowser(String url, boolean isOffscreenRendered, boolean isTransparent,
+ public CefBrowser createBrowser(String url, boolean isTransparent,
CefRequestContext context) {
if (isDisposed_)
throw new IllegalStateException("Can't create browser. CefClient is disposed");
- return CefBrowserFactory.create(this, url, isOffscreenRendered, isTransparent, context);
+ return CefBrowserFactory.create(this, url, isTransparent, context);
}
@Override
@@ -405,27 +377,6 @@ public class CefClient extends CefClientHandler
public void onTakeFocus(CefBrowser browser, boolean next) {
if (browser == null) return;
- browser.setFocus(false);
- Container parent = browser.getUIComponent().getParent();
- if (parent != null) {
- FocusTraversalPolicy policy = null;
- while (parent != null) {
- policy = parent.getFocusTraversalPolicy();
- if (policy != null) break;
- parent = parent.getParent();
- }
- if (policy != null) {
- Component nextComp = next
- ? policy.getComponentAfter(parent, browser.getUIComponent())
- : policy.getComponentBefore(parent, browser.getUIComponent());
- if (nextComp == null) {
- policy.getDefaultComponent(parent).requestFocus();
- } else {
- nextComp.requestFocus();
- }
- }
- }
- focusedBrowser_ = null;
if (focusHandler_ != null) focusHandler_.onTakeFocus(browser, next);
}
@@ -442,8 +393,6 @@ public class CefClient extends CefClientHandler
public void onGotFocus(CefBrowser browser) {
if (browser == null) return;
- focusedBrowser_ = browser;
- browser.setFocus(true);
if (focusHandler_ != null) focusHandler_.onGotFocus(browser);
}
@@ -584,8 +533,6 @@ public class CefClient extends CefClientHandler
}
if (browser_.isEmpty() && isDisposed_) {
- KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(
- propertyChangeListener);
removeContextMenuHandler(this);
removeDialogHandler(this);
removeDisplayHandler(this);
diff --git a/java/org/cef/browser/CefBrowser.java b/java/org/cef/browser/CefBrowser.java
index 43ae8f6..6f5e9fa 100644
--- a/java/org/cef/browser/CefBrowser.java
+++ b/java/org/cef/browser/CefBrowser.java
@@ -14,7 +14,6 @@ import org.cef.handler.CefWindowHandler;
import org.cef.misc.CefPdfPrintSettings;
import org.cef.network.CefRequest;
-import java.awt.Component;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.Vector;
@@ -31,12 +30,6 @@ public interface CefBrowser {
*/
public void createImmediately();
- /**
- * Get the underlying UI component (e.g. java.awt.Canvas).
- * @return The underlying UI component.
- */
- public Component getUIComponent();
-
/**
* Get the client associated with this browser.
* @return The browser client.
@@ -380,4 +373,16 @@ public interface CefBrowser {
* @throws UnsupportedOperationException if not supported
*/
public CompletableFuture<BufferedImage> createScreenshot(boolean nativeResolution);
+
+ /**
+ * Get the windowless max frame rate
+ * @return The max frame rate
+ */
+ public int getWindowlessFrameRate();
+
+ /**
+ * Set the windowless max frame rate
+ * @param framerate The frame rate
+ */
+ public void setWindowlessFrameRate(int framerate);
}
diff --git a/java/org/cef/browser/CefBrowserFactory.java b/java/org/cef/browser/CefBrowserFactory.java
index 708d0f2..98a1678 100644
--- a/java/org/cef/browser/CefBrowserFactory.java
+++ b/java/org/cef/browser/CefBrowserFactory.java
@@ -10,9 +10,8 @@ import org.cef.CefClient;
* Creates a new instance of CefBrowser according the passed values
*/
public class CefBrowserFactory {
- public static CefBrowser create(CefClient client, String url, boolean isOffscreenRendered,
+ public static CefBrowser create(CefClient client, String url,
boolean isTransparent, CefRequestContext context) {
- if (isOffscreenRendered) return new CefBrowserOsr(client, url, isTransparent, context);
- return new CefBrowserWr(client, url, context);
+ return new CefBrowserOsr(client, url, isTransparent, context);
}
}
diff --git a/java/org/cef/browser/CefBrowserOsr.java b/java/org/cef/browser/CefBrowserOsr.java
index 902bc86..9e79df1 100644
--- a/java/org/cef/browser/CefBrowserOsr.java
+++ b/java/org/cef/browser/CefBrowserOsr.java
@@ -4,68 +4,21 @@
package org.cef.browser;
-import com.jogamp.nativewindow.NativeSurface;
-import com.jogamp.opengl.GL;
-import com.jogamp.opengl.GL2;
-import com.jogamp.opengl.GLAutoDrawable;
-import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLContext;
-import com.jogamp.opengl.GLEventListener;
-import com.jogamp.opengl.GLProfile;
-import com.jogamp.opengl.awt.GLCanvas;
-import com.jogamp.opengl.util.GLBuffers;
-
import org.cef.CefClient;
-import org.cef.OS;
import org.cef.callback.CefDragData;
import org.cef.handler.CefRenderHandler;
import org.cef.handler.CefScreenInfo;
import java.awt.Component;
-import java.awt.Cursor;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
import java.awt.Point;
import java.awt.Rectangle;
-import java.awt.datatransfer.StringSelection;
import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
-import java.awt.dnd.DragSourceAdapter;
-import java.awt.dnd.DragSourceDropEvent;
-import java.awt.dnd.DropTarget;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
-import java.awt.geom.AffineTransform;
-import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
-import java.lang.ClassNotFoundException;
-import java.lang.IllegalAccessException;
-import java.lang.IllegalArgumentException;
-import java.lang.NoSuchMethodException;
-import java.lang.SecurityException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import javax.swing.MenuSelectionManager;
-import javax.swing.SwingUtilities;
/**
* This class represents an off-screen rendered browser.
@@ -73,9 +26,6 @@ import javax.swing.SwingUtilities;
* CefBrowser instance, please use CefBrowserFactory.
*/
class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
- private CefRenderer renderer_;
- private GLCanvas canvas_;
- private long window_handle_ = 0;
private boolean justCreated_ = false;
private Rectangle browser_rect_ = new Rectangle(0, 0, 1, 1); // Work around CEF issue #1437.
private Point screenPoint_ = new Point(0, 0);
@@ -92,8 +42,6 @@ class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
CefRequestContext context, CefBrowserOsr parent, Point inspectAt) {
super(client, url, context, parent, inspectAt);
isTransparent_ = transparent;
- renderer_ = new CefRenderer(transparent);
- createGLCanvas();
}
@Override
@@ -103,11 +51,6 @@ class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
createBrowserIfRequired(false);
}
- @Override
- public Component getUIComponent() {
- return canvas_;
- }
-
@Override
public CefRenderHandler getRenderHandler() {
return this;
@@ -120,215 +63,6 @@ class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
client, url, isTransparent_, context, (CefBrowserOsr) this, inspectAt);
}
- private synchronized long getWindowHandle() {
- if (window_handle_ == 0) {
- NativeSurface surface = canvas_.getNativeSurface();
- if (surface != null) {
- surface.lockSurface();
- window_handle_ = getWindowHandle(surface.getSurfaceHandle());
- surface.unlockSurface();
- assert (window_handle_ != 0);
- }
- }
- return window_handle_;
- }
-
- @SuppressWarnings("serial")
- private void createGLCanvas() {
- GLProfile glprofile = GLProfile.getMaxFixedFunc(true);
- GLCapabilities glcapabilities = new GLCapabilities(glprofile);
- canvas_ = new GLCanvas(glcapabilities) {
- private Method scaleFactorAccessor = null;
- private boolean removed_ = true;
-
- @Override
- public void paint(Graphics g) {
- createBrowserIfRequired(true);
- if (g instanceof Graphics2D) {
- GraphicsConfiguration config = ((Graphics2D) g).getDeviceConfiguration();
- depth = config.getColorModel().getPixelSize();
- depth_per_component = config.getColorModel().getComponentSize()[0];
-
- if (OS.isMacintosh()
- && System.getProperty("java.runtime.version").startsWith("1.8")) {
- // This fixes a weird thing on MacOS: the scale factor being read from
- // getTransform().getScaleX() is incorrect for Java 8 VMs; it is always
- // 1, even though Retina display scaling of window sizes etc. is
- // definitely ongoing somewhere in the lower levels of AWT. This isn't
- // too big of a problem for us, because the transparent scaling handles
- // the situation, except for one thing: the screenshot-grabbing
- // code below, which reads from the OpenGL context, must know the real
- // scale factor, because the image to be read is larger by that factor
- // and thus a bigger buffer is required. This is why there's some
- // admittedly-ugly reflection magic going on below that's able to get
- // the real scale factor.
- // All of this is not relevant for either Windows or MacOS JDKs > 8,
- // for which the official "getScaleX()" approach works fine.
- try {
- if (scaleFactorAccessor == null) {
- scaleFactorAccessor = getClass()
- .getClassLoader()
- .loadClass("sun.awt.CGraphicsDevice")
- .getDeclaredMethod("getScaleFactor");
- }
- Object factor = scaleFactorAccessor.invoke(config.getDevice());
- if (factor instanceof Integer) {
- scaleFactor_ = ((Integer) factor).doubleValue();
- } else {
- scaleFactor_ = 1.0;
- }
- } catch (InvocationTargetException | IllegalAccessException
- | IllegalArgumentException | NoSuchMethodException
- | SecurityException | ClassNotFoundException exc) {
- scaleFactor_ = 1.0;
- }
- } else {
- scaleFactor_ = ((Graphics2D) g).getTransform().getScaleX();
- }
- }
- super.paint(g);
- }
-
- @Override
- public void addNotify() {
- super.addNotify();
- if (removed_) {
- notifyAfterParentChanged();
- removed_ = false;
- }
- }
-
- @Override
- public void removeNotify() {
- if (!removed_) {
- if (!isClosed()) {
- notifyAfterParentChanged();
- }
- removed_ = true;
- }
- super.removeNotify();
- }
- };
-
- // The GLContext will be re-initialized when changing displays, resulting in calls to
- // dispose/init/reshape.
- canvas_.addGLEventListener(new GLEventListener() {
- @Override
- public void reshape(
- GLAutoDrawable glautodrawable, int x, int y, int width, int height) {
- int newWidth = width;
- int newHeight = height;
- if (OS.isMacintosh()) {
- // HiDPI display scale correction support code
- // For some reason this does seem to be necessary on MacOS only.
- // If doing this correction on Windows, the browser content would be too
- // small and in the lower left corner of the canvas only.
- newWidth = (int) (width / scaleFactor_);
- newHeight = (int) (height / scaleFactor_);
- }
- browser_rect_.setBounds(x, y, newWidth, newHeight);
- screenPoint_ = canvas_.getLocationOnScreen();
- wasResized(newWidth, newHeight);
- }
-
- @Override
- public void init(GLAutoDrawable glautodrawable) {
- renderer_.initialize(glautodrawable.getGL().getGL2());
- }
-
- @Override
- public void dispose(GLAutoDrawable glautodrawable) {
- renderer_.cleanup(glautodrawable.getGL().getGL2());
- }
-
- @Override
- public void display(GLAutoDrawable glautodrawable) {
- renderer_.render(glautodrawable.getGL().getGL2());
- }
- });
-
- canvas_.addMouseListener(new MouseListener() {
- @Override
- public void mousePressed(MouseEvent e) {
- sendMouseEvent(e);
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- sendMouseEvent(e);
- }
-
- @Override
- public void mouseEntered(MouseEvent e) {
- sendMouseEvent(e);
- }
-
- @Override
- public void mouseExited(MouseEvent e) {
- sendMouseEvent(e);
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- sendMouseEvent(e);
- }
- });
-
- canvas_.addMouseMotionListener(new MouseMotionListener() {
- @Override
- public void mouseMoved(MouseEvent e) {
- sendMouseEvent(e);
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {
- sendMouseEvent(e);
- }
- });
-
- canvas_.addMouseWheelListener(new MouseWheelListener() {
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- sendMouseWheelEvent(e);
- }
- });
-
- canvas_.addKeyListener(new KeyListener() {
- @Override
- public void keyTyped(KeyEvent e) {
- sendKeyEvent(e);
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- sendKeyEvent(e);
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- sendKeyEvent(e);
- }
- });
-
- canvas_.setFocusable(true);
- canvas_.addFocusListener(new FocusListener() {
- @Override
- public void focusLost(FocusEvent e) {
- setFocus(false);
- }
-
- @Override
- public void focusGained(FocusEvent e) {
- // Dismiss any Java menus that are currently displayed.
- MenuSelectionManager.defaultManager().clearSelectedPath();
- setFocus(true);
- }
- });
-
- // Connect the Canvas with a drag and drop listener.
- new DropTarget(canvas_, new CefDropTargetListener(this));
- }
-
@Override
public Rectangle getViewRect(CefBrowser browser) {
return browser_rect_;
@@ -343,50 +77,19 @@ class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
@Override
public void onPopupShow(CefBrowser browser, boolean show) {
- if (!show) {
- renderer_.clearPopupRects();
- invalidate();
- }
}
@Override
public void onPopupSize(CefBrowser browser, Rectangle size) {
- renderer_.onPopupSize(size);
}
@Override
public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects,
ByteBuffer buffer, int width, int height) {
- // if window is closing, canvas_ or opengl context could be null
- final GLContext context = canvas_ != null ? canvas_.getContext() : null;
-
- if (context == null) {
- return;
- }
-
- // This result can occur due to GLContext re-initialization when changing displays.
- if (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
- return;
- }
-
- renderer_.onPaint(canvas_.getGL().getGL2(), popup, dirtyRects, buffer, width, height);
- context.release();
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- canvas_.display();
- }
- });
}
@Override
public boolean onCursorChange(CefBrowser browser, final int cursorType) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- canvas_.setCursor(new Cursor(cursorType));
- }
- });
-
- // OSR always handles the cursor change.
return true;
}
@@ -419,35 +122,15 @@ class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
@Override
public boolean startDragging(CefBrowser browser, CefDragData dragData, int mask, int x, int y) {
- int action = getDndAction(mask);
- MouseEvent triggerEvent =
- new MouseEvent(canvas_, MouseEvent.MOUSE_DRAGGED, 0, 0, x, y, 0, false);
- DragGestureEvent ev = new DragGestureEvent(
- new SyntheticDragGestureRecognizer(canvas_, action, triggerEvent), action,
- new Point(x, y), new ArrayList<>(Arrays.asList(triggerEvent)));
-
- DragSource.getDefaultDragSource().startDrag(ev, /*dragCursor=*/null,
- new StringSelection(dragData.getFragmentText()), new DragSourceAdapter() {
- @Override
- public void dragDropEnd(DragSourceDropEvent dsde) {
- dragSourceEndedAt(dsde.getLocation(), action);
- dragSourceSystemDragEnded();
- }
- });
return true;
}
@Override
public void updateDragCursor(CefBrowser browser, int operation) {
- // TODO: Consider calling onCursorChange() if we want different cursors based on
- // |operation|.
}
private void createBrowserIfRequired(boolean hasParent) {
long windowHandle = 0;
- if (hasParent) {
- windowHandle = getWindowHandle();
- }
if (getNativeRef("CefBrowser") == 0) {
if (getParentBrowser() != null) {
@@ -480,159 +163,6 @@ class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
@Override
public CompletableFuture<BufferedImage> createScreenshot(boolean nativeResolution) {
- int width = (int) Math.ceil(canvas_.getWidth() * scaleFactor_);
- int height = (int) Math.ceil(canvas_.getHeight() * scaleFactor_);
-
- // In order to grab a screenshot of the browser window, we need to get the OpenGL internals
- // from the GLCanvas that displays the browser.
- GL2 gl = canvas_.getGL().getGL2();
- int textureId = renderer_.getTextureID();
-
- // This mirrors the two ways in which CefRenderer may render images internally - either via
- // an incrementally updated texture that is the same size as the window and simply rendered
- // onto a textured quad by graphics hardware, in which case we capture the data directly
- // from this texture, or by directly writing pixels into the OpenGL framebuffer, in which
- // case we directly read those pixels back. The latter is the way chosen if there is no
- // hardware rasterizer capability detected. We can simply distinguish both approaches by
- // looking whether the textureId of the renderer is a valid (non-zero) one.
- boolean useReadPixels = (textureId == 0);
-
- // This Callable encapsulates the pixel-reading code. After running it, the screenshot
- // BufferedImage contains the grabbed image.
- final Callable<BufferedImage> pixelGrabberCallable = new Callable<BufferedImage>() {
- @Override
- public BufferedImage call() {
- BufferedImage screenshot =
- new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- ByteBuffer buffer = GLBuffers.newDirectByteBuffer(width * height * 4);
-
- gl.getContext().makeCurrent();
- try {
- if (useReadPixels) {
- // If pixels are copied directly to the framebuffer, we also directly read
- // them back.
- gl.glReadPixels(
- 0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer);
- } else {
- // In this case, read the texture pixel data from the previously-retrieved
- // texture ID
- gl.glEnable(GL.GL_TEXTURE_2D);
- gl.glBindTexture(GL.GL_TEXTURE_2D, textureId);
- gl.glGetTexImage(
- GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer);
- gl.glDisable(GL.GL_TEXTURE_2D);
- }
- } finally {
- gl.getContext().release();
- }
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- // The OpenGL functions only support RGBA, while Java BufferedImage uses
- // ARGB. We must convert.
- int r = (buffer.get() & 0xff);
- int g = (buffer.get() & 0xff);
- int b = (buffer.get() & 0xff);
- int a = (buffer.get() & 0xff);
- int argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
- // If pixels were read from the framebuffer, we have to flip the resulting
- // image on the Y axis, as the OpenGL framebuffer's y axis starts at the
- // bottom of the image pointing "upwards", while BufferedImage has the
- // origin in the upper left corner. This flipping is done when drawing into
- // the BufferedImage.
- screenshot.setRGB(x, useReadPixels ? (height - y - 1) : y, argb);
- }
- }
-
- if (!nativeResolution && scaleFactor_ != 1.0) {
- // HiDPI images should be resized down to "normal" levels
- BufferedImage resized =
- new BufferedImage((int) (screenshot.getWidth() / scaleFactor_),
- (int) (screenshot.getHeight() / scaleFactor_),
- BufferedImage.TYPE_INT_ARGB);
- AffineTransform tempTransform = new AffineTransform();
- tempTransform.scale(1.0 / scaleFactor_, 1.0 / scaleFactor_);
- AffineTransformOp tempScaleOperation =
- new AffineTransformOp(tempTransform, AffineTransformOp.TYPE_BILINEAR);
- resized = tempScaleOperation.filter(screenshot, resized);
- return resized;
- } else {
- return screenshot;
- }
- }
- };
-
- if (SwingUtilities.isEventDispatchThread()) {
- // If called on the AWT event thread, just access the GL API
- try {
- BufferedImage screenshot = pixelGrabberCallable.call();
- return CompletableFuture.completedFuture(screenshot);
- } catch (Exception e) {
- CompletableFuture<BufferedImage> future = new CompletableFuture<BufferedImage>();
- future.completeExceptionally(e);
- return future;
- }
- } else {
- // If called from another thread, register a GLEventListener and trigger an async
- // redraw, during which we use the GL API to grab the pixel data. An unresolved Future
- // is returned, on which the caller can wait for a result (but not with the Event
- // Thread, as we need that for pixel grabbing, which is why there's a safeguard in place
- // to catch that situation if it accidentally happens).
- CompletableFuture<BufferedImage> future = new CompletableFuture<BufferedImage>() {
- private void safeguardGet() {
- if (SwingUtilities.isEventDispatchThread()) {
- throw new RuntimeException(
- "Waiting on this Future using the AWT Event Thread is illegal, "
- + "because it can potentially deadlock the thread.");
- }
- }
-
- @Override
- public BufferedImage get() throws InterruptedException, ExecutionException {
- safeguardGet();
- return super.get();
- }
-
- @Override
- public BufferedImage get(long timeout, TimeUnit unit)
- throws InterruptedException, ExecutionException, TimeoutException {
- safeguardGet();
- return super.get(timeout, unit);
- }
- };
- canvas_.addGLEventListener(new GLEventListener() {
- @Override
- public void reshape(
- GLAutoDrawable aDrawable, int aArg1, int aArg2, int aArg3, int aArg4) {
- // ignore
- }
-
- @Override
- public void init(GLAutoDrawable aDrawable) {
- // ignore
- }
-
- @Override
- public void dispose(GLAutoDrawable aDrawable) {
- // ignore
- }
-
- @Override
- public void display(GLAutoDrawable aDrawable) {
- canvas_.removeGLEventListener(this);
- try {
- future.complete(pixelGrabberCallable.call());
- } catch (Exception e) {
- future.completeExceptionally(e);
- }
- }
- });
-
- // This repaint triggers an indirect call to the listeners' display method above, which
- // ultimately completes the future that we return immediately.
- canvas_.repaint();
-
- return future;
- }
+ return null;
}
}
diff --git a/java/org/cef/browser/CefBrowserWr.java b/java/org/cef/browser/CefBrowserWr.java
deleted file mode 100644
index 583c4f4..0000000
--- a/java/org/cef/browser/CefBrowserWr.java
+++ /dev/null
@@ -1,424 +0,0 @@
-// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
-// reserved. Use of this source code is governed by a BSD-style license that
-// can be found in the LICENSE file.
-
-package org.cef.browser;
-
-import org.cef.CefClient;
-import org.cef.OS;
-import org.cef.handler.CefWindowHandler;
-import org.cef.handler.CefWindowHandlerAdapter;
-
-import java.awt.BorderLayout;
-import java.awt.Canvas;
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.MouseInfo;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.Window;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
-import java.awt.event.HierarchyBoundsListener;
-import java.awt.event.HierarchyEvent;
-import java.awt.event.HierarchyListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseWheelEvent;
-import java.awt.image.BufferedImage;
-import java.util.Date;
-import java.util.concurrent.CompletableFuture;
-
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-import javax.swing.MenuSelectionManager;
-import javax.swing.SwingUtilities;
-import javax.swing.Timer;
-import javax.swing.ToolTipManager;
-
-/**
- * This class represents a windowed rendered browser.
- * The visibility of this class is "package". To create a new
- * CefBrowser instance, please use CefBrowserFactory.
- */
-class CefBrowserWr extends CefBrowser_N {
- private Canvas canvas_ = null;
- private Component component_ = null;
- private Rectangle content_rect_ = new Rectangle(0, 0, 0, 0);
- private long window_handle_ = 0;
- private boolean justCreated_ = false;
- private double scaleFactor_ = 1.0;
- private Timer delayedUpdate_ = new Timer(100, new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- if (isClosed()) return;
-
- boolean hasCreatedUI = createBrowserIfRequired(true);
-
- if (hasCreatedUI) {
- delayedUpdate_.restart();
- } else {
- // If on Mac, this is needed due to the quirk described below
- // (in org.cef.browser.CefBrowserWr.CefBrowserWr(...).new JPanel()
- // {...}.paint(Graphics)). If on Linux, this is needed to invoke an
- // XMoveResizeWindow call shortly after the UI was created. That seems to be
- // necessary to actually get a windowed renderer to display something.
- if (OS.isMacintosh() || OS.isLinux()) doUpdate();
- }
- }
- });
- }
- });
-
- private CefWindowHandlerAdapter win_handler_ = new CefWindowHandlerAdapter() {
- private Point lastPos = new Point(-1, -1);
- private long[] nextClick = new long[MouseInfo.getNumberOfButtons()];
- private int[] clickCnt = new int[MouseInfo.getNumberOfButtons()];
-
- @Override
- public Rectangle getRect(CefBrowser browser) {
- synchronized (content_rect_) {
- return content_rect_;
- }
- }
-
- @Override
- public void onMouseEvent(CefBrowser browser, int event, final int screenX,
- final int screenY, final int modifier, final int button) {
- final Point pt = new Point(screenX, screenY);
- if (event == MouseEvent.MOUSE_MOVED) {
- // Remove mouse-moved events if the position of the cursor hasn't
- // changed.
- if (pt.equals(lastPos)) return;
- lastPos = pt;
-
- // Change mouse-moved event to mouse-dragged event if the left mouse
- // button is pressed.
- if ((modifier & MouseEvent.BUTTON1_DOWN_MASK) != 0)
- event = MouseEvent.MOUSE_DRAGGED;
- }
-
- final int finalEvent = event;
-
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- // Send mouse event to the root UI component instead to the browser UI.
- // Otherwise no mouse-entered and no mouse-exited events would be fired.
- Component parent = SwingUtilities.getRoot(component_);
- if (parent == null) {
- return;
- }
- SwingUtilities.convertPointFromScreen(pt, parent);
-
- int clickCnt = 0;
- long now = new Date().getTime();
- if (finalEvent == MouseEvent.MOUSE_WHEEL) {
- int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL;
- int rotation = button > 0 ? 1 : -1;
- component_.dispatchEvent(new MouseWheelEvent(parent, finalEvent, now,
- modifier, pt.x, pt.y, 0, false, scrollType, 3, rotation));
- } else {
- clickCnt = getClickCount(finalEvent, button);
- component_.dispatchEvent(new MouseEvent(parent, finalEvent, now, modifier,
- pt.x, pt.y, screenX, screenY, clickCnt, false, button));
- }
-
- // Always fire a mouse-clicked event after a mouse-released event.
- if (finalEvent == MouseEvent.MOUSE_RELEASED) {
- component_.dispatchEvent(
- new MouseEvent(parent, MouseEvent.MOUSE_CLICKED, now, modifier,
- pt.x, pt.y, screenX, screenY, clickCnt, false, button));
- }
- }
- });
- }
-
- public int getClickCount(int event, int button) {
- // avoid exceptions by using modulo
- int idx = button % nextClick.length;
-
- switch (event) {
- case MouseEvent.MOUSE_PRESSED:
- long currTime = new Date().getTime();
- if (currTime > nextClick[idx]) {
- nextClick[idx] = currTime
- + (Integer) Toolkit.getDefaultToolkit().getDesktopProperty(
- "awt.multiClickInterval");
- clickCnt[idx] = 1;
- } else {
- clickCnt[idx]++;
- }
- // FALL THRU
- case MouseEvent.MOUSE_RELEASED:
- return clickCnt[idx];
- default:
- return 0;
- }
- }
- };
-
- CefBrowserWr(CefClient client, String url, CefRequestContext context) {
- this(client, url, context, null, null);
- }
-
- @SuppressWarnings("serial")
- private CefBrowserWr(CefClient client, String url, CefRequestContext context,
- CefBrowserWr parent, Point inspectAt) {
- super(client, url, context, parent, inspectAt);
- delayedUpdate_.setRepeats(false);
-
- // Disabling lightweight of popup menu is required because
- // otherwise it will be displayed behind the content of component_
- JPopupMenu.setDefaultLightWeightPopupEnabled(false);
- ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
-
- // We're using a JComponent instead of a Canvas now because the
- // JComponent has clipping informations, which aren't accessible for Canvas.
- component_ = new JPanel(new BorderLayout()) {
- private boolean removed_ = true;
-
- @Override
- public void setBounds(int x, int y, int width, int height) {
- super.setBounds(x, y, width, height);
- wasResized((int) (width * scaleFactor_), (int) (height * scaleFactor_));
- }
-
- @Override
- public void setBounds(Rectangle r) {
- setBounds(r.x, r.y, r.width, r.height);
- }
-
- @Override
- public void setSize(int width, int height) {
- super.setSize(width, height);
- wasResized((int) (width * scaleFactor_), (int) (height * scaleFactor_));
- }
-
- @Override
- public void setSize(Dimension d) {
- setSize(d.width, d.height);
- }
-
- @Override
- public void paint(Graphics g) {
- // If the user resizes the UI component, the new size and clipping
- // informations are forwarded to the native code.
- // But on Mac the last resize information doesn't resize the native UI
- // accurately (sometimes the native UI is too small). An easy way to
- // solve this, is to send the last Update-Information again. Therefore
- // we're setting up a delayedUpdate timer which is reset each time
- // paint is called. This prevents the us of sending the UI update too
- // often.
- if (g instanceof Graphics2D) {
- scaleFactor_ = ((Graphics2D) g).getTransform().getScaleX();
- }
- doUpdate();
- delayedUpdate_.restart();
- }
-
- @Override
- public void addNotify() {
- super.addNotify();
- if (removed_) {
- setParent(getWindowHandle(this), canvas_);
- removed_ = false;
- }
- }
-
- @Override
- public void removeNotify() {
- if (!removed_) {
- if (!isClosed()) {
- setParent(0, null);
- }
- removed_ = true;