OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 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 17 matching lines...) Expand all Loading... |
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 // A Position iterator with constant-time | 34 // A Position iterator with constant-time |
35 // increment, decrement, and several predicates on the Position it is at. | 35 // increment, decrement, and several predicates on the Position it is at. |
36 // Conversion to/from Position is O(n) in the offset. | 36 // Conversion to/from Position is O(n) in the offset. |
37 class PositionIterator { | 37 class PositionIterator { |
| 38 STACK_ALLOCATED(); |
38 public: | 39 public: |
39 PositionIterator() | 40 PositionIterator() |
40 : m_anchorNode(0) | 41 : m_anchorNode(nullptr) |
41 , m_nodeAfterPositionInAnchor(0) | 42 , m_nodeAfterPositionInAnchor(nullptr) |
42 , m_offsetInAnchor(0) | 43 , m_offsetInAnchor(0) |
43 { | 44 { |
44 } | 45 } |
45 | 46 |
46 PositionIterator(const Position& pos) | 47 PositionIterator(const Position& pos) |
47 : m_anchorNode(pos.anchorNode()) | 48 : m_anchorNode(pos.anchorNode()) |
48 , m_nodeAfterPositionInAnchor(m_anchorNode->traverseToChildAt(pos.deprec
atedEditingOffset())) | 49 , m_nodeAfterPositionInAnchor(m_anchorNode->traverseToChildAt(pos.deprec
atedEditingOffset())) |
49 , m_offsetInAnchor(m_nodeAfterPositionInAnchor ? 0 : pos.deprecatedEditi
ngOffset()) | 50 , m_offsetInAnchor(m_nodeAfterPositionInAnchor ? 0 : pos.deprecatedEditi
ngOffset()) |
50 { | 51 { |
51 } | 52 } |
52 operator Position() const; | 53 operator Position() const; |
53 | 54 |
54 void increment(); | 55 void increment(); |
55 void decrement(); | 56 void decrement(); |
56 | 57 |
57 Node* node() const { return m_anchorNode; } | 58 Node* node() const { return m_anchorNode; } |
58 int offsetInLeafNode() const { return m_offsetInAnchor; } | 59 int offsetInLeafNode() const { return m_offsetInAnchor; } |
59 | 60 |
60 bool atStart() const; | 61 bool atStart() const; |
61 bool atEnd() const; | 62 bool atEnd() const; |
62 bool atStartOfNode() const; | 63 bool atStartOfNode() const; |
63 bool atEndOfNode() const; | 64 bool atEndOfNode() const; |
64 bool isCandidate() const; | 65 bool isCandidate() const; |
65 | 66 |
66 private: | 67 private: |
67 Node* m_anchorNode; | 68 RawPtrWillBeMember<Node> m_anchorNode; |
68 Node* m_nodeAfterPositionInAnchor; // If this is non-null, m_nodeAfterPositi
onInAnchor->parentNode() == m_anchorNode; | 69 RawPtrWillBeMember<Node> m_nodeAfterPositionInAnchor; // If this is non-null
, m_nodeAfterPositionInAnchor->parentNode() == m_anchorNode; |
69 int m_offsetInAnchor; | 70 int m_offsetInAnchor; |
70 }; | 71 }; |
71 | 72 |
72 } // namespace WebCore | 73 } // namespace WebCore |
73 | 74 |
74 #endif // PositionIterator_h | 75 #endif // PositionIterator_h |
OLD | NEW |