| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 { | 51 { |
| 52 } | 52 } |
| 53 | 53 |
| 54 void FrameTree::setName(const AtomicString& name, const AtomicString& fallbackNa
me) | 54 void FrameTree::setName(const AtomicString& name, const AtomicString& fallbackNa
me) |
| 55 { | 55 { |
| 56 m_name = name; | 56 m_name = name; |
| 57 if (!parent()) { | 57 if (!parent()) { |
| 58 m_uniqueName = name; | 58 m_uniqueName = name; |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 m_uniqueName = AtomicString(); // Remove our old frame name so it's not cons
idered in uniqueChildName. | 61 |
| 62 m_uniqueName = parent()->tree().uniqueChildName(name.isEmpty() ? fallbackNam
e : name); | 62 // Remove our old frame name so it's not considered in calculateUniqueNameFo
rChildFrame. |
| 63 m_uniqueName = AtomicString(); |
| 64 |
| 65 m_uniqueName = parent()->tree().calculateUniqueNameForChildFrame(true, name,
fallbackName); |
| 63 } | 66 } |
| 64 | 67 |
| 65 void FrameTree::setNameForReplacementFrame(const AtomicString& name, const Atomi
cString& uniqueName) | 68 void FrameTree::setPrecalculatedName(const AtomicString& name, const AtomicStrin
g& uniqueName) |
| 66 { | 69 { |
| 70 if (!parent()) { |
| 71 ASSERT(uniqueName == name); |
| 72 } else { |
| 73 ASSERT(!uniqueName.isEmpty()); |
| 74 } |
| 75 |
| 67 m_name = name; | 76 m_name = name; |
| 68 m_uniqueName = uniqueName; | 77 m_uniqueName = uniqueName; |
| 69 } | 78 } |
| 70 | 79 |
| 71 Frame* FrameTree::parent() const | 80 Frame* FrameTree::parent() const |
| 72 { | 81 { |
| 73 if (!m_thisFrame->client()) | 82 if (!m_thisFrame->client()) |
| 74 return nullptr; | 83 return nullptr; |
| 75 return m_thisFrame->client()->parent(); | 84 return m_thisFrame->client()->parent(); |
| 76 } | 85 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 125 |
| 117 bool FrameTree::uniqueNameExists(const AtomicString& name) const | 126 bool FrameTree::uniqueNameExists(const AtomicString& name) const |
| 118 { | 127 { |
| 119 for (Frame* frame = top(); frame; frame = frame->tree().traverseNext()) { | 128 for (Frame* frame = top(); frame; frame = frame->tree().traverseNext()) { |
| 120 if (frame->tree().uniqueName() == name) | 129 if (frame->tree().uniqueName() == name) |
| 121 return true; | 130 return true; |
| 122 } | 131 } |
| 123 return false; | 132 return false; |
| 124 } | 133 } |
| 125 | 134 |
| 126 AtomicString FrameTree::uniqueChildName(const AtomicString& requestedName) const | 135 AtomicString FrameTree::calculateUniqueNameForNewChildFrame( |
| 136 const AtomicString& name, |
| 137 const AtomicString& fallbackName) const |
| 127 { | 138 { |
| 139 return calculateUniqueNameForChildFrame(false, name, fallbackName); |
| 140 } |
| 141 |
| 142 AtomicString FrameTree::calculateUniqueNameForChildFrame( |
| 143 bool existingChildFrame, |
| 144 const AtomicString& name, |
| 145 const AtomicString& fallbackName) const |
| 146 { |
| 147 const AtomicString& requestedName = name.isEmpty() ? fallbackName : name; |
| 128 if (!requestedName.isEmpty() && !uniqueNameExists(requestedName) && requeste
dName != "_blank") | 148 if (!requestedName.isEmpty() && !uniqueNameExists(requestedName) && requeste
dName != "_blank") |
| 129 return requestedName; | 149 return requestedName; |
| 130 | 150 |
| 131 // Create a repeatable name for a child about to be added to us. The name mu
st be | 151 // Create a repeatable name for a child about to be added to us. The name mu
st be |
| 132 // unique within the frame tree. The string we generate includes a "path" of
names | 152 // unique within the frame tree. The string we generate includes a "path" of
names |
| 133 // from the root frame down to us. For this path to be unique, each set of s
iblings must | 153 // from the root frame down to us. For this path to be unique, each set of s
iblings must |
| 134 // contribute a unique name to the path, which can't collide with any HTML-a
ssigned names. | 154 // contribute a unique name to the path, which can't collide with any HTML-a
ssigned names. |
| 135 // We generate this path component by index in the child list along with an
unlikely | 155 // We generate this path component by index in the child list along with an
unlikely |
| 136 // frame name that can't be set in HTML because it collides with comment syn
tax. | 156 // frame name that can't be set in HTML because it collides with comment syn
tax. |
| 137 | 157 |
| 138 const char framePathPrefix[] = "<!--framePath "; | 158 const char framePathPrefix[] = "<!--framePath "; |
| 139 const int framePathPrefixLength = 14; | 159 const int framePathPrefixLength = 14; |
| 140 const int framePathSuffixLength = 3; | 160 const int framePathSuffixLength = 3; |
| 141 | 161 |
| 142 // Find the nearest parent that has a frame with a path in it. | 162 // Find the nearest parent that has a frame with a path in it. |
| 143 WillBeHeapVector<RawPtrWillBeMember<Frame>, 16> chain; | 163 WillBeHeapVector<RawPtrWillBeMember<Frame>, 16> chain; |
| 144 Frame* frame; | 164 Frame* frame; |
| 145 for (frame = m_thisFrame; frame; frame = frame->tree().parent()) { | 165 for (frame = m_thisFrame; frame; frame = frame->tree().parent()) { |
| 146 if (frame->tree().uniqueName().startsWith(framePathPrefix)) | 166 if (frame->tree().uniqueName().startsWith(framePathPrefix)) |
| 147 break; | 167 break; |
| 148 chain.append(frame); | 168 chain.append(frame); |
| 149 } | 169 } |
| 150 StringBuilder name; | 170 StringBuilder uniqueName; |
| 151 name.append(framePathPrefix); | 171 uniqueName.append(framePathPrefix); |
| 152 if (frame) { | 172 if (frame) { |
| 153 name.append(frame->tree().uniqueName().string().substring(framePathPrefi
xLength, | 173 uniqueName.append(frame->tree().uniqueName().string().substring(framePat
hPrefixLength, |
| 154 frame->tree().uniqueName().length() - framePathPrefixLength - frameP
athSuffixLength)); | 174 frame->tree().uniqueName().length() - framePathPrefixLength - frameP
athSuffixLength)); |
| 155 } | 175 } |
| 156 for (int i = chain.size() - 1; i >= 0; --i) { | 176 for (int i = chain.size() - 1; i >= 0; --i) { |
| 157 frame = chain[i]; | 177 frame = chain[i]; |
| 158 name.append('/'); | 178 uniqueName.append('/'); |
| 159 name.append(frame->tree().uniqueName()); | 179 uniqueName.append(frame->tree().uniqueName()); |
| 160 } | 180 } |
| 161 | 181 |
| 162 name.appendLiteral("/<!--frame"); | 182 uniqueName.appendLiteral("/<!--frame"); |
| 163 name.appendNumber(childCount() - 1); | 183 uniqueName.appendNumber(childCount() - (existingChildFrame ? 1 : 0)); |
| 164 name.appendLiteral("-->-->"); | 184 uniqueName.appendLiteral("-->-->"); |
| 165 | 185 |
| 166 return name.toAtomicString(); | 186 return uniqueName.toAtomicString(); |
| 167 } | 187 } |
| 168 | 188 |
| 169 Frame* FrameTree::scopedChild(unsigned index) const | 189 Frame* FrameTree::scopedChild(unsigned index) const |
| 170 { | 190 { |
| 171 unsigned scopedIndex = 0; | 191 unsigned scopedIndex = 0; |
| 172 for (Frame* child = firstChild(); child; child = child->tree().nextSibling()
) { | 192 for (Frame* child = firstChild(); child; child = child->tree().nextSibling()
) { |
| 173 if (child->client()->inShadowTree()) | 193 if (child->client()->inShadowTree()) |
| 174 continue; | 194 continue; |
| 175 if (scopedIndex == index) | 195 if (scopedIndex == index) |
| 176 return child; | 196 return child; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 { | 422 { |
| 403 if (!frame) { | 423 if (!frame) { |
| 404 printf("Null input frame\n"); | 424 printf("Null input frame\n"); |
| 405 return; | 425 return; |
| 406 } | 426 } |
| 407 | 427 |
| 408 printFrames(frame->tree().top(), frame, 0); | 428 printFrames(frame->tree().top(), frame, 0); |
| 409 } | 429 } |
| 410 | 430 |
| 411 #endif | 431 #endif |
| OLD | NEW |