| 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-2008, 2013, 2014 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004-2008, 2013, 2014 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 dirAttributeChanged(value); | 369 dirAttributeChanged(value); |
| 370 } else if (name == langAttr) { | 370 } else if (name == langAttr) { |
| 371 pseudoStateChanged(CSSSelector::PseudoLang); | 371 pseudoStateChanged(CSSSelector::PseudoLang); |
| 372 } else { | 372 } else { |
| 373 const AtomicString& eventName = eventNameForAttributeName(name); | 373 const AtomicString& eventName = eventNameForAttributeName(name); |
| 374 if (!eventName.isNull()) | 374 if (!eventName.isNull()) |
| 375 setAttributeEventListener(eventName, createAttributeEventListener(th
is, name, value, eventParameterName())); | 375 setAttributeEventListener(eventName, createAttributeEventListener(th
is, name, value, eventParameterName())); |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 PassRefPtrWillBeRawPtr<DocumentFragment> HTMLElement::textToFragment(const Strin
g& text, ExceptionState& exceptionState) | 379 RawPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, Excepti
onState& exceptionState) |
| 380 { | 380 { |
| 381 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(doc
ument()); | 381 RawPtr<DocumentFragment> fragment = DocumentFragment::create(document()); |
| 382 unsigned i, length = text.length(); | 382 unsigned i, length = text.length(); |
| 383 UChar c = 0; | 383 UChar c = 0; |
| 384 for (unsigned start = 0; start < length; ) { | 384 for (unsigned start = 0; start < length; ) { |
| 385 | 385 |
| 386 // Find next line break. | 386 // Find next line break. |
| 387 for (i = start; i < length; i++) { | 387 for (i = start; i < length; i++) { |
| 388 c = text[i]; | 388 c = text[i]; |
| 389 if (c == '\r' || c == '\n') | 389 if (c == '\r' || c == '\n') |
| 390 break; | 390 break; |
| 391 } | 391 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 return; | 455 return; |
| 456 } | 456 } |
| 457 String textWithConsistentLineBreaks = text; | 457 String textWithConsistentLineBreaks = text; |
| 458 textWithConsistentLineBreaks.replace("\r\n", "\n"); | 458 textWithConsistentLineBreaks.replace("\r\n", "\n"); |
| 459 textWithConsistentLineBreaks.replace('\r', '\n'); | 459 textWithConsistentLineBreaks.replace('\r', '\n'); |
| 460 replaceChildrenWithText(this, textWithConsistentLineBreaks, exceptionSta
te); | 460 replaceChildrenWithText(this, textWithConsistentLineBreaks, exceptionSta
te); |
| 461 return; | 461 return; |
| 462 } | 462 } |
| 463 | 463 |
| 464 // Add text nodes and <br> elements. | 464 // Add text nodes and <br> elements. |
| 465 RefPtrWillBeRawPtr<DocumentFragment> fragment = textToFragment(text, excepti
onState); | 465 RawPtr<DocumentFragment> fragment = textToFragment(text, exceptionState); |
| 466 if (!exceptionState.hadException()) | 466 if (!exceptionState.hadException()) |
| 467 replaceChildrenWithFragment(this, fragment.release(), exceptionState); | 467 replaceChildrenWithFragment(this, fragment.release(), exceptionState); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void HTMLElement::setOuterText(const String& text, ExceptionState& exceptionStat
e) | 470 void HTMLElement::setOuterText(const String& text, ExceptionState& exceptionStat
e) |
| 471 { | 471 { |
| 472 if (ieForbidsInsertHTML()) { | 472 if (ieForbidsInsertHTML()) { |
| 473 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); | 473 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); |
| 474 return; | 474 return; |
| 475 } | 475 } |
| 476 if (shouldProhibitSetInnerOuterText(*this)) { | 476 if (shouldProhibitSetInnerOuterText(*this)) { |
| 477 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); | 477 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); |
| 478 return; | 478 return; |
| 479 } | 479 } |
| 480 | 480 |
| 481 ContainerNode* parent = parentNode(); | 481 ContainerNode* parent = parentNode(); |
| 482 if (!parent) { | 482 if (!parent) { |
| 483 exceptionState.throwDOMException(NoModificationAllowedError, "The elemen
t has no parent."); | 483 exceptionState.throwDOMException(NoModificationAllowedError, "The elemen
t has no parent."); |
| 484 return; | 484 return; |
| 485 } | 485 } |
| 486 | 486 |
| 487 RefPtrWillBeRawPtr<Node> prev = previousSibling(); | 487 RawPtr<Node> prev = previousSibling(); |
| 488 RefPtrWillBeRawPtr<Node> next = nextSibling(); | 488 RawPtr<Node> next = nextSibling(); |
| 489 RefPtrWillBeRawPtr<Node> newChild = nullptr; | 489 RawPtr<Node> newChild = nullptr; |
| 490 | 490 |
| 491 // Convert text to fragment with <br> tags instead of linebreaks if needed. | 491 // Convert text to fragment with <br> tags instead of linebreaks if needed. |
| 492 if (text.contains('\r') || text.contains('\n')) | 492 if (text.contains('\r') || text.contains('\n')) |
| 493 newChild = textToFragment(text, exceptionState); | 493 newChild = textToFragment(text, exceptionState); |
| 494 else | 494 else |
| 495 newChild = Text::create(document(), text); | 495 newChild = Text::create(document(), text); |
| 496 | 496 |
| 497 // textToFragment might cause mutation events. | 497 // textToFragment might cause mutation events. |
| 498 if (!parentNode()) | 498 if (!parentNode()) |
| 499 exceptionState.throwDOMException(HierarchyRequestError, "The element has
no parent."); | 499 exceptionState.throwDOMException(HierarchyRequestError, "The element has
no parent."); |
| 500 | 500 |
| 501 if (exceptionState.hadException()) | 501 if (exceptionState.hadException()) |
| 502 return; | 502 return; |
| 503 | 503 |
| 504 parent->replaceChild(newChild.release(), this, exceptionState); | 504 parent->replaceChild(newChild.release(), this, exceptionState); |
| 505 | 505 |
| 506 RefPtrWillBeRawPtr<Node> node = next ? next->previousSibling() : nullptr; | 506 RawPtr<Node> node = next ? next->previousSibling() : nullptr; |
| 507 if (!exceptionState.hadException() && node && node->isTextNode()) | 507 if (!exceptionState.hadException() && node && node->isTextNode()) |
| 508 mergeWithNextTextNode(toText(node.get()), exceptionState); | 508 mergeWithNextTextNode(toText(node.get()), exceptionState); |
| 509 | 509 |
| 510 if (!exceptionState.hadException() && prev && prev->isTextNode()) | 510 if (!exceptionState.hadException() && prev && prev->isTextNode()) |
| 511 mergeWithNextTextNode(toText(prev.get()), exceptionState); | 511 mergeWithNextTextNode(toText(prev.get()), exceptionState); |
| 512 } | 512 } |
| 513 | 513 |
| 514 void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment,
MutableStylePropertySet* style) | 514 void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment,
MutableStylePropertySet* style) |
| 515 { | 515 { |
| 516 // Vertical alignment with respect to the current baseline of the text | 516 // Vertical alignment with respect to the current baseline of the text |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 #ifndef NDEBUG | 1036 #ifndef NDEBUG |
| 1037 | 1037 |
| 1038 // For use in the debugger | 1038 // For use in the debugger |
| 1039 void dumpInnerHTML(blink::HTMLElement*); | 1039 void dumpInnerHTML(blink::HTMLElement*); |
| 1040 | 1040 |
| 1041 void dumpInnerHTML(blink::HTMLElement* element) | 1041 void dumpInnerHTML(blink::HTMLElement* element) |
| 1042 { | 1042 { |
| 1043 printf("%s\n", element->innerHTML().ascii().data()); | 1043 printf("%s\n", element->innerHTML().ascii().data()); |
| 1044 } | 1044 } |
| 1045 #endif | 1045 #endif |
| OLD | NEW |