| 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 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // Clamp tabindex to the range of 'short' to match Firefox's behavio
r. | 318 // Clamp tabindex to the range of 'short' to match Firefox's behavio
r. |
| 319 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short
>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max())))); | 319 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short
>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max())))); |
| 320 } | 320 } |
| 321 } else { | 321 } else { |
| 322 AtomicString eventName = eventNameForAttributeName(name); | 322 AtomicString eventName = eventNameForAttributeName(name); |
| 323 if (!eventName.isNull()) | 323 if (!eventName.isNull()) |
| 324 setAttributeEventListener(eventName, createAttributeEventListener(th
is, name, value)); | 324 setAttributeEventListener(eventName, createAttributeEventListener(th
is, name, value)); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 String HTMLElement::innerHTML() const | |
| 329 { | |
| 330 return createMarkup(this, ChildrenOnly); | |
| 331 } | |
| 332 | |
| 333 String HTMLElement::outerHTML() const | |
| 334 { | |
| 335 return createMarkup(this); | |
| 336 } | |
| 337 | |
| 338 void HTMLElement::setInnerHTML(const String& html, ExceptionState& es) | |
| 339 { | |
| 340 if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html
, this, AllowScriptingContent, "innerHTML", es)) { | |
| 341 ContainerNode* container = this; | |
| 342 if (hasLocalName(templateTag)) | |
| 343 container = toHTMLTemplateElement(this)->content(); | |
| 344 replaceChildrenWithFragment(container, fragment.release(), es); | |
| 345 } | |
| 346 } | |
| 347 | |
| 348 static void mergeWithNextTextNode(PassRefPtr<Node> node, ExceptionState& es) | |
| 349 { | |
| 350 ASSERT(node && node->isTextNode()); | |
| 351 Node* next = node->nextSibling(); | |
| 352 if (!next || !next->isTextNode()) | |
| 353 return; | |
| 354 | |
| 355 RefPtr<Text> textNode = toText(node.get()); | |
| 356 RefPtr<Text> textNext = toText(next); | |
| 357 textNode->appendData(textNext->data()); | |
| 358 if (textNext->parentNode()) // Might have been removed by mutation event. | |
| 359 textNext->remove(es); | |
| 360 } | |
| 361 | |
| 362 void HTMLElement::setOuterHTML(const String& html, ExceptionState& es) | |
| 363 { | |
| 364 Node* p = parentNode(); | |
| 365 if (!p || !p->isHTMLElement()) { | |
| 366 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError); | |
| 367 return; | |
| 368 } | |
| 369 RefPtr<HTMLElement> parent = toHTMLElement(p); | |
| 370 RefPtr<Node> prev = previousSibling(); | |
| 371 RefPtr<Node> next = nextSibling(); | |
| 372 | |
| 373 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, pa
rent.get(), AllowScriptingContent, "outerHTML", es); | |
| 374 if (es.hadException()) | |
| 375 return; | |
| 376 | |
| 377 parent->replaceChild(fragment.release(), this, es); | |
| 378 RefPtr<Node> node = next ? next->previousSibling() : 0; | |
| 379 if (!es.hadException() && node && node->isTextNode()) | |
| 380 mergeWithNextTextNode(node.release(), es); | |
| 381 | |
| 382 if (!es.hadException() && prev && prev->isTextNode()) | |
| 383 mergeWithNextTextNode(prev.release(), es); | |
| 384 } | |
| 385 | |
| 386 PassRefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, Exc
eptionState& es) | 328 PassRefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, Exc
eptionState& es) |
| 387 { | 329 { |
| 388 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document()); | 330 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document()); |
| 389 unsigned int i, length = text.length(); | 331 unsigned int i, length = text.length(); |
| 390 UChar c = 0; | 332 UChar c = 0; |
| 391 for (unsigned int start = 0; start < length; ) { | 333 for (unsigned int start = 0; start < length; ) { |
| 392 | 334 |
| 393 // Find next line break. | 335 // Find next line break. |
| 394 for (i = start; i < length; i++) { | 336 for (i = start; i < length; i++) { |
| 395 c = text[i]; | 337 c = text[i]; |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 #ifndef NDEBUG | 1072 #ifndef NDEBUG |
| 1131 | 1073 |
| 1132 // For use in the debugger | 1074 // For use in the debugger |
| 1133 void dumpInnerHTML(WebCore::HTMLElement*); | 1075 void dumpInnerHTML(WebCore::HTMLElement*); |
| 1134 | 1076 |
| 1135 void dumpInnerHTML(WebCore::HTMLElement* element) | 1077 void dumpInnerHTML(WebCore::HTMLElement* element) |
| 1136 { | 1078 { |
| 1137 printf("%s\n", element->innerHTML().ascii().data()); | 1079 printf("%s\n", element->innerHTML().ascii().data()); |
| 1138 } | 1080 } |
| 1139 #endif | 1081 #endif |
| OLD | NEW |