| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 Member<Node> m_containerNode; | 71 Member<Node> m_containerNode; |
| 72 mutable int m_offsetInContainer; | 72 mutable int m_offsetInContainer; |
| 73 Member<Node> m_childBeforeBoundary; | 73 Member<Node> m_childBeforeBoundary; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 inline RangeBoundaryPoint::RangeBoundaryPoint(RawPtr<Node> container) | 76 inline RangeBoundaryPoint::RangeBoundaryPoint(RawPtr<Node> container) |
| 77 : m_containerNode(container) | 77 : m_containerNode(container) |
| 78 , m_offsetInContainer(0) | 78 , m_offsetInContainer(0) |
| 79 , m_childBeforeBoundary(nullptr) | 79 , m_childBeforeBoundary(nullptr) |
| 80 { | 80 { |
| 81 ASSERT(m_containerNode); | 81 DCHECK(m_containerNode); |
| 82 } | 82 } |
| 83 | 83 |
| 84 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) | 84 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) |
| 85 : m_containerNode(other.container()) | 85 : m_containerNode(other.container()) |
| 86 , m_offsetInContainer(other.offset()) | 86 , m_offsetInContainer(other.offset()) |
| 87 , m_childBeforeBoundary(other.childBefore()) | 87 , m_childBeforeBoundary(other.childBefore()) |
| 88 { | 88 { |
| 89 } | 89 } |
| 90 | 90 |
| 91 inline Node* RangeBoundaryPoint::container() const | 91 inline Node* RangeBoundaryPoint::container() const |
| 92 { | 92 { |
| 93 return m_containerNode.get(); | 93 return m_containerNode.get(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 inline Node* RangeBoundaryPoint::childBefore() const | 96 inline Node* RangeBoundaryPoint::childBefore() const |
| 97 { | 97 { |
| 98 return m_childBeforeBoundary.get(); | 98 return m_childBeforeBoundary.get(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 inline void RangeBoundaryPoint::ensureOffsetIsValid() const | 101 inline void RangeBoundaryPoint::ensureOffsetIsValid() const |
| 102 { | 102 { |
| 103 if (m_offsetInContainer >= 0) | 103 if (m_offsetInContainer >= 0) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 ASSERT(m_childBeforeBoundary); | 106 DCHECK(m_childBeforeBoundary); |
| 107 m_offsetInContainer = m_childBeforeBoundary->nodeIndex() + 1; | 107 m_offsetInContainer = m_childBeforeBoundary->nodeIndex() + 1; |
| 108 } | 108 } |
| 109 | 109 |
| 110 inline bool RangeBoundaryPoint::inShadowIncludingDocument() const | 110 inline bool RangeBoundaryPoint::inShadowIncludingDocument() const |
| 111 { | 111 { |
| 112 return m_containerNode && m_containerNode->inShadowIncludingDocument(); | 112 return m_containerNode && m_containerNode->inShadowIncludingDocument(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 inline const Position RangeBoundaryPoint::toPosition() const | 115 inline const Position RangeBoundaryPoint::toPosition() const |
| 116 { | 116 { |
| 117 ensureOffsetIsValid(); | 117 ensureOffsetIsValid(); |
| 118 return Position::editingPositionOf(m_containerNode.get(), m_offsetInContaine
r); | 118 return Position::editingPositionOf(m_containerNode.get(), m_offsetInContaine
r); |
| 119 } | 119 } |
| 120 | 120 |
| 121 inline int RangeBoundaryPoint::offset() const | 121 inline int RangeBoundaryPoint::offset() const |
| 122 { | 122 { |
| 123 ensureOffsetIsValid(); | 123 ensureOffsetIsValid(); |
| 124 return m_offsetInContainer; | 124 return m_offsetInContainer; |
| 125 } | 125 } |
| 126 | 126 |
| 127 inline void RangeBoundaryPoint::clear() | 127 inline void RangeBoundaryPoint::clear() |
| 128 { | 128 { |
| 129 m_containerNode.clear(); | 129 m_containerNode.clear(); |
| 130 m_offsetInContainer = 0; | 130 m_offsetInContainer = 0; |
| 131 m_childBeforeBoundary = nullptr; | 131 m_childBeforeBoundary = nullptr; |
| 132 } | 132 } |
| 133 | 133 |
| 134 inline void RangeBoundaryPoint::set(RawPtr<Node> container, int offset, Node* ch
ildBefore) | 134 inline void RangeBoundaryPoint::set(RawPtr<Node> container, int offset, Node* ch
ildBefore) |
| 135 { | 135 { |
| 136 ASSERT(container); | 136 DCHECK(container); |
| 137 ASSERT(offset >= 0); | 137 DCHECK_GE(offset, 0); |
| 138 ASSERT(childBefore == (offset ? NodeTraversal::childAt(*container, offset -
1) : 0)); | 138 DCHECK_EQ(childBefore, offset ? NodeTraversal::childAt(*container, offset -
1) : 0); |
| 139 m_containerNode = container; | 139 m_containerNode = container; |
| 140 m_offsetInContainer = offset; | 140 m_offsetInContainer = offset; |
| 141 m_childBeforeBoundary = childBefore; | 141 m_childBeforeBoundary = childBefore; |
| 142 } | 142 } |
| 143 | 143 |
| 144 inline void RangeBoundaryPoint::setOffset(int offset) | 144 inline void RangeBoundaryPoint::setOffset(int offset) |
| 145 { | 145 { |
| 146 ASSERT(m_containerNode); | 146 DCHECK(m_containerNode); |
| 147 ASSERT(m_containerNode->offsetInCharacters()); | 147 DCHECK(m_containerNode->offsetInCharacters()); |
| 148 ASSERT(m_offsetInContainer >= 0); | 148 DCHECK_GE(m_offsetInContainer, 0); |
| 149 ASSERT(!m_childBeforeBoundary); | 149 DCHECK(!m_childBeforeBoundary); |
| 150 m_offsetInContainer = offset; | 150 m_offsetInContainer = offset; |
| 151 } | 151 } |
| 152 | 152 |
| 153 inline void RangeBoundaryPoint::setToBeforeChild(Node& child) | 153 inline void RangeBoundaryPoint::setToBeforeChild(Node& child) |
| 154 { | 154 { |
| 155 ASSERT(child.parentNode()); | 155 DCHECK(child.parentNode()); |
| 156 m_childBeforeBoundary = child.previousSibling(); | 156 m_childBeforeBoundary = child.previousSibling(); |
| 157 m_containerNode = child.parentNode(); | 157 m_containerNode = child.parentNode(); |
| 158 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; | 158 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; |
| 159 } | 159 } |
| 160 | 160 |
| 161 inline void RangeBoundaryPoint::setToStartOfNode(Node& container) | 161 inline void RangeBoundaryPoint::setToStartOfNode(Node& container) |
| 162 { | 162 { |
| 163 m_containerNode = &container; | 163 m_containerNode = &container; |
| 164 m_offsetInContainer = 0; | 164 m_offsetInContainer = 0; |
| 165 m_childBeforeBoundary = nullptr; | 165 m_childBeforeBoundary = nullptr; |
| 166 } | 166 } |
| 167 | 167 |
| 168 inline void RangeBoundaryPoint::setToEndOfNode(Node& container) | 168 inline void RangeBoundaryPoint::setToEndOfNode(Node& container) |
| 169 { | 169 { |
| 170 m_containerNode = &container; | 170 m_containerNode = &container; |
| 171 if (m_containerNode->offsetInCharacters()) { | 171 if (m_containerNode->offsetInCharacters()) { |
| 172 m_offsetInContainer = m_containerNode->maxCharacterOffset(); | 172 m_offsetInContainer = m_containerNode->maxCharacterOffset(); |
| 173 m_childBeforeBoundary = nullptr; | 173 m_childBeforeBoundary = nullptr; |
| 174 } else { | 174 } else { |
| 175 m_childBeforeBoundary = m_containerNode->lastChild(); | 175 m_childBeforeBoundary = m_containerNode->lastChild(); |
| 176 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; | 176 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 inline void RangeBoundaryPoint::childBeforeWillBeRemoved() | 180 inline void RangeBoundaryPoint::childBeforeWillBeRemoved() |
| 181 { | 181 { |
| 182 ASSERT(m_offsetInContainer); | 182 DCHECK(m_offsetInContainer); |
| 183 m_childBeforeBoundary = m_childBeforeBoundary->previousSibling(); | 183 m_childBeforeBoundary = m_childBeforeBoundary->previousSibling(); |
| 184 if (!m_childBeforeBoundary) | 184 if (!m_childBeforeBoundary) |
| 185 m_offsetInContainer = 0; | 185 m_offsetInContainer = 0; |
| 186 else if (m_offsetInContainer > 0) | 186 else if (m_offsetInContainer > 0) |
| 187 --m_offsetInContainer; | 187 --m_offsetInContainer; |
| 188 } | 188 } |
| 189 | 189 |
| 190 inline void RangeBoundaryPoint::invalidateOffset() const | 190 inline void RangeBoundaryPoint::invalidateOffset() const |
| 191 { | 191 { |
| 192 m_offsetInContainer = invalidOffset; | 192 m_offsetInContainer = invalidOffset; |
| 193 } | 193 } |
| 194 | 194 |
| 195 inline bool operator==(const RangeBoundaryPoint& a, const RangeBoundaryPoint& b) | 195 inline bool operator==(const RangeBoundaryPoint& a, const RangeBoundaryPoint& b) |
| 196 { | 196 { |
| 197 if (a.container() != b.container()) | 197 if (a.container() != b.container()) |
| 198 return false; | 198 return false; |
| 199 if (a.childBefore() || b.childBefore()) { | 199 if (a.childBefore() || b.childBefore()) { |
| 200 if (a.childBefore() != b.childBefore()) | 200 if (a.childBefore() != b.childBefore()) |
| 201 return false; | 201 return false; |
| 202 } else { | 202 } else { |
| 203 if (a.offset() != b.offset()) | 203 if (a.offset() != b.offset()) |
| 204 return false; | 204 return false; |
| 205 } | 205 } |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 } // namespace blink | 209 } // namespace blink |
| 210 | 210 |
| 211 #endif | 211 #endif |
| OLD | NEW |