Example #1
0
 private void updateFeedbackPosition() {
   if (isVertical()) {
     feedbackPopup.setPopupPosition(
         handle.getAbsoluteLeft() + handle.getOffsetWidth(),
         handle.getAbsoluteTop()
             + handle.getOffsetHeight() / 2
             - feedbackPopup.getOffsetHeight() / 2);
   } else {
     feedbackPopup.setPopupPosition(
         handle.getAbsoluteLeft()
             + handle.getOffsetWidth() / 2
             - feedbackPopup.getOffsetWidth() / 2,
         handle.getAbsoluteTop() - feedbackPopup.getOffsetHeight());
   }
 }
Example #2
0
  private void setValueByEvent(Event event, boolean updateToServer) {
    double v = min; // Fallback to min

    final int coord = getEventPosition(event);

    final int handleSize, baseSize, baseOffset;
    if (isVertical()) {
      handleSize = handle.getOffsetHeight();
      baseSize = base.getOffsetHeight();
      baseOffset = base.getAbsoluteTop() - Window.getScrollTop() - handleSize / 2;
    } else {
      handleSize = handle.getOffsetWidth();
      baseSize = base.getOffsetWidth();
      baseOffset = base.getAbsoluteLeft() - Window.getScrollLeft() + handleSize / 2;
    }

    if (isVertical()) {
      v = (baseSize - (coord - baseOffset)) / (double) (baseSize - handleSize) * (max - min) + min;
    } else {
      v = (coord - baseOffset) / (double) (baseSize - handleSize) * (max - min) + min;
    }

    if (v < min) {
      v = min;
    } else if (v > max) {
      v = max;
    }

    setValue(v, updateToServer);
  }
  public void testSimpleDrag() {
    delayTestFinish(5000);
    final Element elem = Document.get().getElementById(id);
    Document.get().createClickEvent(0, 10, 10, 10, 10, false, false, false, false);

    NativeEvent evt;

    final int oldX = elem.getAbsoluteLeft();
    final int oldY = elem.getAbsoluteTop();

    evt = Document.get().createMouseDownEvent(0, 10, 10, 10, 10, false, false, false, false, 1);
    elem.dispatchEvent(evt);

    assertEquals("draggable x after mouse down", oldX, elem.getAbsoluteLeft());
    assertEquals("draggabel y after mouse down", oldY, elem.getAbsoluteTop());

    new Step() {
      @Override
      void run() {
        NativeEvent evt =
            Document.get().createMouseMoveEvent(0, 20, 20, 200, 200, false, false, false, false, 1);
        elem.dispatchEvent(evt);

        assertEquals("draggable x after mouse move", oldX + 190, elem.getAbsoluteLeft());
        assertEquals("draggabel y after mouse move", oldY + 190, elem.getAbsoluteTop());
      }
    };

    new Step() {
      @Override
      void run() {
        NativeEvent evt =
            Document.get().createMouseUpEvent(0, 20, 20, 100, 100, false, false, false, false, 1);
        elem.dispatchEvent(evt);

        assertEquals("draggable x after mouse up", oldX + 90, elem.getAbsoluteLeft());
        assertEquals("draggable y after mouse up", oldY + 90, elem.getAbsoluteTop());
      }
    };

    new Step() {
      @Override
      void run() {
        finishTest();
      }
    };
  }
Example #4
0
  private boolean isVisible() {
    Element element = lockTarget.getWidget().getElement();
    boolean visible =
        UIObject.isVisible(element)
            && (element.getAbsoluteLeft() != 0)
            && (element.getAbsoluteTop() != 0);

    return visible;
  }
Example #5
0
  /**
   * Collects the position information of the given UI object and returns a position info bean.
   *
   * <p>
   *
   * @param element the object to read the position data from
   * @return the position data
   */
  public static PositionBean generatePositionInfo(Element element) {

    PositionBean result = new PositionBean();
    result.setHeight(element.getOffsetHeight());
    result.setWidth(element.getOffsetWidth());
    result.setTop(element.getAbsoluteTop());
    result.setLeft(element.getAbsoluteLeft());
    return result;
  }
Example #6
0
  private boolean isSetupChunk(Element el, AceEditorNative editor) {
    int pageX = el.getAbsoluteLeft();
    int pageY = el.getAbsoluteTop();

    Position position = editor.getRenderer().screenToTextCoordinates(pageX, pageY);

    String line = editor.getSession().getLine(position.getRow());

    return line.contains("r setup");
  }
Example #7
0
 private int computeNewValue(DragEvent e) {
   Element ele = getElement();
   int offset = (int) e.X - ele.getAbsoluteLeft();
   int width = ele.getClientWidth();
   int value = offset * 100 / width;
   if (value > 100) {
     value = 100;
   } else if (value < 0) {
     value = 0;
   }
   return value;
 }
