| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "core/dom/shadow/ElementShadow.h" | 28 #include "core/dom/shadow/ElementShadow.h" |
| 29 #include "core/editing/EditingUtilities.h" | 29 #include "core/editing/EditingUtilities.h" |
| 30 #include "core/editing/TextAffinity.h" | 30 #include "core/editing/TextAffinity.h" |
| 31 #include "wtf/text/CString.h" | 31 #include "wtf/text/CString.h" |
| 32 #include <stdio.h> | 32 #include <stdio.h> |
| 33 #include <ostream> // NOLINT | 33 #include <ostream> // NOLINT |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 #if ENABLE(ASSERT) | 37 #if DCHECK_IS_ON() |
| 38 static bool canBeAnchorNode(Node* node) | 38 static bool canBeAnchorNode(Node* node) |
| 39 { | 39 { |
| 40 return !node || !node->isPseudoElement(); | 40 return !node || !node->isPseudoElement(); |
| 41 } | 41 } |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 template <typename Strategy> | 44 template <typename Strategy> |
| 45 const TreeScope* PositionTemplate<Strategy>::commonAncestorTreeScope(const Posit
ionTemplate<Strategy>& a, const PositionTemplate<Strategy>& b) | 45 const TreeScope* PositionTemplate<Strategy>::commonAncestorTreeScope(const Posit
ionTemplate<Strategy>& a, const PositionTemplate<Strategy>& b) |
| 46 { | 46 { |
| 47 if (!a.computeContainerNode() || !b.computeContainerNode()) | 47 if (!a.computeContainerNode() || !b.computeContainerNode()) |
| 48 return nullptr; | 48 return nullptr; |
| 49 return a.computeContainerNode()->treeScope().commonAncestorTreeScope(b.compu
teContainerNode()->treeScope()); | 49 return a.computeContainerNode()->treeScope().commonAncestorTreeScope(b.compu
teContainerNode()->treeScope()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 template <typename Strategy> | 53 template <typename Strategy> |
| 54 PositionTemplate<Strategy> PositionTemplate<Strategy>::editingPositionOf(Node* a
nchorNode, int offset) | 54 PositionTemplate<Strategy> PositionTemplate<Strategy>::editingPositionOf(Node* a
nchorNode, int offset) |
| 55 { | 55 { |
| 56 if (!anchorNode || anchorNode->isTextNode()) | 56 if (!anchorNode || anchorNode->isTextNode()) |
| 57 return PositionTemplate<Strategy>(anchorNode, offset); | 57 return PositionTemplate<Strategy>(anchorNode, offset); |
| 58 | 58 |
| 59 if (!Strategy::editingIgnoresContent(anchorNode)) | 59 if (!Strategy::editingIgnoresContent(anchorNode)) |
| 60 return PositionTemplate<Strategy>(anchorNode, offset); | 60 return PositionTemplate<Strategy>(anchorNode, offset); |
| 61 | 61 |
| 62 if (offset == 0) | 62 if (offset == 0) |
| 63 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::Before
Anchor); | 63 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::Before
Anchor); |
| 64 | 64 |
| 65 // Note: |offset| can be >= 1, if |anchorNode| have child nodes, e.g. | 65 // Note: |offset| can be >= 1, if |anchorNode| have child nodes, e.g. |
| 66 // using Node.appendChild() to add a child node TEXTAREA. | 66 // using Node.appendChild() to add a child node TEXTAREA. |
| 67 ASSERT(offset >= 1); | 67 DCHECK_GE(offset, 1); |
| 68 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterAncho
r); | 68 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterAncho
r); |
| 69 } | 69 } |
| 70 | 70 |
| 71 template <typename Strategy> | 71 template <typename Strategy> |
| 72 PositionTemplate<Strategy>::PositionTemplate(Node* anchorNode, PositionAnchorTyp
e anchorType) | 72 PositionTemplate<Strategy>::PositionTemplate(Node* anchorNode, PositionAnchorTyp
e anchorType) |
| 73 : m_anchorNode(anchorNode) | 73 : m_anchorNode(anchorNode) |
| 74 , m_offset(0) | 74 , m_offset(0) |
| 75 , m_anchorType(anchorType) | 75 , m_anchorType(anchorType) |
| 76 { | 76 { |
| 77 if (!m_anchorNode) { | 77 if (!m_anchorNode) { |
| 78 m_anchorType = PositionAnchorType::OffsetInAnchor; | 78 m_anchorType = PositionAnchorType::OffsetInAnchor; |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 if (m_anchorNode->isTextNode()) { | 81 if (m_anchorNode->isTextNode()) { |
| 82 ASSERT(m_anchorType == PositionAnchorType::BeforeAnchor || m_anchorType
== PositionAnchorType::AfterAnchor); | 82 DCHECK(m_anchorType == PositionAnchorType::BeforeAnchor || m_anchorType
== PositionAnchorType::AfterAnchor); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 if (m_anchorNode->isDocumentNode()) { | 85 if (m_anchorNode->isDocumentNode()) { |
| 86 // Since |RangeBoundaryPoint| can't represent before/after Document, we | 86 // Since |RangeBoundaryPoint| can't represent before/after Document, we |
| 87 // should not use them. | 87 // should not use them. |
| 88 DCHECK(isBeforeChildren() || isAfterChildren()) << m_anchorType; | 88 DCHECK(isBeforeChildren() || isAfterChildren()) << m_anchorType; |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 ASSERT(canBeAnchorNode(m_anchorNode.get())); | 91 #if DCHECK_IS_ON() |
| 92 ASSERT(m_anchorType != PositionAnchorType::OffsetInAnchor); | 92 DCHECK(canBeAnchorNode(m_anchorNode.get())); |
| 93 #endif |
| 94 DCHECK_NE(m_anchorType, PositionAnchorType::OffsetInAnchor); |
| 93 } | 95 } |
| 94 | 96 |
| 95 template <typename Strategy> | 97 template <typename Strategy> |
| 96 PositionTemplate<Strategy>::PositionTemplate(Node* anchorNode, int offset) | 98 PositionTemplate<Strategy>::PositionTemplate(Node* anchorNode, int offset) |
| 97 : m_anchorNode(anchorNode) | 99 : m_anchorNode(anchorNode) |
| 98 , m_offset(offset) | 100 , m_offset(offset) |
| 99 , m_anchorType(PositionAnchorType::OffsetInAnchor) | 101 , m_anchorType(PositionAnchorType::OffsetInAnchor) |
| 100 { | 102 { |
| 101 if (m_anchorNode) | 103 if (m_anchorNode) |
| 102 ASSERT(offset >= 0); | 104 DCHECK_GE(offset, 0); |
| 103 else | 105 else |
| 104 ASSERT(offset == 0); | 106 DCHECK_EQ(offset, 0); |
| 105 ASSERT(canBeAnchorNode(m_anchorNode.get())); | 107 #if DCHECK_IS_ON() |
| 108 DCHECK(canBeAnchorNode(m_anchorNode.get())); |
| 109 #endif |
| 106 } | 110 } |
| 107 | 111 |
| 108 template <typename Strategy> | 112 template <typename Strategy> |
| 109 PositionTemplate<Strategy>::PositionTemplate(const PositionTemplate& other) | 113 PositionTemplate<Strategy>::PositionTemplate(const PositionTemplate& other) |
| 110 : m_anchorNode(other.m_anchorNode) | 114 : m_anchorNode(other.m_anchorNode) |
| 111 , m_offset(other.m_offset) | 115 , m_offset(other.m_offset) |
| 112 , m_anchorType(other.m_anchorType) | 116 , m_anchorType(other.m_anchorType) |
| 113 { | 117 { |
| 114 } | 118 } |
| 115 | 119 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 287 } |
| 284 | 288 |
| 285 template <typename Strategy> | 289 template <typename Strategy> |
| 286 Node* PositionTemplate<Strategy>::commonAncestorContainer(const PositionTemplate
<Strategy>& other) const | 290 Node* PositionTemplate<Strategy>::commonAncestorContainer(const PositionTemplate
<Strategy>& other) const |
| 287 { | 291 { |
| 288 return Strategy::commonAncestor(*computeContainerNode(), *other.computeConta
inerNode()); | 292 return Strategy::commonAncestor(*computeContainerNode(), *other.computeConta
inerNode()); |
| 289 } | 293 } |
| 290 | 294 |
| 291 int comparePositions(const PositionInFlatTree& positionA, const PositionInFlatTr
ee& positionB) | 295 int comparePositions(const PositionInFlatTree& positionA, const PositionInFlatTr
ee& positionB) |
| 292 { | 296 { |
| 293 ASSERT(positionA.isNotNull()); | 297 DCHECK(positionA.isNotNull()); |
| 294 ASSERT(positionB.isNotNull()); | 298 DCHECK(positionB.isNotNull()); |
| 295 | 299 |
| 296 positionA.anchorNode()->updateDistribution(); | 300 positionA.anchorNode()->updateDistribution(); |
| 297 Node* containerA = positionA.computeContainerNode(); | 301 Node* containerA = positionA.computeContainerNode(); |
| 298 positionB.anchorNode()->updateDistribution(); | 302 positionB.anchorNode()->updateDistribution(); |
| 299 Node* containerB = positionB.computeContainerNode(); | 303 Node* containerB = positionB.computeContainerNode(); |
| 300 int offsetA = positionA.computeOffsetInContainerNode(); | 304 int offsetA = positionA.computeOffsetInContainerNode(); |
| 301 int offsetB = positionB.computeOffsetInContainerNode(); | 305 int offsetB = positionB.computeOffsetInContainerNode(); |
| 302 return comparePositionsInFlatTree(containerA, offsetA, containerB, offsetB); | 306 return comparePositionsInFlatTree(containerA, offsetA, containerB, offsetB); |
| 303 } | 307 } |
| 304 | 308 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 418 |
| 415 PositionInFlatTree toPositionInFlatTree(const Position& pos) | 419 PositionInFlatTree toPositionInFlatTree(const Position& pos) |
| 416 { | 420 { |
| 417 if (pos.isNull()) | 421 if (pos.isNull()) |
| 418 return PositionInFlatTree(); | 422 return PositionInFlatTree(); |
| 419 | 423 |
| 420 if (pos.isOffsetInAnchor()) { | 424 if (pos.isOffsetInAnchor()) { |
| 421 Node* anchor = pos.anchorNode(); | 425 Node* anchor = pos.anchorNode(); |
| 422 if (anchor->offsetInCharacters()) | 426 if (anchor->offsetInCharacters()) |
| 423 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode()
); | 427 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode()
); |
| 424 ASSERT(!anchor->isSlotOrActiveInsertionPoint()); | 428 DCHECK(!anchor->isSlotOrActiveInsertionPoint()); |
| 425 int offset = pos.computeOffsetInContainerNode(); | 429 int offset = pos.computeOffsetInContainerNode(); |
| 426 Node* child = NodeTraversal::childAt(*anchor, offset); | 430 Node* child = NodeTraversal::childAt(*anchor, offset); |
| 427 if (!child) { | 431 if (!child) { |
| 428 if (anchor->isShadowRoot()) | 432 if (anchor->isShadowRoot()) |
| 429 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorTy
pe::AfterChildren); | 433 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorTy
pe::AfterChildren); |
| 430 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren)
; | 434 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren)
; |
| 431 } | 435 } |
| 432 child->updateDistribution(); | 436 child->updateDistribution(); |
| 433 if (child->isSlotOrActiveInsertionPoint()) { | 437 if (child->isSlotOrActiveInsertionPoint()) { |
| 434 if (anchor->isShadowRoot()) | 438 if (anchor->isShadowRoot()) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 | 611 |
| 608 void showTree(const blink::Position* pos) | 612 void showTree(const blink::Position* pos) |
| 609 { | 613 { |
| 610 if (pos) | 614 if (pos) |
| 611 pos->showTreeForThis(); | 615 pos->showTreeForThis(); |
| 612 else | 616 else |
| 613 fprintf(stderr, "Cannot showTree for (nil)\n"); | 617 fprintf(stderr, "Cannot showTree for (nil)\n"); |
| 614 } | 618 } |
| 615 | 619 |
| 616 #endif | 620 #endif |
| OLD | NEW |