private int getTargetItemIndex(Element target) {
    assert !target.equals(this.getElement()); // The markup is now broken

    while (!target.getParentElement().equals(this.getElement())) {
      target = target.getParentElement();
    }
    return DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) target);
  }
Example #2
0
  @Override
  public void onBrowserEvent(Event event) {
    if (disabled || readonly) {
      return;
    }
    final Element targ = DOM.eventGetTarget(event);

    if (DOM.eventGetType(event) == Event.ONMOUSEWHEEL) {
      processMouseWheelEvent(event);
    } else if (dragging || targ == handle) {
      processHandleEvent(event);
    } else if (targ == smaller) {
      decreaseValue(true);
    } else if (targ == bigger) {
      increaseValue(true);
    } else if (DOM.eventGetType(event) == Event.MOUSEEVENTS) {
      processBaseEvent(event);
    } else if (BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYPRESS
        || !BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYDOWN) {

      if (handleNavigation(event.getKeyCode(), event.getCtrlKey(), event.getShiftKey())) {

        feedbackPopup.show();

        delayedValueUpdater.trigger();

        DOM.eventPreventDefault(event);
        DOM.eventCancelBubble(event, true);
      }
    } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONFOCUS) {
      feedbackPopup.show();
    } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONBLUR) {
      feedbackPopup.hide();
    } else if (DOM.eventGetType(event) == Event.ONMOUSEDOWN) {
      feedbackPopup.show();
    }
    if (WidgetUtil.isTouchEvent(event)) {
      event.preventDefault(); // avoid simulated events
      event.stopPropagation();
    }
  }
  protected void scrollToSelectedRow() {
    if (iCourses.getSelectedRow() < 0) return;

    Element scroll = iCoursesPanel.getElement();

    com.google.gwt.dom.client.Element item =
        iCourses.getTable().getRowFormatter().getElement(iCourses.getSelectedRow());
    if (item == null) return;

    int realOffset = 0;
    while (item != null && !item.equals(scroll)) {
      realOffset += item.getOffsetTop();
      item = item.getOffsetParent();
    }

    scroll.setScrollTop(realOffset - scroll.getOffsetHeight() / 2);
  }
Example #4
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;
    }