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

Side by Side Diff: Source/core/dom/shadow/ComposedTreeTraversal.cpp

Issue 1030153002: Add ComposedTreeTraversal::lastWithin/lastWithinOrSelf (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 2015-03-26T12:42 hayato's review: Change the argument const and add assertions 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Neither the name of Google Inc. nor the names of its 10 * * Neither the name of Google Inc. nor the names of its
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 unsigned ComposedTreeTraversal::countChildren(const Node& node) 235 unsigned ComposedTreeTraversal::countChildren(const Node& node)
236 { 236 {
237 assertPrecondition(node); 237 assertPrecondition(node);
238 unsigned count = 0; 238 unsigned count = 0;
239 for (Node* runner = traverseFirstChild(node); runner; runner = traverseNextS ibling(*runner)) 239 for (Node* runner = traverseFirstChild(node); runner; runner = traverseNextS ibling(*runner))
240 ++count; 240 ++count;
241 return count; 241 return count;
242 } 242 }
243 243
244 Node* ComposedTreeTraversal::lastWithin(const Node& current)
245 {
246 assertPrecondition(current);
247 Node* descendant = lastChild(current);
hayato 2015/03/26 03:48:44 Could you use travrseLastChild instead of lastChil
hajimehoshi 2015/03/26 03:56:11 Done. Besides, renamed |current| to |node| for co
248 for (Node* child = descendant; child; child = lastChild(*child))
249 descendant = child;
250 return descendant;
251 }
252
253 Node& ComposedTreeTraversal::lastWithinOrSelf(const Node& current)
254 {
255 assertPrecondition(current);
256 Node* lastDescendant = ComposedTreeTraversal::lastWithin(current);
257 return lastDescendant ? *lastDescendant : const_cast<Node&>(current);
258 }
259
244 } // namespace 260 } // namespace
OLDNEW
« no previous file with comments | « Source/core/dom/shadow/ComposedTreeTraversal.h ('k') | Source/core/dom/shadow/ComposedTreeTraversalTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698