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

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

Issue 188033005: Have Position deal with more references (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/dom/Position.cpp » ('j') | no next file with comments »
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); } 145 bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); }
146 146
147 Element* element() const; 147 Element* element() const;
148 PassRefPtr<CSSComputedStyleDeclaration> computedStyle() const; 148 PassRefPtr<CSSComputedStyleDeclaration> computedStyle() const;
149 149
150 // Move up or down the DOM by one position. 150 // Move up or down the DOM by one position.
151 // Offsets are computed using render text for nodes that have renderers - bu t note that even when 151 // Offsets are computed using render text for nodes that have renderers - bu t note that even when
152 // using composed characters, the result may be inside a single user-visible character if a ligature is formed. 152 // using composed characters, the result may be inside a single user-visible character if a ligature is formed.
153 Position previous(PositionMoveType = CodePoint) const; 153 Position previous(PositionMoveType = CodePoint) const;
154 Position next(PositionMoveType = CodePoint) const; 154 Position next(PositionMoveType = CodePoint) const;
155 static int uncheckedPreviousOffset(const Node*, int current); 155 static int uncheckedPreviousOffset(const Node&, int current);
156 static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, int curre nt); 156 static int uncheckedPreviousOffsetForBackwardDeletion(const Node&, int curre nt);
157 static int uncheckedNextOffset(const Node*, int current); 157 static int uncheckedNextOffset(const Node&, int current);
158 158
159 // These can be either inside or just before/after the node, depending on 159 // These can be either inside or just before/after the node, depending on
160 // if the node is ignored by editing or not. 160 // if the node is ignored by editing or not.
161 // FIXME: These should go away. They only make sense for legacy positions. 161 // FIXME: These should go away. They only make sense for legacy positions.
162 bool atFirstEditingPositionForNode() const; 162 bool atFirstEditingPositionForNode() const;
163 bool atLastEditingPositionForNode() const; 163 bool atLastEditingPositionForNode() const;
164 164
165 // Returns true if the visually equivalent positions around have different e ditability 165 // Returns true if the visually equivalent positions around have different e ditability
166 bool atEditingBoundary() const; 166 bool atEditingBoundary() const;
167 Node* parentEditingBoundary() const; 167 Node* parentEditingBoundary() const;
(...skipping 18 matching lines...) Expand all
186 void getInlineBoxAndOffset(EAffinity, InlineBox*&, int& caretOffset) const; 186 void getInlineBoxAndOffset(EAffinity, InlineBox*&, int& caretOffset) const;
187 void getInlineBoxAndOffset(EAffinity, TextDirection primaryDirection, Inline Box*&, int& caretOffset) const; 187 void getInlineBoxAndOffset(EAffinity, TextDirection primaryDirection, Inline Box*&, int& caretOffset) const;
188 188
189 TextDirection primaryDirection() const; 189 TextDirection primaryDirection() const;
190 190
191 static bool hasRenderedNonAnonymousDescendantsWithHeight(RenderObject*); 191 static bool hasRenderedNonAnonymousDescendantsWithHeight(RenderObject*);
192 static bool nodeIsUserSelectNone(Node*); 192 static bool nodeIsUserSelectNone(Node*);
193 static bool nodeIsUserSelectAll(const Node*); 193 static bool nodeIsUserSelectAll(const Node*);
194 static Node* rootUserSelectAllForNode(Node*); 194 static Node* rootUserSelectAllForNode(Node*);
195 195
196 static ContainerNode* findParent(const Node*);
197
198 void debugPosition(const char* msg = "") const; 196 void debugPosition(const char* msg = "") const;
199 197
200 #ifndef NDEBUG 198 #ifndef NDEBUG
201 void formatForDebugger(char* buffer, unsigned length) const; 199 void formatForDebugger(char* buffer, unsigned length) const;
202 void showAnchorTypeAndOffset() const; 200 void showAnchorTypeAndOffset() const;
203 void showTreeForThis() const; 201 void showTreeForThis() const;
204 #endif 202 #endif
205 203
206 private: 204 private:
207 int offsetForPositionAfterAnchor() const; 205 int offsetForPositionAfterAnchor() const;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 return Position(node.parentNode(), node.nodeIndex(), Position::PositionIsOff setInAnchor); 251 return Position(node.parentNode(), node.nodeIndex(), Position::PositionIsOff setInAnchor);
254 } 252 }
255 253
256 inline Position positionInParentAfterNode(const Node& node) 254 inline Position positionInParentAfterNode(const Node& node)
257 { 255 {
258 ASSERT(node.parentNode()); 256 ASSERT(node.parentNode());
259 return Position(node.parentNode(), node.nodeIndex() + 1, Position::PositionI sOffsetInAnchor); 257 return Position(node.parentNode(), node.nodeIndex() + 1, Position::PositionI sOffsetInAnchor);
260 } 258 }
261 259
262 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1) 260 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1)
263 inline Position positionBeforeNode(Node* anchorNode) 261 inline Position positionBeforeNode(Node& anchorNode)
264 { 262 {
265 ASSERT(anchorNode); 263 return Position(PassRefPtr<Node>(anchorNode), Position::PositionIsBeforeAnch or);
266 return Position(anchorNode, Position::PositionIsBeforeAnchor);
267 } 264 }
268 265
269 inline Position positionAfterNode(Node* anchorNode) 266 inline Position positionAfterNode(Node& anchorNode)
270 { 267 {
271 ASSERT(anchorNode); 268 return Position(PassRefPtr<Node>(anchorNode), Position::PositionIsAfterAncho r);
272 return Position(anchorNode, Position::PositionIsAfterAnchor);
273 } 269 }
274 270
275 inline int lastOffsetInNode(Node* node) 271 inline int lastOffsetInNode(Node& node)
276 { 272 {
277 return node->offsetInCharacters() ? node->maxCharacterOffset() : static_cast <int>(node->countChildren()); 273 return node.offsetInCharacters() ? node.maxCharacterOffset() : static_cast<i nt>(node.countChildren());
278 } 274 }
279 275
280 // firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to countChildren() 276 // firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to countChildren()
281 inline Position firstPositionInNode(Node* anchorNode) 277 inline Position firstPositionInNode(Node* anchorNode)
282 { 278 {
283 if (anchorNode->isTextNode()) 279 if (anchorNode->isTextNode())
284 return Position(anchorNode, 0, Position::PositionIsOffsetInAnchor); 280 return Position(anchorNode, 0, Position::PositionIsOffsetInAnchor);
285 return Position(anchorNode, Position::PositionIsBeforeChildren); 281 return Position(anchorNode, Position::PositionIsBeforeChildren);
286 } 282 }
287 283
288 inline Position lastPositionInNode(Node* anchorNode) 284 inline Position lastPositionInNode(Node* anchorNode)
289 { 285 {
290 if (anchorNode->isTextNode()) 286 if (anchorNode->isTextNode())
291 return Position(anchorNode, lastOffsetInNode(anchorNode), Position::Posi tionIsOffsetInAnchor); 287 return Position(anchorNode, lastOffsetInNode(*anchorNode), Position::Pos itionIsOffsetInAnchor);
292 return Position(anchorNode, Position::PositionIsAfterChildren); 288 return Position(anchorNode, Position::PositionIsAfterChildren);
293 } 289 }
294 290
295 inline int minOffsetForNode(Node* anchorNode, int offset) 291 inline int minOffsetForNode(Node* anchorNode, int offset)
296 { 292 {
297 if (anchorNode->offsetInCharacters()) 293 if (anchorNode->offsetInCharacters())
298 return std::min(offset, anchorNode->maxCharacterOffset()); 294 return std::min(offset, anchorNode->maxCharacterOffset());
299 295
300 int newOffset = 0; 296 int newOffset = 0;
301 for (Node* node = anchorNode->firstChild(); node && newOffset < offset; node = node->nextSibling()) 297 for (Node* node = anchorNode->firstChild(); node && newOffset < offset; node = node->nextSibling())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 336
341 } // namespace WebCore 337 } // namespace WebCore
342 338
343 #ifndef NDEBUG 339 #ifndef NDEBUG
344 // Outside the WebCore namespace for ease of invocation from gdb. 340 // Outside the WebCore namespace for ease of invocation from gdb.
345 void showTree(const WebCore::Position&); 341 void showTree(const WebCore::Position&);
346 void showTree(const WebCore::Position*); 342 void showTree(const WebCore::Position*);
347 #endif 343 #endif
348 344
349 #endif // Position_h 345 #endif // Position_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/Position.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698