Exemple #1
0
 private static void assertMouseCoordinates(Event event) {
   assertEquals("clientX", CLIENT_X, event.getClientX());
   assertEquals("clientY", CLIENT_Y, event.getClientY());
   assertEquals("screenX", SCREEN_X, event.getScreenX());
   assertEquals("screenY", SCREEN_Y, event.getScreenY());
 }
    public void endDrag(final Event evt, int action) {
      if (curState_ == STATE_NONE) return;

      // remove the properties used to position for dragging
      if (dragElement_ != null) {
        dragElement_.getStyle().clearLeft();
        dragElement_.getStyle().clearPosition();
        dragElement_.getStyle().clearZIndex();
        dragElement_.getStyle().clearDisplay();
        dragElement_.getStyle().clearOpacity();

        // insert this tab where the placeholder landed if we're not
        // cancelling
        if (action == ACTION_COMMIT) {
          dragTabsHost_.removeChild(dragElement_);
          dragTabsHost_.insertAfter(dragElement_, dragPlaceholder_);
        }
      }

      // remove the placeholder
      if (dragPlaceholder_ != null) {
        dragTabsHost_.removeChild(dragPlaceholder_);
        dragPlaceholder_ = null;
      }

      if (dragElement_ != null && action == ACTION_EXTERNAL) {
        // if we own the dragged tab, change to external drag state
        dragElement_.getStyle().setOpacity(0.4);
        curState_ = STATE_EXTERNAL;
      } else {
        // otherwise, we're back to pristine
        curState_ = STATE_NONE;
        events_.fireEvent(new DocTabDragStateChangedEvent(DocTabDragStateChangedEvent.STATE_NONE));
      }

      if (dragElement_ != null && action == ACTION_COMMIT) {
        // let observer know we moved; adjust the destination position one to
        // the left if we're right of the start position to account for the
        // position of the tab prior to movement
        if (startPos_ != null && startPos_ != destPos_) {
          TabReorderEvent event = new TabReorderEvent(startPos_, destPos_);
          fireEvent(event);
        }
      }

      // this is the case when we adopt someone else's doc
      if (dragElement_ == null && evt != null && action == ACTION_COMMIT) {
        // pull the document ID and source window out
        String data = evt.getDataTransfer().getData(getDataTransferFormat());
        if (StringUtil.isNullOrEmpty(data)) return;

        // the data format is docID|windowID; windowID can be omitted if
        // the main window is the origin
        String pieces[] = data.split("\\|");
        if (pieces.length < 1) return;

        events_.fireEvent(
            new DocWindowChangedEvent(
                pieces[0], pieces.length > 1 ? pieces[1] : "", initDragParams_, destPos_));
      }

      // this is the case when our own drag ends; if it ended outside our
      // window and outside all satellites, treat it as a tab tear-off
      if (dragElement_ != null && evt != null && action == ACTION_CANCEL) {
        // if this is the last tab in satellite, we don't want to tear
        // it out
        boolean isLastSatelliteTab = docTabs_.size() == 1 && Satellite.isCurrentWindowSatellite();

        // did the user drag the tab outside this doc?
        if (!isLastSatelliteTab
            && DomUtils.elementFromPoint(evt.getClientX(), evt.getClientY()) == null) {
          // did it end in any RStudio satellite window?
          String targetWindowName;
          Satellite satellite = RStudioGinjector.INSTANCE.getSatellite();
          if (Satellite.isCurrentWindowSatellite()) {
            // this is a satellite, ask the main window
            targetWindowName = satellite.getWindowAtPoint(evt.getScreenX(), evt.getScreenY());
          } else {
            // this is the main window, query our own satellites
            targetWindowName =
                RStudioGinjector.INSTANCE
                    .getSatelliteManager()
                    .getWindowAtPoint(evt.getScreenX(), evt.getScreenY());
          }
          if (targetWindowName == null) {
            // it was dragged over nothing RStudio owns--pop it out
            events_.fireEvent(
                new PopoutDocInitiatedEvent(
                    initDragParams_.getDocId(), new Point(evt.getScreenX(), evt.getScreenY())));
          }
        }
      }

      if (curState_ != STATE_EXTERNAL) {
        // if we're in an end state, clear the drag element
        dragElement_ = null;
      }
    }