OLD | NEW |
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 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
6 * (C) 2007 David Smith (catfish.man@gmail.com) | 6 * (C) 2007 David Smith (catfish.man@gmail.com) |
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. |
8 * (C) 2007 Eric Seidel (eric@webkit.org) | 8 * (C) 2007 Eric Seidel (eric@webkit.org) |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 2258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 | 2269 |
2270 parent->replaceChild(fragment.release(), this, exceptionState); | 2270 parent->replaceChild(fragment.release(), this, exceptionState); |
2271 RefPtr<Node> node = next ? next->previousSibling() : 0; | 2271 RefPtr<Node> node = next ? next->previousSibling() : 0; |
2272 if (!exceptionState.hadException() && node && node->isTextNode()) | 2272 if (!exceptionState.hadException() && node && node->isTextNode()) |
2273 mergeWithNextTextNode(node.release(), exceptionState); | 2273 mergeWithNextTextNode(node.release(), exceptionState); |
2274 | 2274 |
2275 if (!exceptionState.hadException() && prev && prev->isTextNode()) | 2275 if (!exceptionState.hadException() && prev && prev->isTextNode()) |
2276 mergeWithNextTextNode(prev.release(), exceptionState); | 2276 mergeWithNextTextNode(prev.release(), exceptionState); |
2277 } | 2277 } |
2278 | 2278 |
| 2279 Node* Element::insertAdjacent(const String& where, Node* newChild, ExceptionStat
e& exceptionState) |
| 2280 { |
| 2281 if (equalIgnoringCase(where, "beforeBegin")) { |
| 2282 if (ContainerNode* parent = this->parentNode()) { |
| 2283 parent->insertBefore(newChild, this, exceptionState); |
| 2284 if (!exceptionState.hadException()) |
| 2285 return newChild; |
| 2286 } |
| 2287 return 0; |
| 2288 } |
| 2289 |
| 2290 if (equalIgnoringCase(where, "afterBegin")) { |
| 2291 insertBefore(newChild, firstChild(), exceptionState); |
| 2292 return exceptionState.hadException() ? 0 : newChild; |
| 2293 } |
| 2294 |
| 2295 if (equalIgnoringCase(where, "beforeEnd")) { |
| 2296 appendChild(newChild, exceptionState); |
| 2297 return exceptionState.hadException() ? 0 : newChild; |
| 2298 } |
| 2299 |
| 2300 if (equalIgnoringCase(where, "afterEnd")) { |
| 2301 if (ContainerNode* parent = this->parentNode()) { |
| 2302 parent->insertBefore(newChild, nextSibling(), exceptionState); |
| 2303 if (!exceptionState.hadException()) |
| 2304 return newChild; |
| 2305 } |
| 2306 return 0; |
| 2307 } |
| 2308 |
| 2309 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + wher
e + "') is not one of 'beforeBegin', 'afterBegin', 'beforeEnd', or 'afterEnd'.")
; |
| 2310 return 0; |
| 2311 } |
| 2312 |
| 2313 // Step 1 of http://domparsing.spec.whatwg.org/#insertadjacenthtml() |
| 2314 static Element* contextElementForInsertion(const String& where, Element* element
, ExceptionState& exceptionState) |
| 2315 { |
| 2316 if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "aft
erEnd")) { |
| 2317 ContainerNode* parent = element->parentNode(); |
| 2318 if (!parent || !parent->isElementNode()) { |
| 2319 exceptionState.throwDOMException(NoModificationAllowedError, "The el
ement has no parent."); |
| 2320 return 0; |
| 2321 } |
| 2322 return toElement(parent); |
| 2323 } |
| 2324 if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "befo
reEnd")) |
| 2325 return element; |
| 2326 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + wher
e + "') is not one of 'beforeBegin', 'afterBegin', 'beforeEnd', or 'afterEnd'.")
; |
| 2327 return 0; |
| 2328 } |
| 2329 |
| 2330 void Element::insertAdjacentHTML(const String& where, const String& markup, Exce
ptionState& exceptionState) |
| 2331 { |
| 2332 RefPtr<Element> contextElement = contextElementForInsertion(where, this, exc
eptionState); |
| 2333 if (!contextElement) |
| 2334 return; |
| 2335 |
| 2336 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup,
contextElement.get(), AllowScriptingContent, "insertAdjacentHTML", exceptionStat
e); |
| 2337 if (!fragment) |
| 2338 return; |
| 2339 insertAdjacent(where, fragment.get(), exceptionState); |
| 2340 } |
| 2341 |
2279 String Element::innerText() | 2342 String Element::innerText() |
2280 { | 2343 { |
2281 // We need to update layout, since plainText uses line boxes in the render t
ree. | 2344 // We need to update layout, since plainText uses line boxes in the render t
ree. |
2282 document().updateLayoutIgnorePendingStylesheets(); | 2345 document().updateLayoutIgnorePendingStylesheets(); |
2283 | 2346 |
2284 if (!renderer()) | 2347 if (!renderer()) |
2285 return textContent(true); | 2348 return textContent(true); |
2286 | 2349 |
2287 return plainText(rangeOfContents(const_cast<Element*>(this)).get()); | 2350 return plainText(rangeOfContents(const_cast<Element*>(this)).get()); |
2288 } | 2351 } |
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3536 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi
stItems | 3599 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi
stItems |
3537 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg
i?id=88405 | 3600 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg
i?id=88405 |
3538 if (hasTagName(optionTag) || hasTagName(optgroupTag)) | 3601 if (hasTagName(optionTag) || hasTagName(optgroupTag)) |
3539 return false; | 3602 return false; |
3540 if (FullscreenElementStack::isActiveFullScreenElement(this)) | 3603 if (FullscreenElementStack::isActiveFullScreenElement(this)) |
3541 return false; | 3604 return false; |
3542 return true; | 3605 return true; |
3543 } | 3606 } |
3544 | 3607 |
3545 } // namespace WebCore | 3608 } // namespace WebCore |
OLD | NEW |