12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.tk.quantum;
27
28 import com.sun.javafx.embed.HostDragStartListener;
29 import javafx.application.Platform;
30 import javafx.collections.ObservableList;
31 import javafx.event.EventType;
32 import javafx.scene.input.InputMethodEvent;
33 import javafx.scene.input.InputMethodRequests;
34 import javafx.scene.input.InputMethodTextRun;
35 import javafx.scene.input.MouseEvent;
36 import javafx.scene.input.ScrollEvent;
37 import javafx.scene.image.PixelFormat;
38 import java.nio.IntBuffer;
39 import java.security.AccessController;
40 import java.security.PrivilegedAction;
41 import com.sun.javafx.cursor.CursorFrame;
42 import com.sun.javafx.embed.AbstractEvents;
43 import com.sun.javafx.embed.EmbeddedSceneDTInterface;
44 import com.sun.javafx.embed.EmbeddedSceneInterface;
45 import com.sun.javafx.embed.HostInterface;
46 import com.sun.javafx.scene.input.KeyCodeMap;
47 import com.sun.javafx.scene.traversal.Direction;
48 import com.sun.javafx.sg.prism.NGNode;
49 import com.sun.javafx.tk.TKClipboard;
50 import com.sun.javafx.tk.Toolkit;
51 import com.sun.prism.paint.Color;
52 import com.sun.prism.paint.Paint;
53 import com.sun.glass.ui.Pixels;
54 import java.nio.ByteOrder;
55
56 final class EmbeddedScene extends GlassScene implements EmbeddedSceneInterface {
57
58 // TODO: synchronize access to embedder from ET and RT
59 private HostInterface host;
60
61 private UploadingPainter painter;
62 private PaintRenderJob paintRenderJob;
198 }
199 return false;
200 }
201
202 @Override
203 public void setSize(final int width, final int height) {
204 Platform.runLater(() -> {
205 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
206 if (sceneListener != null) {
207 sceneListener.changedSize(width, height);
208 }
209 return null;
210 }, getAccessControlContext());
211 });
212 }
213
214 /**
215 * @param dest the destination buffer
216 * @param width the logical width of the buffer
217 * @param height the logical height of the buffer
218 * @param scale the scale factor
219 * @return
220 */
221 @Override
222 public boolean getPixels(final IntBuffer dest, final int width, final int height) {
223 return QuantumToolkit.runWithRenderLock(() -> {
224 int scaledWidth = width;
225 int scaledHeight = height;
226
227 // The dest buffer scale factor is expected to match painter.getPixelScaleFactor().
228 if (getRenderScaleX() != texScaleFactorX ||
229 getRenderScaleY() != texScaleFactorY ||
230 texBits == null)
231 {
232 return false;
233 }
234 scaledWidth = Math.round(scaledWidth * texScaleFactorX);
235 scaledHeight = Math.round(scaledHeight * texScaleFactorY);
236
237 dest.rewind();
238 texBits.rewind();
252 dest.put(linebuf);
253 }
254 return true;
255 }
256 dest.put(texBits);
257 return true;
258 });
259 }
260
261 @Override
262 protected Color getClearColor() {
263 if (fillPaint != null && fillPaint.getType() == Paint.Type.COLOR &&
264 ((Color)fillPaint).getAlpha() == 0f)
265 {
266 return (Color)fillPaint;
267 }
268 return super.getClearColor();
269 }
270
271 @Override
272 public void mouseEvent(final int type, final int button,
273 final boolean primaryBtnDown, final boolean middleBtnDown, final boolean secondaryBtnDown,
274 final int x, final int y, final int xAbs, final int yAbs,
275 final boolean shift, final boolean ctrl, final boolean alt, final boolean meta,
276 final boolean popupTrigger)
277 {
278 Platform.runLater(() -> {
279 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
280 if (sceneListener == null) {
281 return null;
282 }
283 // Click events are generated in Scene, so we don't expect them here
284 assert type != AbstractEvents.MOUSEEVENT_CLICKED;
285 EventType<MouseEvent> eventType = AbstractEvents.mouseIDToFXEventID(type);
286 sceneListener.mouseEvent(eventType, x, y, xAbs, yAbs,
287 AbstractEvents.mouseButtonToFXMouseButton(button),
288 popupTrigger, false, // do we know if it's synthesized? RT-20142
289 shift, ctrl, alt, meta,
290 primaryBtnDown, middleBtnDown, secondaryBtnDown);
291 return null;
292 }, getAccessControlContext());
293 });
294 }
295
296 @Override
297 public void scrollEvent(final int type,
298 final double scrollX, final double scrollY,
299 final double totalScrollX, final double totalScrollY,
300 double xMultiplier, double yMultiplier,
301 final double x, final double y,
302 final double xAbs, final double yAbs,
303 final boolean shift, final boolean ctrl, final boolean alt, final boolean meta,
304 final boolean inertia) {
305 {
306 Platform.runLater(() -> {
307 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
308 if (sceneListener == null) {
309 return null;
310 }
311 sceneListener.scrollEvent(AbstractEvents.scrollIDToFXEventType(type), scrollX, scrollY, totalScrollX, totalScrollY, xMultiplier, yMultiplier,
312 0, 0, 0, 0, 0, x, y, xAbs, yAbs, shift, ctrl, alt, meta, false, inertia);
313 return null;
314 }, getAccessControlContext());
315 });
316 }
317 }
318
319 @Override
320 public void inputMethodEvent(final EventType<InputMethodEvent> type,
321 final ObservableList<InputMethodTextRun> composed, final String committed,
322 final int caretPosition) {
323 Platform.runLater(() -> {
324 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
325 if (sceneListener != null) {
326 sceneListener.inputMethodEvent(type, composed, committed, caretPosition);
327 }
328 return null;
329 });
330 });
331 }
332
333 @Override
334 public void menuEvent(final int x, final int y, final int xAbs, final int yAbs, final boolean isKeyboardTrigger) {
335 Platform.runLater(() -> {
336 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
337 if (sceneListener != null) {
338 sceneListener.menuEvent(x, y, xAbs, yAbs, isKeyboardTrigger);
339 }
340 return null;
341 }, getAccessControlContext());
342 });
343 }
344
345 @Override
346 public void keyEvent(final int type, final int key, final char[] ch, final int modifiers) {
347 Platform.runLater(() -> {
348 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
349 if (sceneListener != null) {
350 boolean shiftDown = (modifiers & AbstractEvents.MODIFIER_SHIFT) != 0;
351 boolean controlDown = (modifiers & AbstractEvents.MODIFIER_CONTROL) != 0;
352 boolean altDown = (modifiers & AbstractEvents.MODIFIER_ALT) != 0;
353 boolean metaDown = (modifiers & AbstractEvents.MODIFIER_META) != 0;
354
355 String str = new String(ch);
356 String text = str; // TODO: this must be a text like "HOME", "F1", or "A"
357 javafx.scene.input.KeyEvent keyEvent = new javafx.scene.input.KeyEvent(
358 AbstractEvents.keyIDToFXEventType(type),
359 str, text,
360 KeyCodeMap.valueOf(key),
361 shiftDown, controlDown, altDown, metaDown);
362 sceneListener.keyEvent(keyEvent);
363 }
364 return null;
365 }, getAccessControlContext());
366 });
367 }
368
369 @Override
370 public void zoomEvent(final int type, final double zoomFactor, final double totalZoomFactor,
371 final double x, final double y, final double screenX, final double screenY,
372 boolean shift, boolean ctrl, boolean alt, boolean meta, boolean inertia)
373 {
374 Platform.runLater(() -> {
375 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
376 if (sceneListener == null) {
377 return null;
378 }
379 sceneListener.zoomEvent(AbstractEvents.zoomIDToFXEventType(type),
380 zoomFactor, totalZoomFactor,
381 x, y, screenX, screenY,
382 shift, ctrl, alt, meta, false, inertia);
383 return null;
384 }, getAccessControlContext());
385 });
386 }
387
388 @Override
389 public void rotateEvent(final int type, final double angle, final double totalAngle,
390 final double x, final double y, final double screenX, final double screenY,
391 boolean shift, boolean ctrl, boolean alt, boolean meta, boolean inertia)
392 {
393 Platform.runLater(() -> {
394 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
395 if (sceneListener == null) {
396 return null;
397 }
398 sceneListener.rotateEvent(AbstractEvents.rotateIDToFXEventType(type),
399 angle, totalAngle,
400 x, y, screenX, screenY,
401 shift, ctrl, alt, meta, false, inertia);
402 return null;
403 }, getAccessControlContext());
404 });
405 }
406
407 @Override
408 public void swipeEvent(final int type, final double x, final double y, final double screenX, final double screenY,
409 boolean shift, boolean ctrl, boolean alt, boolean meta)
410 {
411 Platform.runLater(() -> {
412 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
413 if (sceneListener == null) {
414 return null;
415 }
416 sceneListener.swipeEvent(AbstractEvents.swipeIDToFXEventType(type),
417 0, x, y, screenX, screenY,
418 shift, ctrl, alt, meta, false);
419 return null;
420 }, getAccessControlContext());
421 });
422 }
423
424 @Override
425 public void setCursor(final Object cursor) {
426 super.setCursor(cursor);
427 host.setCursor((CursorFrame) cursor);
428 }
429
430 @Override
431 public void setDragStartListener(HostDragStartListener l) {
432 embeddedDnD.setDragStartListener(l);
433 }
434
435 @Override
436 public EmbeddedSceneDTInterface createDropTarget() {
437 return embeddedDnD.createDropTarget();
438 }
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.tk.quantum;
27
28 import com.sun.javafx.embed.HostDragStartListener;
29 import javafx.application.Platform;
30 import javafx.collections.ObservableList;
31 import javafx.event.EventType;
32 import javafx.scene.input.*;
33 import javafx.scene.image.PixelFormat;
34 import java.nio.IntBuffer;
35 import java.security.AccessController;
36 import java.security.PrivilegedAction;
37 import com.sun.javafx.cursor.CursorFrame;
38 import com.sun.javafx.embed.EmbeddedSceneDTInterface;
39 import com.sun.javafx.embed.EmbeddedSceneInterface;
40 import com.sun.javafx.embed.HostInterface;
41 import com.sun.javafx.scene.input.KeyCodeMap;
42 import com.sun.javafx.scene.traversal.Direction;
43 import com.sun.javafx.sg.prism.NGNode;
44 import com.sun.javafx.tk.TKClipboard;
45 import com.sun.javafx.tk.Toolkit;
46 import com.sun.prism.paint.Color;
47 import com.sun.prism.paint.Paint;
48 import com.sun.glass.ui.Pixels;
49 import java.nio.ByteOrder;
50
51 final class EmbeddedScene extends GlassScene implements EmbeddedSceneInterface {
52
53 // TODO: synchronize access to embedder from ET and RT
54 private HostInterface host;
55
56 private UploadingPainter painter;
57 private PaintRenderJob paintRenderJob;
193 }
194 return false;
195 }
196
197 @Override
198 public void setSize(final int width, final int height) {
199 Platform.runLater(() -> {
200 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
201 if (sceneListener != null) {
202 sceneListener.changedSize(width, height);
203 }
204 return null;
205 }, getAccessControlContext());
206 });
207 }
208
209 /**
210 * @param dest the destination buffer
211 * @param width the logical width of the buffer
212 * @param height the logical height of the buffer
213 * @return
214 */
215 @Override
216 public boolean getPixels(final IntBuffer dest, final int width, final int height) {
217 return QuantumToolkit.runWithRenderLock(() -> {
218 int scaledWidth = width;
219 int scaledHeight = height;
220
221 // The dest buffer scale factor is expected to match painter.getPixelScaleFactor().
222 if (getRenderScaleX() != texScaleFactorX ||
223 getRenderScaleY() != texScaleFactorY ||
224 texBits == null)
225 {
226 return false;
227 }
228 scaledWidth = Math.round(scaledWidth * texScaleFactorX);
229 scaledHeight = Math.round(scaledHeight * texScaleFactorY);
230
231 dest.rewind();
232 texBits.rewind();
246 dest.put(linebuf);
247 }
248 return true;
249 }
250 dest.put(texBits);
251 return true;
252 });
253 }
254
255 @Override
256 protected Color getClearColor() {
257 if (fillPaint != null && fillPaint.getType() == Paint.Type.COLOR &&
258 ((Color)fillPaint).getAlpha() == 0f)
259 {
260 return (Color)fillPaint;
261 }
262 return super.getClearColor();
263 }
264
265 @Override
266 public void mouseEvent(final EventType<MouseEvent> type, MouseButton button,
267 final boolean primaryBtnDown, final boolean middleBtnDown, final boolean secondaryBtnDown,
268 final int x, final int y, final int xAbs, final int yAbs,
269 final boolean shift, final boolean ctrl, final boolean alt, final boolean meta,
270 final boolean popupTrigger)
271 {
272 Platform.runLater(() -> {
273 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
274 if (sceneListener == null) {
275 return null;
276 }
277 // Click events are generated in Scene, so we don't expect them here
278 assert type != MouseEvent.MOUSE_CLICKED;
279 sceneListener.mouseEvent(type, x, y, xAbs, yAbs,
280 button,
281 popupTrigger, false, // do we know if it's synthesized? RT-20142
282 shift, ctrl, alt, meta,
283 primaryBtnDown, middleBtnDown, secondaryBtnDown);
284 return null;
285 }, getAccessControlContext());
286 });
287 }
288
289 @Override
290 public void scrollEvent(final EventType<ScrollEvent> type,
291 final double scrollX, final double scrollY,
292 final double totalScrollX, final double totalScrollY,
293 double xMultiplier, double yMultiplier,
294 final double x, final double y,
295 final double xAbs, final double yAbs,
296 final boolean shift, final boolean ctrl, final boolean alt, final boolean meta,
297 final boolean inertia) {
298 {
299 Platform.runLater(() -> {
300 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
301 if (sceneListener == null) {
302 return null;
303 }
304 sceneListener.scrollEvent(type, scrollX, scrollY, totalScrollX, totalScrollY, xMultiplier, yMultiplier,
305 0, 0, 0, 0, 0, x, y, xAbs, yAbs, shift, ctrl, alt, meta, false, inertia);
306 return null;
307 }, getAccessControlContext());
308 });
309 }
310 }
311
312 @Override
313 public void inputMethodEvent(final EventType<InputMethodEvent> type,
314 final ObservableList<InputMethodTextRun> composed, final String committed,
315 final int caretPosition) {
316 Platform.runLater(() -> {
317 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
318 if (sceneListener != null) {
319 sceneListener.inputMethodEvent(type, composed, committed, caretPosition);
320 }
321 return null;
322 });
323 });
324 }
325
326 @Override
327 public void menuEvent(final int x, final int y, final int xAbs, final int yAbs, final boolean isKeyboardTrigger) {
328 Platform.runLater(() -> {
329 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
330 if (sceneListener != null) {
331 sceneListener.menuEvent(x, y, xAbs, yAbs, isKeyboardTrigger);
332 }
333 return null;
334 }, getAccessControlContext());
335 });
336 }
337
338 @Override
339 public void keyEvent(final EventType<KeyEvent> type, final int key, final char[] ch, boolean shift, boolean ctrl,
340 boolean alt, boolean meta) {
341 Platform.runLater(() -> {
342 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
343 if (sceneListener != null) {
344 String str = new String(ch);
345 String text = str; // TODO: this must be a text like "HOME", "F1", or "A"
346 javafx.scene.input.KeyEvent keyEvent = new javafx.scene.input.KeyEvent(
347 type, str, text,
348 KeyCodeMap.valueOf(key),
349 shift, ctrl, alt, meta);
350 sceneListener.keyEvent(keyEvent);
351 }
352 return null;
353 }, getAccessControlContext());
354 });
355 }
356
357 @Override
358 public void zoomEvent(final EventType<ZoomEvent> type, final double zoomFactor, final double totalZoomFactor,
359 final double x, final double y, final double screenX, final double screenY,
360 boolean shift, boolean ctrl, boolean alt, boolean meta, boolean inertia)
361 {
362 Platform.runLater(() -> {
363 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
364 if (sceneListener == null) {
365 return null;
366 }
367 sceneListener.zoomEvent(type, zoomFactor, totalZoomFactor, x, y, screenX, screenY,
368 shift, ctrl, alt, meta, false, inertia);
369 return null;
370 }, getAccessControlContext());
371 });
372 }
373
374 @Override
375 public void rotateEvent(final EventType<RotateEvent> type, final double angle, final double totalAngle,
376 final double x, final double y, final double screenX, final double screenY,
377 boolean shift, boolean ctrl, boolean alt, boolean meta, boolean inertia)
378 {
379 Platform.runLater(() -> {
380 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
381 if (sceneListener == null) {
382 return null;
383 }
384 sceneListener.rotateEvent(type, angle, totalAngle, x, y, screenX, screenY,
385 shift, ctrl, alt, meta, false, inertia);
386 return null;
387 }, getAccessControlContext());
388 });
389 }
390
391 @Override
392 public void swipeEvent(final EventType<SwipeEvent> type, final double x, final double y, final double screenX, final double screenY,
393 boolean shift, boolean ctrl, boolean alt, boolean meta)
394 {
395 Platform.runLater(() -> {
396 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
397 if (sceneListener == null) {
398 return null;
399 }
400 sceneListener.swipeEvent(type, 0, x, y, screenX, screenY, shift, ctrl, alt, meta, false);
401 return null;
402 }, getAccessControlContext());
403 });
404 }
405
406 @Override
407 public void setCursor(final Object cursor) {
408 super.setCursor(cursor);
409 host.setCursor((CursorFrame) cursor);
410 }
411
412 @Override
413 public void setDragStartListener(HostDragStartListener l) {
414 embeddedDnD.setDragStartListener(l);
415 }
416
417 @Override
418 public EmbeddedSceneDTInterface createDropTarget() {
419 return embeddedDnD.createDropTarget();
420 }
|