Package com.google.gwt.dom.client

Examples of com.google.gwt.dom.client.Node


    ContentView renderedContent = renderedContentView;
    HtmlView filteredHtml = filteredHtmlView;

    // The element before all previous text node siblings of target,
    // or null if no such element
    Node nodeletBeforeTextNodes;
    ContentNode wrapperBeforeTextNodes;

    // Our cursors
    Text current = target;
    ContentNode possibleOwnerNode;

    // Go leftwards to find the start of the text nodelet sequence
    for (nodeletBeforeTextNodes = filteredHtml.getPreviousSibling(target);
         nodeletBeforeTextNodes != null;
         nodeletBeforeTextNodes = filteredHtml.getPreviousSibling(nodeletBeforeTextNodes)) {
      Text maybeText = filteredHtml.asText(nodeletBeforeTextNodes);
      if (maybeText == null) {
        break;
      }
      current = maybeText;
    }

    Element parentNodelet = filteredHtml.getParentElement(target);
    if (parentNodelet == null) {
      throw new RuntimeException(
          "Somehow we are asking for the wrapper of something not in the editor??");
    }
    ContentElement parentElement = NodeManager.getBackReference(parentNodelet);

    // Find our foothold in wrapper land
    if (nodeletBeforeTextNodes == null) {
      // reached the beginning
      wrapperBeforeTextNodes = null;
      possibleOwnerNode = renderedContent.getFirstChild(parentElement);
    } else {
      // reached an element
      wrapperBeforeTextNodes = NodeManager.getBackReference(
          nodeletBeforeTextNodes.<Element>cast());
      possibleOwnerNode = renderedContent.getNextSibling(wrapperBeforeTextNodes);
    }

    // Scan to find a matching pair
    while (true) {
      // TODO(danilatos): Clarify and possibly reorganise this loop
      // TODO(danilatos): Write more unit tests to thoroughly cover all scenarios

      if (possibleOwnerNode == null) {
        // Scenario (D)
        throw new HtmlInserted(
              Point.inElement(parentElement, (ContentNode) null),
              Point.start(filteredHtml, parentNodelet)
            );
      }

      ContentTextNode possibleOwner;
      try {
        possibleOwner = (ContentTextNode) possibleOwnerNode;
      } catch (ClassCastException e) {
        if (possibleOwnerNode.isImplAttached()) {
          // Scenario (C)
          throw new HtmlInserted(
                Point.inElement(parentElement, possibleOwnerNode),
                Point.inElementReverse(filteredHtml, parentNodelet, nodeletBeforeTextNodes)
              );
        } else {
          // Scenario (A)
          // Not minor, an element has gone missing
          throw new HtmlMissing(possibleOwnerNode, parentNodelet);
        }
      }

      ContentNode nextNode = renderedContent.getNextSibling(possibleOwner);
      if (nextNode != null && !nextNode.isImplAttached()) {
        // Scenario (E)
        throw new HtmlMissing(nextNode, parentNodelet);
      }

      if (current != possibleOwner.getImplNodelet()) {
        // Scenario (B)
        if (attemptRepair) {
          possibleOwner.setTextNodelet(current);
          return nullifyIfWrongDocument(possibleOwner);
        } else {
          // TODO(danilatos): Ensure repairs handle nodes on either
          // side, as this is kind of a "replace" error
          throw new HtmlInserted(
              Point.inElement(parentElement, possibleOwner),
              Point.inElement(parentNodelet, current));
        }
      }

      Node nextNodelet = nextNode == null ? null : nextNode.getImplNodelet();

      while (current != nextNodelet && current != null) {
        // TODO(danilatos): Fix up every where in the code to use .equals
        // for GWT DOM.
        if (current == target) {
View Full Code Here


    }
    return output;
  }

  Point<Node> wrapperElementPointToNodeletPoint(Point<ContentNode> point) {
    Node nodeletAfter;

    // TODO(danilatos): return null for points that don't correspond to a location
    // in the html.

    if (point.getNodeAfter() == null) {
      // Scan backwards over trailing, non-implemented html (such as the spacer BR
      // for paragraphs) until we reach the last nodelet that has a wrapper -
      // then go one forward again and that's the nodeAfter we want to use.
      // E.g. if the content point is at the end of a paragraph, we want the nodelet
      // point to be the paragraph nodelet and the nodeAfter to be the spacer br,
      // if it is present.
      // TODO(danilatos): Clean this up & make more efficient.
      Element container = ((ContentElement) point.getContainer()).getContainerNodelet();

      // NOTE(danilatos): This could be null because the doodad is handling its own
      // rendering explicitly, so there is no clear mapping to the corresponding html
      // point.
      if (container == null) {
        return null;
      }

      Node lastWrappedNodelet = container.getLastChild();
      while (lastWrappedNodelet != null && !DomHelper.isTextNode(lastWrappedNodelet)
          && NodeManager.getBackReference(lastWrappedNodelet.<Element>cast()) == null) {
        lastWrappedNodelet = lastWrappedNodelet.getPreviousSibling();
      }
      nodeletAfter = lastWrappedNodelet == null
          ? container.getFirstChild() : lastWrappedNodelet.getNextSibling();
    } else {
      nodeletAfter = point.getNodeAfter().getImplNodeletRightwards();
    }

    if (nodeletAfter == null) {
      ContentElement visibleNode = renderedContentView.getVisibleNode(
          point.getContainer()).asElement();
      assert visibleNode != null;

      Element el = visibleNode.getContainerNodelet();
      return el != null ? Point.<Node>inElement(el, null) : null;
    } else {
      Node parentNode = nodeletAfter.getParentNode();
      // NOTE(danilatos): Instead, getImplNodeletRightwards(), (or the use of
      // some other utility method) should probably instead be guaranteeing nodeletAfter
      // being attached (visibly rendered), otherwise it should be null.
      // For now, we instead check that it has a parent (it might not in both
      // normal and abnormal circumstances).
View Full Code Here

    Point.El<Node> elementPoint = point.asElementPoint();
    if (elementPoint != null) {
      return elementPoint;
    }
    Element parent;
    Node nodeAfter;
    Text text = point.getContainer().cast();
    parent = text.getParentElement();
    int offset = point.getTextOffset();
    if (offset == 0) {
      nodeAfter = text;
View Full Code Here

  }

  public void moveCaret(int distance) {
    Point<Node> caret = getSelectionStart();
    if (!caret.isInTextNode()) {
      Node before = Point.nodeBefore(htmlView, caret.asElementPoint());
      if (DomHelper.isTextNode(before)) {
        caret = Point.inText(before, before.<Text>cast().getLength());
      } else if (DomHelper.isTextNode(caret.getNodeAfter())) {
        caret = Point.inText(caret.getNodeAfter(), 0);
      } else {
        throw new RuntimeException("Unimplemented/Invalid");
      }
View Full Code Here

    // Attempt to associate our location with a node
    // This should be a last resort, ideally we should be given selections
    // in the correct text node, when the selection is at a text node boundary
    if (node == null) {
      HtmlView filteredHtml = filteredHtmlView;
      Node nodeBefore = Point.nodeBefore(filteredHtml, previousSelectionStart.asElementPoint());
      Node nodeAfter = previousSelectionStart.getNodeAfter();
      //TODO(danilatos): Usually we would want nodeBefore as a preference, but
      // not always...
      if (nodeBefore != null && DomHelper.isTextNode(nodeBefore)) {
        node = nodeBefore.cast();
        previousSelectionStart = Point.<Node>inText(node, 0);
      } else if (nodeAfter != null && DomHelper.isTextNode(nodeAfter)) {
        node = nodeAfter.cast();
        previousSelectionStart = Point.<Node>inText(node, node.getLength());
      }
    }

    TypingState t = findTypingState(previousSelectionStart);
View Full Code Here

        contentRange = RestrictedRange.around(renderedContent, firstWrapper, lastWrapper);

        // Ensure methods we call on the text node operate on the same view as us
        assert wrapper.getFilteredHtmlView() == filteredHtml;

        Node htmlNodeBefore = filteredHtml.getPreviousSibling(firstWrapper.getImplNodelet());
        Element htmlParent = filteredHtml.getParentElement(node);
        ContentNode cnodeAfter = contentRange.getNodeAfter();
        Node htmlNodeAfter = cnodeAfter == null ? null : cnodeAfter.getImplNodelet();
        htmlRange = RestrictedRange.between(
            htmlNodeBefore, Point.inElement(htmlParent, htmlNodeAfter));

        if (partOfMutatingRange(filteredHtml.asText(previousSelectionStart.getContainer()))) {
          // This must be true if getWrapper worked correctly. Program error
          // otherwise (not browser error)
          assert firstWrapper.getImplNodelet() == htmlRange.getStartNode(filteredHtml);

          // NOTE(danilatos): We are asking the firstWrapper to give us the offset of
          // a nodelet that might not actually belong to it, but to its next sibling.
          // This is ok, because we tell it what node to stop the search at, and it
          // doesn't know any better.
          minpre = previousSelectionStart.getTextOffset() +
            firstWrapper.getOffset(node, htmlNodeAfter);
        }


      } catch (HtmlInserted e) {
        // Exception caught -> no wrapper for this node (we're starting a new chunk of text)
        Node nodeAfter = e.getHtmlPoint().getNodeAfter();
        if (!DomHelper.isTextNode(nodeAfter)) {
          throw e;
        }
        node = nodeAfter.cast();

        contentRange = RestrictedRange.collapsedAt(renderedContent, e.getContentPoint());
        Node before = contentRange.getNodeBefore() == null
            ? null : contentRange.getNodeBefore().getImplNodelet();
        Node after = contentRange.getNodeAfter() == null
            ? null : contentRange.getNodeAfter().getImplNodelet();
        htmlRange    = RestrictedRange.between(before,
            Point.inElement(contentRange.getContainer().getImplNodelet(), after));
      }
    }
View Full Code Here

          if (prev != null && prev.isTextNode()) {
            firstWrapper = (ContentTextNode)prev;
          }
        } else {
          ContentNode nextNode = renderedContent.getNextSibling(lastWrapper);
          Node nextNodelet = nextNode != null ? nextNode.getImplNodelet() : null;
          if (selOffset == selNode.getLength() &&
              filteredHtml.getNextSibling(selNode) == nextNodelet) {
            // if we are at end of mutating node
            if (nextNode != null && nextNode.isTextNode()) {
              lastWrapper = (ContentTextNode)nextNode;
View Full Code Here

     * @return The current value of the text in the html, within our tracked range
     */
    private String calculateNewValue() {
      HtmlView filteredHtml = filteredHtmlView;
      Text fromIncl = htmlRange.getStartNode(filteredHtml).cast();
      Node toExcl = htmlRange.getPointAfter().getNodeAfter();

      return ContentTextNode.sumTextNodes(fromIncl, toExcl, filteredHtml);
    }
View Full Code Here

        (signal.getType().equals(BrowserEvents.DOMCharacterDataModified) ||
         signal.getType().equals(BrowserEvents.DOMNodeInserted))) {

      Text textNode = signal.getTarget().cast();
      if (textNode.getLength() > 0) {
        Node e = textNode.getPreviousSibling();
        if (e != null && !DomHelper.isTextNode(e)
            && e.<Element>cast().getTagName().toLowerCase().equals("a")) {

          FocusedPointRange<Node> selection =  editorInteractor.getHtmlSelection();
          if (selection.isCollapsed() && selection.getFocus().getTextOffset() == 0) {
            editorInteractor.noteWebkitEndOfLinkHackOccurred(textNode);
          }
View Full Code Here

  private boolean maybeStrip(Node node) {
    if (node == null || DomHelper.isTextNode(node)) return false;

    Element element = node.cast();
    if (!NodeManager.hasBackReference(element)) {
      Node n;
      while ((n = element.getFirstChild()) != null) {
        element.getParentNode().insertBefore(n, element);
      }
      element.removeFromParent();
      return true;
View Full Code Here

TOP

Related Classes of com.google.gwt.dom.client.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.