Esempio n. 1
0
  /**
   * Copy constructor. Generating a copy of the given model.
   *
   * <p>
   *
   * @param model the model to copy
   */
  public PositionBean(PositionBean model) {

    m_height = model.getHeight();
    m_left = model.getLeft();
    m_top = model.getTop();
    m_width = model.getWidth();
  }
Esempio n. 2
0
  /**
   * Resets the in line editing toolbar position.
   *
   * <p>
   */
  private void resetToolbarContainerPosition() {

    if (m_toolbarContainer != null) {
      PositionBean position = PositionBean.generatePositionInfo(m_contentElement);
      m_toolbarContainer.getStyle().setTop(position.getTop() - 5, Unit.PX);
      m_toolbarContainer.getStyle().setLeft(position.getLeft(), Unit.PX);
    }
  }
Esempio n. 3
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;
  }
Esempio n. 4
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);
    }
  }