| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace WebCore { | 34 namespace WebCore { |
| 35 | 35 |
| 36 using namespace HTMLNames; | 36 using namespace HTMLNames; |
| 37 | 37 |
| 38 PositionIterator::operator Position() const | 38 PositionIterator::operator Position() const |
| 39 { | 39 { |
| 40 if (m_nodeAfterPositionInAnchor) { | 40 if (m_nodeAfterPositionInAnchor) { |
| 41 ASSERT(m_nodeAfterPositionInAnchor->parentNode() == m_anchorNode); | 41 ASSERT(m_nodeAfterPositionInAnchor->parentNode() == m_anchorNode); |
| 42 // FIXME: This check is inadaquete because any ancestor could be ignored
by editing | 42 // FIXME: This check is inadaquete because any ancestor could be ignored
by editing |
| 43 if (editingIgnoresContent(m_nodeAfterPositionInAnchor->parentNode().hand
le().raw())) | 43 if (editingIgnoresContent(m_nodeAfterPositionInAnchor->parentNode())) |
| 44 return positionBeforeNode(m_anchorNode); | 44 return positionBeforeNode(m_anchorNode); |
| 45 return positionInParentBeforeNode(m_nodeAfterPositionInAnchor); | 45 return positionInParentBeforeNode(m_nodeAfterPositionInAnchor); |
| 46 } | 46 } |
| 47 if (m_anchorNode->hasChildNodes()) | 47 if (m_anchorNode->hasChildNodes()) |
| 48 return lastPositionInOrAfterNode(m_anchorNode.raw()); | 48 return lastPositionInOrAfterNode(m_anchorNode); |
| 49 return createLegacyEditingPosition(m_anchorNode, m_offsetInAnchor); | 49 return createLegacyEditingPosition(m_anchorNode, m_offsetInAnchor); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void PositionIterator::increment() | 52 void PositionIterator::increment() |
| 53 { | 53 { |
| 54 if (!m_anchorNode) | 54 if (!m_anchorNode) |
| 55 return; | 55 return; |
| 56 | 56 |
| 57 if (m_nodeAfterPositionInAnchor) { | 57 if (m_nodeAfterPositionInAnchor) { |
| 58 m_anchorNode = m_nodeAfterPositionInAnchor; | 58 m_anchorNode = m_nodeAfterPositionInAnchor; |
| 59 m_nodeAfterPositionInAnchor = m_anchorNode->firstChild(); | 59 m_nodeAfterPositionInAnchor = m_anchorNode->firstChild(); |
| 60 m_offsetInAnchor = 0; | 60 m_offsetInAnchor = 0; |
| 61 return; | 61 return; |
| 62 } | 62 } |
| 63 | 63 |
| 64 if (!m_anchorNode->hasChildNodes() && m_offsetInAnchor < lastOffsetForEditin
g(m_anchorNode.raw())) | 64 if (!m_anchorNode->hasChildNodes() && m_offsetInAnchor < lastOffsetForEditin
g(m_anchorNode)) |
| 65 m_offsetInAnchor = Position::uncheckedNextOffset(m_anchorNode, m_offsetI
nAnchor); | 65 m_offsetInAnchor = Position::uncheckedNextOffset(m_anchorNode, m_offsetI
nAnchor); |
| 66 else { | 66 else { |
| 67 m_nodeAfterPositionInAnchor = m_anchorNode; | 67 m_nodeAfterPositionInAnchor = m_anchorNode; |
| 68 m_anchorNode = m_nodeAfterPositionInAnchor->parentNode(); | 68 m_anchorNode = m_nodeAfterPositionInAnchor->parentNode(); |
| 69 m_nodeAfterPositionInAnchor = m_nodeAfterPositionInAnchor->nextSibling()
; | 69 m_nodeAfterPositionInAnchor = m_nodeAfterPositionInAnchor->nextSibling()
; |
| 70 m_offsetInAnchor = 0; | 70 m_offsetInAnchor = 0; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 void PositionIterator::decrement() | 74 void PositionIterator::decrement() |
| 75 { | 75 { |
| 76 if (!m_anchorNode) | 76 if (!m_anchorNode) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 if (m_nodeAfterPositionInAnchor) { | 79 if (m_nodeAfterPositionInAnchor) { |
| 80 m_anchorNode = m_nodeAfterPositionInAnchor->previousSibling(); | 80 m_anchorNode = m_nodeAfterPositionInAnchor->previousSibling(); |
| 81 if (m_anchorNode) { | 81 if (m_anchorNode) { |
| 82 m_nodeAfterPositionInAnchor = nullptr; | 82 m_nodeAfterPositionInAnchor = nullptr; |
| 83 m_offsetInAnchor = m_anchorNode->hasChildNodes() ? 0 : lastOffsetFor
Editing(m_anchorNode.raw()); | 83 m_offsetInAnchor = m_anchorNode->hasChildNodes() ? 0 : lastOffsetFor
Editing(m_anchorNode); |
| 84 } else { | 84 } else { |
| 85 m_nodeAfterPositionInAnchor = m_nodeAfterPositionInAnchor->parentNod
e(); | 85 m_nodeAfterPositionInAnchor = m_nodeAfterPositionInAnchor->parentNod
e(); |
| 86 m_anchorNode = m_nodeAfterPositionInAnchor->parentNode(); | 86 m_anchorNode = m_nodeAfterPositionInAnchor->parentNode(); |
| 87 m_offsetInAnchor = 0; | 87 m_offsetInAnchor = 0; |
| 88 } | 88 } |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 if (m_anchorNode->hasChildNodes()) { | 92 if (m_anchorNode->hasChildNodes()) { |
| 93 m_anchorNode = m_anchorNode->lastChild(); | 93 m_anchorNode = m_anchorNode->lastChild(); |
| 94 m_offsetInAnchor = m_anchorNode->hasChildNodes()? 0: lastOffsetForEditin
g(m_anchorNode.raw()); | 94 m_offsetInAnchor = m_anchorNode->hasChildNodes() ? 0: lastOffsetForEditi
ng(m_anchorNode); |
| 95 } else { | 95 } else { |
| 96 if (m_offsetInAnchor) | 96 if (m_offsetInAnchor) |
| 97 m_offsetInAnchor = Position::uncheckedPreviousOffset(m_anchorNode, m
_offsetInAnchor); | 97 m_offsetInAnchor = Position::uncheckedPreviousOffset(m_anchorNode, m
_offsetInAnchor); |
| 98 else { | 98 else { |
| 99 m_nodeAfterPositionInAnchor = m_anchorNode; | 99 m_nodeAfterPositionInAnchor = m_anchorNode; |
| 100 m_anchorNode = m_anchorNode->parentNode(); | 100 m_anchorNode = m_anchorNode->parentNode(); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool PositionIterator::atStart() const | 105 bool PositionIterator::atStart() const |
| 106 { | 106 { |
| 107 if (!m_anchorNode) | 107 if (!m_anchorNode) |
| 108 return true; | 108 return true; |
| 109 if (m_anchorNode->parentNode()) | 109 if (m_anchorNode->parentNode()) |
| 110 return false; | 110 return false; |
| 111 return (!m_anchorNode->hasChildNodes() && !m_offsetInAnchor) || (m_nodeAfter
PositionInAnchor && !m_nodeAfterPositionInAnchor->previousSibling()); | 111 return (!m_anchorNode->hasChildNodes() && !m_offsetInAnchor) || (m_nodeAfter
PositionInAnchor && !m_nodeAfterPositionInAnchor->previousSibling()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool PositionIterator::atEnd() const | 114 bool PositionIterator::atEnd() const |
| 115 { | 115 { |
| 116 if (!m_anchorNode) | 116 if (!m_anchorNode) |
| 117 return true; | 117 return true; |
| 118 if (m_nodeAfterPositionInAnchor) | 118 if (m_nodeAfterPositionInAnchor) |
| 119 return false; | 119 return false; |
| 120 return !m_anchorNode->parentNode() && (m_anchorNode->hasChildNodes() || m_of
fsetInAnchor >= lastOffsetForEditing(m_anchorNode.raw())); | 120 return !m_anchorNode->parentNode() && (m_anchorNode->hasChildNodes() || m_of
fsetInAnchor >= lastOffsetForEditing(m_anchorNode)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool PositionIterator::atStartOfNode() const | 123 bool PositionIterator::atStartOfNode() const |
| 124 { | 124 { |
| 125 if (!m_anchorNode) | 125 if (!m_anchorNode) |
| 126 return true; | 126 return true; |
| 127 if (!m_nodeAfterPositionInAnchor) | 127 if (!m_nodeAfterPositionInAnchor) |
| 128 return !m_anchorNode->hasChildNodes() && !m_offsetInAnchor; | 128 return !m_anchorNode->hasChildNodes() && !m_offsetInAnchor; |
| 129 return !m_nodeAfterPositionInAnchor->previousSibling(); | 129 return !m_nodeAfterPositionInAnchor->previousSibling(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool PositionIterator::atEndOfNode() const | 132 bool PositionIterator::atEndOfNode() const |
| 133 { | 133 { |
| 134 if (!m_anchorNode) | 134 if (!m_anchorNode) |
| 135 return true; | 135 return true; |
| 136 if (m_nodeAfterPositionInAnchor) | 136 if (m_nodeAfterPositionInAnchor) |
| 137 return false; | 137 return false; |
| 138 return m_anchorNode->hasChildNodes() || m_offsetInAnchor >= lastOffsetForEdi
ting(m_anchorNode.raw()); | 138 return m_anchorNode->hasChildNodes() || m_offsetInAnchor >= lastOffsetForEdi
ting(m_anchorNode); |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool PositionIterator::isCandidate() const | 141 bool PositionIterator::isCandidate() const |
| 142 { | 142 { |
| 143 if (!m_anchorNode) | 143 if (!m_anchorNode) |
| 144 return false; | 144 return false; |
| 145 | 145 |
| 146 RenderObject* renderer = m_anchorNode->renderer(); | 146 RenderObject* renderer = m_anchorNode->renderer(); |
| 147 if (!renderer) | 147 if (!renderer) |
| 148 return false; | 148 return false; |
| 149 | 149 |
| 150 if (renderer->style()->visibility() != VISIBLE) | 150 if (renderer->style()->visibility() != VISIBLE) |
| 151 return false; | 151 return false; |
| 152 | 152 |
| 153 if (renderer->isBR()) | 153 if (renderer->isBR()) |
| 154 return !m_offsetInAnchor && !Position::nodeIsUserSelectNone(m_anchorNode
->parentNode()); | 154 return !m_offsetInAnchor && !Position::nodeIsUserSelectNone(m_anchorNode
->parentNode()); |
| 155 | 155 |
| 156 if (renderer->isText()) | 156 if (renderer->isText()) |
| 157 return !Position::nodeIsUserSelectNone(m_anchorNode) && Position(*this).
inRenderedText(); | 157 return !Position::nodeIsUserSelectNone(m_anchorNode) && Position(*this).
inRenderedText(); |
| 158 | 158 |
| 159 if (isTableElement(m_anchorNode.raw()) || editingIgnoresContent(m_anchorNode
.raw())) | 159 if (isTableElement(m_anchorNode) || editingIgnoresContent(m_anchorNode)) |
| 160 return (atStartOfNode() || atEndOfNode()) && !Position::nodeIsUserSelect
None(m_anchorNode->parentNode()); | 160 return (atStartOfNode() || atEndOfNode()) && !Position::nodeIsUserSelect
None(m_anchorNode->parentNode()); |
| 161 | 161 |
| 162 if (!m_anchorNode->hasTagName(htmlTag) && renderer->isBlockFlow()) { | 162 if (!m_anchorNode->hasTagName(htmlTag) && renderer->isBlockFlow()) { |
| 163 if (toRenderBlock(renderer)->logicalHeight() || m_anchorNode->hasTagName
(bodyTag)) { | 163 if (toRenderBlock(renderer)->logicalHeight() || m_anchorNode->hasTagName
(bodyTag)) { |
| 164 if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(renderer
)) | 164 if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(renderer
)) |
| 165 return atStartOfNode() && !Position::nodeIsUserSelectNone(m_anch
orNode); | 165 return atStartOfNode() && !Position::nodeIsUserSelectNone(m_anch
orNode); |
| 166 return m_anchorNode->rendererIsEditable() && !Position::nodeIsUserSe
lectNone(m_anchorNode) && Position(*this).atEditingBoundary(); | 166 return m_anchorNode->rendererIsEditable() && !Position::nodeIsUserSe
lectNone(m_anchorNode) && Position(*this).atEditingBoundary(); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 return false; | 170 return false; |
| 171 } | 171 } |
| 172 | 172 |
| 173 } // namespace WebCore | 173 } // namespace WebCore |
| OLD | NEW |