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