Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 | 37 |
| 38 public: | 38 public: |
| 39 explicit RangeBoundaryPoint(Node* container); | 39 explicit RangeBoundaryPoint(Node* container); |
| 40 | 40 |
| 41 explicit RangeBoundaryPoint(const RangeBoundaryPoint&); | 41 explicit RangeBoundaryPoint(const RangeBoundaryPoint&); |
| 42 | 42 |
| 43 bool isConnected() const; | 43 bool isConnected() const; |
| 44 const Position toPosition() const; | 44 const Position toPosition() const; |
| 45 | 45 |
| 46 Node* container() const; | 46 Node* container() const; |
| 47 int offset() const; | 47 unsigned offset() const; |
| 48 Node* childBefore() const; | 48 Node* childBefore() const; |
| 49 | 49 |
| 50 void clear(); | 50 void clear(); |
| 51 | 51 |
| 52 void set(Node* container, int offset, Node* childBefore); | 52 void set(Node* container, unsigned offset, Node* childBefore); |
| 53 void setOffset(int); | 53 void setOffset(unsigned); |
| 54 | 54 |
| 55 void setToBeforeChild(Node&); | 55 void setToBeforeChild(Node&); |
| 56 void setToStartOfNode(Node&); | 56 void setToStartOfNode(Node&); |
| 57 void setToEndOfNode(Node&); | 57 void setToEndOfNode(Node&); |
| 58 | 58 |
| 59 void childBeforeWillBeRemoved(); | 59 void childBeforeWillBeRemoved(); |
| 60 void invalidateOffset(); | 60 void invalidateOffset(); |
| 61 void markValid() const; | 61 void markValid() const; |
| 62 | 62 |
| 63 DEFINE_INLINE_TRACE() { | 63 DEFINE_INLINE_TRACE() { |
| 64 visitor->trace(m_containerNode); | 64 visitor->trace(m_containerNode); |
| 65 visitor->trace(m_childBeforeBoundary); | 65 visitor->trace(m_childBeforeBoundary); |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 uint64_t domTreeVersion() const; | 69 uint64_t domTreeVersion() const; |
| 70 void ensureOffsetIsValid() const; | 70 void ensureOffsetIsValid() const; |
| 71 bool isOffsetValid() const; | 71 bool isOffsetValid() const; |
| 72 | 72 |
| 73 static const int invalidOffset = -1; | 73 static const unsigned invalidOffset = static_cast<unsigned>(-1); |
|
Sunny
2017/02/21 12:32:05
Hi tkent@, I've tried working on this issue before
tkent
2017/02/22 02:08:43
Adding a boolean flag is a more graceful way.
Howe
| |
| 74 | 74 |
| 75 Member<Node> m_containerNode; | 75 Member<Node> m_containerNode; |
| 76 Member<Node> m_childBeforeBoundary; | 76 Member<Node> m_childBeforeBoundary; |
| 77 mutable uint64_t m_domTreeVersion; | 77 mutable uint64_t m_domTreeVersion; |
| 78 mutable int m_offsetInContainer; | 78 mutable unsigned m_offsetInContainer; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 inline RangeBoundaryPoint::RangeBoundaryPoint(Node* container) | 81 inline RangeBoundaryPoint::RangeBoundaryPoint(Node* container) |
| 82 : m_containerNode(container), | 82 : m_containerNode(container), |
| 83 m_childBeforeBoundary(nullptr), | 83 m_childBeforeBoundary(nullptr), |
| 84 m_domTreeVersion(domTreeVersion()), | 84 m_domTreeVersion(domTreeVersion()), |
| 85 m_offsetInContainer(0) {} | 85 m_offsetInContainer(0) {} |
| 86 | 86 |
| 87 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) | 87 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) |
| 88 : m_containerNode(other.container()), | 88 : m_containerNode(other.container()), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 128 } |
| 129 | 129 |
| 130 inline const Position RangeBoundaryPoint::toPosition() const { | 130 inline const Position RangeBoundaryPoint::toPosition() const { |
| 131 ensureOffsetIsValid(); | 131 ensureOffsetIsValid(); |
| 132 // TODO(yosin): We should return |Position::beforeAnchor| when | 132 // TODO(yosin): We should return |Position::beforeAnchor| when |
| 133 // |m_containerNode| isn't |Text| node. | 133 // |m_containerNode| isn't |Text| node. |
| 134 return Position::editingPositionOf(m_containerNode.get(), | 134 return Position::editingPositionOf(m_containerNode.get(), |
| 135 m_offsetInContainer); | 135 m_offsetInContainer); |
| 136 } | 136 } |
| 137 | 137 |
| 138 inline int RangeBoundaryPoint::offset() const { | 138 inline unsigned RangeBoundaryPoint::offset() const { |
| 139 ensureOffsetIsValid(); | 139 ensureOffsetIsValid(); |
| 140 return m_offsetInContainer; | 140 return m_offsetInContainer; |
| 141 } | 141 } |
| 142 | 142 |
| 143 inline void RangeBoundaryPoint::clear() { | 143 inline void RangeBoundaryPoint::clear() { |
| 144 m_containerNode.clear(); | 144 m_containerNode.clear(); |
| 145 m_offsetInContainer = 0; | 145 m_offsetInContainer = 0; |
| 146 m_childBeforeBoundary = nullptr; | 146 m_childBeforeBoundary = nullptr; |
| 147 m_domTreeVersion = 0; | 147 m_domTreeVersion = 0; |
| 148 } | 148 } |
| 149 | 149 |
| 150 inline void RangeBoundaryPoint::set(Node* container, | 150 inline void RangeBoundaryPoint::set(Node* container, |
| 151 int offset, | 151 unsigned offset, |
| 152 Node* childBefore) { | 152 Node* childBefore) { |
| 153 DCHECK(container); | 153 DCHECK(container); |
| 154 DCHECK_GE(offset, 0); | 154 DCHECK_GE(offset, 0u); |
| 155 DCHECK_EQ(childBefore, | 155 DCHECK_EQ(childBefore, |
| 156 offset ? NodeTraversal::childAt(*container, offset - 1) : 0); | 156 offset ? NodeTraversal::childAt(*container, offset - 1) : 0); |
| 157 m_containerNode = container; | 157 m_containerNode = container; |
| 158 m_offsetInContainer = offset; | 158 m_offsetInContainer = offset; |
| 159 m_childBeforeBoundary = childBefore; | 159 m_childBeforeBoundary = childBefore; |
| 160 markValid(); | 160 markValid(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 inline void RangeBoundaryPoint::setOffset(int offset) { | 163 inline void RangeBoundaryPoint::setOffset(unsigned offset) { |
| 164 DCHECK(m_containerNode); | 164 DCHECK(m_containerNode); |
| 165 DCHECK(m_containerNode->isCharacterDataNode()); | 165 DCHECK(m_containerNode->isCharacterDataNode()); |
| 166 DCHECK_GE(m_offsetInContainer, 0); | 166 DCHECK_GE(m_offsetInContainer, 0u); |
| 167 DCHECK(!m_childBeforeBoundary); | 167 DCHECK(!m_childBeforeBoundary); |
| 168 m_offsetInContainer = offset; | 168 m_offsetInContainer = offset; |
| 169 markValid(); | 169 markValid(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 inline void RangeBoundaryPoint::setToBeforeChild(Node& child) { | 172 inline void RangeBoundaryPoint::setToBeforeChild(Node& child) { |
| 173 DCHECK(child.parentNode()); | 173 DCHECK(child.parentNode()); |
| 174 m_childBeforeBoundary = child.previousSibling(); | 174 m_childBeforeBoundary = child.previousSibling(); |
| 175 m_containerNode = child.parentNode(); | 175 m_containerNode = child.parentNode(); |
| 176 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; | 176 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 193 m_childBeforeBoundary = m_containerNode->lastChild(); | 193 m_childBeforeBoundary = m_containerNode->lastChild(); |
| 194 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; | 194 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; |
| 195 } | 195 } |
| 196 markValid(); | 196 markValid(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 inline void RangeBoundaryPoint::childBeforeWillBeRemoved() { | 199 inline void RangeBoundaryPoint::childBeforeWillBeRemoved() { |
| 200 m_childBeforeBoundary = m_childBeforeBoundary->previousSibling(); | 200 m_childBeforeBoundary = m_childBeforeBoundary->previousSibling(); |
| 201 if (!isOffsetValid()) | 201 if (!isOffsetValid()) |
| 202 return; | 202 return; |
| 203 DCHECK_GT(m_offsetInContainer, 0); | 203 DCHECK_GT(m_offsetInContainer, 0u); |
| 204 if (!m_childBeforeBoundary) | 204 if (!m_childBeforeBoundary) |
| 205 m_offsetInContainer = 0; | 205 m_offsetInContainer = 0; |
| 206 else if (m_offsetInContainer > 0) | 206 else if (m_offsetInContainer > 0) |
| 207 --m_offsetInContainer; | 207 --m_offsetInContainer; |
| 208 markValid(); | 208 markValid(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 inline void RangeBoundaryPoint::invalidateOffset() { | 211 inline void RangeBoundaryPoint::invalidateOffset() { |
| 212 m_offsetInContainer = invalidOffset; | 212 m_offsetInContainer = invalidOffset; |
| 213 } | 213 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 226 } else { | 226 } else { |
| 227 if (a.offset() != b.offset()) | 227 if (a.offset() != b.offset()) |
| 228 return false; | 228 return false; |
| 229 } | 229 } |
| 230 return true; | 230 return true; |
| 231 } | 231 } |
| 232 | 232 |
| 233 } // namespace blink | 233 } // namespace blink |
| 234 | 234 |
| 235 #endif | 235 #endif |
| OLD | NEW |