Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 346626

Summary: DND causes javascript error
Product: [RT] RAP Reporter: Michael Klein <michael.klein>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P1    
Version: 1.4   
Target Milestone: 1.4 RC2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description Michael Klein CLA 2011-05-20 06:12:28 EDT
Environment: Firefox 4.0.1/IE 9.0.8112 on Win7

The bug occurs using RAP 1.4 RC1 (maintenance branch) and HEAD


Steps to reproduce:
* create a composite
* add a label to the composite
* add drag support to the composite
* add drag support to the label
* try to drag the label and drop it anywhere (don't have to be a drop target)
-> Javascript error occurred

Expected:
Regardless whether or not this is a reasonable use case, nested drag 
sources should never cause a javascript error which ends in an client crash.


Here is a snippet to reproduce:

public class Snippet implements IEntryPoint {

  public int createUI() {
    Display display = new Display();
    Shell shell = new Shell(display, SWT.TITLE);
    createContent(shell);
    shell.layout();
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    return 0;
  }

  private void createContent(Shell shell) {
    shell.setLayout(new GridLayout(2, false));
    
    // drag label
    Composite labelDragParent = new Composite(shell, SWT.NONE);
    labelDragParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    labelDragParent.setLayout(new GridLayout(1, false));
    
    Label labelDrag = new Label(labelDragParent, SWT.BORDER);
    labelDrag.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    labelDrag.setText("Drag");
    
    // drop label
    Composite labelDropParent = new Composite(shell, SWT.NONE);
    labelDropParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    labelDropParent.setLayout(new GridLayout(1, false));
    
    Label labelDrop = new Label(labelDropParent, SWT.BORDER);
    labelDrop.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    labelDrop.setText("Drop");
    
    // drag support
    DragSource dragSource = new DragSource(labelDragParent, DND.DROP_MOVE);
    dragSource.setTransfer(new Transfer[] {TextTransfer.getInstance()});
    
    dragSource = new DragSource(labelDrag, DND.DROP_MOVE);
    dragSource.setTransfer(new Transfer[] {TextTransfer.getInstance()});
  }

}
Comment 1 Ivan Furnadjiev CLA 2011-05-20 10:47:43 EDT
Created attachment 196225 [details]
Proposed fix

The fix is to stop the propagation of dragEnd event in DNDSupport.js#_dragEndHandler.
Comment 2 Ivan Furnadjiev CLA 2011-05-22 03:40:42 EDT
Applied patch to CVS HEAD and v14_Maintenance branch.