| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2011 Igalia S.L. | 4 * Copyright (C) 2011 Igalia S.L. |
| 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 Document& document = context.document(); | 460 Document& document = context.document(); |
| 461 RefPtrWillBeRawPtr<DocumentFragment> fragment = document.createDocumentFragm
ent(); | 461 RefPtrWillBeRawPtr<DocumentFragment> fragment = document.createDocumentFragm
ent(); |
| 462 | 462 |
| 463 if (text.isEmpty()) | 463 if (text.isEmpty()) |
| 464 return fragment.release(); | 464 return fragment.release(); |
| 465 | 465 |
| 466 String string = text; | 466 String string = text; |
| 467 string.replace("\r\n", "\n"); | 467 string.replace("\r\n", "\n"); |
| 468 string.replace('\r', '\n'); | 468 string.replace('\r', '\n'); |
| 469 | 469 |
| 470 if (shouldPreserveNewline(context)) { | 470 if (!isRichlyEditablePosition(context.startPosition()) || shouldPreserveNewl
ine(context)) { |
| 471 fragment->appendChild(document.createTextNode(string)); | 471 fragment->appendChild(document.createTextNode(string)); |
| 472 if (string.endsWith('\n')) { | 472 if (string.endsWith('\n')) { |
| 473 RefPtrWillBeRawPtr<HTMLBRElement> element = HTMLBRElement::create(do
cument); | 473 RefPtrWillBeRawPtr<HTMLBRElement> element = HTMLBRElement::create(do
cument); |
| 474 element->setAttribute(classAttr, AppleInterchangeNewline); | 474 element->setAttribute(classAttr, AppleInterchangeNewline); |
| 475 fragment->appendChild(element.release()); | 475 fragment->appendChild(element.release()); |
| 476 } | 476 } |
| 477 return fragment.release(); | 477 return fragment.release(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 // A string with no newlines gets added inline, rather than being put into a
paragraph. | 480 // A string with no newlines gets added inline, rather than being put into a
paragraph. |
| 481 if (string.find('\n') == kNotFound) { | 481 if (string.find('\n') == kNotFound) { |
| 482 fillContainerFromString(fragment.get(), string); | 482 fillContainerFromString(fragment.get(), string); |
| 483 return fragment.release(); | 483 return fragment.release(); |
| 484 } | 484 } |
| 485 | 485 |
| 486 // Break string into paragraphs. Extra line breaks turn into empty paragraph
s. | 486 // Break string into paragraphs. Extra line breaks turn into empty paragraph
s. |
| 487 Element* block = enclosingBlock(context.startPosition().nodeAsRangeFirstNode
()); | 487 Element* block = enclosingBlock(context.startPosition().nodeAsRangeFirstNode
()); |
| 488 bool useClonesOfEnclosingBlock = block | 488 bool useClonesOfEnclosingBlock = block |
| 489 && !isHTMLBodyElement(*block) | 489 && !isHTMLBodyElement(*block) |
| 490 && !isHTMLHtmlElement(*block) | 490 && !isHTMLHtmlElement(*block) |
| 491 && block != rootEditableElementOf(context.startPosition()); | 491 && block != rootEditableElementOf(context.startPosition()); |
| 492 bool useLineBreak = enclosingTextFormControl(context.startPosition()); | |
| 493 | 492 |
| 494 Vector<String> list; | 493 Vector<String> list; |
| 495 string.split('\n', true, list); // true gets us empty strings in the list | 494 string.split('\n', true, list); // true gets us empty strings in the list |
| 496 size_t numLines = list.size(); | 495 size_t numLines = list.size(); |
| 497 for (size_t i = 0; i < numLines; ++i) { | 496 for (size_t i = 0; i < numLines; ++i) { |
| 498 const String& s = list[i]; | 497 const String& s = list[i]; |
| 499 | 498 |
| 500 RefPtrWillBeRawPtr<Element> element = nullptr; | 499 RefPtrWillBeRawPtr<Element> element = nullptr; |
| 501 if (s.isEmpty() && i + 1 == numLines) { | 500 if (s.isEmpty() && i + 1 == numLines) { |
| 502 // For last line, use the "magic BR" rather than a P. | 501 // For last line, use the "magic BR" rather than a P. |
| 503 element = HTMLBRElement::create(document); | 502 element = HTMLBRElement::create(document); |
| 504 element->setAttribute(classAttr, AppleInterchangeNewline); | 503 element->setAttribute(classAttr, AppleInterchangeNewline); |
| 505 } else if (useLineBreak) { | |
| 506 element = HTMLBRElement::create(document); | |
| 507 fillContainerFromString(fragment.get(), s); | |
| 508 } else { | 504 } else { |
| 509 if (useClonesOfEnclosingBlock) | 505 if (useClonesOfEnclosingBlock) |
| 510 element = block->cloneElementWithoutChildren(); | 506 element = block->cloneElementWithoutChildren(); |
| 511 else | 507 else |
| 512 element = createDefaultParagraphElement(document); | 508 element = createDefaultParagraphElement(document); |
| 513 fillContainerFromString(element.get(), s); | 509 fillContainerFromString(element.get(), s); |
| 514 } | 510 } |
| 515 fragment->appendChild(element.release()); | 511 fragment->appendChild(element.release()); |
| 516 } | 512 } |
| 517 return fragment.release(); | 513 return fragment.release(); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 RefPtrWillBeRawPtr<Text> textNext = toText(next); | 694 RefPtrWillBeRawPtr<Text> textNext = toText(next); |
| 699 textNode->appendData(textNext->data()); | 695 textNode->appendData(textNext->data()); |
| 700 if (textNext->parentNode()) // Might have been removed by mutation event. | 696 if (textNext->parentNode()) // Might have been removed by mutation event. |
| 701 textNext->remove(exceptionState); | 697 textNext->remove(exceptionState); |
| 702 } | 698 } |
| 703 | 699 |
| 704 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; | 700 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; |
| 705 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingInFlatTreeStrat
egy>; | 701 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingInFlatTreeStrat
egy>; |
| 706 | 702 |
| 707 } // namespace blink | 703 } // namespace blink |
| OLD | NEW |