Java 类com.google.gwt.dom.client.BRElement 实例源码

项目:Wiab.pro    文件:ParagraphHelperBr.java   
/**
 * Get the spacer for the given paragraph.
 * Lazily creates & registers one if not present.
 * If there's one that the browser created, registers it as our own.
 * If the browser put a different one in to the one that we were already
 * using, replace ours with the browser's.
 * @param paragraph
 * @return The spacer
 */
protected BRElement getSpacer(Element paragraph) {
  Node last = paragraph.getLastChild();
  BRElement spacer = paragraph.getPropertyJSO(BR_REF).cast();
  if (spacer == null) {
    // Register our spacer, using one the browser put in if present
    spacer = isSpacer(last) ? last.<BRElement>cast() : Document.get().createBRElement();
    setupSpacer(paragraph, spacer);
  } else if (isSpacer(last) && last != spacer) {
    // The browser put a different one in by itself, so let's use that one
    if (spacer.hasParentElement()) {
      spacer.removeFromParent();
    }
    spacer = last.<BRElement>cast();
    setupSpacer(paragraph, spacer);
  }
  return spacer;
}
项目:incubator-wave    文件:ParagraphHelperBr.java   
/**
 * Get the spacer for the given paragraph.
 * Lazily creates & registers one if not present.
 * If there's one that the browser created, registers it as our own.
 * If the browser put a different one in to the one that we were already
 * using, replace ours with the browser's.
 * @param paragraph
 * @return The spacer
 */
protected BRElement getSpacer(Element paragraph) {
  Node last = paragraph.getLastChild();
  BRElement spacer = paragraph.getPropertyJSO(BR_REF).cast();
  if (spacer == null) {
    // Register our spacer, using one the browser put in if present
    spacer = isSpacer(last) ? last.<BRElement>cast() : Document.get().createBRElement();
    setupSpacer(paragraph, spacer);
  } else if (isSpacer(last) && last != spacer) {
    // The browser put a different one in by itself, so let's use that one
    if (spacer.hasParentElement()) {
      spacer.removeFromParent();
    }
    spacer = last.<BRElement>cast();
    setupSpacer(paragraph, spacer);
  }
  return spacer;
}
项目:Wiab.pro    文件:ParagraphHelperWebkit.java   
private void ensureSpacerIfDoesntEndWithText(Element paragraph) {
  Node last = paragraph.getLastChild();
  BRElement spacer = getSpacer(paragraph);
  if (last == spacer) {
    last = last.getPreviousSibling();
  }
  if (last == null || DomHelper.isElement(last)) {
    paragraph.appendChild(spacer);
  } else {
    spacer.removeFromParent();
  }
}
项目:Wiab.pro    文件:ParagraphHelperBr.java   
/**
 * @param n Node to test, or null
 * @return true if n is a spacer <br/>, WHETHER OR NOT we created it
 *   or the browser's native editor created it
 */
protected boolean isSpacer(Node n) {
  if (n == null) {
    return false;
  }
  if (DomHelper.isTextNode(n)) {
    return false;
  }
  Element e = n.cast();
  return e.getTagName().equalsIgnoreCase(BRElement.TAG) && !NodeManager.hasBackReference(e);
}
项目:Wiab.pro    文件:ParagraphHelperEmptyLineBr.java   
/**
 * {@inheritDoc}
 */
@Override
public void onRemovingChild(Node child, Element paragraph) {
  Node first = paragraph.getFirstChild();
  BRElement spacer = getSpacer(paragraph);
  if (first == null) {
    appendSpacer(paragraph);
  } else if (first != spacer) {
    spacer.removeFromParent();
  }
}
项目:Wiab.pro    文件:Blip.java   
/**
 * Converts the given {@code HTML} into robot compatible plaintext.
 *
 * @param html the {@code HTML} to convert.
 * @return a plain text version of the given {@code HTML}.
 */
private static String convertToPlainText(String html) {
  StringBuffer result = new StringBuffer();
  Matcher matcher = MARKUP_PATTERN.matcher(html);
  while (matcher.find()) {
    String replacement = "";
    String tag = matcher.group().substring(1, matcher.group().length() - 1).split(" ")[0];
    if (ParagraphElement.TAG.equalsIgnoreCase(tag) || BRElement.TAG.equalsIgnoreCase(tag)) {
      replacement = "\n";
    }
    matcher.appendReplacement(result, replacement);
  }
  matcher.appendTail(result);
  return result.toString();
}
项目:Wiab.pro    文件:Markup.java   
/**
 * Converts the given {@code HTML} into robot compatible plain text.
 *
 * @param html the text to convert.
 * @return a plain text version of the given html text.
 */
private static String convertToPlainText(String html) {
  StringBuffer result = new StringBuffer();
  Matcher matcher = MARKUP_PATTERN.matcher(html);
  while (matcher.find()) {
    String replacement = "";
    String tag = matcher.group().substring(1, matcher.group().length() - 1).split(" ")[0];
    if (ParagraphElement.TAG.equalsIgnoreCase(tag) || BRElement.TAG.equalsIgnoreCase(tag)) {
      replacement = "\n";
    }
    matcher.appendReplacement(result, replacement);
  }
  matcher.appendTail(result);
  return result.toString();
}
项目:incubator-wave    文件:ParagraphHelperWebkit.java   
private void ensureSpacerIfDoesntEndWithText(Element paragraph) {
  Node last = paragraph.getLastChild();
  BRElement spacer = getSpacer(paragraph);
  if (last == spacer) {
    last = last.getPreviousSibling();
  }
  if (last == null || DomHelper.isElement(last)) {
    paragraph.appendChild(spacer);
  } else {
    spacer.removeFromParent();
  }
}
项目:incubator-wave    文件:ParagraphHelperEmptyLineBr.java   
/**
 * {@inheritDoc}
 */
@Override
public void onRemovingChild(Node child, Element paragraph) {
  Node first = paragraph.getFirstChild();
  BRElement spacer = getSpacer(paragraph);
  if (first == null) {
    appendSpacer(paragraph);
  } else if (first != spacer) {
    spacer.removeFromParent();
  }
}
项目:Wiab.pro    文件:ParagraphHelperBr.java   
/**
 * Setup the given br element as the paragraph's spacer
 * @param paragraph
 * @param spacer
 */
private void setupSpacer(Element paragraph, BRElement spacer) {
  NodeManager.setTransparency(spacer, Skip.DEEP);
  paragraph.setPropertyJSO(BR_REF, spacer);
}
项目:incubator-wave    文件:ParagraphHelperBr.java   
/**
 * Setup the given br element as the paragraph's spacer
 * @param paragraph
 * @param spacer
 */
private void setupSpacer(Element paragraph, BRElement spacer) {
  NodeManager.setTransparency(spacer, Skip.DEEP);
  paragraph.setPropertyJSO(BR_REF, spacer);
}