forked from chromiumembedded/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCefBrowserOsr.java
More file actions
162 lines (136 loc) · 5.42 KB
/
Copy pathCefBrowserOsr.java
File metadata and controls
162 lines (136 loc) · 5.42 KB
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
// 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.callback.CefDragData;
import org.cef.handler.CefRenderHandler;
import org.cef.handler.CefScreenInfo;
import java.awt.*;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;
/**
* This class represents an off-screen rendered browser.
* The visibility of this class is "package". To create a new
* CefBrowser instance, please use CefBrowserFactory.
*/
public class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler {
private boolean justCreated_ = false;
protected Rectangle browser_rect_ = new Rectangle(0, 0, 1, 1); // Work around CEF issue #1437.
private Point screenPoint_ = new Point(0, 0);
private double scaleFactor_ = 1.0;
private int depth = 32;
private int depth_per_component = 8;
private boolean isTransparent_;
public CefBrowserOsr(CefClient client, String url, boolean transparent, CefRequestContext context) {
this(client, url, transparent, context, null, null);
}
private CefBrowserOsr(CefClient client, String url, boolean transparent,
CefRequestContext context, CefBrowserOsr parent, Point inspectAt) {
super(client, url, context, parent, inspectAt);
isTransparent_ = transparent;
}
@Override
public void createImmediately() {
justCreated_ = true;
// Create the browser immediately.
createBrowserIfRequired(false);
}
@Override
public CefRenderHandler getRenderHandler() {
return this;
}
@Override
protected CefBrowser_N createDevToolsBrowser(CefClient client, String url, CefRequestContext context, CefBrowser_N parent, Point inspectAt) {
return null;
}
@Override
public Rectangle getViewRect(CefBrowser browser) {
return browser_rect_;
}
@Override
public Point getScreenPoint(CefBrowser browser, Point viewPoint) {
Point screenPoint = new Point(screenPoint_);
screenPoint.translate(viewPoint.x, viewPoint.y);
return screenPoint;
}
@Override
public void onPopupShow(CefBrowser browser, boolean show) {
}
@Override
public void onPopupSize(CefBrowser browser, Rectangle size) {
}
@Override
public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, ByteBuffer buffer, int width, int height) {
}
@Override
public boolean onCursorChange(CefBrowser browser, final int cursorType) {
return true;
}
private static final class SyntheticDragGestureRecognizer extends DragGestureRecognizer {
public SyntheticDragGestureRecognizer(Component c, int action, MouseEvent triggerEvent) {
super(new DragSource(), c, action);
appendEvent(triggerEvent);
}
protected void registerListeners() {}
protected void unregisterListeners() {}
};
private static int getDndAction(int mask) {
// Default to copy if multiple operations are specified.
int action = DnDConstants.ACTION_NONE;
if ((mask & CefDragData.DragOperations.DRAG_OPERATION_COPY)
== CefDragData.DragOperations.DRAG_OPERATION_COPY) {
action = DnDConstants.ACTION_COPY;
} else if ((mask & CefDragData.DragOperations.DRAG_OPERATION_MOVE)
== CefDragData.DragOperations.DRAG_OPERATION_MOVE) {
action = DnDConstants.ACTION_MOVE;
} else if ((mask & CefDragData.DragOperations.DRAG_OPERATION_LINK)
== CefDragData.DragOperations.DRAG_OPERATION_LINK) {
action = DnDConstants.ACTION_LINK;
}
return action;
}
@Override
public boolean startDragging(CefBrowser browser, CefDragData dragData, int mask, int x, int y) {
return true;
}
@Override
public void updateDragCursor(CefBrowser browser, int operation) {
}
private void createBrowserIfRequired(boolean hasParent) {
long windowHandle = 0;
if (getNativeRef("CefBrowser") == 0) {
if (getParentBrowser() != null) {
createDevTools(getParentBrowser(), getClient(), windowHandle, true, isTransparent_,
getInspectAt());
} else {
createBrowser(getClient(), windowHandle, getUrl(), true, isTransparent_,
getRequestContext());
}
} else if (hasParent && justCreated_) {
notifyAfterParentChanged();
setFocus(true);
justCreated_ = false;
}
}
private void notifyAfterParentChanged() {
// With OSR there is no native window to reparent but we still need to send the
// notification.
getClient().onAfterParentChanged(this);
}
@Override
public boolean getScreenInfo(CefBrowser browser, CefScreenInfo screenInfo) {
screenInfo.Set(scaleFactor_, depth, depth_per_component, false, browser_rect_.getBounds(),
browser_rect_.getBounds());
return true;
}
@Override
public CompletableFuture<BufferedImage> createScreenshot(boolean nativeResolution) {
return null;
}
}