OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
3 * Copyright (C) 2006 Apple Computer, Inc. | 3 * Copyright (C) 2006 Apple Computer, Inc. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 LocalFrame* FrameTree::lastChild() const | 111 LocalFrame* FrameTree::lastChild() const |
112 { | 112 { |
113 if (!m_thisFrame->loader().client()) | 113 if (!m_thisFrame->loader().client()) |
114 return 0; | 114 return 0; |
115 // FIXME: Temporary hack to stage converting locations that really should be
Frame. | 115 // FIXME: Temporary hack to stage converting locations that really should be
Frame. |
116 return toLocalFrame(m_thisFrame->loader().client()->lastChild()); | 116 return toLocalFrame(m_thisFrame->loader().client()->lastChild()); |
117 } | 117 } |
118 | 118 |
| 119 bool FrameTree::uniqueNameExists(const AtomicString& name) const |
| 120 { |
| 121 for (LocalFrame* frame = top(); frame; frame = frame->tree().traverseNext())
{ |
| 122 if (frame->tree().uniqueName() == name) |
| 123 return true; |
| 124 } |
| 125 return false; |
| 126 } |
| 127 |
119 AtomicString FrameTree::uniqueChildName(const AtomicString& requestedName) const | 128 AtomicString FrameTree::uniqueChildName(const AtomicString& requestedName) const |
120 { | 129 { |
121 if (!requestedName.isEmpty() && !child(requestedName) && requestedName != "_
blank") | 130 if (!requestedName.isEmpty() && !uniqueNameExists(requestedName) && requeste
dName != "_blank") |
122 return requestedName; | 131 return requestedName; |
123 | 132 |
124 // Create a repeatable name for a child about to be added to us. The name mu
st be | 133 // Create a repeatable name for a child about to be added to us. The name mu
st be |
125 // unique within the frame tree. The string we generate includes a "path" of
names | 134 // unique within the frame tree. The string we generate includes a "path" of
names |
126 // from the root frame down to us. For this path to be unique, each set of s
iblings must | 135 // from the root frame down to us. For this path to be unique, each set of s
iblings must |
127 // contribute a unique name to the path, which can't collide with any HTML-a
ssigned names. | 136 // contribute a unique name to the path, which can't collide with any HTML-a
ssigned names. |
128 // We generate this path component by index in the child list along with an
unlikely | 137 // We generate this path component by index in the child list along with an
unlikely |
129 // frame name that can't be set in HTML because it collides with comment syn
tax. | 138 // frame name that can't be set in HTML because it collides with comment syn
tax. |
130 | 139 |
131 const char framePathPrefix[] = "<!--framePath "; | 140 const char framePathPrefix[] = "<!--framePath "; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return 0; | 186 return 0; |
178 } | 187 } |
179 | 188 |
180 LocalFrame* FrameTree::scopedChild(const AtomicString& name) const | 189 LocalFrame* FrameTree::scopedChild(const AtomicString& name) const |
181 { | 190 { |
182 TreeScope* scope = m_thisFrame->document(); | 191 TreeScope* scope = m_thisFrame->document(); |
183 if (!scope) | 192 if (!scope) |
184 return 0; | 193 return 0; |
185 | 194 |
186 for (LocalFrame* child = firstChild(); child; child = child->tree().nextSibl
ing()) | 195 for (LocalFrame* child = firstChild(); child; child = child->tree().nextSibl
ing()) |
187 if (child->tree().uniqueName() == name && child->inScope(scope)) | 196 if (child->tree().name() == name && child->inScope(scope)) |
188 return child; | 197 return child; |
189 return 0; | 198 return 0; |
190 } | 199 } |
191 | 200 |
192 inline unsigned FrameTree::scopedChildCount(TreeScope* scope) const | 201 inline unsigned FrameTree::scopedChildCount(TreeScope* scope) const |
193 { | 202 { |
194 if (!scope) | 203 if (!scope) |
195 return 0; | 204 return 0; |
196 | 205 |
197 unsigned scopedCount = 0; | 206 unsigned scopedCount = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
219 { | 228 { |
220 unsigned count = 0; | 229 unsigned count = 0; |
221 for (LocalFrame* result = firstChild(); result; result = result->tree().next
Sibling()) | 230 for (LocalFrame* result = firstChild(); result; result = result->tree().next
Sibling()) |
222 ++count; | 231 ++count; |
223 return count; | 232 return count; |
224 } | 233 } |
225 | 234 |
226 LocalFrame* FrameTree::child(const AtomicString& name) const | 235 LocalFrame* FrameTree::child(const AtomicString& name) const |
227 { | 236 { |
228 for (LocalFrame* child = firstChild(); child; child = child->tree().nextSibl
ing()) | 237 for (LocalFrame* child = firstChild(); child; child = child->tree().nextSibl
ing()) |
229 if (child->tree().uniqueName() == name) | 238 if (child->tree().name() == name) |
230 return child; | 239 return child; |
231 return 0; | 240 return 0; |
232 } | 241 } |
233 | 242 |
234 LocalFrame* FrameTree::find(const AtomicString& name) const | 243 LocalFrame* FrameTree::find(const AtomicString& name) const |
235 { | 244 { |
236 if (name == "_self" || name == "_current" || name.isEmpty()) | 245 if (name == "_self" || name == "_current" || name.isEmpty()) |
237 return m_thisFrame; | 246 return m_thisFrame; |
238 | 247 |
239 if (name == "_top") | 248 if (name == "_top") |
240 return top(); | 249 return top(); |
241 | 250 |
242 if (name == "_parent") | 251 if (name == "_parent") |
243 return parent() ? parent() : m_thisFrame; | 252 return parent() ? parent() : m_thisFrame; |
244 | 253 |
245 // Since "_blank" should never be any frame's name, the following just amoun
ts to an optimization. | 254 // Since "_blank" should never be any frame's name, the following just amoun
ts to an optimization. |
246 if (name == "_blank") | 255 if (name == "_blank") |
247 return 0; | 256 return 0; |
248 | 257 |
249 // Search subtree starting with this frame first. | 258 // Search subtree starting with this frame first. |
250 for (LocalFrame* frame = m_thisFrame; frame; frame = frame->tree().traverseN
ext(m_thisFrame)) | 259 for (LocalFrame* frame = m_thisFrame; frame; frame = frame->tree().traverseN
ext(m_thisFrame)) |
251 if (frame->tree().uniqueName() == name) | 260 if (frame->tree().name() == name) |
252 return frame; | 261 return frame; |
253 | 262 |
254 // Search the entire tree for this page next. | 263 // Search the entire tree for this page next. |
255 Page* page = m_thisFrame->page(); | 264 Page* page = m_thisFrame->page(); |
256 | 265 |
257 // The frame could have been detached from the page, so check it. | 266 // The frame could have been detached from the page, so check it. |
258 if (!page) | 267 if (!page) |
259 return 0; | 268 return 0; |
260 | 269 |
261 for (LocalFrame* frame = page->mainFrame(); frame; frame = frame->tree().tra
verseNext()) | 270 for (LocalFrame* frame = page->mainFrame(); frame; frame = frame->tree().tra
verseNext()) |
262 if (frame->tree().uniqueName() == name) | 271 if (frame->tree().name() == name) |
263 return frame; | 272 return frame; |
264 | 273 |
265 // Search the entire tree of each of the other pages in this namespace. | 274 // Search the entire tree of each of the other pages in this namespace. |
266 // FIXME: Is random order OK? | 275 // FIXME: Is random order OK? |
267 const HashSet<Page*>& pages = Page::ordinaryPages(); | 276 const HashSet<Page*>& pages = Page::ordinaryPages(); |
268 HashSet<Page*>::const_iterator end = pages.end(); | 277 HashSet<Page*>::const_iterator end = pages.end(); |
269 for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) { | 278 for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) { |
270 Page* otherPage = *it; | 279 Page* otherPage = *it; |
271 if (otherPage != page) { | 280 if (otherPage != page) { |
272 for (LocalFrame* frame = otherPage->mainFrame(); frame; frame = fram
e->tree().traverseNext()) { | 281 for (LocalFrame* frame = otherPage->mainFrame(); frame; frame = fram
e->tree().traverseNext()) { |
273 if (frame->tree().uniqueName() == name) | 282 if (frame->tree().name() == name) |
274 return frame; | 283 return frame; |
275 } | 284 } |
276 } | 285 } |
277 } | 286 } |
278 | 287 |
279 return 0; | 288 return 0; |
280 } | 289 } |
281 | 290 |
282 bool FrameTree::isDescendantOf(const LocalFrame* ancestor) const | 291 bool FrameTree::isDescendantOf(const LocalFrame* ancestor) const |
283 { | 292 { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 { | 409 { |
401 if (!frame) { | 410 if (!frame) { |
402 printf("Null input frame\n"); | 411 printf("Null input frame\n"); |
403 return; | 412 return; |
404 } | 413 } |
405 | 414 |
406 printFrames(frame->tree().top(), frame, 0); | 415 printFrames(frame->tree().top(), frame, 0); |
407 } | 416 } |
408 | 417 |
409 #endif | 418 #endif |
OLD | NEW |