Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: Source/core/dom/Position.h

Issue 1000533004: Move implementation of Range::firstNode and Range::pastLastNode to Position (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-03-13T16:48:34 Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/dom/Position.cpp » ('j') | Source/core/dom/Range.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void clear() { m_anchorNode.clear(); m_offset = 0; m_anchorType = PositionIs OffsetInAnchor; m_isLegacyEditingPosition = false; } 98 void clear() { m_anchorNode.clear(); m_offset = 0; m_anchorType = PositionIs OffsetInAnchor; m_isLegacyEditingPosition = false; }
99 99
100 // These are always DOM compliant values. Editing positions like [img, 0] ( aka [img, before]) 100 // These are always DOM compliant values. Editing positions like [img, 0] ( aka [img, before])
101 // will return img->parentNode() and img->nodeIndex() from these functions. 101 // will return img->parentNode() and img->nodeIndex() from these functions.
102 Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent 102 Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent
103 Text* containerText() const; 103 Text* containerText() const;
104 104
105 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions 105 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions
106 Position parentAnchoredEquivalent() const; // Convenience method for DOM pos itions that also fixes up some positions for editing 106 Position parentAnchoredEquivalent() const; // Convenience method for DOM pos itions that also fixes up some positions for editing
107 107
108 // Returns |PositionIsAnchor| type |Position| which is compatible with
109 // |RangeBoundaryPoint| as safe to pass |Range| constructor. Return value
110 // of this function is different from |parentAnchoredEquivalent()| which
111 // returns editing specific position.
112 Position toOffsetInAnchor() const;
113
108 // Inline O(1) access for Positions which callers know to be parent-anchored 114 // Inline O(1) access for Positions which callers know to be parent-anchored
109 int offsetInContainerNode() const 115 int offsetInContainerNode() const
110 { 116 {
111 ASSERT(anchorType() == PositionIsOffsetInAnchor); 117 ASSERT(anchorType() == PositionIsOffsetInAnchor);
112 return m_offset; 118 return m_offset;
113 } 119 }
114 120
115 // New code should not use this function. 121 // New code should not use this function.
116 int deprecatedEditingOffset() const 122 int deprecatedEditingOffset() const
117 { 123 {
118 if (m_isLegacyEditingPosition || (m_anchorType != PositionIsAfterAnchor && m_anchorType != PositionIsAfterChildren)) 124 if (m_isLegacyEditingPosition || (m_anchorType != PositionIsAfterAnchor && m_anchorType != PositionIsAfterChildren))
119 return m_offset; 125 return m_offset;
120 return offsetForPositionAfterAnchor(); 126 return offsetForPositionAfterAnchor();
121 } 127 }
122 128
123 // These are convenience methods which are smart about whether the position is neighbor anchored or parent anchored 129 // These are convenience methods which are smart about whether the position is neighbor anchored or parent anchored
124 Node* computeNodeBeforePosition() const; 130 Node* computeNodeBeforePosition() const;
125 Node* computeNodeAfterPosition() const; 131 Node* computeNodeAfterPosition() const;
126 132
133 // Returns node as |Range::firstNode()|. This position must be a
134 // |PositionIs::OffsetInAhcor| to behave as |Range| boundary point.
135 Node* nodeAsRangeFirstNode() const;
136
137 // Returns a node as past last as same as |Range::pastLastNode()|. This
138 // function is supposed to used in HTML serialization and plain text
139 // iterator. This position must be a |PositionIs::OffsetInAhcor| to
140 // behave as |Range| boundary point.
141 Node* nodeAsRangePastLastNode() const;
142
127 Node* anchorNode() const { return m_anchorNode.get(); } 143 Node* anchorNode() const { return m_anchorNode.get(); }
128 144
129 // FIXME: Callers should be moved off of node(), node() is not always the co ntainer for this position. 145 // FIXME: Callers should be moved off of node(), node() is not always the co ntainer for this position.
130 // For nodes which editingIgnoresContent(node()) returns true, positions lik e [ignoredNode, 0] 146 // For nodes which editingIgnoresContent(node()) returns true, positions lik e [ignoredNode, 0]
131 // will be treated as before ignoredNode (thus node() is really after the po sition, not containing it). 147 // will be treated as before ignoredNode (thus node() is really after the po sition, not containing it).
132 Node* deprecatedNode() const { return m_anchorNode.get(); } 148 Node* deprecatedNode() const { return m_anchorNode.get(); }
133 149
134 Document* document() const { return m_anchorNode ? &m_anchorNode->document() : 0; } 150 Document* document() const { return m_anchorNode ? &m_anchorNode->document() : 0; }
135 bool inDocument() const { return m_anchorNode && m_anchorNode->inDocument(); } 151 bool inDocument() const { return m_anchorNode && m_anchorNode->inDocument(); }
136 Element* rootEditableElement() const 152 Element* rootEditableElement() const
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 332
317 } // namespace blink 333 } // namespace blink
318 334
319 #ifndef NDEBUG 335 #ifndef NDEBUG
320 // Outside the WebCore namespace for ease of invocation from gdb. 336 // Outside the WebCore namespace for ease of invocation from gdb.
321 void showTree(const blink::Position&); 337 void showTree(const blink::Position&);
322 void showTree(const blink::Position*); 338 void showTree(const blink::Position*);
323 #endif 339 #endif
324 340
325 #endif // Position_h 341 #endif // Position_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/Position.cpp » ('j') | Source/core/dom/Range.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698