简体   繁体   English

GWT图像拖放IE9无法正常工作

[英]GWT Image Drag and Drop on IE9 not working

I'm using GWT 2.5 and I want to make some images in one Panel Draggable and Dropable in another Panel. 我正在使用GWT 2.5,我想在另一个Panel中的一个Panel Draggable和Dropable中制作一些图像。 This is working fine on Firefox, but on IE9 it just don't want to work. 这在Firefox上工作正常,但在IE9上它只是不想工作。

I searched really almost all the day, and didn't find any solution for that. 我几乎整天都在搜索,并没有找到任何解决方案。 The best threads I found were these here: 我找到的最好的主题是这里:

Drag and Drop in GWT 2.4 在GWT 2.4中拖放

GWT native drag & drop - DragStartEvent not firing on IE9 GWT本机拖放 - DragStartEvent不会在IE9上触发

The difference is that I'm dragging Images, an not Labels. 不同之处在于我拖动图像,而不是标签。 So this could be the problem. 所以这可能是问题所在。

So the code looks something like this: 所以代码看起来像这样:

// Draggable Image
final Image img = new Image(imageName);
img.addDragStartHandler(new DragStartHandler() {
  @Override
  public void onDragStart(final DragStartEvent event) { 
    event.setData("text", img.getUrl());
  }
});
img.getElement().setDraggable(Element.DRAGGABLE_TRUE);

Then I put it in my "source" panel: 然后我把它放在我的“源”面板中:

// Image in the source container
wunschContainer = new AbsolutePanel();
img.setPixelSize(size, size);
wunschContainer.add(img, left, top);

The Images are displayed correctly (Firefox and IE9) 图像显示正确(Firefox和IE9)

The Target Panel looks like this (it's a subclass of AbsolutePanel and implements HasDragOverHandlers and HasDropHandlers) 目标面板看起来像这样(它是AbsolutePanel的子类,并实现了HasDragOverHandlers和HasDropHandlers)

// Event-handlers for the target container.
this.addDragOverHandler(new DragOverHandler() {
  @Override
  public void onDragOver(final DragOverEvent event) {
  }
});

this.addDropHandler(new DropHandler() {
  @Override
  public void onDrop(final DropEvent event) {
    event.preventDefault();
    final String data = event.getData("text");
    /* ... some more handling ..., creates an image to be displayed here */
    add(image, left, top);
  }
});

In Firefox, when I drag the image, the dragging image is displayed under the mouse pointer. 在Firefox中,当我拖动图像时,拖动图像显示在鼠标指针下。 On IE9 I can't see an image at all, just a symbol (circle with a slash on it, this "not allowed" symbol). 在IE9上我根本看不到图像,只是一个符号(带有斜线的圆圈,这个“不允许”的符号)。 And when I release the mouse button, then nothing happen. 当我释放鼠标按钮时,什么也没发生。 I checked also with "F12" that I was using the IE9-mode, and no compatibility mode. 我还检查了“F12”,我使用的是IE9模式,没有兼容模式。

I really don't know what the problem is. 我真的不知道问题是什么。 The code seems ok (works on FF). 代码似乎没问题(适用于FF)。 Is there a problem making DnD with GWT-Images? 使用GWT-Images制作DnD有问题吗? The interesting part is, that the "onDragStart()" methode is being fired. 有趣的是,“onDragStart()”方法正在被解雇。 But the "drag" is not being done. 但“阻力”还没有完成。

Oh, I'm using GWT devmode to test this. 哦,我正在使用GWT devmode来测试这个。 Can this be a problem? 这可能是个问题吗?

I'd like to solve this using only GWT. 我想只使用GWT来解决这个问题。 Or should I go and use another library, like gwt-dnd? 或者我应该去使用另一个库,比如gwt-dnd? Does anybody got plain GWT DnD working on IE9? 有没有人在IE9上使用普通的 GWT DnD? I can't believe I'm the first one trying that :-(. 我不敢相信我是第一个尝试这个:-(。

So, I tried really a lot of things, and I came across with a solution. 所以,我尝试了很多东西,我遇到了一个解决方案。

The problem seems to be in the "onDragOver()" method. 问题似乎出现在“onDragOver()”方法中。 As I posted in my original question, I have an empty implementation of the method: 正如我在原始问题中发布的那样,我有一个方法的空实现:

this.addDragOverHandler(new DragOverHandler() {
  @Override
  public void onDragOver(final DragOverEvent event) {
  }
});

As this is how I found in many pages. 这就是我在很多页面中找到的。 The method must be present, or else the Drag n Drop wont work. 必须存在该方法,否则Drag n Drop将不起作用。 But it seems that for IE I need even to prevent the default behaviour (or do something else. Just logging the method was not "something"). 但似乎对于IE我甚至需要阻止默认行为(或做其他事情。只是记录方法不是“某事”)。 So I added a "event.preventDefault();" 所以我添加了一个“event.preventDefault();” to the method, and now it works. 方法,现在它的工作原理。

this.addDragOverHandler(new DragOverHandler() {
  @Override
  public void onDragOver(final DragOverEvent event) {
    event.preventDefault();
  }
});

Just strange, that I couldn't find this information anywhere. 奇怪的是,我无法在任何地方找到这些信息。 This is hopefully useful for somebody else 8-). 这对其他人有用8-)。

I have been having the same issue with IE9 using GWT 2.6 and I have found that setting the data in the onDragStart puts IE9 off. 我使用GWT 2.6遇到了与IE9相同的问题,我发现在onDragStart中设置数据会使IE9关闭。 All other browsers work fine. 所有其他浏览器工作正常。 So I ended up doing the following: 所以我最终做了以下事情:

        this.addDragStartHandler(new DragStartHandler(){

        @Override
        public void onDragStart(DragStartEvent event) {
            if(!isIE9()){
                event.setData(RangeSliderControl.KEY, key); // This causes IE9 to not work                  
            }
        }}
    );

and off course I have added the isIE9() method to my code as follows: 当然我已经将isIE9()方法添加到我的代码中,如下所示:

    /**
* Gets the name of the used browser.
*/
public static boolean isIE9() {
    return (getBrowserName().indexOf("msie 9.0") != -1);
};

/**
* Gets the name of the used browser.
*/
public static native String getBrowserName() /*-{
    return navigator.userAgent.toLowerCase();
}-*/;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM