using DOM::DoNotUpdateLayout;
using DOM::EditingTextImpl;
using DOM::ElementImpl;
-using DOM::EStayInBlock;
using DOM::HTMLElementImpl;
using DOM::HTMLImageElementImpl;
using DOM::NamedAttrMapImpl;
using DOM::Position;
using DOM::Range;
using DOM::RangeImpl;
-using DOM::StayInBlock;
using DOM::TextImpl;
using DOM::TreeWalkerImpl;
void CompositeEditCommand::deleteInsignificantTextDownstream(const DOM::Position &pos)
{
- Position end = VisiblePosition(pos, VP_DEFAULT_AFFINITY).next().deepEquivalent().downstream(StayInBlock);
+ Position end = VisiblePosition(pos, VP_DEFAULT_AFFINITY).next().deepEquivalent().downstream();
deleteInsignificantText(pos, end);
}
VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY);
VisiblePosition visibleParagraphStart(startOfParagraph(visiblePos));
VisiblePosition visibleParagraphEnd(endOfParagraph(visiblePos, IncludeLineBreak));
- Position paragraphStart = visibleParagraphStart.deepEquivalent().upstream(StayInBlock);
- Position paragraphEnd = visibleParagraphEnd.deepEquivalent().upstream(StayInBlock);
+ Position paragraphStart = visibleParagraphStart.deepEquivalent().upstream();
+ Position paragraphEnd = visibleParagraphEnd.deepEquivalent().upstream();
// Perform some checks to see if we need to perform work in this function.
if (paragraphStart.node()->isBlockFlow()) {
insertNodeAfter(newBlock, paragraphStart.node());
}
else {
- insertNodeBefore(newBlock, paragraphStart.upstream(StayInBlock).node());
+ insertNodeBefore(newBlock, paragraphStart.upstream().node());
}
while (moveNode && !moveNode->isBlockFlow()) {
// Adjust to the positions we want to use for applying style.
Selection selection = endingSelection();
- Position start(selection.start().downstream(StayInBlock));
- Position end(selection.end().upstream(StayInBlock));
+ Position start(selection.start().downstream());
+ Position end(selection.end().upstream());
if (RangeImpl::compareBoundaryPoints(end, start) < 0) {
Position swap = start;
start = end;
}
NodeImpl *beyondEnd = end.node()->traverseNextNode(); // Calculate loop end point.
- start = start.upstream(StayInBlock); // Move upstream to ensure we do not add redundant spans.
+ start = start.upstream(); // Move upstream to ensure we do not add redundant spans.
NodeImpl *startNode = start.node();
if (startNode->isTextNode() && start.offset() >= startNode->caretMaxOffset()) // Move out of text node if range does not include its characters.
startNode = startNode->traverseNextNode();
void ApplyStyleCommand::applyInlineStyle(CSSMutableStyleDeclarationImpl *style)
{
// adjust to the positions we want to use for applying style
- Position start(endingSelection().start().downstream(StayInBlock).equivalentRangeCompliantPosition());
- Position end(endingSelection().end().upstream(StayInBlock));
+ Position start(endingSelection().start().downstream().equivalentRangeCompliantPosition());
+ Position end(endingSelection().end().upstream());
if (RangeImpl::compareBoundaryPoints(end, start) < 0) {
Position swap = start;
// This will ensure we remove all traces of the relevant styles from the selection
// and prevent us from adding redundant ones, as described in:
// <rdar://problem/3724344> Bolding and unbolding creates extraneous tags
- removeInlineStyle(style, start.upstream(StayInBlock), end);
+ removeInlineStyle(style, start.upstream(), end);
start = endingSelection().start();
end = endingSelection().end();
CSSValueImpl *textDecorationSpecialProperty = style->getPropertyCSSValue(CSS_PROP__KHTML_TEXT_DECORATIONS_IN_EFFECT);
if (textDecorationSpecialProperty) {
- pushDownTextDecorationStyleAtBoundaries(start.downstream(StayInBlock), end.upstream(StayInBlock));
+ pushDownTextDecorationStyleAtBoundaries(start.downstream(), end.upstream());
style = style->copy();
style->setProperty(CSS_PROP_TEXT_DECORATION, textDecorationSpecialProperty->cssText(), style->getPropertyPriority(CSS_PROP__KHTML_TEXT_DECORATIONS_IN_EFFECT));
}
ASSERT(node);
ASSERT(node->isElementNode());
- Position pos = Position(node, node->childNodeCount()).upstream(StayInBlock);
+ Position pos = Position(node, node->childNodeCount()).upstream();
return RangeImpl::compareBoundaryPoints(node, 0, start.node(), start.offset()) >= 0 &&
RangeImpl::compareBoundaryPoints(pos, end) <= 0;
}
ASSERT(node);
ASSERT(node->isElementNode());
- Position pos = Position(node, node->childNodeCount()).upstream(StayInBlock);
+ Position pos = Position(node, node->childNodeCount()).upstream();
bool isFullyBeforeStart = RangeImpl::compareBoundaryPoints(pos, start) < 0;
bool isFullyAfterEnd = RangeImpl::compareBoundaryPoints(node, 0, end.node(), end.offset()) > 0;
Position end = m_selectionToDelete.end();
end = positionOutsideContainingSpecialElement(end);
- m_upstreamStart = positionBeforePossibleContainingSpecialElement(start.upstream(StayInBlock));
- m_downstreamStart = positionBeforePossibleContainingSpecialElement(start.downstream(StayInBlock));
- m_upstreamEnd = positionAfterPossibleContainingSpecialElement(end.upstream(StayInBlock));
- m_downstreamEnd = positionAfterPossibleContainingSpecialElement(end.downstream(StayInBlock));
+ m_upstreamStart = positionBeforePossibleContainingSpecialElement(start.upstream());
+ m_downstreamStart = positionBeforePossibleContainingSpecialElement(start.downstream());
+ m_upstreamEnd = positionAfterPossibleContainingSpecialElement(end.upstream());
+ m_downstreamEnd = positionAfterPossibleContainingSpecialElement(end.downstream());
//
// Handle leading and trailing whitespace, as well as smart delete adjustments to the selection
pos = visiblePos.deepEquivalent();
// Expand out one character upstream for smart delete and recalculate
// positions based on this change.
- m_upstreamStart = pos.upstream(StayInBlock);
- m_downstreamStart = pos.downstream(StayInBlock);
+ m_upstreamStart = pos.upstream();
+ m_downstreamStart = pos.downstream();
m_leadingWhitespace = m_upstreamStart.leadingWhitespacePosition(visiblePos.affinity());
}
// Expand out one character downstream for smart delete and recalculate
// positions based on this change.
pos = VisiblePosition(end, m_selectionToDelete.endAffinity()).next().deepEquivalent();
- m_upstreamEnd = pos.upstream(StayInBlock);
- m_downstreamEnd = pos.downstream(StayInBlock);
+ m_upstreamEnd = pos.upstream();
+ m_downstreamEnd = pos.downstream();
m_trailingWhitespace = m_downstreamEnd.trailingWhitespacePosition(VP_DEFAULT_AFFINITY);
}
}
}
}
else {
- Position pos = m_endingPosition.downstream(StayInBlock);
+ Position pos = m_endingPosition.downstream();
pos = Position(pos.node(), pos.offset() - 1);
if (nextCharacterIsCollapsibleWhitespace(pos) && !pos.isRenderedCharacter()) {
LOG(Editing, "replace trailing [invalid]");
// Insert the BR after the caret position. In the case the
// position is a block, do an append. We don't want to insert
// the BR *after* the block.
- Position upstream(pos.upstream(StayInBlock));
+ Position upstream(pos.upstream());
NodeImpl *cb = pos.node()->enclosingBlockFlowElement();
if (cb == pos.node())
appendNode(node, cb);
// Insert the BR after the caret position. In the case the
// position is a block, do an append. We don't want to insert
// the BR *before* the block.
- Position upstream(pos.upstream(StayInBlock));
+ Position upstream(pos.upstream());
NodeImpl *cb = pos.node()->enclosingBlockFlowElement();
if (cb == pos.node())
appendNode(node, cb);
ElementImpl *breakNode = createBreakElement(document());
NodeImpl *nodeToInsert = breakNode;
- Position pos(selection.start().upstream(StayInBlock));
+ Position pos(selection.start().upstream());
pos = positionOutsideContainingSpecialElement(pos);
else if (atStart) {
LOG(Editing, "input newline case 2");
// Insert node before downstream position, and place caret there as well.
- Position endingPosition = pos.downstream(StayInBlock);
+ Position endingPosition = pos.downstream();
insertNodeBeforePosition(nodeToInsert, endingPosition);
setEndingSelection(endingPosition, DOWNSTREAM);
}
LOG(Editing, "input newline case 3");
// Insert BR after this node. Place caret in the position that is downstream
// of the current position, reckoned before inserting the BR in between.
- Position endingPosition = pos.downstream(StayInBlock);
+ Position endingPosition = pos.downstream();
insertNodeAfterPosition(nodeToInsert, pos);
setEndingSelection(endingPosition, DOWNSTREAM);
}
if (prevInDifferentBlock || isFirstInBlock) {
LOG(Editing, "insert paragraph separator: first in block case");
- pos = pos.downstream(StayInBlock);
+ pos = pos.downstream();
pos = positionOutsideContainingSpecialElement(pos);
Position refPos;
NodeImpl *refNode;
// Check if pos.node() is a <br>. If it is, and the document is in quirks mode,
// then this <br> will collapse away when we add a block after it. Add an extra <br>.
if (!document()->inStrictMode()) {
- Position upstreamPos = pos.upstream(StayInBlock);
+ Position upstreamPos = pos.upstream();
if (upstreamPos.node()->id() == ID_BR)
insertNodeAfter(createBreakElement(document()), upstreamPos.node());
}
// Move downstream. Typing style code will take care of carrying along the
// style of the upstream position.
- pos = pos.downstream(StayInBlock);
+ pos = pos.downstream();
startNode = pos.node();
// Build up list of ancestors in between the start node and the start block.
}
// Make sure we do not cause a rendered space to become unrendered.
- // FIXME: We need the affinity for pos, but pos.downstream(StayInBlock) does not give it
+ // FIXME: We need the affinity for pos, but pos.downstream() does not give it
Position leadingWhitespace = pos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY);
if (leadingWhitespace.isNotNull()) {
TextImpl *textNode = static_cast<TextImpl *>(leadingWhitespace.node());
EAffinity affinity = selection.startAffinity();
if (selection.isRange()) {
deleteSelection(false, false);
- pos = endingSelection().start().upstream(StayInBlock);
+ pos = endingSelection().start().upstream();
affinity = endingSelection().startAffinity();
}
Position pos = selection.start();
if (adjustDownstream)
- pos = pos.downstream(StayInBlock);
+ pos = pos.downstream();
else
- pos = pos.upstream(StayInBlock);
+ pos = pos.upstream();
Selection typingStyleRange;
assert(text.find('\n') == -1);
Selection selection = endingSelection();
- bool adjustDownstream = isFirstVisiblePositionOnLine(VisiblePosition(selection.start().downstream(StayInBlock), DOWNSTREAM));
+ bool adjustDownstream = isFirstVisiblePositionOnLine(VisiblePosition(selection.start().downstream(), DOWNSTREAM));
// Delete the current selection, or collapse whitespace, as needed
if (selection.isRange())
// By checking the character at the downstream position, we can
// check if there is a rendered WS at the caret
Position pos(textNode, offset);
- Position downstream = pos.downstream(StayInBlock);
+ Position downstream = pos.downstream();
if (downstream.offset() < (long)text.length() && isCollapsibleWhitespace(text[downstream.offset()]))
count--; // leave this WS in
if (count > 0)
// decide whether to later append nodes to the end
NodeImpl *beyondEndNode = 0;
if (!isEndOfParagraph(visibleEnd) && !m_fragment.hasInterchangeNewlineAtEnd()) {
- Position beyondEndPos = selection.end().downstream(StayInBlock);
+ Position beyondEndPos = selection.end().downstream();
if (!isFirstVisiblePositionInSpecialElement(beyondEndPos))
beyondEndNode = beyondEndPos.node();
}
NodeImpl *block = startPos.node()->enclosingBlockFlowElement();
NodeImpl *linePlaceholder = findBlockPlaceholder(block);
if (!linePlaceholder) {
- Position downstream = startPos.downstream(StayInBlock);
+ Position downstream = startPos.downstream();
downstream = positionOutsideContainingSpecialElement(downstream);
if (downstream.node()->id() == ID_BR && downstream.offset() == 0 &&
m_fragment.hasInterchangeNewlineAtEnd() &&
else if (!insertionBlockIsRoot && isProbablyBlock(refNode) && isLastVisiblePositionInBlock(visiblePos)) {
insertNodeAfterAndUpdateNodesInserted(refNode, insertionBlock);
} else if (mergeStart && !isProbablyBlock(refNode)) {
- Position pos = visiblePos.next().deepEquivalent().downstream(StayInBlock);
+ Position pos = visiblePos.next().deepEquivalent().downstream();
insertNodeAtAndUpdateNodesInserted(refNode, pos.node(), pos.offset());
} else {
insertNodeAtAndUpdateNodesInserted(refNode, insertionPos.node(), insertionPos.offset());
removeLinePlaceholderIfNeeded(linePlaceholder);
if (!m_lastNodeInserted) {
- lastPositionToSelect = endingSelection().end().downstream(StayInBlock);
+ lastPositionToSelect = endingSelection().end().downstream();
}
else {
bool insertParagraph = false;
VisiblePosition next = pos.next();
// Select up to the paragraph separator that was added.
- lastPositionToSelect = next.deepEquivalent().downstream(StayInBlock);
+ lastPositionToSelect = next.deepEquivalent().downstream();
updateNodesInserted(lastPositionToSelect.node());
} else {
// Select up to the preexising paragraph separator.
VisiblePosition next = pos.next();
- lastPositionToSelect = next.deepEquivalent().downstream(StayInBlock);
+ lastPositionToSelect = next.deepEquivalent().downstream();
}
}
}
// upstream() and downstream() want to return positions that are either in a
// text node or at just before a non-text node. This method checks for that.
-static bool isStreamer (Position pos)
+static bool isStreamer (Position pos)
{
NodeImpl *currentNode = pos.node();
if (!currentNode)
// for <rdar://problem/4103339>. See also Ken's comments in the header. Fundamentally, upstream()
// scans backward in the DOM starting at "this" to return a visible DOM position that is either in
// a text node, or just after a replaced or BR element (btw downstream() also considers empty blocks).
-// If "stayInBlock" is specified, the search stops when it would have entered into a part of the DOM
-// with a different enclosing block, including a nested one. Otherwise, the search stops at the start
-// of the entire DOM tree. If "stayInBlock" stops the search, this method returns the highest previous
-// position that is either in an atomic node (i.e. text) or is the end of a non-atomic node
-// (_regardless_ of visibility). If the end-of-DOM stopped the search, this method returns the
-// highest previous visible node that is either in an atomic node (i.e. text) or is the end of a
-// non-atomic node.
-Position Position::upstream(EStayInBlock stayInBlock) const
+// The search stops when it would have entered into a part of the DOM with a different enclosing
+// block, including a nested one. Then this method returns the highest previous position that is
+// either in an atomic node (i.e. text) or is the end of a non-atomic node (_regardless_ of
+// visibility).
+Position Position::upstream() const
{
// start at equivalent deep position
Position start = equivalentDeepPosition();
return Position();
// iterate backward from there, looking for a qualified position
- NodeImpl *block = stayInBlock ? startNode->enclosingBlockFlowOrTableElement() : 0;
+ NodeImpl *block = startNode->enclosingBlockFlowOrTableElement();
Position lastVisible = *this;
Position lastStreamer = *this;
Position currentPos = start;
// limit traversal to block or table enclosing the original element
// NOTE: This includes not going into nested blocks
- if (stayInBlock && block != currentNode->enclosingBlockFlowOrTableElement())
+ if (block != currentNode->enclosingBlockFlowOrTableElement())
return lastStreamer;
// track last streamer position (regardless of visibility)
// for <rdar://problem/4103339>. See also Ken's comments in the header. Fundamentally, downstream()
// scans forward in the DOM starting at "this" to return the first visible DOM position that is
// either in a text node, or just before a replaced, BR element, or empty block flow element (i.e.
-// non-text nodes with no children). If "stayInBlock" is specified, the search stops when it would
+// non-text nodes with no children). The search stops when it would
// have entered into a part of the DOM with a different enclosing block, including a nested one.
-// Otherwise, the search stops at the end of the entire DOM tree. If "stayInBlock" stops the search,
-// this method returns the first previous position that is either in an atomic node (i.e. text) or is
-// at offset 0 (_regardless_ of visibility). If the end-of-DOM stopped the search, this method returns
-// the first previous visible node that is either in an atomic node (i.e. text) or is at offset 0.
-Position Position::downstream(EStayInBlock stayInBlock) const
+// If the search stops, this method returns the first previous position that is either in an
+// atomic node (i.e. text) or is at offset 0 (_regardless_ of visibility).
+Position Position::downstream() const
{
// start at equivalent deep position
Position start = equivalentDeepPosition();
return Position();
// iterate forward from there, looking for a qualified position
- NodeImpl *block = stayInBlock ? startNode->enclosingBlockFlowOrTableElement() : 0;
+ NodeImpl *block = startNode->enclosingBlockFlowOrTableElement();
Position lastVisible = *this;
Position lastStreamer = *this;
Position currentPos = start;
// limit traversal to block or table enclosing the original element
// return the last streamer position regardless of visibility
// NOTE: This includes not going into nested blocks
- if (stayInBlock && block != currentNode->enclosingBlockFlowOrTableElement())
+ if (block != currentNode->enclosingBlockFlowOrTableElement())
return lastStreamer;
// track last streamer position (regardless of visibility)
if (isNull())
return Position();
- if (upstream(StayInBlock).node()->id() == ID_BR)
+ if (upstream().node()->id() == ID_BR)
return Position();
Position prev = previousCharacterPosition(affinity);
}
}
- if (downstream(StayInBlock).node()->id() == ID_BR)
+ if (downstream().node()->id() == ID_BR)
return Position();
Position next = nextCharacterPosition(affinity);