| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 b.computeContainerNode()->treeScope()); | 60 b.computeContainerNode()->treeScope()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 template <typename Strategy> | 63 template <typename Strategy> |
| 64 PositionTemplate<Strategy> PositionTemplate<Strategy>::editingPositionOf( | 64 PositionTemplate<Strategy> PositionTemplate<Strategy>::editingPositionOf( |
| 65 Node* anchorNode, | 65 Node* anchorNode, |
| 66 int offset) { | 66 int offset) { |
| 67 if (!anchorNode || anchorNode->isTextNode()) | 67 if (!anchorNode || anchorNode->isTextNode()) |
| 68 return PositionTemplate<Strategy>(anchorNode, offset); | 68 return PositionTemplate<Strategy>(anchorNode, offset); |
| 69 | 69 |
| 70 if (!Strategy::editingIgnoresContent(anchorNode)) | 70 if (!editingIgnoresContent(anchorNode)) |
| 71 return PositionTemplate<Strategy>(anchorNode, offset); | 71 return PositionTemplate<Strategy>(anchorNode, offset); |
| 72 | 72 |
| 73 if (offset == 0) | 73 if (offset == 0) |
| 74 return PositionTemplate<Strategy>(anchorNode, | 74 return PositionTemplate<Strategy>(anchorNode, |
| 75 PositionAnchorType::BeforeAnchor); | 75 PositionAnchorType::BeforeAnchor); |
| 76 | 76 |
| 77 // Note: |offset| can be >= 1, if |anchorNode| have child nodes, e.g. | 77 // Note: |offset| can be >= 1, if |anchorNode| have child nodes, e.g. |
| 78 // using Node.appendChild() to add a child node TEXTAREA. | 78 // using Node.appendChild() to add a child node TEXTAREA. |
| 79 DCHECK_GE(offset, 1); | 79 DCHECK_GE(offset, 1); |
| 80 return PositionTemplate<Strategy>(anchorNode, | 80 return PositionTemplate<Strategy>(anchorNode, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 template <typename Strategy> | 172 template <typename Strategy> |
| 173 PositionTemplate<Strategy> | 173 PositionTemplate<Strategy> |
| 174 PositionTemplate<Strategy>::parentAnchoredEquivalent() const { | 174 PositionTemplate<Strategy>::parentAnchoredEquivalent() const { |
| 175 if (!m_anchorNode) | 175 if (!m_anchorNode) |
| 176 return PositionTemplate<Strategy>(); | 176 return PositionTemplate<Strategy>(); |
| 177 | 177 |
| 178 // FIXME: This should only be necessary for legacy positions, but is also | 178 // FIXME: This should only be necessary for legacy positions, but is also |
| 179 // needed for positions before and after Tables | 179 // needed for positions before and after Tables |
| 180 if (m_offset == 0 && !isAfterAnchorOrAfterChildren()) { | 180 if (m_offset == 0 && !isAfterAnchorOrAfterChildren()) { |
| 181 if (Strategy::parent(*m_anchorNode) && | 181 if (Strategy::parent(*m_anchorNode) && |
| 182 (Strategy::editingIgnoresContent(m_anchorNode.get()) || | 182 (editingIgnoresContent(m_anchorNode.get()) || |
| 183 isDisplayInsideTable(m_anchorNode.get()))) | 183 isDisplayInsideTable(m_anchorNode.get()))) |
| 184 return inParentBeforeNode(*m_anchorNode); | 184 return inParentBeforeNode(*m_anchorNode); |
| 185 return PositionTemplate<Strategy>(m_anchorNode.get(), 0); | 185 return PositionTemplate<Strategy>(m_anchorNode.get(), 0); |
| 186 } | 186 } |
| 187 if (!m_anchorNode->isCharacterDataNode() && | 187 if (!m_anchorNode->isCharacterDataNode() && |
| 188 (isAfterAnchorOrAfterChildren() || | 188 (isAfterAnchorOrAfterChildren() || |
| 189 static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()) && | 189 static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()) && |
| 190 (Strategy::editingIgnoresContent(m_anchorNode.get()) || | 190 (editingIgnoresContent(m_anchorNode.get()) || |
| 191 isDisplayInsideTable(m_anchorNode.get())) && | 191 isDisplayInsideTable(m_anchorNode.get())) && |
| 192 computeContainerNode()) { | 192 computeContainerNode()) { |
| 193 return inParentAfterNode(*m_anchorNode); | 193 return inParentAfterNode(*m_anchorNode); |
| 194 } | 194 } |
| 195 | 195 |
| 196 return PositionTemplate<Strategy>(computeContainerNode(), | 196 return PositionTemplate<Strategy>(computeContainerNode(), |
| 197 computeOffsetInContainerNode()); | 197 computeOffsetInContainerNode()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 template <typename Strategy> | 200 template <typename Strategy> |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 478 |
| 479 return newOffset; | 479 return newOffset; |
| 480 } | 480 } |
| 481 | 481 |
| 482 // static | 482 // static |
| 483 template <typename Strategy> | 483 template <typename Strategy> |
| 484 PositionTemplate<Strategy> | 484 PositionTemplate<Strategy> |
| 485 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(Node* node) { | 485 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(Node* node) { |
| 486 if (!node) | 486 if (!node) |
| 487 return PositionTemplate<Strategy>(); | 487 return PositionTemplate<Strategy>(); |
| 488 return Strategy::editingIgnoresContent(node) ? beforeNode(node) | 488 return editingIgnoresContent(node) ? beforeNode(node) |
| 489 : firstPositionInNode(node); | 489 : firstPositionInNode(node); |
| 490 } | 490 } |
| 491 | 491 |
| 492 // static | 492 // static |
| 493 template <typename Strategy> | 493 template <typename Strategy> |
| 494 PositionTemplate<Strategy> | 494 PositionTemplate<Strategy> |
| 495 PositionTemplate<Strategy>::lastPositionInOrAfterNode(Node* node) { | 495 PositionTemplate<Strategy>::lastPositionInOrAfterNode(Node* node) { |
| 496 if (!node) | 496 if (!node) |
| 497 return PositionTemplate<Strategy>(); | 497 return PositionTemplate<Strategy>(); |
| 498 return Strategy::editingIgnoresContent(node) ? afterNode(node) | 498 return editingIgnoresContent(node) ? afterNode(node) |
| 499 : lastPositionInNode(node); | 499 : lastPositionInNode(node); |
| 500 } | 500 } |
| 501 | 501 |
| 502 PositionInFlatTree toPositionInFlatTree(const Position& pos) { | 502 PositionInFlatTree toPositionInFlatTree(const Position& pos) { |
| 503 if (pos.isNull()) | 503 if (pos.isNull()) |
| 504 return PositionInFlatTree(); | 504 return PositionInFlatTree(); |
| 505 | 505 |
| 506 Node* const anchor = pos.anchorNode(); | 506 Node* const anchor = pos.anchorNode(); |
| 507 if (pos.isOffsetInAnchor()) { | 507 if (pos.isOffsetInAnchor()) { |
| 508 if (anchor->isCharacterDataNode()) | 508 if (anchor->isCharacterDataNode()) |
| 509 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode()); | 509 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode()); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 } | 672 } |
| 673 | 673 |
| 674 void showTree(const blink::Position* pos) { | 674 void showTree(const blink::Position* pos) { |
| 675 if (pos) | 675 if (pos) |
| 676 pos->showTreeForThis(); | 676 pos->showTreeForThis(); |
| 677 else | 677 else |
| 678 LOG(INFO) << "Cannot showTree for <null>"; | 678 LOG(INFO) << "Cannot showTree for <null>"; |
| 679 } | 679 } |
| 680 | 680 |
| 681 #endif | 681 #endif |
| OLD | NEW |