本文整理匯總了Java中com.google.gwt.dom.client.Node.cast方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.cast方法的具體用法?Java Node.cast怎麽用?Java Node.cast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.dom.client.Node
的用法示例。
在下文中一共展示了Node.cast方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setFocusElement
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* Ensure that the rendered content view's DOM has focus
*
* NOTE(patcoleman): Fixes firefox bug that causes invalid selections while
* mutating DOM that doesn't have focus - fixed by finding the next parent element directly
* editable, and forcing this to have the focus.
*/
private static void setFocusElement(Node node) {
if (UserAgent.isFirefox()) {
// adjust to parent if node is a text node
Element toFocus;
if (DomHelper.isTextNode(node)) {
toFocus = node.getParentElement();
} else {
toFocus = node.<Element>cast();
}
// traverse up until we have a concretely editable element:
while (toFocus != null &&
DomHelper.getContentEditability(toFocus) != ElementEditability.EDITABLE) {
toFocus = toFocus.getParentElement();
}
// then focus it:
if (toFocus != null) {
DomHelper.focus(toFocus);
}
}
}
示例2: getSpacer
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* 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;
}
示例3: getSkipLevel
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
@Override
protected Skip getSkipLevel(Node node) {
// TODO(danilatos): Detect and repair new elements. Currently we just ignore them.
if (DomHelper.isTextNode(node) || NodeManager.hasBackReference(node.<Element>cast())) {
return Skip.NONE;
} else {
Element element = node.<Element>cast();
Skip level = NodeManager.getTransparency(element);
if (level == null) {
if (!getDocumentElement().isOrHasChild(element)) {
return Skip.INVALID;
}
register(element);
}
// For now, we treat unknown nodes as shallow as well.
// TODO(danilatos): Either strip them or extract them
return level == null ? Skip.SHALLOW : level;
}
}
示例4: setImplNodelet
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* Also affects the container nodelet. If the current container nodelet is the
* same as the current impl nodelet, the new container will be the same as the new
* impl nodelet. If it is null, it will stay null. Other scenarios are not supported
*
* @deprecated Use {@link #setImplNodelets(Element, Element)} instead of this method.
*/
@Override
@Deprecated // Use #setImplNodelets(impl, container) instead
public void setImplNodelet(Node nodelet) {
Preconditions.checkNotNull(nodelet,
"Null nodelet not supported with this deprecated method, use setImplNodelets instead");
Preconditions.checkState(containerNodelet == null || containerNodelet == getImplNodelet(),
"Cannot set only the impl nodelet if the container nodelet is different");
Preconditions.checkArgument(!DomHelper.isTextNode(nodelet),
"element cannot have text implnodelet");
Element element = nodelet.cast();
if (this.containerNodelet != null) {
setContainerNodelet(element);
}
setImplNodeletInner(element);
}
示例5: nodeOffsetToNodeletPoint
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* Converts a nodelet/offset pair to a Point of Node.
* Just a simple mapping, it is agnostic to inconsistencies, filtered views, etc.
* @param node
* @param offset
* @return html node point
*/
public static Point<Node> nodeOffsetToNodeletPoint(Node node, int offset) {
if (isTextNode(node)) {
return Point.inText(node, offset);
} else {
Element container = node.<Element>cast();
return Point.inElement(container, nodeAfterFromOffset(container, offset));
}
}
示例6: getNearestElementPosition
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
private OffsetPosition getNearestElementPosition(Node focusNode, int focusOffset) {
Node startContainer;
if (focusNode == null) {
return null;
}
Element e =
DomHelper.isTextNode(focusNode) ? focusNode.getParentElement() : focusNode.<Element>cast();
return e == null ? null
: new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
}
示例7: getPosition
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
private OffsetPosition getPosition(Node focusNode, int focusOffset) {
if (focusNode == null || focusNode.getParentElement() == null) {
// Return null if cannot get selection, or selection is inside an
// "unattached" node.
return null;
}
if (DomHelper.isTextNode(focusNode)) {
// We don't want to split the existing child text node, so we just add
// duplicate the string up to the offset.
Node txt =
Document.get().createTextNode(
focusNode.getNodeValue().substring(0, focusOffset));
try {
mutationListener.startTransientMutations();
focusNode.getParentNode().insertBefore(txt, focusNode);
txt.getParentNode().insertAfter(SPAN, txt);
OffsetPosition ret =
new OffsetPosition(SPAN.getOffsetLeft(), SPAN.getOffsetTop(), SPAN.getOffsetParent());
return ret;
} finally {
SPAN.removeFromParent();
txt.removeFromParent();
mutationListener.endTransientMutations();
}
} else {
Element e = focusNode.cast();
return new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
}
}
示例8: getBounds
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
private IntRange getBounds(Node node, int offset) {
if (node == null || node.getParentElement() == null) {
// Return null if cannot get selection, or selection is inside an
// "unattached" node.
return null;
}
if (DomHelper.isTextNode(node)) {
Element parentElement = node.getParentElement();
return new IntRange(parentElement.getAbsoluteTop(), parentElement.getAbsoluteBottom());
} else {
Element e = node.<Element>cast();
return new IntRange(e.getAbsoluteTop(), e.getAbsoluteBottom());
}
}
示例9: isSpacer
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* @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);
}
示例10: maybeStrip
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* Remove the given node (leaving its children in the dom) if
* it does not correspond to a wrapper ContentNode
* @param node
* @return true if the node was removed, false if not.
*/
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;
}
return false;
}
示例11: maybeStripMarker
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
private void maybeStripMarker(Node node, Element parent, boolean leading) {
if (node == null) {
logEndNotFound("node is null");
return;
}
if (DomHelper.isTextNode(node)) {
Text textNode = node.cast();
String text = textNode.getData();
if (!text.isEmpty()) {
if (leading) {
if (text.charAt(0) == MARKER_CHAR) {
textNode.setData(text.substring(1));
}
} else {
if (text.charAt(text.length() - 1) == MARKER_CHAR) {
textNode.setData(text.substring(0, text.length() - 1));
} else {
logEndNotFound("last character is not marker");
}
}
} else {
logEndNotFound("text node is empty");
}
if (textNode.getData().isEmpty()) {
parent.removeChild(textNode);
}
} else {
// In some cases, Safari will put the marker inside of a div, so this
// traverses down the left or right side of the tree to find it.
// For example: x<div><span>pasted</span>x</div>
maybeStripMarker(leading ? node.getFirstChild() : node.getLastChild(), node.<Element> cast(),
leading);
}
}
示例12: getNextOrPrevNodeDepthFirst
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
@Override
protected Node getNextOrPrevNodeDepthFirst(ReadableDomDocument<Node, Element, Text> doc,
Node start, Node stopAt, boolean enter, boolean rightwards) {
if (!DomHelper.isTextNode(start) && start.<Element>cast().getPropertyBoolean(
ContentElement.COMPLEX_IMPLEMENTATION_MARKER)) {
// If the nodelet is marked as part of a complex implementation structure
// (e.g. a part of an image thumbnail's implementation), then we find the
// next html node by instead popping up into the filtered content view,
// getting the next node from there, and popping back down into html land.
// This should be both faster and more accurate than doing a depth first
// search through the impl dom of an arbitrarily complex doodad.
// Go upwards to find the backreference to the doodad wrapper
Element e = start.cast();
while (!NodeManager.hasBackReference(e)) {
e = e.getParentElement();
}
// This must be true, otherwise we could get into an infinite loop
assert (start == stopAt || !start.isOrHasChild(stopAt));
// Try to get a wrapper for stopAt as well.
// TODO(danilatos): How robust is this?
// What are the chances that it would ever fail in practice anyway?
ContentNode stopAtWrapper = null;
for (int tries = 1; tries <= 3; tries++) {
try {
stopAtWrapper = nodeManager.findNodeWrapper(stopAt);
break;
} catch (InconsistencyException ex) {
stopAt = stopAt.getParentElement();
}
}
// Do a depth first next-node-find in the content view
ContentNode next = DocHelper.getNextOrPrevNodeDepthFirst(renderedContentView,
NodeManager.getBackReference(e),
stopAtWrapper, enter, rightwards);
// return the impl nodelet
return next != null ? next.getImplNodelet() : null;
} else {
// In other cases, just do the default.
return super.getNextOrPrevNodeDepthFirst(doc, start, stopAt, enter, rightwards);
}
}
示例13: print
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* @param n Node to pretty print
* @param selection Selection to mark in pretty print
* @param indent Indentation level to print with.
* @param multiLine True if output should be multi-line
* @return A pretty-print HTML string (with '<' and '>' already escaped)
*/
private static String print(Node n, PointRange<Node> selection, int indent, boolean multiLine) {
// Inspect selection's relevance to this element
boolean collapsed = selection != null && selection.isCollapsed();
boolean printStartMarker =
selection != null && selection.getFirst().getContainer().equals(n);
boolean printEndMarker =
selection != null && !collapsed && selection.getSecond().getContainer().equals(n);
String startMarker =
printStartMarker ? (collapsed ? "|" : "[") : "";
String endMarker = printEndMarker ? "]" : "";
if (DomHelper.isTextNode(n)) {
// Print text node as 'value'
String value = displayWhitespace(n.getNodeValue());
int startOffset = printStartMarker ? selection.getFirst().getTextOffset() : 0;
int endOffset = printEndMarker ? selection.getSecond().getTextOffset() : value.length();
String ret = "'" + value.substring(0, startOffset)
+ startMarker
+ value.substring(startOffset, endOffset)
+ endMarker
+ value.substring(endOffset, value.length())
+ "'" ;
return multiLine ? StringUtil.xmlEscape(ret) : ret;
} else {
Element e = n.cast();
if (e.getChildCount() == 0) {
// Print child-less element as self-closing tag
return startTag(e, true, multiLine);
} else {
boolean singleLineHtml = multiLine &&
(e.getChildCount() == 1 &&
e.getFirstChild()
.getChildCount() == 0);
// Print element w/ children. One line each for start tag, child, end tag
String pretty = startTag(e, false, multiLine);
Node child = e.getFirstChild();
Node startNodeAfter = selection.getFirst().getNodeAfter();
Node endNodeAfter = selection.getSecond().getNodeAfter();
while (child != null) {
pretty += (multiLine && !singleLineHtml ? newLine(indent + 1) : "")
+ (printStartMarker && child.equals(startNodeAfter) ? startMarker : "")
+ (printEndMarker && child.equals(endNodeAfter) ? endMarker : "")
+ print(child, selection, indent + 1, multiLine);
child = child.getNextSibling();
}
if (printEndMarker && endNodeAfter == null) {
pretty += endMarker;
}
return pretty + (multiLine && !singleLineHtml ? newLine(indent) : "")
+ endTag(e, multiLine);
}
}
}
示例14: somethingHappened
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
*
* TODO: use isSameRange. currently, it'll just start a new typing sequence
* @param previousSelectionStart Where the selection start is,
* before the result of typing
* @throws HtmlMissing
* @throws HtmlInserted
*/
public void somethingHappened(Point<Node> previousSelectionStart)
throws HtmlMissing, HtmlInserted {
Preconditions.checkNotNull(previousSelectionStart,
"Typing extractor notified with null selection");
Text node = previousSelectionStart.isInTextNode()
? previousSelectionStart.getContainer().<Text>cast()
: null;
// 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);
if (t == null) {
t = getFreshTypingState();
if (node != null) {
// check the selection is in a text point, and start the sequence
Preconditions.checkNotNull(previousSelectionStart.asTextPoint(),
"previousSelectionStart must be a text point");
t.startTypingSequence(previousSelectionStart.asTextPoint());
} else {
// otherwise make sure we're not in a text point, and start the sequence
Preconditions.checkState(!previousSelectionStart.isInTextNode(),
"previousSelectionStart must not be a text point");
t.startTypingSequence(previousSelectionStart.asElementPoint());
}
} else {
t.continueTypingSequence(previousSelectionStart);
}
t.setLastTextNode(node);
timerService.schedule(flushCmd);
}
示例15: asElement
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public Element asElement(Node node) {
return node.getNodeType() == Node.ELEMENT_NODE ? node.<Element>cast() : null;
}