| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) | 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) |
| 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) | 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) |
| 5 * (C) 2001 Peter Kelly (pmk@post.com) | 5 * (C) 2001 Peter Kelly (pmk@post.com) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 7 * rights reserved. | 7 * rights reserved. |
| 8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 Range* Range::create(Document& ownerDocument, | 94 Range* Range::create(Document& ownerDocument, |
| 95 const Position& start, | 95 const Position& start, |
| 96 const Position& end) { | 96 const Position& end) { |
| 97 return new Range(ownerDocument, start.computeContainerNode(), | 97 return new Range(ownerDocument, start.computeContainerNode(), |
| 98 start.computeOffsetInContainerNode(), | 98 start.computeOffsetInContainerNode(), |
| 99 end.computeContainerNode(), | 99 end.computeContainerNode(), |
| 100 end.computeOffsetInContainerNode()); | 100 end.computeOffsetInContainerNode()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // TODO(yosin): We should move |Range::createAdjustedToTreeScope()| to |
| 104 // "Document.cpp" since it is use only one place in "Document.cpp". |
| 103 Range* Range::createAdjustedToTreeScope(const TreeScope& treeScope, | 105 Range* Range::createAdjustedToTreeScope(const TreeScope& treeScope, |
| 104 const Position& position) { | 106 const Position& position) { |
| 105 Range* range = create(treeScope.document(), position, position); | 107 DCHECK(position.isNotNull()); |
| 106 | 108 // Note: Since |Position::computeContanerNode()| returns |nullptr| if |
| 107 // Make sure the range is in this scope. | 109 // |position| is |BeforeAnchor| or |AfterAnchor|. |
| 108 Node* firstNode = range->firstNode(); | 110 Node* const anchorNode = position.anchorNode(); |
| 109 DCHECK(firstNode); | 111 if (anchorNode->treeScope() == treeScope) |
| 110 Node* shadowHostInThisScopeOrFirstNode = | 112 return create(treeScope.document(), position, position); |
| 111 treeScope.ancestorInThisScope(firstNode); | 113 Node* const shadowHost = treeScope.ancestorInThisScope(anchorNode); |
| 112 DCHECK(shadowHostInThisScopeOrFirstNode); | 114 return Range::create(treeScope.document(), Position::beforeNode(shadowHost), |
| 113 if (shadowHostInThisScopeOrFirstNode == firstNode) | 115 Position::beforeNode(shadowHost)); |
| 114 return range; | |
| 115 | |
| 116 // If not, create a range for the shadow host in this scope. | |
| 117 ContainerNode* container = shadowHostInThisScopeOrFirstNode->parentNode(); | |
| 118 DCHECK(container); | |
| 119 unsigned offset = shadowHostInThisScopeOrFirstNode->nodeIndex(); | |
| 120 return Range::create(treeScope.document(), container, offset, container, | |
| 121 offset); | |
| 122 } | 116 } |
| 123 | 117 |
| 124 void Range::dispose() { | 118 void Range::dispose() { |
| 125 // A prompt detach from the owning Document helps avoid GC overhead. | 119 // A prompt detach from the owning Document helps avoid GC overhead. |
| 126 m_ownerDocument->detachRange(this); | 120 m_ownerDocument->detachRange(this); |
| 127 } | 121 } |
| 128 | 122 |
| 129 bool Range::isConnected() const { | 123 bool Range::isConnected() const { |
| 130 DCHECK_EQ(m_start.isConnected(), m_end.isConnected()); | 124 DCHECK_EQ(m_start.isConnected(), m_end.isConnected()); |
| 131 return m_start.isConnected(); | 125 return m_start.isConnected(); |
| (...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 .data() | 1765 .data() |
| 1772 << "start offset: " << range->startOffset() | 1766 << "start offset: " << range->startOffset() |
| 1773 << ", end offset: " << range->endOffset(); | 1767 << ", end offset: " << range->endOffset(); |
| 1774 } else { | 1768 } else { |
| 1775 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " | 1769 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " |
| 1776 "invalid."; | 1770 "invalid."; |
| 1777 } | 1771 } |
| 1778 } | 1772 } |
| 1779 | 1773 |
| 1780 #endif | 1774 #endif |
| OLD | NEW |