Example #1
0
    @Override
    public void onBrowserEvent(Event event) {
      Element td = getEventTargetCell(event);

      if (td == null) {
        return;
      }
      Element tr = DOM.getParent(td);

      String index = tr.getAttribute("item-index");
      if (index == null || "".equals(index)) {
        return;
      }

      switch (DOM.eventGetType(event)) {
        case Event.ONMOUSEOVER:
          onRowHovered(tr);
          break;

        case Event.ONCLICK:
          onRowClicked(tr);
          event.preventDefault();
          event.stopPropagation();
          break;
      }
    }
Example #2
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;
        }
      }
    }
  /**
   * Detect dialog's edges and update mouse cursor according to hovered dialog edge
   *
   * @param event
   * @return
   */
  private boolean updateResizeCursor(Event event) {
    int cursorX = event.getClientX();
    int initialX = getAbsoluteLeft();
    int width = getOffsetWidth();

    int cursorY = event.getClientY();
    int initialY = getAbsoluteTop();
    int height = getOffsetHeight();

    rightEdge = (initialX + width - EDGE_THRESHOLD) < cursorX && cursorX < (initialX + width);
    bottomEdge = (initialY + height - EDGE_THRESHOLD) < cursorY && cursorY < (initialY + height);

    String cursor =
        bottomEdge && rightEdge
            ? "se-resize"
            : //$NON-NLS-1$
            rightEdge
                ? "e-resize"
                : bottomEdge ? "n-resize" : "default"; // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    if (parentElementStyle == null) {
      parentElementStyle = getElement().getParentElement().getStyle();
    }
    getElement().getParentElement().getStyle().setProperty("cursor", cursor); // $NON-NLS-1$

    return rightEdge || bottomEdge;
  }
Example #4
0
  /** Tests createDblClickEvent(). */
  public void testTriggerDblClickEvent() {
    BubbleAssertingEventListener listener =
        new BubbleAssertingEventListener("dblclick", true) {
          @Override
          public void onBrowserEvent(Event event) {
            if (cancelled) {
              return;
            }
            if (event.getTypeInt() == Event.ONCLICK) {
              // Some browsers (IE, I'm looking at you) synthesize an extra click
              // event when a double-click is triggered. This synthesized click
              // will *not* have the same properties as the dblclick, so we will
              // not try to assert them here.
              return;
            }

            super.onBrowserEvent(event);
            assertMouseCoordinates(event);
          }
        };
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

    child.dispatchEvent(
        Document.get()
            .createDblClickEvent(
                MOUSE_DETAIL, SCREEN_X, SCREEN_Y, CLIENT_X, CLIENT_Y, true, true, true, true));
    listener.cancel();

    assertTrue("Expected child to receive event", listener.childReceived);
    assertTrue("Expected parent to receive event", listener.parentReceived);
  }
Example #5
0
  /** Test an event that supports shift keys by testing each shift key individually. */
  private void testTriggerEventWithShiftKeys(
      BubbleAssertingEventListener listener, EventCreator creator) {
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

    listener.setExpectedShiftKeys(true, true, true, true);
    child.dispatchEvent(creator.createEvent(true, true, true, true));
    listener.assertReceived();

    listener.setExpectedShiftKeys(true, false, false, false);
    child.dispatchEvent(creator.createEvent(true, false, false, false));
    listener.assertReceived();

    listener.setExpectedShiftKeys(false, true, false, false);
    child.dispatchEvent(creator.createEvent(false, true, false, false));
    listener.assertReceived();

    listener.setExpectedShiftKeys(false, false, true, false);
    child.dispatchEvent(creator.createEvent(false, false, true, false));
    listener.assertReceived();

    listener.setExpectedShiftKeys(false, false, false, true);
    child.dispatchEvent(creator.createEvent(false, false, false, true));
    listener.assertReceived();
  }
