| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "public/web/WebFrame.h" | 6 #include "public/web/WebFrame.h" |
| 7 | 7 |
| 8 #include "core/frame/RemoteFrame.h" | 8 #include "core/frame/RemoteFrame.h" |
| 9 #include "web/OpenedFrameTracker.h" | 9 #include "web/OpenedFrameTracker.h" |
| 10 #include "web/WebLocalFrameImpl.h" | 10 #include "web/WebLocalFrameImpl.h" |
| 11 #include "web/WebRemoteFrameImpl.h" | 11 #include "web/WebRemoteFrameImpl.h" |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 | 13 |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 WebCore::Frame* toWebCoreFrame(WebFrame* frame) | 17 WebCore::Frame* toWebCoreFrame(const WebFrame* frame) |
| 18 { | 18 { |
| 19 if (!frame) | 19 if (!frame) |
| 20 return 0; | 20 return 0; |
| 21 | 21 |
| 22 return frame->isWebLocalFrame() | 22 return frame->isWebLocalFrame() |
| 23 ? static_cast<WebCore::Frame*>(toWebLocalFrameImpl(frame)->frame()) | 23 ? static_cast<WebCore::Frame*>(toWebLocalFrameImpl(frame)->frame()) |
| 24 : toWebRemoteFrameImpl(frame)->frame(); | 24 : toWebRemoteFrameImpl(frame)->frame(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void WebFrame::swap(WebFrame* frame) | 27 void WebFrame::swap(WebFrame* frame) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 child->m_parent = this; | 75 child->m_parent = this; |
| 76 WebFrame* oldLast = m_lastChild; | 76 WebFrame* oldLast = m_lastChild; |
| 77 m_lastChild = child; | 77 m_lastChild = child; |
| 78 | 78 |
| 79 if (oldLast) { | 79 if (oldLast) { |
| 80 child->m_previousSibling = oldLast; | 80 child->m_previousSibling = oldLast; |
| 81 oldLast->m_nextSibling = child; | 81 oldLast->m_nextSibling = child; |
| 82 } else { | 82 } else { |
| 83 m_firstChild = child; | 83 m_firstChild = child; |
| 84 } | 84 } |
| 85 |
| 86 toWebCoreFrame(this)->tree().invalidateScopedChildCount(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void WebFrame::removeChild(WebFrame* child) | 89 void WebFrame::removeChild(WebFrame* child) |
| 88 { | 90 { |
| 89 child->m_parent = 0; | 91 child->m_parent = 0; |
| 90 | 92 |
| 91 if (m_firstChild == child) | 93 if (m_firstChild == child) |
| 92 m_firstChild = child->m_nextSibling; | 94 m_firstChild = child->m_nextSibling; |
| 93 else | 95 else |
| 94 child->m_previousSibling->m_nextSibling = child->m_nextSibling; | 96 child->m_previousSibling->m_nextSibling = child->m_nextSibling; |
| 95 | 97 |
| 96 if (m_lastChild == child) | 98 if (m_lastChild == child) |
| 97 m_lastChild = child->m_previousSibling; | 99 m_lastChild = child->m_previousSibling; |
| 98 else | 100 else |
| 99 child->m_nextSibling->m_previousSibling = child->m_previousSibling; | 101 child->m_nextSibling->m_previousSibling = child->m_previousSibling; |
| 100 | 102 |
| 101 child->m_previousSibling = child->m_nextSibling = 0; | 103 child->m_previousSibling = child->m_nextSibling = 0; |
| 104 |
| 105 toWebCoreFrame(this)->tree().invalidateScopedChildCount(); |
| 102 } | 106 } |
| 103 | 107 |
| 104 WebFrame* WebFrame::parent() const | 108 WebFrame* WebFrame::parent() const |
| 105 { | 109 { |
| 106 return m_parent; | 110 return m_parent; |
| 107 } | 111 } |
| 108 | 112 |
| 109 WebFrame* WebFrame::top() const | 113 WebFrame* WebFrame::top() const |
| 110 { | 114 { |
| 111 WebFrame* frame = const_cast<WebFrame*>(this); | 115 WebFrame* frame = const_cast<WebFrame*>(this); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 127 WebFrame* WebFrame::previousSibling() const | 131 WebFrame* WebFrame::previousSibling() const |
| 128 { | 132 { |
| 129 return m_previousSibling; | 133 return m_previousSibling; |
| 130 } | 134 } |
| 131 | 135 |
| 132 WebFrame* WebFrame::nextSibling() const | 136 WebFrame* WebFrame::nextSibling() const |
| 133 { | 137 { |
| 134 return m_nextSibling; | 138 return m_nextSibling; |
| 135 } | 139 } |
| 136 | 140 |
| 141 WebFrame* WebFrame::traversePrevious(bool wrap) const |
| 142 { |
| 143 WebCore::Frame* frame = toWebCoreFrame(this); |
| 144 if (!frame) |
| 145 return 0; |
| 146 return fromFrame(frame->tree().traversePreviousWithWrap(wrap)); |
| 147 } |
| 148 |
| 149 WebFrame* WebFrame::traverseNext(bool wrap) const |
| 150 { |
| 151 WebCore::Frame* frame = toWebCoreFrame(this); |
| 152 if (!frame) |
| 153 return 0; |
| 154 return fromFrame(frame->tree().traverseNextWithWrap(wrap)); |
| 155 } |
| 156 |
| 157 WebFrame* WebFrame::findChildByName(const WebString& name) const |
| 158 { |
| 159 WebCore::Frame* frame = toWebCoreFrame(this); |
| 160 if (!frame) |
| 161 return 0; |
| 162 // FIXME: It's not clear this should ever be called to find a remote frame. |
| 163 // Perhaps just disallow that completely? |
| 164 return fromFrame(frame->tree().child(name)); |
| 165 } |
| 166 |
| 167 WebFrame* WebFrame::fromFrame(WebCore::Frame* frame) |
| 168 { |
| 169 if (!frame) |
| 170 return 0; |
| 171 |
| 172 if (frame->isLocalFrame()) |
| 173 return WebLocalFrameImpl::fromFrame(toLocalFrame(*frame)); |
| 174 return WebRemoteFrameImpl::fromFrame(toRemoteFrame(*frame)); |
| 175 } |
| 176 |
| 137 WebFrame::WebFrame() | 177 WebFrame::WebFrame() |
| 138 : m_parent(0) | 178 : m_parent(0) |
| 139 , m_previousSibling(0) | 179 , m_previousSibling(0) |
| 140 , m_nextSibling(0) | 180 , m_nextSibling(0) |
| 141 , m_firstChild(0) | 181 , m_firstChild(0) |
| 142 , m_lastChild(0) | 182 , m_lastChild(0) |
| 143 , m_opener(0) | 183 , m_opener(0) |
| 144 , m_openedFrameTracker(new OpenedFrameTracker) | 184 , m_openedFrameTracker(new OpenedFrameTracker) |
| 145 { | 185 { |
| 146 } | 186 } |
| 147 | 187 |
| 148 WebFrame::~WebFrame() | 188 WebFrame::~WebFrame() |
| 149 { | 189 { |
| 150 m_openedFrameTracker.reset(0); | 190 m_openedFrameTracker.reset(0); |
| 151 } | 191 } |
| 152 | 192 |
| 153 } // namespace blink | 193 } // namespace blink |
| OLD | NEW |