changeset 10650:cfa038af148b

8187671: [WebView] Drag and Drop of text or html results in an image Reviewed-by: arajkumar, mbilla, ghb Contributed-by: rajath.kamath@oracle.com
author mbilla
date Fri, 29 Sep 2017 12:00:27 +0530
parents c77ae1a020b3
children acd30e210f23 2d8efe4ae6fd
files modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java modules/javafx.web/src/main/java/com/sun/javafx/webkit/drt/UIClientImpl.java modules/javafx.web/src/main/java/com/sun/webkit/UIClient.java modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java modules/javafx.web/src/main/native/Source/WebCore/platform/java/DragClientJava.cpp
diffstat 5 files changed, 34 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java	Fri Sep 29 08:55:07 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java	Fri Sep 29 12:00:27 2017 +0530
@@ -312,7 +312,7 @@
     @Override public void startDrag(WCImage image,
         int imageOffsetX, int imageOffsetY,
         int eventPosX, int eventPosY,
-        String[] mimeTypes, Object[] values
+        String[] mimeTypes, Object[] values, boolean isImageSource
     ){
         content = new ClipboardContent();
         for (int i = 0; i < mimeTypes.length; ++i) if (values[i] != null) {
@@ -346,24 +346,26 @@
             //Image need to be created by target request only.
             //QuantumClipboard.putContent have to be rewritten in Glass manner
             //with postponed data requests (DelayedCallback data object).
-            Object platformImage = image.getWidth() > 0 && image.getHeight() > 0 ?
-                    image.getPlatformImage() : null;
-            if (platformImage != null) {
-                try {
-                    File temp = File.createTempFile("jfx", ".png");
-                    temp.deleteOnExit();
-                    ImageIO.write(
-                        toBufferedImage(Toolkit.getImageAccessor().fromPlatformImage(
-                            Toolkit.getToolkit().loadPlatformImage(
-                                platformImage
-                            )
-                        )),
-                        "png",
-                        temp);
-                    content.put(DataFormat.FILES, Arrays.asList(temp));
-                } catch (IOException | SecurityException e) {
-                    //That is ok. It was just an attempt.
-                    //e.printStackTrace();
+            if (isImageSource) {
+                Object platformImage = image.getWidth() > 0 && image.getHeight() > 0 ?
+                        image.getPlatformImage() : null;
+                if (platformImage != null) {
+                    try {
+                        File temp = File.createTempFile("jfx", ".png");
+                        temp.deleteOnExit();
+                        ImageIO.write(
+                            toBufferedImage(Toolkit.getImageAccessor().fromPlatformImage(
+                                Toolkit.getToolkit().loadPlatformImage(
+                                    platformImage
+                                )
+                            )),
+                            "png",
+                            temp);
+                        content.put(DataFormat.FILES, Arrays.asList(temp));
+                    } catch (IOException | SecurityException e) {
+                        //That is ok. It was just an attempt.
+                        //e.printStackTrace();
+                    }
                 }
             }
         }
--- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/drt/UIClientImpl.java	Fri Sep 29 08:55:07 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/drt/UIClientImpl.java	Fri Sep 29 12:00:27 2017 +0530
@@ -179,7 +179,7 @@
      */
     @Override
     public void startDrag(WCImage frame, int imageOffsetX, int imageOffsetY,
-            int eventPosX, int eventPosY, String[] mimeTypes, Object[] values)
+            int eventPosX, int eventPosY, String[] mimeTypes, Object[] values, boolean isImageSource)
     {
         throw new UnsupportedOperationException("Not supported yet");
     }
--- a/modules/javafx.web/src/main/java/com/sun/webkit/UIClient.java	Fri Sep 29 08:55:07 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/webkit/UIClient.java	Fri Sep 29 12:00:27 2017 +0530
@@ -50,8 +50,8 @@
             WCImage frame,
             int imageOffsetX, int imageOffsetY,
             int eventPosX, int eventPosY,
-            String[] mimeTypes,
-            Object[] values);
+            String[] mimeTypes, Object[] values,
+            boolean isImageSource);
     public void confirmStartDrag();
     public boolean isDragConfirmed();
 }
--- a/modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java	Fri Sep 29 08:55:07 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java	Fri Sep 29 12:00:27 2017 +0530
@@ -2262,18 +2262,17 @@
           Object image,
           int imageOffsetX, int imageOffsetY,
           int eventPosX, int eventPosY,
-          String[] mimeTypes,
-          Object[] values)
+          String[] mimeTypes, Object[] values,
+          boolean isImageSource)
     {
         log.log(Level.FINER, "Start drag: ");
-
         if (uiClient != null) {
             uiClient.startDrag(
                   WCImage.getImage(image),
                   imageOffsetX, imageOffsetY,
                   eventPosX, eventPosY,
-                  mimeTypes,
-                  values);
+                  mimeTypes, values,
+                  isImageSource);
         }
     }
 
--- a/modules/javafx.web/src/main/native/Source/WebCore/platform/java/DragClientJava.cpp	Fri Sep 29 08:55:07 2017 +0530
+++ b/modules/javafx.web/src/main/native/Source/WebCore/platform/java/DragClientJava.cpp	Fri Sep 29 12:00:27 2017 +0530
@@ -133,7 +133,7 @@
     const FloatPoint&,
     DataTransfer& DataTransfer,
     Frame&,
-    DragSourceAction)
+    DragSourceAction dragSourceAction)
 {
     JNIEnv* env = WebCore_GetJavaEnv();
     static jmethodID mid = env->GetMethodID(
@@ -144,6 +144,7 @@
         "II"
         "[Ljava/lang/String;"
         "[Ljava/lang/Object;"
+        "Z"
         ")V");
     ASSERT(mid);
 
@@ -189,13 +190,16 @@
     jobject jimage = dragImage.get() && dragImage.get()->javaImage()
                   ? jobject(*(dragImage.get()->javaImage())) : nullptr;
 
+    bool isImageSource = dragSourceAction & DragSourceActionImage;
+
     env->CallVoidMethod(m_webPage, mid, jimage,
         eventPos.x() - dragImageOrigin.x(),
         eventPos.y() - dragImageOrigin.y(),
         eventPos.x(),
         eventPos.y(),
         jobjectArray(jmimeTypes),
-        jobjectArray(jvalues) );
+        jobjectArray(jvalues),
+        bool_to_jbool(isImageSource));
     CheckAndClearException(env);
 }