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

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:55 hayato's review: Add assertPostcondition, use traverseLastChild 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& node)
245 {
246 assertPrecondition(node);
247 Node* descendant = traverseLastChild(node);
248 for (Node* child = descendant; child; child = lastChild(*child))
249 descendant = child;
250 assertPostcondition(descendant);
251 return descendant;
252 }
253
254 Node& ComposedTreeTraversal::lastWithinOrSelf(const Node& node)
255 {
256 assertPrecondition(node);
257 Node* lastDescendant = lastWithin(node);
258 Node& result = lastDescendant ? *lastDescendant : const_cast<Node&>(node);
259 assertPostcondition(&result);
260 return result;
261 }
262
244 } // namespace 263 } // 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