| 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 16 matching lines...) Expand all Loading... |
| 27 #define RangeBoundaryPoint_h | 27 #define RangeBoundaryPoint_h |
| 28 | 28 |
| 29 #include "core/dom/Node.h" | 29 #include "core/dom/Node.h" |
| 30 #include "core/dom/Position.h" | 30 #include "core/dom/Position.h" |
| 31 | 31 |
| 32 namespace WebCore { | 32 namespace WebCore { |
| 33 | 33 |
| 34 class RangeBoundaryPoint { | 34 class RangeBoundaryPoint { |
| 35 DISALLOW_ALLOCATION(); | 35 DISALLOW_ALLOCATION(); |
| 36 public: | 36 public: |
| 37 explicit RangeBoundaryPoint(PassRefPtr<Node> container); | 37 explicit RangeBoundaryPoint(PassRefPtrWillBeRawPtr<Node> container); |
| 38 | 38 |
| 39 explicit RangeBoundaryPoint(const RangeBoundaryPoint&); | 39 explicit RangeBoundaryPoint(const RangeBoundaryPoint&); |
| 40 | 40 |
| 41 const Position toPosition() const; | 41 const Position toPosition() const; |
| 42 | 42 |
| 43 Node* container() const; | 43 Node* container() const; |
| 44 int offset() const; | 44 int offset() const; |
| 45 Node* childBefore() const; | 45 Node* childBefore() const; |
| 46 | 46 |
| 47 void clear(); | 47 void clear(); |
| 48 | 48 |
| 49 void set(PassRefPtr<Node> container, int offset, Node* childBefore); | 49 void set(PassRefPtrWillBeRawPtr<Node> container, int offset, Node* childBefo
re); |
| 50 void setOffset(int offset); | 50 void setOffset(int offset); |
| 51 | 51 |
| 52 void setToBeforeChild(Node&); | 52 void setToBeforeChild(Node&); |
| 53 void setToStartOfNode(Node&); | 53 void setToStartOfNode(Node&); |
| 54 void setToEndOfNode(Node&); | 54 void setToEndOfNode(Node&); |
| 55 | 55 |
| 56 void childBeforeWillBeRemoved(); | 56 void childBeforeWillBeRemoved(); |
| 57 void invalidateOffset() const; | 57 void invalidateOffset() const; |
| 58 void ensureOffsetIsValid() const; | 58 void ensureOffsetIsValid() const; |
| 59 | 59 |
| 60 void trace(Visitor*); | 60 void trace(Visitor*); |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 static const int invalidOffset = -1; | 63 static const int invalidOffset = -1; |
| 64 | 64 |
| 65 RefPtrWillBeMember<Node> m_containerNode; | 65 RefPtrWillBeMember<Node> m_containerNode; |
| 66 mutable int m_offsetInContainer; | 66 mutable int m_offsetInContainer; |
| 67 RefPtrWillBeMember<Node> m_childBeforeBoundary; | 67 RefPtrWillBeMember<Node> m_childBeforeBoundary; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 inline RangeBoundaryPoint::RangeBoundaryPoint(PassRefPtr<Node> container) | 70 inline RangeBoundaryPoint::RangeBoundaryPoint(PassRefPtrWillBeRawPtr<Node> conta
iner) |
| 71 : m_containerNode(container) | 71 : m_containerNode(container) |
| 72 , m_offsetInContainer(0) | 72 , m_offsetInContainer(0) |
| 73 , m_childBeforeBoundary(nullptr) | 73 , m_childBeforeBoundary(nullptr) |
| 74 { | 74 { |
| 75 ASSERT(m_containerNode); | 75 ASSERT(m_containerNode); |
| 76 } | 76 } |
| 77 | 77 |
| 78 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) | 78 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) |
| 79 : m_containerNode(other.container()) | 79 : m_containerNode(other.container()) |
| 80 , m_offsetInContainer(other.offset()) | 80 , m_offsetInContainer(other.offset()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return m_offsetInContainer; | 113 return m_offsetInContainer; |
| 114 } | 114 } |
| 115 | 115 |
| 116 inline void RangeBoundaryPoint::clear() | 116 inline void RangeBoundaryPoint::clear() |
| 117 { | 117 { |
| 118 m_containerNode.clear(); | 118 m_containerNode.clear(); |
| 119 m_offsetInContainer = 0; | 119 m_offsetInContainer = 0; |
| 120 m_childBeforeBoundary = nullptr; | 120 m_childBeforeBoundary = nullptr; |
| 121 } | 121 } |
| 122 | 122 |
| 123 inline void RangeBoundaryPoint::set(PassRefPtr<Node> container, int offset, Node
* childBefore) | 123 inline void RangeBoundaryPoint::set(PassRefPtrWillBeRawPtr<Node> container, int
offset, Node* childBefore) |
| 124 { | 124 { |
| 125 ASSERT(container); | 125 ASSERT(container); |
| 126 ASSERT(offset >= 0); | 126 ASSERT(offset >= 0); |
| 127 ASSERT(childBefore == (offset ? container->traverseToChildAt(offset - 1) : 0
)); | 127 ASSERT(childBefore == (offset ? container->traverseToChildAt(offset - 1) : 0
)); |
| 128 m_containerNode = container; | 128 m_containerNode = container; |
| 129 m_offsetInContainer = offset; | 129 m_offsetInContainer = offset; |
| 130 m_childBeforeBoundary = childBefore; | 130 m_childBeforeBoundary = childBefore; |
| 131 } | 131 } |
| 132 | 132 |
| 133 inline void RangeBoundaryPoint::setOffset(int offset) | 133 inline void RangeBoundaryPoint::setOffset(int offset) |
| 134 { | 134 { |
| 135 ASSERT(m_containerNode); | 135 ASSERT(m_containerNode); |
| 136 ASSERT(m_containerNode->offsetInCharacters()); | 136 ASSERT(m_containerNode->offsetInCharacters()); |
| 137 ASSERT(m_offsetInContainer >= 0); | 137 ASSERT(m_offsetInContainer >= 0); |
| 138 ASSERT(!m_childBeforeBoundary); | 138 ASSERT(!m_childBeforeBoundary); |
| 139 m_offsetInContainer = offset; | 139 m_offsetInContainer = offset; |
| 140 } | 140 } |
| 141 | 141 |
| 142 inline void RangeBoundaryPoint::setToBeforeChild(Node& child) | 142 inline void RangeBoundaryPoint::setToBeforeChild(Node& child) |
| 143 { | 143 { |
| 144 ASSERT(child.parentNode()); | 144 ASSERT(child.parentNode()); |
| 145 m_childBeforeBoundary = child.previousSibling(); | 145 m_childBeforeBoundary = child.previousSibling(); |
| 146 m_containerNode = child.parentNode(); | 146 m_containerNode = child.parentNode(); |
| 147 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; | 147 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; |
| 148 } | 148 } |
| 149 | 149 |
| 150 inline void RangeBoundaryPoint::setToStartOfNode(Node& container) | 150 inline void RangeBoundaryPoint::setToStartOfNode(Node& container) |
| 151 { | 151 { |
| 152 m_containerNode = PassRefPtr<Node>(container); | 152 m_containerNode = &container; |
| 153 m_offsetInContainer = 0; | 153 m_offsetInContainer = 0; |
| 154 m_childBeforeBoundary = nullptr; | 154 m_childBeforeBoundary = nullptr; |
| 155 } | 155 } |
| 156 | 156 |
| 157 inline void RangeBoundaryPoint::setToEndOfNode(Node& container) | 157 inline void RangeBoundaryPoint::setToEndOfNode(Node& container) |
| 158 { | 158 { |
| 159 m_containerNode = PassRefPtr<Node>(container); | 159 m_containerNode = &container; |
| 160 if (m_containerNode->offsetInCharacters()) { | 160 if (m_containerNode->offsetInCharacters()) { |
| 161 m_offsetInContainer = m_containerNode->maxCharacterOffset(); | 161 m_offsetInContainer = m_containerNode->maxCharacterOffset(); |
| 162 m_childBeforeBoundary = nullptr; | 162 m_childBeforeBoundary = nullptr; |
| 163 } else { | 163 } else { |
| 164 m_childBeforeBoundary = m_containerNode->lastChild(); | 164 m_childBeforeBoundary = m_containerNode->lastChild(); |
| 165 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; | 165 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 inline void RangeBoundaryPoint::childBeforeWillBeRemoved() | 169 inline void RangeBoundaryPoint::childBeforeWillBeRemoved() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 197 } else { | 197 } else { |
| 198 if (a.offset() != b.offset()) | 198 if (a.offset() != b.offset()) |
| 199 return false; | 199 return false; |
| 200 } | 200 } |
| 201 return true; | 201 return true; |
| 202 } | 202 } |
| 203 | 203 |
| 204 } | 204 } |
| 205 | 205 |
| 206 #endif | 206 #endif |
| OLD | NEW |