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 16 matching lines...) Expand all Loading... | |
27 #define PositionIterator_h | 27 #define PositionIterator_h |
28 | 28 |
29 #include "core/dom/Node.h" | 29 #include "core/dom/Node.h" |
30 #include "core/editing/EditingStrategy.h" | 30 #include "core/editing/EditingStrategy.h" |
31 #include "core/editing/EditingUtilities.h" | 31 #include "core/editing/EditingUtilities.h" |
32 #include "core/html/HTMLHtmlElement.h" | 32 #include "core/html/HTMLHtmlElement.h" |
33 #include "core/layout/LayoutBlock.h" | 33 #include "core/layout/LayoutBlock.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 // A Position iterator with constant-time | 37 // A Position iterator with nearly constant-time |
38 // increment, decrement, and several predicates on the Position it is at. | 38 // increment, decrement, and several predicates on the Position it is at. |
39 // Conversion to/from Position is O(n) in the offset. | 39 // Conversion from Position is O(n) in the depth. |
40 // Conversion to Position is O(1). | |
41 // PositionIteratorAlgorithm must be used without DOM tree change. | |
40 template <typename Strategy> | 42 template <typename Strategy> |
41 class PositionIteratorAlgorithm { | 43 class PositionIteratorAlgorithm { |
42 STACK_ALLOCATED(); | 44 STACK_ALLOCATED(); |
43 public: | 45 public: |
44 explicit PositionIteratorAlgorithm(const PositionTemplate<Strategy>&); | 46 explicit PositionIteratorAlgorithm(const PositionTemplate<Strategy>&); |
45 PositionIteratorAlgorithm(); | 47 PositionIteratorAlgorithm(); |
46 | 48 |
47 // Since |deprecatedComputePosition()| is slow, new code should use | 49 // Since |deprecatedComputePosition()| is slow, new code should use |
48 // |computePosition()| instead. | 50 // |computePosition()| instead. |
49 PositionTemplate<Strategy> deprecatedComputePosition() const; | 51 PositionTemplate<Strategy> deprecatedComputePosition() const; |
50 PositionTemplate<Strategy> computePosition() const; | 52 PositionTemplate<Strategy> computePosition() const; |
51 | 53 |
54 // increment() takes O(1) other than increment into new parent. | |
hajimehoshi
2015/10/08 04:57:27
I don't understand this sentence.
yoichio
2015/10/21 04:35:05
Update
| |
55 // In later case, it takes time of O(<number of childlen>) but the case | |
hajimehoshi
2015/10/08 04:57:27
nit: In the latter case
yoichio
2015/10/21 04:35:05
Done.
| |
56 // happens at most depth-of-the-tree times over whole tree traversal. | |
52 void increment(); | 57 void increment(); |
58 // decrement() takes O(1) other than decrement into new node that has | |
59 // childlen. | |
60 // In later case, it takes time of O(<number of childlen>). | |
hajimehoshi
2015/10/08 04:57:27
nit: ditto
yoichio
2015/10/21 04:35:05
Done.
| |
53 void decrement(); | 61 void decrement(); |
54 | 62 |
55 Node* node() const { return m_anchorNode; } | 63 Node* node() const { return m_anchorNode; } |
56 int offsetInLeafNode() const { return m_offsetInAnchor; } | 64 int offsetInLeafNode() const { return m_offsetInAnchor; } |
57 | 65 |
58 bool atStart() const; | 66 bool atStart() const; |
59 bool atEnd() const; | 67 bool atEnd() const; |
60 bool atStartOfNode() const; | 68 bool atStartOfNode() const; |
61 bool atEndOfNode() const; | 69 bool atEndOfNode() const; |
62 | 70 |
63 private: | 71 private: |
64 PositionIteratorAlgorithm(Node* anchorNode, int offsetInAnchorNode); | 72 PositionIteratorAlgorithm(Node* anchorNode, int offsetInAnchorNode); |
65 | 73 |
66 RawPtrWillBeMember<Node> m_anchorNode; | 74 RawPtrWillBeMember<Node> m_anchorNode; |
67 RawPtrWillBeMember<Node> m_nodeAfterPositionInAnchor; // If this is non-null , Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode; | 75 RawPtrWillBeMember<Node> m_nodeAfterPositionInAnchor; // If this is non-null , Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode; |
76 // TOOD: Replace |m_offsetInAnchor| with | |
77 // m_offsetOfNodeAfterPositionInAnchor[m_depthToAnchorNode]. | |
68 int m_offsetInAnchor; | 78 int m_offsetInAnchor; |
79 size_t m_depthToAnchorNode; | |
80 // If |m_nodeAfterPositionInAnchor| is not null, | |
81 // m_offsetsInAnchorNode[m_depthToAnchorNode] == | |
82 // Strategy::index(m_nodeAfterPositionInAnchor). | |
83 Vector<int> m_offsetsInAnchorNode; | |
84 uint64_t m_domTreeVersion; | |
69 }; | 85 }; |
70 | 86 |
71 extern template class PositionIteratorAlgorithm<EditingStrategy>; | 87 extern template class PositionIteratorAlgorithm<EditingStrategy>; |
72 extern template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; | 88 extern template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; |
73 | 89 |
74 using PositionIterator = PositionIteratorAlgorithm<EditingStrategy>; | 90 using PositionIterator = PositionIteratorAlgorithm<EditingStrategy>; |
75 using PositionIteratorInComposedTree = PositionIteratorAlgorithm<EditingInCompos edTreeStrategy>; | 91 using PositionIteratorInComposedTree = PositionIteratorAlgorithm<EditingInCompos edTreeStrategy>; |
76 | 92 |
77 } // namespace blink | 93 } // namespace blink |
78 | 94 |
79 #endif // PositionIterator_h | 95 #endif // PositionIterator_h |
OLD | NEW |