Example #8
0
  public WidgetArea(Widget widget, Widget reference) {
    setLeft(widget.getAbsoluteLeft());
    setTop(widget.getAbsoluteTop());

    if (reference != null) {
      setLeft(
          getLeft() - reference.getAbsoluteLeft() - DOMUtil.getBorderLeft(reference.getElement()));
      setTop(getTop() - reference.getAbsoluteTop() - DOMUtil.getBorderTop(reference.getElement()));
    }
    setRight(getLeft() + widget.getOffsetWidth());
    setBottom(getTop() + widget.getOffsetHeight());

    Element elem = widget.getElement().getOffsetParent();
    Element p;

    while (elem != null && (p = elem.getOffsetParent()) != null) {
      int left = elem.getAbsoluteLeft();

      if (getLeft() < left) {
        setLeft(left);
      }

      int top = elem.getAbsoluteTop();
      if (getTop() < top) {
        setTop(top);
      }

      int bottom = top + elem.getOffsetHeight();
      if (getBottom() > bottom) {
        setBottom(bottom);
      }

      int right = left + elem.getOffsetWidth();
      if (getRight() > right) {
        setRight(right);
      }

      elem = p;
    }
  }
  @Override
  public void onBrowserEvent(Event event) {
    GWT.log("slider mouse event: " + DOM.eventGetTypeString(event));
    if (DOM.eventGetType(event) == Event.ONCONTEXTMENU) {

      event.stopPropagation();
      event.preventDefault();

      int x = event.getClientX();
      int y = event.getClientY();
      NodeList<Node> children = getChildren().get(0).getElement().getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        Node child = children.getItem(i);
        Element widget = (Element) child;
        String id = widget.getId();
        GWT.log("checking " + id + " to see if its the rightclicked element");
        int left = widget.getAbsoluteLeft();
        int width = widget.getOffsetWidth();
        int top = widget.getAbsoluteTop();
        int height = widget.getOffsetHeight();

        if (left < x && left + width > x && top < y && top + height > y) {

          this.clickedElement = DOM.getElementById(id);

          GWT.log(editor.getElement().getId() + " context menu for " + id);
          GWT.log("positioning context menu at " + event.getClientX() + "x" + event.getClientY());
          contextMenu.show(event.getClientX(), event.getClientY(), menu);
          break;
        }
      }

    } else if (DOM.eventGetType(event) == Event.ONCLICK) {
      ContextMenu.hide();
    }
    super.onBrowserEvent(event);
  }
Example #10
0
  private Position toDocumentPosition(Element el, AceEditorNative editor) {
    int pageX = el.getAbsoluteLeft();
    int pageY = el.getAbsoluteTop();

    return editor.getRenderer().screenToTextCoordinates(pageX, pageY);
  }
Example #11
0
 /** Kindly borrowed from PlayN. * */
 protected static float getRelativeX(NativeEvent e, Element target) {
   return e.getClientX()
       - target.getAbsoluteLeft()
       + target.getScrollLeft()
       + target.getOwnerDocument().getScrollLeft();
 }
Example #12
0
  /**
   * Returns a position info representing the dimensions of all visible child elements of the given
   * panel (excluding elements with position:absolute). If the panel has no visible child elements,
   * it's outer dimensions are returned.
   *
   * <p>
   *
   * @param panel the panel
   * @param levels the levels to traverse down the DOM tree
   * @param includeSelf <code>true</code> to include the outer dimensions of the given panel
   * @return the position info
   */
  public static PositionBean getInnerDimensions(Element panel, int levels, boolean includeSelf) {

    boolean first = true;
    int top = 0;
    int left = 0;
    int bottom = 0;
    int right = 0;
    // if overflow is set to hidden, use the outer dimensions
    if (!Overflow.HIDDEN.getCssName().equals(DomUtil.getCurrentStyle(panel, Style.overflow))) {
      if (!includeSelf) {
        // check for any text content
        NodeList<Node> children = panel.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
          if ((children.getItem(i).getNodeType() == Node.TEXT_NODE)
              && (children.getItem(i).getNodeValue().trim().length() > 0)) {
            includeSelf = true;
            break;
          }
        }
      }
      if (includeSelf) {
        top = panel.getAbsoluteTop();
        left = panel.getAbsoluteLeft();
        bottom = top + panel.getOffsetHeight();
        right = left + panel.getOffsetWidth();
        first = false;
      }
      Element child = panel.getFirstChildElement();
      while (child != null) {
        String tagName = child.getTagName();
        if (tagName.equalsIgnoreCase("br")
            || tagName.equalsIgnoreCase("tr")
            || tagName.equalsIgnoreCase("thead")
            || tagName.equalsIgnoreCase("tfoot")
            || tagName.equalsIgnoreCase("script")
            || tagName.equalsIgnoreCase("style")) {
          // ignore tags with no relevant position info
          child = child.getNextSiblingElement();
          continue;
        }
        String positioning = DomUtil.getCurrentStyle(child, Style.position);
        if (!Display.NONE.getCssName().equals(DomUtil.getCurrentStyle(child, Style.display))
            && !(positioning.equalsIgnoreCase(Position.ABSOLUTE.getCssName())
                || positioning.equalsIgnoreCase(Position.FIXED.getCssName()))) {
          PositionBean childDimensions =
              levels > 0
                  ? getInnerDimensions(child, levels - 1, true)
                  : generatePositionInfo(panel);
          if (first) {
            first = false;
            top = childDimensions.getTop();
            left = childDimensions.getLeft();
            bottom = top + childDimensions.getHeight();
            right = left + childDimensions.getWidth();
          } else {
            int wTop = childDimensions.getTop();
            top = top < wTop ? top : wTop;
            int wLeft = childDimensions.getLeft();
            left = left < wLeft ? left : wLeft;
            int wBottom = wTop + childDimensions.getHeight();
            bottom = bottom > wBottom ? bottom : wBottom;
            int wRight = wLeft + childDimensions.getWidth();
            right = right > wRight ? right : wRight;
          }
        }
        child = child.getNextSiblingElement();
      }
    }
    if (!first) {
      PositionBean result = new PositionBean();
      result.setHeight(bottom - top);
      result.setWidth(right - left);
      result.setTop(top);
      result.setLeft(left);
      return result;
    } else {
      return generatePositionInfo(panel);
    }
  }