Example #6
0
  /**
   * Check to see if the touch has moved off of the element.
   *
   * <p>NOTE that in iOS the elasticScroll may make the touch/move cancel more difficult.
   *
   * @param event
   */
  private void onTouchMove(Event event) {

    if (!this.touchMoved) {
      Touch move = null;

      for (int i = 0; i < event.getChangedTouches().length(); i++) {
        if (event.getChangedTouches().get(i).getIdentifier() == this.touchId) {
          move = event.getChangedTouches().get(i);
        }
      }

      // Check to see if we moved off of the original element

      // Use Page coordinates since we compare with widget's absolute
      // coordinates
      if (move != null) {
        int yCord = move.getPageY();
        int xCord = move.getPageX();

        // is y above element
        boolean yTop = this.getAbsoluteTop() > yCord;
        boolean yBottom = (this.getAbsoluteTop() + this.getOffsetHeight()) < yCord; // y below

        // is x to the left of element
        boolean xLeft = this.getAbsoluteLeft() > xCord;
        boolean xRight = (this.getAbsoluteLeft() + this.getOffsetWidth()) < xCord; // x to the right

        if (yTop || yBottom || xLeft || xRight) {
          this.touchMoved = true;
          onHoldPressOffStyle(); // Go back to normal style
        }
      }
    }
  }
  @Override
  public void setCampaignList(List<Campaign> campaignList) {
    int i = 0;
    TableSectionElement tbody = campaignTable.getTBodies().getItem(0);
    for (final Campaign cam : campaignList) {
      TableRowElement tr = tbody.insertRow(i);
      tr.setAttribute("class", "items");

      TableCellElement tdName = tr.insertCell(0);
      tdName.setInnerText(cam.getTitle());

      TableCellElement tdCat = tr.insertCell(1);
      tdCat.setAttribute("class", "text-right color-success");
      tdCat.setInnerText(cam.getTags().get(0));

      TableCellElement tcDate = tr.insertCell(2);
      tcDate.setInnerText(cam.getDate());

      TableCellElement tcOp = tr.insertCell(3);
      tcOp.setClassName("text-center");

      AnchorElement aEdit = Document.get().createAnchorElement();
      aEdit.setClassName("label label-default");
      aEdit.setInnerHTML("<i class=\"fa fa-pencil\"></i>");

      AnchorElement aDel = Document.get().createAnchorElement();
      aDel.setClassName("label label-danger");
      aDel.setInnerHTML("<i class=\"fa fa-times\"></i>");

      tcOp.appendChild(aEdit);
      tcOp.appendChild(aDel);

      Event.sinkEvents(aEdit, Event.ONCLICK);
      Event.setEventListener(
          aEdit,
          new EventListener() {
            @Override
            public void onBrowserEvent(Event event) {
              System.out.println("ok");
              if (Event.ONCLICK == event.getTypeInt()) {
                listener.goTo(new EditCampaignPlace("", cam));
              }
            }
          });

      Event.sinkEvents(aDel, Event.ONCLICK);
      Event.setEventListener(
          aDel,
          new EventListener() {
            @Override
            public void onBrowserEvent(Event event) {
              if (Event.ONCLICK == event.getTypeInt()) {
                Window.alert("Borrar " + cam.getTitle());
              }
            }
          });
      i++;
    }
  }
 protected void onTargetOver(Event ce) {
   if (disabled || !target.getElement().isOrHasChild(ce.getEventTarget().<Element>cast())) {
     return;
   }
   clearTimer("hide");
   targetXY = new Point(ce.getClientX(), ce.getClientY());
   delayShow();
 }
  @Override
  public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    if (listenTextChangeEvents && (event.getTypeInt() & TEXTCHANGE_EVENTS) == event.getTypeInt()) {
      deferTextChangeEvent();
    }
  }
Example #10
0
 @Override
 public void onBrowserEvent(Event event) {
   if (DOM.eventGetType(event) == Event.ONMOUSEDOWN && enabled) {
     setupPopup();
     popup.setPopupPosition(event.getClientX(), event.getClientY());
     popup.show();
   }
 }
Example #11
0
 /** {@inheritDoc} */
 @Override
 public void onBrowserEvent(Event event) {
   super.onBrowserEvent(event);
   if ((event.getTypeInt() != Event.ONCLICK)
       && ((Element) event.getEventTarget().cast()).isOrHasChild(file.dom)) {
     button.onBrowserEvent(event);
   }
 }
Example #12
0
 @Override
 public void onBrowserEvent(Event event) {
   super.onBrowserEvent(event);
   if (event.getTypeInt() == Event.ONLOAD) {
     Util.notifyParentOfSizeChange(this, true);
     event.cancelBubble(true);
   }
 }
 @Override
 public void sinkEvents(int eventBitsToAdd) {
   // Sink on the actual element because that's what gets clicked
   if (isOrWasAttached()) {
     Event.sinkEvents(getElement(), eventBitsToAdd | Event.getEventsSunk(getElement()));
   } else {
     super.sinkEvents(eventBitsToAdd);
   }
 }
