Exemple #1
0
    @Override
    public void onBrowserEvent(Event event) {
      if (cancelled) {
        return;
      }

      assertEquals(eventType, event.getType());
      if (supportsShiftKeys) {
        assertAllShiftKeys(event, expectedCtrl, expectedAlt, expectedShift, expectedMeta);
      }

      EventTarget target = event.getCurrentEventTarget();
      if (Element.is(target)) {
        if (Element.as(target) == child) {
          assertFalse("Expecting child to receive the event only once", childReceived);
          assertFalse("Expecting child to receive the event before parent", parentReceived);

          childReceived = true;
        } else if (Element.as(target) == parent) {
          assertFalse("Expecting parent to receive the event only once", parentReceived);
          assertTrue("Expecting parent to receive the event after the child", childReceived);

          parentReceived = true;
        }
      }
    }
Exemple #2
0
  public void onBrowserEvent(Event event) {
    double now = Duration.currentTimeMillis();
    // Workaround for Issue_20
    if (lastType.equals(event.getType())
        && now - lastEvnt < 10
        && "body".equalsIgnoreCase(element.getTagName())) {
      return;
    }
    lastEvnt = now;
    lastType = event.getType();

    // Execute the original Gwt listener
    if (getOriginalEventListener() != null && getOriginalEventListener() != this) {
      getOriginalEventListener().onBrowserEvent(event);
    }

    dispatchEvent(event);
  }
 @Override
 public void onBrowserEvent(Event event) {
   String eventType = event.getType();
   if (BrowserEvents.MOUSEMOVE.equals(eventType)) {
     int currentPosition = positionController.getPosition(event);
     cell.setSize(startSize + currentPosition - startPosition);
   } else if (BrowserEvents.MOUSEUP.equals(eventType)) {
     DOM.releaseCapture(resizer);
     DOM.setEventListener(resizer, null);
   }
 }
Exemple #4
0
    @Override
    public void onBrowserEvent(Event event) {
      if (event.getType().equals(eventType)) {
        if (event.getEventTarget().equals(img)) {
          assertFalse("Expecting img to receive the event only once", imgReceived);

          imgReceived = true;
        } else if (event.getEventTarget().equals(parent)) {
          fail("Not expecting parent to receive the event");
        }
      }
    }
Exemple #5
0
  private static String createFailureMessage(UIObject target, Event event, String attribut) {
    StringBuilder sb = new StringBuilder();

    String className =
        target.getClass().isAnonymousClass()
            ? target.getClass().getName()
            : target.getClass().getSimpleName();
    sb.append("The targeted widget (").append(className);
    sb.append(") and its possible parents have to be ").append(attribut);
    sb.append(" to apply a browser '").append(event.getType()).append("\' event");

    return sb.toString();
  }
Exemple #6
0
    @Override
    public void onBrowserEvent(Event event) {
      if (cancelled) {
        return;
      }

      assertEquals(eventType, event.getType());

      if (event.getEventTarget().equals(child)) {
        assertFalse("Expecting child to receive the event only once", childReceived);
        childReceived = true;
      } else if (event.getEventTarget().equals(parent)) {
        fail("Not expecting parent to receive the event");
      }
    }
Exemple #7
0
 /** Dispatch an event in this element. */
 public void dispatchEvent(Event event) {
   dispatchEvent(event, event.getType());
 }
