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 299 matching lines...) Loading... |
310 // Clamp tabindex to the range of 'short' to match Firefox's behavio
r. | 310 // Clamp tabindex to the range of 'short' to match Firefox's behavio
r. |
311 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short
>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max())))); | 311 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short
>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max())))); |
312 } | 312 } |
313 } else { | 313 } else { |
314 AtomicString eventName = eventNameForAttributeName(name); | 314 AtomicString eventName = eventNameForAttributeName(name); |
315 if (!eventName.isNull()) | 315 if (!eventName.isNull()) |
316 setAttributeEventListener(eventName, createAttributeEventListener(th
is, name, value)); | 316 setAttributeEventListener(eventName, createAttributeEventListener(th
is, name, value)); |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 String HTMLElement::innerHTML() const | |
321 { | |
322 return createMarkup(this, ChildrenOnly); | |
323 } | |
324 | |
325 String HTMLElement::outerHTML() const | |
326 { | |
327 return createMarkup(this); | |
328 } | |
329 | |
330 void HTMLElement::setInnerHTML(const String& html, ExceptionState& es) | |
331 { | |
332 if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html
, this, AllowScriptingContent, "innerHTML", es)) { | |
333 ContainerNode* container = this; | |
334 if (hasLocalName(templateTag)) | |
335 container = toHTMLTemplateElement(this)->content(); | |
336 replaceChildrenWithFragment(container, fragment.release(), es); | |
337 } | |
338 } | |
339 | |
340 static void mergeWithNextTextNode(PassRefPtr<Node> node, ExceptionState& es) | |
341 { | |
342 ASSERT(node && node->isTextNode()); | |
343 Node* next = node->nextSibling(); | |
344 if (!next || !next->isTextNode()) | |
345 return; | |
346 | |
347 RefPtr<Text> textNode = toText(node.get()); | |
348 RefPtr<Text> textNext = toText(next); | |
349 textNode->appendData(textNext->data()); | |
350 if (textNext->parentNode()) // Might have been removed by mutation event. | |
351 textNext->remove(es); | |
352 } | |
353 | |
354 void HTMLElement::setOuterHTML(const String& html, ExceptionState& es) | |
355 { | |
356 Node* p = parentNode(); | |
357 if (!p || !p->isHTMLElement()) { | |
358 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError); | |
359 return; | |
360 } | |
361 RefPtr<HTMLElement> parent = toHTMLElement(p); | |
362 RefPtr<Node> prev = previousSibling(); | |
363 RefPtr<Node> next = nextSibling(); | |
364 | |
365 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, pa
rent.get(), AllowScriptingContent, "outerHTML", es); | |
366 if (es.hadException()) | |
367 return; | |
368 | |
369 parent->replaceChild(fragment.release(), this, es); | |
370 RefPtr<Node> node = next ? next->previousSibling() : 0; | |
371 if (!es.hadException() && node && node->isTextNode()) | |
372 mergeWithNextTextNode(node.release(), es); | |
373 | |
374 if (!es.hadException() && prev && prev->isTextNode()) | |
375 mergeWithNextTextNode(prev.release(), es); | |
376 } | |
377 | |
378 PassRefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, Exc
eptionState& es) | 320 PassRefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, Exc
eptionState& es) |
379 { | 321 { |
380 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document()); | 322 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document()); |
381 unsigned int i, length = text.length(); | 323 unsigned int i, length = text.length(); |
382 UChar c = 0; | 324 UChar c = 0; |
383 for (unsigned int start = 0; start < length; ) { | 325 for (unsigned int start = 0; start < length; ) { |
384 | 326 |
385 // Find next line break. | 327 // Find next line break. |
386 for (i = start; i < length; i++) { | 328 for (i = start; i < length; i++) { |
387 c = text[i]; | 329 c = text[i]; |
(...skipping 734 matching lines...) Loading... |
1122 #ifndef NDEBUG | 1064 #ifndef NDEBUG |
1123 | 1065 |
1124 // For use in the debugger | 1066 // For use in the debugger |
1125 void dumpInnerHTML(WebCore::HTMLElement*); | 1067 void dumpInnerHTML(WebCore::HTMLElement*); |
1126 | 1068 |
1127 void dumpInnerHTML(WebCore::HTMLElement* element) | 1069 void dumpInnerHTML(WebCore::HTMLElement* element) |
1128 { | 1070 { |
1129 printf("%s\n", element->innerHTML().ascii().data()); | 1071 printf("%s\n", element->innerHTML().ascii().data()); |
1130 } | 1072 } |
1131 #endif | 1073 #endif |
OLD | NEW |