This source file includes following definitions.
- increment
- decrement
- atStart
- atEnd
- atStartOfNode
- atEndOfNode
- isCandidate
#include "config.h"
#include "core/dom/PositionIterator.h"
#include "core/editing/htmlediting.h"
#include "core/html/HTMLHtmlElement.h"
#include "core/rendering/RenderBlock.h"
namespace WebCore {
using namespace HTMLNames;
PositionIterator::operator Position() const
{
if (m_nodeAfterPositionInAnchor) {
ASSERT(m_nodeAfterPositionInAnchor->parentNode() == m_anchorNode);
if (editingIgnoresContent(m_nodeAfterPositionInAnchor->parentNode()))
return positionBeforeNode(m_anchorNode);
return positionInParentBeforeNode(*m_nodeAfterPositionInAnchor);
}
if (m_anchorNode->hasChildren())
return lastPositionInOrAfterNode(m_anchorNode);
return createLegacyEditingPosition(m_anchorNode, m_offsetInAnchor);
}
void PositionIterator::increment()
{
if (!m_anchorNode)
return;
if (m_nodeAfterPositionInAnchor) {
m_anchorNode = m_nodeAfterPositionInAnchor;
m_nodeAfterPositionInAnchor = m_anchorNode->firstChild();
m_offsetInAnchor = 0;
return;
}
if (!m_anchorNode->hasChildren() && m_offsetInAnchor < lastOffsetForEditing(m_anchorNode))
m_offsetInAnchor = Position::uncheckedNextOffset(m_anchorNode, m_offsetInAnchor);
else {
m_nodeAfterPositionInAnchor = m_anchorNode;
m_anchorNode = m_nodeAfterPositionInAnchor->parentNode();
m_nodeAfterPositionInAnchor = m_nodeAfterPositionInAnchor->nextSibling();
m_offsetInAnchor = 0;
}
}
void PositionIterator::decrement()
{
if (!m_anchorNode)
return;
if (m_nodeAfterPositionInAnchor) {
m_anchorNode = m_nodeAfterPositionInAnchor->previousSibling();
if (m_anchorNode) {
m_nodeAfterPositionInAnchor = 0;
m_offsetInAnchor = m_anchorNode->hasChildren() ? 0 : lastOffsetForEditing(m_anchorNode);
} else {
m_nodeAfterPositionInAnchor = m_nodeAfterPositionInAnchor->parentNode();
m_anchorNode = m_nodeAfterPositionInAnchor->parentNode();
m_offsetInAnchor = 0;
}
return;
}
if (m_anchorNode->hasChildren()) {
m_anchorNode = m_anchorNode->lastChild();
m_offsetInAnchor = m_anchorNode->hasChildren()? 0: lastOffsetForEditing(m_anchorNode);
} else {
if (m_offsetInAnchor)
m_offsetInAnchor = Position::uncheckedPreviousOffset(m_anchorNode, m_offsetInAnchor);
else {
m_nodeAfterPositionInAnchor = m_anchorNode;
m_anchorNode = m_anchorNode->parentNode();
}
}
}
bool PositionIterator::atStart() const
{
if (!m_anchorNode)
return true;
if (m_anchorNode->parentNode())
return false;
return (!m_anchorNode->hasChildren() && !m_offsetInAnchor) || (m_nodeAfterPositionInAnchor && !m_nodeAfterPositionInAnchor->previousSibling());
}
bool PositionIterator::atEnd() const
{
if (!m_anchorNode)
return true;
if (m_nodeAfterPositionInAnchor)
return false;
return !m_anchorNode->parentNode() && (m_anchorNode->hasChildren() || m_offsetInAnchor >= lastOffsetForEditing(m_anchorNode));
}
bool PositionIterator::atStartOfNode() const
{
if (!m_anchorNode)
return true;
if (!m_nodeAfterPositionInAnchor)
return !m_anchorNode->hasChildren() && !m_offsetInAnchor;
return !m_nodeAfterPositionInAnchor->previousSibling();
}
bool PositionIterator::atEndOfNode() const
{
if (!m_anchorNode)
return true;
if (m_nodeAfterPositionInAnchor)
return false;
return m_anchorNode->hasChildren() || m_offsetInAnchor >= lastOffsetForEditing(m_anchorNode);
}
bool PositionIterator::isCandidate() const
{
if (!m_anchorNode)
return false;
RenderObject* renderer = m_anchorNode->renderer();
if (!renderer)
return false;
if (renderer->style()->visibility() != VISIBLE)
return false;
if (renderer->isBR()) {
return !m_offsetInAnchor && (!m_anchorNode->hasChildren() || m_nodeAfterPositionInAnchor) && !Position::nodeIsUserSelectNone(m_anchorNode->parentNode());
}
if (renderer->isText())
return !Position::nodeIsUserSelectNone(m_anchorNode) && Position(*this).inRenderedText();
if (isRenderedTableElement(m_anchorNode) || editingIgnoresContent(m_anchorNode))
return (atStartOfNode() || atEndOfNode()) && !Position::nodeIsUserSelectNone(m_anchorNode->parentNode());
if (!isHTMLHtmlElement(*m_anchorNode) && renderer->isRenderBlockFlow()) {
if (toRenderBlock(renderer)->logicalHeight() || isHTMLBodyElement(*m_anchorNode)) {
if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(renderer))
return atStartOfNode() && !Position::nodeIsUserSelectNone(m_anchorNode);
return m_anchorNode->rendererIsEditable() && !Position::nodeIsUserSelectNone(m_anchorNode) && Position(*this).atEditingBoundary();
}
}
return false;
}
}