Examples of CMutableDocument


Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    editor.init(registries, KeyBindingRegistry.NONE, EditorSettings.DEFAULT);

    // Now the actual test

    ContentSerialisationUtil.setContentString(editor, "<body><line/>abc</body>");
    CMutableDocument doc = editor.getDocument();
    doc.setAnnotation(3, 4, "style/color", "red");

    editor.getContent().debugCheckHealthy2();
    timerService.tick(1000);
    ContentView fullDoc = ((EditorImpl) editor).getContent().getFullContentView();
    assertNotNull(
        DocHelper.getElementWithTagName(fullDoc, AnnotationPaint.SPREAD_FULL_TAGNAME));
    doc.setAnnotation(3, 4, "style/color", null);
    timerService.tick(1000);
    assertNull(DocHelper.getElementWithTagName(fullDoc, AnnotationPaint.SPREAD_FULL_TAGNAME));

    doc.setAnnotation(3, 5, "style/color", "red");
    editor.removeContentAndUnrender();
    editor.reset();
    timerService.tick(1000);
    assertNull(DocHelper.getElementWithTagName(fullDoc, AnnotationPaint.SPREAD_FULL_TAGNAME));
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

   * Builds a string representation of the annotations in the current document.
   *
   * @return formatted string of all the annotations in the document
   */
  private String getAnnotations() {
    CMutableDocument doc = editorImpl.mutable();
    int end = doc.size();
    // Grab a cursor over the whole document for our known keys
    Iterable<RangedAnnotation<Object>> rangedAnnotations =
        editorImpl.getContent().getLocalAnnotations().rangedAnnotations(0, end, null);
    StringBuilder retval = new StringBuilder();
    for (RangedAnnotation<Object> ann : rangedAnnotations) {
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

  /**
   * Sets the caption text of this doodad.
   */
  public void setCaptionText(String text) {
    CMutableDocument doc = element.getMutableDoc();
    ContentElement caption = DocHelper.getElementWithTagName(doc, Caption.TAGNAME, element);
    if (caption != null) {
      doc.emptyElement(caption);
      doc.insertText(Point.<ContentNode> end(caption), text);
    }
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

  /**
   * Gets the text of the image caption
   */
  public String getCaptionText() {
    CMutableDocument doc = element.getMutableDoc();
    return DocHelper.getText(doc, doc, doc.getLocation(element),
        doc.getLocation(Point.end((ContentNode) element)));
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    return busy;
  }

  @VisibleForTesting  // For testing with p/line container.
  void extract(Element srcContainer, ContentRange previousSelection, BiasDirection cursorBias) {
    final CMutableDocument destDoc = mutableDocument;
    final OperationSequencer<Nindo> destOperationSequencer =
        operationSequencer;
    final LocationMapper<ContentNode> mapper = mutableDocument;

    Point<ContentNode> start = normalize(previousSelection.getFirst());
    Point<ContentNode> end = normalize(previousSelection.getSecond());

    // Delete content if a range was selected
    if (!previousSelection.isCollapsed()) {
      PointRange<ContentNode> range = destDoc.deleteRange(start, end);

      start = range.getFirst();
      end = range.getSecond();
    }

    Point<ContentNode> insertAt = end;
    int pos = mapper.getLocation(insertAt);

    String waveXml = null;
    String annotations = null;
    if (useSemanticCopyPaste) {
      waveXml = clipboard.maybeGetWaveXml(srcContainer);
      annotations = clipboard.maybeGetAnnotations(srcContainer);
    }

    // TODO(user): Pass in whether the pasted content is rich or play
    // TODO(patcoleman): once we have non rich-text paste, fix cursor bias correctly
    cursorBias = BiasDirection.LEFT;

    if (useSemanticCopyPaste && waveXml != null) {
      if (!waveXml.isEmpty()) {
        instrumentor.record(Action.CLIPBOARD_PASTE_FROM_WAVE);

        // initialise the XML:
        Builder builder = at(pos);
        XmlStringBuilder createdFromXmlString =
            XmlStringBuilder.createFromXmlStringWithContraints(waveXml,
                PermittedCharacters.BLIP_TEXT);

        // Strip annotations based on behaviour:
        StringMap<String> modified = annotationLogic.stripKeys(
            destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

        double startTime = Duration.currentTimeMillis();
        // apply xml change
        MutableDocumentImpl.appendXmlToBuilder(createdFromXmlString, builder);
        double timeTaken = Duration.currentTimeMillis() - startTime;
        LOG.trace().log("time taken: " + timeTaken);

        // handle the end of annotations
        annotationLogic.unstripKeys(builder, modified.keySet(), CollectionUtils.createStringSet());
        builder.finish();
        Nindo nindo = builder.build();

        try {
          validator.maybeThrowOperationExceptionFor(nindo);

          int locationAfter = destDoc.getLocation(insertAt) + createdFromXmlString.getLength();
          destOperationSequencer.begin();
          destOperationSequencer.consume(nindo);
          destOperationSequencer.end();
          aggressiveSelectionHelper.setCaret(locationAfter);

          LOG.trace().log("annotations: " + String.valueOf(annotations));
          if (annotations != null && !annotations.isEmpty()) {
            List<RangedAnnotation<String>> deserialize =
                AnnotationSerializer.deserialize(annotations);
            for (RangedAnnotation<String> ann : deserialize) {
              destDoc.setAnnotation(pos + ann.start(), pos + ann.end(), ann.key(), ann.value());
              LOG.trace().log(
                  "pos: " + pos + "start: " + (pos + ann.start()) + " end: " + (pos + ann.end())
                      + " key: " + ann.key() + " value: " + ann.value());
            }
          }
        } catch (OperationException e) {
          LOG.error().log("Semantic paste failed");
          // Restore caret
          aggressiveSelectionHelper.setCaret(insertAt);
        }
      }
    } else {
      instrumentor.record(Action.CLIPBOARD_PASTE_FROM_OUTSIDE);

      // initialize tokenizer and builder
      RichTextTokenizer tokenizer = createTokenizer(srcContainer);
      Builder builder = at(pos);

      // handle annotation starts
      StringMap<String> modified = annotationLogic.stripKeys(
          destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

      // parse the tokens and apply ops
      RichTextMutationBuilder mutationBuilder = new RichTextMutationBuilder(modified);
      ReadableStringSet affectedKeys =
          mutationBuilder.applyMutations(tokenizer, builder, destDoc, insertAt.getContainer());

      // close annotations and finish
      annotationLogic.unstripKeys(builder, modified.keySet(), affectedKeys);
      builder.finish();
      Nindo nindo = builder.build();

      try {
        validator.maybeThrowOperationExceptionFor(nindo);

        destOperationSequencer.begin();
        destOperationSequencer.consume(nindo);
        destOperationSequencer.end();

        int cursorLocation = pos + mutationBuilder.getLastGoodCursorOffset();
        Point<ContentNode> caret = mapper.locate(cursorLocation);
        aggressiveSelectionHelper.setCaret(caret);
      } catch (OperationException e) {
        LOG.error().log("Paste failed");
        aggressiveSelectionHelper.setCaret(insertAt);
      }
    }

    srcContainer.setInnerHTML("");

    // Restore focus back to the editor
    // TODO(user): Write a webdriver to test selection is correct after paste.
    DomHelper.focus(destDoc.getDocumentElement().getContainerNodelet());
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

        editorUndoManager = EditorUndoManager.NOP_IMPL;
      }

      OperationSequencer<Nindo> undoingSequencer = new UndoableSequencer(sequencer, responsibility);

      CMutableDocument undoableDocument = content.createSequencedDocumentWrapper(undoingSequencer);

      pasteExtractor = new PasteExtractor(CommandQueue.HIGH_PRIORITY,
          aggressiveSelectionHelper,
          undoableDocument,
          content.getRenderedView(),
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    if (focusedRange != null) {
      from = focusedRange.getFocus();
    }
    if (url != null && !url.isEmpty()) {
      XmlStringBuilder xml = GadgetXmlUtil.constructXml(url, "", user.getAddress());
      CMutableDocument document = editor.getDocument();
      if (document == null) {
        return;
      }
      if (from != -1) {
        Point<ContentNode> point = document.locate(from);
        document.insertXml(point, xml);
      } else {
        LineContainers.appendLine(document, xml);
      }
    }
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

                }
                /*
                 * From UploadToolbarAction in Walkaround
                 * @author hearnden@google.com (David Hearnden)
                 */
                CMutableDocument doc = editor.getDocument();
                FocusedContentRange selection = editor.getSelectionHelper().getSelectionPoints();
                Point<ContentNode> point;
                if (selection != null) {
                  point = selection.getFocus();
                } else {
                  // Focus was probably lost.  Bring it back.
                  editor.focus(false);
                  selection = editor.getSelectionHelper().getSelectionPoints();
                  if (selection != null) {
                    point = selection.getFocus();
                  } else {
                    // Still no selection.  Oh well, put it at the end.
                    point = doc.locate(doc.size() - 1);
                  }
                }
                XmlStringBuilder content = ImageThumbnail.constructXml(attachmentId, fileName);
                ImageThumbnailWrapper thumbnail = ImageThumbnailWrapper.of(doc.insertXml(point, content));
                thumbnail.setAttachmentId(attachmentId);
              }
            });

            attachmentView.setAttachmentId(attachmentIdGenerator.newAttachmentId());
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

  boolean isEmptyLine(ContentElement e) {
    // The line containing element e is considered empty if its line element is the last
    // element or if it is followed by another line element
    ContentElement lineElement = Line.fromParagraph(e).getLineElement();
    CMutableDocument doc = lineElement.getMutableDoc();
    ContentNode next = doc.getNextSibling(lineElement);
    return next == null
        || (next.asElement() != null && LineRendering.isLineElement(next.asElement()));
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    Map<String, String> secondAttrs = new HashMap<String, String>();

    // TODO(patcoleman): use StringMap<String> instead?
    // copy whitelisted attributes
    CMutableDocument doc = element.getMutableDoc();
    Map<String, String> currentAttrs = line.getAttributes();
    if (currentAttrs != null) {
      for (Entry<String, String> entry : currentAttrs.entrySet()) {
        if (attributeKeptOnNewline(entry.getKey(), entry.getValue())) {
          secondAttrs.put(entry.getKey(), entry.getValue());
        }
      }
    }

    // rewrite to null if no attributes
    if (secondAttrs.isEmpty()) {
      secondAttrs = Attributes.EMPTY_MAP;
    }

    ContentElement newLineElement = doc.createElement(
        doc.locate(doc.getLocation(point)), LineContainers.LINE_TAGNAME, secondAttrs);

    ContentElement newLocalParagraph = Line.fromLineElement(newLineElement).getParagraph();
    element.getSelectionHelper().setCaret(
        Point.start(element.getRenderedContentView(), newLocalParagraph));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.