| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2009 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 : m_anchorNode(anchorNode) | 103 : m_anchorNode(anchorNode) |
| 104 , m_offset(0) | 104 , m_offset(0) |
| 105 , m_anchorType(anchorType) | 105 , m_anchorType(anchorType) |
| 106 , m_isLegacyEditingPosition(false) | 106 , m_isLegacyEditingPosition(false) |
| 107 { | 107 { |
| 108 ASSERT(!m_anchorNode || !m_anchorNode->isPseudoElement() || m_anchorNode->is
FirstLetterPseudoElement()); | 108 ASSERT(!m_anchorNode || !m_anchorNode->isPseudoElement() || m_anchorNode->is
FirstLetterPseudoElement()); |
| 109 ASSERT(m_anchorType != PositionIsOffsetInAnchor); | 109 ASSERT(m_anchorType != PositionIsOffsetInAnchor); |
| 110 } | 110 } |
| 111 | 111 |
| 112 template <typename Strategy> | 112 template <typename Strategy> |
| 113 PositionAlgorithm<Strategy>::PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anch
orNode, int offset, AnchorType anchorType) | 113 PositionAlgorithm<Strategy>::PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anch
orNode, int offset) |
| 114 : m_anchorNode(anchorNode) | 114 : m_anchorNode(anchorNode) |
| 115 , m_offset(offset) | 115 , m_offset(offset) |
| 116 , m_anchorType(anchorType) | 116 , m_anchorType(PositionIsOffsetInAnchor) |
| 117 , m_isLegacyEditingPosition(false) | 117 , m_isLegacyEditingPosition(false) |
| 118 { | 118 { |
| 119 ASSERT(!m_anchorNode || !m_anchorNode->isPseudoElement() || m_anchorNode->is
FirstLetterPseudoElement()); | 119 ASSERT(!m_anchorNode || !m_anchorNode->isPseudoElement() || m_anchorNode->is
FirstLetterPseudoElement()); |
| 120 ASSERT(anchorType == PositionIsOffsetInAnchor); | |
| 121 } | 120 } |
| 122 | 121 |
| 123 template <typename Strategy> | 122 template <typename Strategy> |
| 124 PositionAlgorithm<Strategy>::PositionAlgorithm(PassRefPtrWillBeRawPtr<Text> text
Node, unsigned offset) | |
| 125 : m_anchorNode(textNode) | |
| 126 , m_offset(static_cast<int>(offset)) | |
| 127 , m_anchorType(PositionIsOffsetInAnchor) | |
| 128 , m_isLegacyEditingPosition(false) | |
| 129 { | |
| 130 ASSERT(m_anchorNode); | |
| 131 } | |
| 132 | |
| 133 template <typename Strategy> | |
| 134 PositionAlgorithm<Strategy>::PositionAlgorithm(const PositionAlgorithm& other) | 123 PositionAlgorithm<Strategy>::PositionAlgorithm(const PositionAlgorithm& other) |
| 135 : m_anchorNode(other.m_anchorNode) | 124 : m_anchorNode(other.m_anchorNode) |
| 136 , m_offset(other.m_offset) | 125 , m_offset(other.m_offset) |
| 137 , m_anchorType(other.m_anchorType) | 126 , m_anchorType(other.m_anchorType) |
| 138 , m_isLegacyEditingPosition(other.m_isLegacyEditingPosition) | 127 , m_isLegacyEditingPosition(other.m_isLegacyEditingPosition) |
| 139 { | 128 { |
| 140 } | 129 } |
| 141 | 130 |
| 142 // -- | 131 // -- |
| 143 | 132 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 template <typename Strategy> | 221 template <typename Strategy> |
| 233 typename Strategy::PositionType PositionAlgorithm<Strategy>::parentAnchoredEquiv
alent() const | 222 typename Strategy::PositionType PositionAlgorithm<Strategy>::parentAnchoredEquiv
alent() const |
| 234 { | 223 { |
| 235 if (!m_anchorNode) | 224 if (!m_anchorNode) |
| 236 return PositionType(); | 225 return PositionType(); |
| 237 | 226 |
| 238 // FIXME: This should only be necessary for legacy positions, but is also ne
eded for positions before and after Tables | 227 // FIXME: This should only be necessary for legacy positions, but is also ne
eded for positions before and after Tables |
| 239 if (m_offset <= 0 && (m_anchorType != PositionIsAfterAnchor && m_anchorType
!= PositionIsAfterChildren)) { | 228 if (m_offset <= 0 && (m_anchorType != PositionIsAfterAnchor && m_anchorType
!= PositionIsAfterChildren)) { |
| 240 if (Strategy::parent(*m_anchorNode) && (Strategy::editingIgnoresContent(
m_anchorNode.get()) || isRenderedHTMLTableElement(m_anchorNode.get()))) | 229 if (Strategy::parent(*m_anchorNode) && (Strategy::editingIgnoresContent(
m_anchorNode.get()) || isRenderedHTMLTableElement(m_anchorNode.get()))) |
| 241 return inParentBeforeNode(*m_anchorNode); | 230 return inParentBeforeNode(*m_anchorNode); |
| 242 return PositionType(m_anchorNode.get(), 0, PositionIsOffsetInAnchor); | 231 return PositionType(m_anchorNode.get(), 0); |
| 243 } | 232 } |
| 244 if (!m_anchorNode->offsetInCharacters() | 233 if (!m_anchorNode->offsetInCharacters() |
| 245 && (m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsA
fterChildren || static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()
) | 234 && (m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsA
fterChildren || static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()
) |
| 246 && (Strategy::editingIgnoresContent(m_anchorNode.get()) || isRenderedHTM
LTableElement(m_anchorNode.get())) | 235 && (Strategy::editingIgnoresContent(m_anchorNode.get()) || isRenderedHTM
LTableElement(m_anchorNode.get())) |
| 247 && containerNode()) { | 236 && containerNode()) { |
| 248 return inParentAfterNode(*m_anchorNode); | 237 return inParentAfterNode(*m_anchorNode); |
| 249 } | 238 } |
| 250 | 239 |
| 251 return PositionType(containerNode(), computeOffsetInContainerNode(), Positio
nIsOffsetInAnchor); | 240 return PositionType(containerNode(), computeOffsetInContainerNode()); |
| 252 } | 241 } |
| 253 | 242 |
| 254 template <typename Strategy> | 243 template <typename Strategy> |
| 255 typename Strategy::PositionType PositionAlgorithm<Strategy>::toOffsetInAnchor()
const | 244 typename Strategy::PositionType PositionAlgorithm<Strategy>::toOffsetInAnchor()
const |
| 256 { | 245 { |
| 257 if (isNull()) | 246 if (isNull()) |
| 258 return PositionType(); | 247 return PositionType(); |
| 259 | 248 |
| 260 return PositionType(containerNode(), computeOffsetInContainerNode(), Positio
nIsOffsetInAnchor); | 249 return PositionType(containerNode(), computeOffsetInContainerNode()); |
| 261 } | 250 } |
| 262 | 251 |
| 263 template <typename Strategy> | 252 template <typename Strategy> |
| 264 Node* PositionAlgorithm<Strategy>::computeNodeBeforePosition() const | 253 Node* PositionAlgorithm<Strategy>::computeNodeBeforePosition() const |
| 265 { | 254 { |
| 266 if (!m_anchorNode) | 255 if (!m_anchorNode) |
| 267 return 0; | 256 return 0; |
| 268 switch (anchorType()) { | 257 switch (anchorType()) { |
| 269 case PositionIsBeforeChildren: | 258 case PositionIsBeforeChildren: |
| 270 return 0; | 259 return 0; |
| (...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 | 1389 |
| 1401 PositionInComposedTree toPositionInComposedTree(const Position& pos) | 1390 PositionInComposedTree toPositionInComposedTree(const Position& pos) |
| 1402 { | 1391 { |
| 1403 if (pos.isNull()) | 1392 if (pos.isNull()) |
| 1404 return PositionInComposedTree(); | 1393 return PositionInComposedTree(); |
| 1405 | 1394 |
| 1406 PositionInComposedTree position; | 1395 PositionInComposedTree position; |
| 1407 if (pos.anchorType() == Position::PositionIsOffsetInAnchor) { | 1396 if (pos.anchorType() == Position::PositionIsOffsetInAnchor) { |
| 1408 Node* anchor = pos.anchorNode(); | 1397 Node* anchor = pos.anchorNode(); |
| 1409 if (anchor->offsetInCharacters()) | 1398 if (anchor->offsetInCharacters()) |
| 1410 return PositionInComposedTree(anchor, pos.computeOffsetInContainerNo
de(), PositionInComposedTree::PositionIsOffsetInAnchor); | 1399 return PositionInComposedTree(anchor, pos.computeOffsetInContainerNo
de()); |
| 1411 ASSERT(!isActiveInsertionPoint(*anchor)); | 1400 ASSERT(!isActiveInsertionPoint(*anchor)); |
| 1412 int offset = pos.computeOffsetInContainerNode(); | 1401 int offset = pos.computeOffsetInContainerNode(); |
| 1413 Node* child = NodeTraversal::childAt(*anchor, offset); | 1402 Node* child = NodeTraversal::childAt(*anchor, offset); |
| 1414 if (!child) { | 1403 if (!child) { |
| 1415 if (anchor->isShadowRoot()) | 1404 if (anchor->isShadowRoot()) |
| 1416 return PositionInComposedTree(anchor->shadowHost(), PositionInCo
mposedTree::PositionIsAfterChildren); | 1405 return PositionInComposedTree(anchor->shadowHost(), PositionInCo
mposedTree::PositionIsAfterChildren); |
| 1417 return PositionInComposedTree(anchor, PositionInComposedTree::Positi
onIsAfterChildren); | 1406 return PositionInComposedTree(anchor, PositionInComposedTree::Positi
onIsAfterChildren); |
| 1418 } | 1407 } |
| 1419 child->updateDistribution(); | 1408 child->updateDistribution(); |
| 1420 if (isActiveInsertionPoint(*child)) { | 1409 if (isActiveInsertionPoint(*child)) { |
| 1421 if (anchor->isShadowRoot()) | 1410 if (anchor->isShadowRoot()) |
| 1422 return PositionInComposedTree(anchor->shadowHost(), offset, Posi
tionInComposedTree::PositionIsOffsetInAnchor); | 1411 return PositionInComposedTree(anchor->shadowHost(), offset); |
| 1423 return PositionInComposedTree(anchor, offset, PositionInComposedTree
::PositionIsOffsetInAnchor); | 1412 return PositionInComposedTree(anchor, offset); |
| 1424 } | 1413 } |
| 1425 return PositionInComposedTree(ComposedTreeTraversal::parent(*child), Com
posedTreeTraversal::index(*child), PositionInComposedTree::PositionIsOffsetInAnc
hor); | 1414 return PositionInComposedTree(ComposedTreeTraversal::parent(*child), Com
posedTreeTraversal::index(*child)); |
| 1426 } | 1415 } |
| 1427 | 1416 |
| 1428 return PositionInComposedTree(pos.anchorNode(), static_cast<PositionInCompos
edTree::AnchorType>(pos.anchorType())); | 1417 return PositionInComposedTree(pos.anchorNode(), static_cast<PositionInCompos
edTree::AnchorType>(pos.anchorType())); |
| 1429 } | 1418 } |
| 1430 | 1419 |
| 1431 Position toPositionInDOMTree(const PositionInComposedTree& position) | 1420 Position toPositionInDOMTree(const PositionInComposedTree& position) |
| 1432 { | 1421 { |
| 1433 if (position.isNull()) | 1422 if (position.isNull()) |
| 1434 return Position(); | 1423 return Position(); |
| 1435 | 1424 |
| 1436 Node* anchorNode = position.anchorNode(); | 1425 Node* anchorNode = position.anchorNode(); |
| 1437 | 1426 |
| 1438 switch (position.anchorType()) { | 1427 switch (position.anchorType()) { |
| 1439 case PositionInComposedTree::PositionIsAfterChildren: | 1428 case PositionInComposedTree::PositionIsAfterChildren: |
| 1440 // FIXME: When anchorNode is <img>, assertion fails in the constructor. | 1429 // FIXME: When anchorNode is <img>, assertion fails in the constructor. |
| 1441 return Position(anchorNode, Position::PositionIsAfterChildren); | 1430 return Position(anchorNode, Position::PositionIsAfterChildren); |
| 1442 case PositionInComposedTree::PositionIsAfterAnchor: | 1431 case PositionInComposedTree::PositionIsAfterAnchor: |
| 1443 return positionAfterNode(anchorNode); | 1432 return positionAfterNode(anchorNode); |
| 1444 case PositionInComposedTree::PositionIsBeforeChildren: | 1433 case PositionInComposedTree::PositionIsBeforeChildren: |
| 1445 return Position(anchorNode, Position::PositionIsBeforeChildren); | 1434 return Position(anchorNode, Position::PositionIsBeforeChildren); |
| 1446 case PositionInComposedTree::PositionIsBeforeAnchor: | 1435 case PositionInComposedTree::PositionIsBeforeAnchor: |
| 1447 return positionBeforeNode(anchorNode); | 1436 return positionBeforeNode(anchorNode); |
| 1448 case PositionInComposedTree::PositionIsOffsetInAnchor: { | 1437 case PositionInComposedTree::PositionIsOffsetInAnchor: { |
| 1449 int offset = position.offsetInContainerNode(); | 1438 int offset = position.offsetInContainerNode(); |
| 1450 if (anchorNode->offsetInCharacters()) | 1439 if (anchorNode->offsetInCharacters()) |
| 1451 return Position(anchorNode, offset, Position::PositionIsOffsetInAnch
or); | 1440 return Position(anchorNode, offset); |
| 1452 Node* child = ComposedTreeTraversal::childAt(*anchorNode, offset); | 1441 Node* child = ComposedTreeTraversal::childAt(*anchorNode, offset); |
| 1453 if (child) | 1442 if (child) |
| 1454 return Position(child->parentNode(), child->nodeIndex(), Position::P
ositionIsOffsetInAnchor); | 1443 return Position(child->parentNode(), child->nodeIndex()); |
| 1455 if (!position.offsetInContainerNode()) | 1444 if (!position.offsetInContainerNode()) |
| 1456 return Position(anchorNode, Position::PositionIsBeforeChildren); | 1445 return Position(anchorNode, Position::PositionIsBeforeChildren); |
| 1457 | 1446 |
| 1458 // |child| is null when the position is at the end of the children. | 1447 // |child| is null when the position is at the end of the children. |
| 1459 // <div>foo|</div> | 1448 // <div>foo|</div> |
| 1460 return Position(anchorNode, Position::PositionIsAfterChildren); | 1449 return Position(anchorNode, Position::PositionIsAfterChildren); |
| 1461 } | 1450 } |
| 1462 default: | 1451 default: |
| 1463 ASSERT_NOT_REACHED(); | 1452 ASSERT_NOT_REACHED(); |
| 1464 return Position(); | 1453 return Position(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 | 1534 |
| 1546 void showTree(const blink::Position* pos) | 1535 void showTree(const blink::Position* pos) |
| 1547 { | 1536 { |
| 1548 if (pos) | 1537 if (pos) |
| 1549 pos->showTreeForThis(); | 1538 pos->showTreeForThis(); |
| 1550 else | 1539 else |
| 1551 fprintf(stderr, "Cannot showTree for (nil)\n"); | 1540 fprintf(stderr, "Cannot showTree for (nil)\n"); |
| 1552 } | 1541 } |
| 1553 | 1542 |
| 1554 #endif | 1543 #endif |
| OLD | NEW |