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

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

Issue 69003004: Have NodeTraversal::previous*() take a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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 | « Source/core/dom/NodeTraversal.h ('k') | Source/core/editing/ApplyStyleCommand.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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 12 matching lines...) Expand all
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/dom/NodeTraversal.h" 26 #include "core/dom/NodeTraversal.h"
27 27
28 #include "core/dom/ContainerNode.h" 28 #include "core/dom/ContainerNode.h"
29 29
30 namespace WebCore { 30 namespace WebCore {
31 namespace NodeTraversal { 31 namespace NodeTraversal {
32 32
33 Node* previousIncludingPseudo(const Node* current, const Node* stayWithin) 33 Node* previousIncludingPseudo(const Node& current, const Node* stayWithin)
34 { 34 {
35 if (current == stayWithin) 35 if (current == stayWithin)
36 return 0; 36 return 0;
37 if (Node* previous = current->pseudoAwarePreviousSibling()) { 37 if (Node* previous = current.pseudoAwarePreviousSibling()) {
38 while (previous->pseudoAwareLastChild()) 38 while (previous->pseudoAwareLastChild())
39 previous = previous->pseudoAwareLastChild(); 39 previous = previous->pseudoAwareLastChild();
40 return previous; 40 return previous;
41 } 41 }
42 return current->parentNode(); 42 return current.parentNode();
43 } 43 }
44 44
45 Node* nextIncludingPseudo(const Node* current, const Node* stayWithin) 45 Node* nextIncludingPseudo(const Node* current, const Node* stayWithin)
46 { 46 {
47 if (Node* next = current->pseudoAwareFirstChild()) 47 if (Node* next = current->pseudoAwareFirstChild())
48 return next; 48 return next;
49 if (current == stayWithin) 49 if (current == stayWithin)
50 return 0; 50 return 0;
51 if (Node* next = current->pseudoAwareNextSibling()) 51 if (Node* next = current->pseudoAwareNextSibling())
52 return next; 52 return next;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ASSERT(current != stayWithin); 90 ASSERT(current != stayWithin);
91 for (current = current->parentNode(); current; current = current->parentNode ()) { 91 for (current = current->parentNode(); current; current = current->parentNode ()) {
92 if (current == stayWithin) 92 if (current == stayWithin)
93 return 0; 93 return 0;
94 if (current->nextSibling()) 94 if (current->nextSibling())
95 return current->nextSibling(); 95 return current->nextSibling();
96 } 96 }
97 return 0; 97 return 0;
98 } 98 }
99 99
100 Node* previous(const Node* current, const Node* stayWithin) 100 Node* previous(const Node& current, const Node* stayWithin)
101 { 101 {
102 if (current == stayWithin) 102 if (current == stayWithin)
103 return 0; 103 return 0;
104 if (current->previousSibling()) { 104 if (current.previousSibling()) {
105 Node* previous = current->previousSibling(); 105 Node* previous = current.previousSibling();
106 while (previous->lastChild()) 106 while (previous->lastChild())
107 previous = previous->lastChild(); 107 previous = previous->lastChild();
108 return previous; 108 return previous;
109 } 109 }
110 return current->parentNode(); 110 return current.parentNode();
111 } 111 }
112 112
113 Node* previousSkippingChildren(const Node* current, const Node* stayWithin) 113 Node* previousSkippingChildren(const Node& current, const Node* stayWithin)
114 { 114 {
115 if (current == stayWithin) 115 if (current == stayWithin)
116 return 0; 116 return 0;
117 if (current->previousSibling()) 117 if (current.previousSibling())
118 return current->previousSibling(); 118 return current.previousSibling();
119 for (current = current->parentNode(); current; current = current->parentNode ()) { 119 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod e()) {
120 if (current == stayWithin) 120 if (parent == stayWithin)
121 return 0; 121 return 0;
122 if (current->previousSibling()) 122 if (parent->previousSibling())
123 return current->previousSibling(); 123 return parent->previousSibling();
124 } 124 }
125 return 0; 125 return 0;
126 } 126 }
127 127
128 Node* nextPostOrder(const Node* current, const Node* stayWithin) 128 Node* nextPostOrder(const Node* current, const Node* stayWithin)
129 { 129 {
130 if (current == stayWithin) 130 if (current == stayWithin)
131 return 0; 131 return 0;
132 if (!current->nextSibling()) 132 if (!current->nextSibling())
133 return current->parentNode(); 133 return current->parentNode();
134 Node* next = current->nextSibling(); 134 Node* next = current->nextSibling();
135 while (next->firstChild()) 135 while (next->firstChild())
136 next = next->firstChild(); 136 next = next->firstChild();
137 return next; 137 return next;
138 } 138 }
139 139
140 static Node* previousAncestorSiblingPostOrder(const Node* current, const Node* s tayWithin) 140 static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* s tayWithin)
141 { 141 {
142 ASSERT(!current->previousSibling()); 142 ASSERT(!current.previousSibling());
143 for (current = current->parentNode(); current; current = current->parentNode ()) { 143 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod e()) {
144 if (current == stayWithin) 144 if (parent == stayWithin)
145 return 0; 145 return 0;
146 if (current->previousSibling()) 146 if (parent->previousSibling())
147 return current->previousSibling(); 147 return parent->previousSibling();
148 } 148 }
149 return 0; 149 return 0;
150 } 150 }
151 151
152 Node* previousPostOrder(const Node* current, const Node* stayWithin) 152 Node* previousPostOrder(const Node& current, const Node* stayWithin)
153 { 153 {
154 if (current->lastChild()) 154 if (current.lastChild())
155 return current->lastChild(); 155 return current.lastChild();
156 if (current == stayWithin) 156 if (current == stayWithin)
157 return 0; 157 return 0;
158 if (current->previousSibling()) 158 if (current.previousSibling())
159 return current->previousSibling(); 159 return current.previousSibling();
160 return previousAncestorSiblingPostOrder(current, stayWithin); 160 return previousAncestorSiblingPostOrder(current, stayWithin);
161 } 161 }
162 162
163 Node* previousSkippingChildrenPostOrder(const Node* current, const Node* stayWit hin) 163 Node* previousSkippingChildrenPostOrder(const Node& current, const Node* stayWit hin)
164 { 164 {
165 if (current == stayWithin) 165 if (current == stayWithin)
166 return 0; 166 return 0;
167 if (current->previousSibling()) 167 if (current.previousSibling())
168 return current->previousSibling(); 168 return current.previousSibling();
169 return previousAncestorSiblingPostOrder(current, stayWithin); 169 return previousAncestorSiblingPostOrder(current, stayWithin);
170 } 170 }
171 171
172 } 172 }
173 } 173 }
OLDNEW
« no previous file with comments | « Source/core/dom/NodeTraversal.h ('k') | Source/core/editing/ApplyStyleCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698