Exemple #8
0
    @Override
    public boolean fire(Event event, Object[] eventData) {
      if (isEmpty()) {
        return true;
      }

      // first element where the event was fired
      Element eventTarget = getEventTarget(event);
      // last element where the event was dispatched on
      Element liveContextElement = getCurrentEventTarget(event);

      if (eventTarget == null || liveContextElement == null) {
        return true;
      }

      // Compute the live selectors which respond to this event type
      List<String> validSelectors = new ArrayList<String>();
      for (String cssSelector : bindFunctionBySelector.keys()) {
        JsObjectArray<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
        for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) {
          BindFunction f = bindFunctions.get(i);
          if (f.hasEventType(event.getTypeInt()) || f.isTypeOf(event.getType())) {
            validSelectors.add(cssSelector);
            break;
          }
        }
      }

      // Create a structure of elements which matches the selectors
      JsNamedArray<NodeList<Element>> realCurrentTargetBySelector =
          $(eventTarget).closest(validSelectors.toArray(new String[0]), liveContextElement);
      // nothing matches the selectors
      if (realCurrentTargetBySelector.length() == 0) {
        return true;
      }

      Element stopElement = null;
      GqEvent gqEvent = GqEvent.create(event);
      for (String cssSelector : realCurrentTargetBySelector.keys()) {
        JsObjectArray<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
        for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) {
          BindFunction f = bindFunctions.get(i);
          if (f.hasEventType(event.getTypeInt()) || f.isTypeOf(event.getType())) {
            NodeList<Element> n = realCurrentTargetBySelector.get(cssSelector);
            for (int j = 0; n != null && j < n.getLength(); j++) {
              Element element = n.getItem(j);
              // When an event fired in an element stops bubbling we have to fire also all other
              // handlers for this element bound to this element
              if (stopElement == null || element.equals(stopElement)) {
                gqEvent.setCurrentElementTarget(element);
                // data
                eventData = $(element).data(EVENT_DATA);
                if (!f.fire(gqEvent, eventData)) {
                  stopElement = element;
                }
              }
            }
          }
        }
      }

      // trick to reset the right currentTarget on the original event on ie
      gqEvent.setCurrentElementTarget(liveContextElement);
      return stopElement == null;
    }
    @Override
    public void onBrowserEvent(Event event) {
      if (event.getType() == "dragenter") {
        if (dropPoint_ != null
            && event.getClientX() == dropPoint_.getX()
            && event.getClientY() == dropPoint_.getY()) {
          // Very occasionally (~5%?), dropping a tab will generate a
          // superfluous "dragenter" event immediately after the drop event
          // at exactly the same coordinates. We want to ignore this since
          // it will send us into dragging state; to do so, we cache the
          // coordinates when a tab is dropped and suppress entering drag
          // mode from those coordinates very briefly (note that this won't
          // keep the user from immediately dragging the tab around since
          // you need to move the cursor in some way to initiate a drag,
          // invalidating the coordinates.)
          dropPoint_ = null;
          return;
        }

        if (curState_ == STATE_EXTERNAL) {
          // element that was being dragged around outside boundaries
          // has come back in; clear it and treat like a new drag
          dragElement_.getStyle().clearOpacity();
          dragElement_ = null;
          curState_ = STATE_NONE;
        }
        if (curState_ == STATE_NONE) {
          beginDrag(event);
        }
        event.preventDefault();
      } else if (event.getType() == "dragover") {
        if (curState_ == STATE_DRAGGING) drag(event);
        event.preventDefault();
      } else if (event.getType() == "drop") {
        endDrag(event, ACTION_COMMIT);
        event.preventDefault();

        // cache the drop point for 250ms (see comments in event handler for
        // dragenter)
        dropPoint_ = new Point(event.getClientX(), event.getClientY());
        Scheduler.get()
            .scheduleFixedDelay(
                new Scheduler.RepeatingCommand() {
                  @Override
                  public boolean execute() {
                    dropPoint_ = null;
                    return false;
                  }
                },
                250);
      } else if (event.getType() == "dragend") {
        if (curState_ != STATE_NONE) {
          endDrag(event, ACTION_CANCEL);
        }
        event.preventDefault();
      } else if (event.getType() == "dragleave") {
        if (curState_ == STATE_NONE) return;

        // when a drag leaves the window entirely, we get a dragleave event
        // at 0, 0 (which we always want to treat as a cancel)
        if (!(event.getClientX() == 0 && event.getClientY() == 0)) {
          // look at where the cursor is now--if it's inside the tab panel,
          // do nothing, but if it's outside the tab panel, treat that as
          // a cancel
          Element ele = DomUtils.elementFromPoint(event.getClientX(), event.getClientY());
          while (ele != null && ele != Document.get().getBody()) {
            if (ele.getClassName().contains("gwt-TabLayoutPanelTabs")) {
              return;
            }
            ele = ele.getParentElement();
          }
        }

        if (dragElement_ != null) {
          // dim the element being drag to hint that it'll be moved
          endDrag(event, ACTION_EXTERNAL);
        } else {
          // if this wasn't our element, we can cancel the drag entirely
          endDrag(event, ACTION_CANCEL);
        }
      }
    }