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

Side by Side Diff: third_party/WebKit/Source/core/editing/Position.h

Issue 1994043002: Get rid of a redundant function alias lastPositionInNode() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-05-19T14:50:30 Created 4 years, 7 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 | third_party/WebKit/Source/core/editing/SurroundingText.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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 { 277 {
278 return Position::afterNode(anchorNode); 278 return Position::afterNode(anchorNode);
279 } 279 }
280 280
281 template <typename Strategy> 281 template <typename Strategy>
282 int PositionTemplate<Strategy>::lastOffsetInNode(Node* node) 282 int PositionTemplate<Strategy>::lastOffsetInNode(Node* node)
283 { 283 {
284 return node->offsetInCharacters() ? node->maxCharacterOffset() : static_cast <int>(Strategy::countChildren(*node)); 284 return node->offsetInCharacters() ? node->maxCharacterOffset() : static_cast <int>(Strategy::countChildren(*node));
285 } 285 }
286 286
287 // firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to countChildren()
288 template <typename Strategy> 287 template <typename Strategy>
289 PositionTemplate<Strategy> PositionTemplate<Strategy>::firstPositionInNode(Node* anchorNode) 288 PositionTemplate<Strategy> PositionTemplate<Strategy>::firstPositionInNode(Node* anchorNode)
290 { 289 {
291 if (anchorNode->isTextNode()) 290 if (anchorNode->isTextNode())
292 return PositionTemplate<Strategy>(anchorNode, 0); 291 return PositionTemplate<Strategy>(anchorNode, 0);
293 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::BeforeChil dren); 292 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::BeforeChil dren);
294 } 293 }
295 294
296 template <typename Strategy> 295 template <typename Strategy>
297 PositionTemplate<Strategy> PositionTemplate<Strategy>::lastPositionInNode(Node* anchorNode) 296 PositionTemplate<Strategy> PositionTemplate<Strategy>::lastPositionInNode(Node* anchorNode)
298 { 297 {
299 if (anchorNode->isTextNode()) 298 if (anchorNode->isTextNode())
300 return PositionTemplate<Strategy>(anchorNode, lastOffsetInNode(anchorNod e)); 299 return PositionTemplate<Strategy>(anchorNode, lastOffsetInNode(anchorNod e));
301 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterChild ren); 300 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterChild ren);
302 } 301 }
303 302
304 inline Position lastPositionInNode(Node* anchorNode)
305 {
306 return Position::lastPositionInNode(anchorNode);
307 }
308
309 template <typename Strategy> 303 template <typename Strategy>
310 int PositionTemplate<Strategy>::minOffsetForNode(Node* anchorNode, int offset) 304 int PositionTemplate<Strategy>::minOffsetForNode(Node* anchorNode, int offset)
311 { 305 {
312 if (anchorNode->offsetInCharacters()) 306 if (anchorNode->offsetInCharacters())
313 return std::min(offset, anchorNode->maxCharacterOffset()); 307 return std::min(offset, anchorNode->maxCharacterOffset());
314 308
315 int newOffset = 0; 309 int newOffset = 0;
316 for (Node* node = Strategy::firstChild(*anchorNode); node && newOffset < off set; node = Strategy::nextSibling(*node)) 310 for (Node* node = Strategy::firstChild(*anchorNode); node && newOffset < off set; node = Strategy::nextSibling(*node))
317 newOffset++; 311 newOffset++;
318 312
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 354
361 } // namespace blink 355 } // namespace blink
362 356
363 #ifndef NDEBUG 357 #ifndef NDEBUG
364 // Outside the WebCore namespace for ease of invocation from gdb. 358 // Outside the WebCore namespace for ease of invocation from gdb.
365 void showTree(const blink::Position&); 359 void showTree(const blink::Position&);
366 void showTree(const blink::Position*); 360 void showTree(const blink::Position*);
367 #endif 361 #endif
368 362
369 #endif // Position_h 363 #endif // Position_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/SurroundingText.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698