Example #14
0
  /** Tests createLoadEvent(). */
  public void testTriggerLoadEvent() {
    ImgEventListener listener = new ImgEventListener("load");
    Event.setEventListener(parent, listener);
    Event.setEventListener(img, listener);

    img.dispatchEvent(Document.get().createLoadEvent());

    assertTrue("Expected img to receive event", listener.imgReceived);
  }
Example #15
0
 private void choiceDestroyLinkClick(Event e) {
   e.preventDefault();
   if (!isDisabled) {
     pendingDestroyClick = true;
     Element target = e.getEventTarget().cast();
     choiceDestroy($(target));
   } else {
     e.stopPropagation();
   }
 }
Example #16
0
 public void onBrowserEvent(com.google.gwt.user.client.Event event) {
   if (DOM.eventGetType(event) == Event.ONCONTEXTMENU) {
     if (isFileListShowing()) {
       getFileList().showContextMenu(event);
     } else if (isUserListVisible()) {
       getGroups().setCurrent(null);
       getGroups().showPopup(event.getClientX(), event.getClientY());
     }
   }
 };
Example #17
0
  /**
   * Tests createErrorEvent().
   *
   * <p>Failed in all modes due to HtmlUnit bug: https://sourceforge.net/tracker/?func
   * =detail&aid=2888342&group_id=47038&atid=448266
   */
  @DoNotRunWith({Platform.HtmlUnitBug})
  public void testTriggerErrorEvent() {
    ImgEventListener listener = new ImgEventListener("error");
    Event.setEventListener(parent, listener);
    Event.setEventListener(img, listener);

    img.dispatchEvent(Document.get().createErrorEvent());

    assertTrue("Expected child to receive event", listener.imgReceived);
  }
Example #18
0
 @Override
 public void onBrowserEvent(Event event) {
   if (cancelled) {
     return;
   }
   super.onBrowserEvent(event);
   assertEquals(KEY_CODE, event.getKeyCode());
   // shouldn't throw:
   event.getCharCode();
 }
Example #19
0
  /** Tests createChangeEvent(). */
  public void testTriggerChangeEvent() {
    BubbleAssertingEventListener listener = new BubbleAssertingEventListener("change", false);
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

    child.dispatchEvent(Document.get().createChangeEvent());
    listener.cancel();

    assertTrue("Expected child to receive event", listener.childReceived);
  }
Example #20
0
 /**
  * Assert that all shift keys are in the expected state.
  *
  * @param event the event that was triggered
  */
 private static void assertAllShiftKeys(
     Event event,
     boolean expectedCtrl,
     boolean expectedAlt,
     boolean expectedShift,
     boolean expectedMeta) {
   assertEquals("Expecting ctrl = " + expectedCtrl, expectedCtrl, event.getCtrlKey());
   assertEquals("Expecting alt = " + expectedAlt, expectedAlt, event.getAltKey());
   assertEquals("Expecting shift = " + expectedShift, expectedShift, event.getShiftKey());
   assertEquals("Expecting meta = " + expectedMeta, expectedMeta, event.getMetaKey());
 }
  @Override
  public void onBrowserEvent(Event event) {
    // When resize support is disabled, fall-back to default browser behavior
    if (!resizeSupportEnabled) {
      super.onBrowserEvent(event);
      return;
    }

    // Set the default dialog's dimensions as minimal dimensions
    if (minWidth == 0 || minHeight == 0) {
      minWidth = getOffsetWidth();
      minHeight = getOffsetHeight();
    }

    // While dragging dialog's edge is on, disable default event behavior
    if (dragging) {
      event.preventDefault();
    } else {
      super.onBrowserEvent(event);
    }

    final int eventType = DOM.eventGetType(event);
    if (Event.ONMOUSEMOVE == eventType) {
      if (dragging) {
        // Get cursor's position
        int cursorX = event.getClientX();
        int cursorY = event.getClientY();

        // Calculates dialog's new dimensions
        int newWidth = cursorX - DOM.getAbsoluteLeft(getElement()) + EDGE_SIZE;
        int newHeight = cursorY - DOM.getAbsoluteTop(getElement()) + EDGE_SIZE;

        updateDialogDimensions(newWidth, newHeight);
      } else {
        updateResizeCursor(event);
      }
    } else if (Event.ONMOUSEDOWN == eventType) {
      if (updateResizeCursor(event) && !dragging) {
        event.preventDefault();
        dragging = true;
        DOM.setCapture(getElement());
      }
    } else if (Event.ONMOUSEUP == eventType) {
      if (dragging) {
        dragging = false;
        DOM.releaseCapture(getElement());
      }
    } else if (Event.ONMOUSEOUT == eventType) {
      if (!dragging) {
        updateResizeCursor(event);
      }
    }
  }
