本文整理匯總了Java中com.google.gwt.dom.client.Node類的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Node類屬於com.google.gwt.dom.client包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: forceElementPoint
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
/**
* Converts the given point to a parent-nodeAfter point, splitting a
* text node if necessary.
*
* @param point
* @return a point at the same location, between node boundaries
*/
public static Point.El<Node> forceElementPoint(Point<Node> point) {
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;
} else if (offset == text.getLength()) {
nodeAfter = text.getNextSibling();
} else {
nodeAfter = text.splitText(offset);
}
return Point.inElement(parent, nodeAfter);
}
示例3: setOnlyChild
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
/**
* Ensures the given container contains exactly one child, the given one.
* Provides the important property that if the container is already the parent
* of the given child, then the child is not removed and re-added, it is left
* there; any siblings, if present, are removed.
*
* @param container
* @param child
*/
public static void setOnlyChild(Element container, Node child) {
if (child.getParentElement() != container) {
// simple case
emptyElement(container);
container.appendChild(child);
} else {
// tricky case - avoid removing then re-appending the same child
while (child.getNextSibling() != null) {
child.getNextSibling().removeFromParent();
}
while (child.getPreviousSibling() != null) {
child.getPreviousSibling().removeFromParent();
}
}
}
示例4: setCaret
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public void setCaret(Point<ContentNode> caret) {
if (caret == null) {
throw new IllegalArgumentException("setCaret: caret may not be null");
}
caret = findOrCreateValidSelectionPoint2(caret);
Point<Node> nodeletCaret = // check if we have a place:
(caret == null ? null : nodeManager.wrapperPointToNodeletPoint(caret));
// Ignore if there is no matching html location
if (nodeletCaret != null) {
NativeSelectionUtil.setCaret(nodeletCaret);
}
saveSelection();
}
示例5: deleteText
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
private void deleteText(int amount) {
Point<Node> sel = getSelectionStart();
Text txt = sel == null ? null : sel.getContainer().<Text>cast();
int startIndex = sel.getTextOffset(), len;
while (amount > 0) {
if (txt == null || !DomHelper.isTextNode(txt)) {
throw new RuntimeException("Action ran off end of text node");
}
String data = txt.getData();
int remainingInNode = data.length() - startIndex;
if (remainingInNode >= amount) {
len = amount;
} else {
len = remainingInNode;
}
txt.setData(data.substring(0, startIndex) + data.substring(startIndex + len));
amount -= len;
startIndex = 0;
txt = htmlView.getNextSibling(txt).cast();
}
moveCaret(0);
}
示例6: getPoint
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
/**
* Evalulates the LazyPoint to a Point.
*/
@Override
public Point<Node> getPoint() {
assert ref.getParentElement() != null : "Reference node must be attached when getting point";
switch (pointType) {
case AFTER_NODE:
return Point.inElement(ref.getParentElement(), ref.getNextSibling());
case BEFORE_NODE:
return Point.inElement(ref.getParentElement(), ref);
case AT_START:
return Point.inElement(ref, ref.getFirstChild());
default:
throw new RuntimeException("invalid case");
}
}
示例7: prepareForPaste
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
@Override
public void prepareForPaste() {
super.prepareForPaste();
// N.B.(davidbyttow): In FF3, focus is not implicitly set by setting the
// selection when appending a DOM element dynamically. So we must explicitly
// set the focus.
DomHelper.focus(iframe);
NativeSelectionUtil.setCaret(Point.<Node>end(element));
}
示例8: NOTE
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
/**
* Search for node by pasting that element at a textRange and locating that
* element directly using getElementById. This is a huge shortcut when there
* are many nodes in parent. However, use with caution as it can fragment text
* nodes.
*
* NOTE(user): The text node fragmentation is a real issue, it causes repairs
* to happen. The constant splitting and repairing can also have performance
* issues that needs to be investigated. We should repair the damage here,
* when its clear how to fix the problem.
*
* @param target
* @param parent
* @return Point
*/
@SuppressWarnings("unused") // NOTE(user): Use later for nodes with many siblings.
private Point<Node> searchForRangeUsingPaste(JsTextRangeIE target, Element parent) {
Element elem = null;
try {
target.pasteHTML("<b id='__paste_target__'>X</b>");
elem = Document.get().getElementById("__paste_target__");
Node nextSibling = elem.getNextSibling();
if (DomHelper.isTextNode(nextSibling)) {
return Point.inText(nextSibling, 0);
} else {
return Point.inElement(parent, nextSibling);
}
} finally {
if (elem != null) {
elem.removeFromParent();
}
}
}
示例9: checkForWebkitEndOfLinkHack
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
void checkForWebkitEndOfLinkHack(SignalEvent signal) {
// If it's inserting text
if (DomHelper.isTextNode(signal.getTarget()) &&
(signal.getType().equals(JsEvents.DOM_CHARACTER_DATA_MODIFIED) ||
signal.getType().equals(JsEvents.DOM_NODE_INSERTED))) {
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);
}
}
}
}
}
示例10: 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;
}
示例11: deletify
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
private void deletify(Element element) {
if (element == null) {
// NOTE(danilatos): Not handling the case where the content element
// is transparent w.r.t. the rendered view, but has visible children.
return;
}
DiffManager.styleElement(element, DiffType.DELETE);
DomHelper.makeUnselectable(element);
for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
if (!DomHelper.isTextNode(n)) {
deletify(n.<Element> cast());
}
}
}
示例12: continueTypingSequence
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
/**
* Continue tracking an existing typing sequence, after we have determined
* that this selection is indeed part of an existing one
* @param previousSelectionStart
* @throws HtmlMissing
* @throws HtmlInserted
*/
private void continueTypingSequence(Point<Node> previousSelectionStart)
throws HtmlMissing, HtmlInserted {
if (firstWrapper != null) {
// minpost is only needed if we allow non-typing actions (such as moving
// with arrow keys) to stay as part of the same typing sequence. otherwise,
// minpost should always correspond to the last cursor position.
// TODO(danilatos): Ensure this is the case
updateMinPre(previousSelectionStart);
// TODO(danilatos): Is it possible to ever need to check neighbouring
// nodes if we're not in a text node now? If we're not, we are almost
// certainly somewhere were there are no valid neighbouring text nodes,
// otherwise the selection should have been reported as in one of
// those nodes.....
checkNeighbouringTextNodes(previousSelectionStart);
}
}
示例13: handleDOMMutation
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
/**
* Handles DOM mutation events.
* @param event
* @param contentRange last known selection
*/
public void handleDOMMutation(SignalEvent event, ContentRange contentRange) {
// Early exit if non-safari or non-mac
if (!(UserAgent.isSafari() && UserAgent.isMac())) {
return;
}
// We don't care about DOMMutations that we generate while we are reverting.
if (isReverting) {
return;
}
previousContentRange = contentRange;
Node n = event.getTarget();
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element e = Element.as(event.getTarget());
if (DOM_EVENTS_IGNORE.contains(event.getType())) {
// ignore
} else if (event.getType().equals(JsEvents.DOM_NODE_INSERTED) && handleDOMNodeInserted(e)) {
} else if (event.getType().equals(JsEvents.DOM_NODE_REMOVED) && handleDOMNodeRemoved(e)) {
}
}
}
示例14: isPartOfThisState
import com.google.gwt.dom.client.Node; //導入依賴的package包/類
private boolean isPartOfThisState(Point<Node> point) {
checkRangeIsValid();
Text node = point.isInTextNode()
? point.getContainer().<Text>cast()
: null;
if (node == null) {
// If we're not in a text node - i.e. we just started typing
// either in an empty element, or between elements.
if (htmlRange.getNodeAfter() == point.getNodeAfter()
&& htmlRange.getContainer() == point.getContainer()) {
return true;
} else if (point.getNodeAfter() == null) {
return false;
} else {
return partOfMutatingRange(point.getNodeAfter());
}
}
// The first check is redundant but speeds up the general case
return node == lastTextNode || partOfMutatingRange(node);
}
示例15: 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;
}
}