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

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

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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2009 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if (!m_anchorNode->offsetInCharacters() 224 if (!m_anchorNode->offsetInCharacters()
225 && (m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsA fterChildren || static_cast<unsigned>(m_offset) == m_anchorNode->countChildren() ) 225 && (m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsA fterChildren || static_cast<unsigned>(m_offset) == m_anchorNode->countChildren() )
226 && (editingIgnoresContent(m_anchorNode.get()) || isRenderedHTMLTableElem ent(m_anchorNode.get())) 226 && (editingIgnoresContent(m_anchorNode.get()) || isRenderedHTMLTableElem ent(m_anchorNode.get()))
227 && containerNode()) { 227 && containerNode()) {
228 return positionInParentAfterNode(*m_anchorNode); 228 return positionInParentAfterNode(*m_anchorNode);
229 } 229 }
230 230
231 return Position(containerNode(), computeOffsetInContainerNode(), PositionIsO ffsetInAnchor); 231 return Position(containerNode(), computeOffsetInContainerNode(), PositionIsO ffsetInAnchor);
232 } 232 }
233 233
234 Position Position::toOffsetInAnchor() const
235 {
236 if (isNull())
237 return Position();
238
239 return Position(containerNode(), computeOffsetInContainerNode(), Position::P ositionIsOffsetInAnchor);
240 }
241
234 Node* Position::computeNodeBeforePosition() const 242 Node* Position::computeNodeBeforePosition() const
235 { 243 {
236 if (!m_anchorNode) 244 if (!m_anchorNode)
237 return 0; 245 return 0;
238 switch (anchorType()) { 246 switch (anchorType()) {
239 case PositionIsBeforeChildren: 247 case PositionIsBeforeChildren:
240 return 0; 248 return 0;
241 case PositionIsAfterChildren: 249 case PositionIsAfterChildren:
242 return m_anchorNode->lastChild(); 250 return m_anchorNode->lastChild();
243 case PositionIsOffsetInAnchor: 251 case PositionIsOffsetInAnchor:
(...skipping 21 matching lines...) Expand all
265 return NodeTraversal::childAt(*m_anchorNode, m_offset); 273 return NodeTraversal::childAt(*m_anchorNode, m_offset);
266 case PositionIsBeforeAnchor: 274 case PositionIsBeforeAnchor:
267 return m_anchorNode.get(); 275 return m_anchorNode.get();
268 case PositionIsAfterAnchor: 276 case PositionIsAfterAnchor:
269 return m_anchorNode->nextSibling(); 277 return m_anchorNode->nextSibling();
270 } 278 }
271 ASSERT_NOT_REACHED(); 279 ASSERT_NOT_REACHED();
272 return 0; 280 return 0;
273 } 281 }
274 282
283 // An implementation of |Range::firstNode()|.
284 Node* Position::nodeAsRangeFirstNode() const
285 {
286 ASSERT(m_anchorType == PositionIsOffsetInAnchor);
287 if (!m_anchorNode)
288 return nullptr;
289 if (m_anchorNode->offsetInCharacters())
290 return m_anchorNode.get();
291 if (Node* child = NodeTraversal::childAt(*m_anchorNode, m_offset))
292 return child;
293 if (!m_offset)
294 return m_anchorNode.get();
295 return NodeTraversal::nextSkippingChildren(*m_anchorNode);
296 }
297
298 // An implementation of |Range::pastLastNode()|.
299 Node* Position::nodeAsRangePastLastNode() const
300 {
301 ASSERT(m_anchorType == PositionIsOffsetInAnchor);
302 if (!m_anchorNode)
303 return nullptr;
304 if (m_anchorNode->offsetInCharacters())
305 return NodeTraversal::nextSkippingChildren(*m_anchorNode);
306 if (Node* child = NodeTraversal::childAt(*m_anchorNode, m_offset))
307 return child;
308 return NodeTraversal::nextSkippingChildren(*m_anchorNode);
309 }
310
275 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo de, int offset) 311 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo de, int offset)
276 { 312 {
277 if (anchorNode && editingIgnoresContent(anchorNode)) { 313 if (anchorNode && editingIgnoresContent(anchorNode)) {
278 if (offset == 0) 314 if (offset == 0)
279 return Position::PositionIsBeforeAnchor; 315 return Position::PositionIsBeforeAnchor;
280 return Position::PositionIsAfterAnchor; 316 return Position::PositionIsAfterAnchor;
281 } 317 }
282 return Position::PositionIsOffsetInAnchor; 318 return Position::PositionIsOffsetInAnchor;
283 } 319 }
284 320
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 pos.showTreeForThis(); 1349 pos.showTreeForThis();
1314 } 1350 }
1315 1351
1316 void showTree(const blink::Position* pos) 1352 void showTree(const blink::Position* pos)
1317 { 1353 {
1318 if (pos) 1354 if (pos)
1319 pos->showTreeForThis(); 1355 pos->showTreeForThis();
1320 } 1356 }
1321 1357
1322 #endif 1358 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Position.h ('k') | Source/core/dom/Range.cpp » ('j') | Source/core/dom/Range.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698