Example #22
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");
        }
      }
    }
Example #23
0
  private boolean choicesClick(Event e) {
    e.preventDefault();

    Element target = e.getEventTarget().cast();
    GQuery $e = $(target);

    if (activeField
        && !($e.hasClass(css.searchChoice()) || !$e.parents("." + css.searchChoice()).isEmpty())
        && !resultsShowing) {
      resultsShow();
    }
    return false;
  }
  public static boolean dispatchKeyType(Event e, Handler<KeyEvent> handler) {
    final KeyEvent event = EventTranslator.toKeyEvent(e);

    if (e.getCharCode() == 0) return true;
    if (e.getCharCode() == '\n') return true;
    if (e.getCharCode() == '\r') return true;
    if (event.has(ModifierKey.META) || event.has(ModifierKey.ALT) || event.has(ModifierKey.CONTROL))
      return true;

    handler.handle(event);

    return !event.isConsumed();
  }
Example #25
0
  /**
   * TODO check if we need to support this with touch based devices.
   *
   * <p>Checks if the cursor was inside the browser content area when the event happened.
   *
   * @param event The event to be checked
   * @return true, if the cursor is inside the browser content area
   *     <p>false, otherwise
   */
  private boolean cursorInsideBrowserContentArea(Event event) {
    if (event.getClientX() < 0 || event.getClientY() < 0) {
      // Outside to the left or above
      return false;
    }

    if (event.getClientX() > Window.getClientWidth()
        || event.getClientY() > Window.getClientHeight()) {
      // Outside to the right or below
      return false;
    }

    return true;
  }
Example #26
0
  @Override
  protected void gwtSetUp() throws Exception {
    parent = Document.get().createDivElement();
    child = Document.get().createTextInputElement();
    img = Document.get().createImageElement();

    Document.get().getBody().appendChild(parent);
    parent.appendChild(child);
    parent.appendChild(img);

    Event.sinkEvents(parent, ALL_EVENTS);
    Event.sinkEvents(child, ALL_EVENTS);
    Event.sinkEvents(img, ALL_EVENTS);
  }
Example #27
0
  private void onTouchStart(Event event) {

    onHoldPressDownStyle(); // Show style change

    // Stop the event from bubbling up
    event.stopPropagation();

    // Only handle if we have exactly one touch
    if (event.getTargetTouches().length() == 1) {
      Touch start = event.getTargetTouches().get(0);
      this.touchId = start.getIdentifier();
      this.touchMoved = false;
    }
  }
Example #28
0
  /**
   * Blurs the time box if the user clicks outside of it.
   *
   * <p>
   *
   * @param event the native preview event
   */
  protected void previewNativeEvent(NativePreviewEvent event) {

    Event nativeEvent = Event.as(event.getNativeEvent());
    if ((nativeEvent.getTypeInt() == Event.ONCLICK)) {
      EventTarget target = nativeEvent.getEventTarget();
      if (!Element.is(target)) {
        return;
      }
      Element element = Element.as(target);
      if (!m_time.getElement().isOrHasChild(element)) {
        m_time.blur();
      }
    }
  }
Example #29
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");
      }
    }
Example #30
0
 private void updateAutoHide(Event event) {
   int x = event.getClientX();
   int y = event.getClientY();
   boolean ix1 =
       x > getDatePickerBox().getAbsoluteLeft()
           && x < getDatePickerBox().getAbsoluteLeft() + getDatePickerBox().getOffsetWidth();
   boolean iy1 =
       y > getDatePickerBox().getAbsoluteTop()
           && y < getDatePickerBox().getAbsoluteTop() + getDatePickerBox().getOffsetHeight();
   boolean ix2 =
       x > dateBox.getAbsoluteLeft() && x < dateBox.getAbsoluteLeft() + dateBox.getOffsetWidth();
   boolean iy2 =
       y > dateBox.getAbsoluteTop() && y < dateBox.getAbsoluteTop() + dateBox.getOffsetHeight();
   getDatePickerBox().setAutoHideEnabled(!(ix1 && iy1 || ix2 && iy2));
 }