| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "core/editing/TextIterator.h" | 51 #include "core/editing/TextIterator.h" |
| 52 #include "core/editing/VisibleUnits.h" | 52 #include "core/editing/VisibleUnits.h" |
| 53 #include "core/editing/htmlediting.h" | 53 #include "core/editing/htmlediting.h" |
| 54 #include "core/editing/markup.h" | 54 #include "core/editing/markup.h" |
| 55 #include "core/html/HTMLElement.h" | 55 #include "core/html/HTMLElement.h" |
| 56 #include "core/html/HTMLInputElement.h" | 56 #include "core/html/HTMLInputElement.h" |
| 57 #include "core/page/Frame.h" | 57 #include "core/page/Frame.h" |
| 58 #include "core/rendering/RenderInline.h" | 58 #include "core/rendering/RenderInline.h" |
| 59 #include "core/rendering/RenderObject.h" | 59 #include "core/rendering/RenderObject.h" |
| 60 #include "core/rendering/RenderText.h" | 60 #include "core/rendering/RenderText.h" |
| 61 #include <wtf/StdLibExtras.h> | 61 #include "wtf/StdLibExtras.h" |
| 62 #include <wtf/Vector.h> | 62 #include "wtf/Vector.h" |
| 63 | 63 |
| 64 namespace WebCore { | 64 namespace WebCore { |
| 65 | 65 |
| 66 using namespace HTMLNames; | 66 using namespace HTMLNames; |
| 67 | 67 |
| 68 enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment }; | 68 enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment }; |
| 69 | 69 |
| 70 // --- ReplacementFragment helper class | 70 // --- ReplacementFragment helper class |
| 71 | 71 |
| 72 class ReplacementFragment { | 72 class ReplacementFragment { |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 551 |
| 552 // Mutate using the CSSOM wrapper so we get the same event behavior
as a script. | 552 // Mutate using the CSSOM wrapper so we get the same event behavior
as a script. |
| 553 if (isBlock(element)) | 553 if (isBlock(element)) |
| 554 element->style()->setPropertyInternal(CSSPropertyDisplay, "inlin
e", false, IGNORE_EXCEPTION); | 554 element->style()->setPropertyInternal(CSSPropertyDisplay, "inlin
e", false, IGNORE_EXCEPTION); |
| 555 if (element->renderer() && element->renderer()->style()->isFloating(
)) | 555 if (element->renderer() && element->renderer()->style()->isFloating(
)) |
| 556 element->style()->setPropertyInternal(CSSPropertyFloat, "none",
false, IGNORE_EXCEPTION); | 556 element->style()->setPropertyInternal(CSSPropertyFloat, "none",
false, IGNORE_EXCEPTION); |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 static bool isProhibitedParagraphChild(const AtomicString& name) | 561 static bool isProhibitedParagraphChild(const QualifiedName& name) |
| 562 { | 562 { |
| 563 // https://dvcs.w3.org/hg/editing/raw-file/57abe6d3cb60/editing.html#prohibi
ted-paragraph-child | 563 // https://dvcs.w3.org/hg/editing/raw-file/57abe6d3cb60/editing.html#prohibi
ted-paragraph-child |
| 564 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, elements, ()); | 564 DEFINE_STATIC_LOCAL(LocalNameLiteralSet, prohibitedChildren, ()); |
| 565 if (elements.isEmpty()) { | 565 if (!prohibitedChildren.isInitialized()) { |
| 566 elements.add(addressTag.localName()); | 566 static const QualifiedName* prohibitedChildrenData[] = { |
| 567 elements.add(articleTag.localName()); | 567 &addressTag, |
| 568 elements.add(asideTag.localName()); | 568 &articleTag, |
| 569 elements.add(blockquoteTag.localName()); | 569 &asideTag, |
| 570 elements.add(captionTag.localName()); | 570 &blockquoteTag, |
| 571 elements.add(centerTag.localName()); | 571 &captionTag, |
| 572 elements.add(colTag.localName()); | 572 ¢erTag, |
| 573 elements.add(colgroupTag.localName()); | 573 &colTag, |
| 574 elements.add(ddTag.localName()); | 574 &colgroupTag, |
| 575 elements.add(detailsTag.localName()); | 575 &ddTag, |
| 576 elements.add(dirTag.localName()); | 576 &detailsTag, |
| 577 elements.add(divTag.localName()); | 577 &dirTag, |
| 578 elements.add(dlTag.localName()); | 578 &divTag, |
| 579 elements.add(dtTag.localName()); | 579 &dlTag, |
| 580 elements.add(fieldsetTag.localName()); | 580 &dtTag, |
| 581 elements.add(figcaptionTag.localName()); | 581 &fieldsetTag, |
| 582 elements.add(figureTag.localName()); | 582 &figcaptionTag, |
| 583 elements.add(footerTag.localName()); | 583 &figureTag, |
| 584 elements.add(formTag.localName()); | 584 &footerTag, |
| 585 elements.add(h1Tag.localName()); | 585 &formTag, |
| 586 elements.add(h2Tag.localName()); | 586 &h1Tag, |
| 587 elements.add(h3Tag.localName()); | 587 &h2Tag, |
| 588 elements.add(h4Tag.localName()); | 588 &h3Tag, |
| 589 elements.add(h5Tag.localName()); | 589 &h4Tag, |
| 590 elements.add(h6Tag.localName()); | 590 &h5Tag, |
| 591 elements.add(headerTag.localName()); | 591 &h6Tag, |
| 592 elements.add(hgroupTag.localName()); | 592 &headerTag, |
| 593 elements.add(hrTag.localName()); | 593 &hgroupTag, |
| 594 elements.add(liTag.localName()); | 594 &hrTag, |
| 595 elements.add(listingTag.localName()); | 595 &liTag, |
| 596 elements.add(mainTag.localName()); // Missing in the specification. | 596 &listingTag, |
| 597 elements.add(menuTag.localName()); | 597 &mainTag, // Missing in the specification. |
| 598 elements.add(navTag.localName()); | 598 &menuTag, |
| 599 elements.add(olTag.localName()); | 599 &navTag, |
| 600 elements.add(pTag.localName()); | 600 &olTag, |
| 601 elements.add(plaintextTag.localName()); | 601 &pTag, |
| 602 elements.add(preTag.localName()); | 602 &plaintextTag, |
| 603 elements.add(sectionTag.localName()); | 603 &preTag, |
| 604 elements.add(summaryTag.localName()); | 604 §ionTag, |
| 605 elements.add(tableTag.localName()); | 605 &summaryTag, |
| 606 elements.add(tbodyTag.localName()); | 606 &tableTag, |
| 607 elements.add(tdTag.localName()); | 607 &tbodyTag, |
| 608 elements.add(tfootTag.localName()); | 608 &tdTag, |
| 609 elements.add(thTag.localName()); | 609 &tfootTag, |
| 610 elements.add(theadTag.localName()); | 610 &thTag, |
| 611 elements.add(trTag.localName()); | 611 &theadTag, |
| 612 elements.add(ulTag.localName()); | 612 &trTag, |
| 613 elements.add(xmpTag.localName()); | 613 &ulTag, |
| 614 &xmpTag, |
| 615 }; |
| 616 prohibitedChildren.init(prohibitedChildrenData, WTF_ARRAY_LENGTH(prohibi
tedChildrenData)); |
| 614 } | 617 } |
| 615 return elements.contains(name); | 618 return prohibitedChildren.contains(&name); |
| 616 } | 619 } |
| 617 | 620 |
| 618 void ReplaceSelectionCommand::makeInsertedContentRoundTrippableWithHTMLTreeBuild
er(InsertedNodes& insertedNodes) | 621 void ReplaceSelectionCommand::makeInsertedContentRoundTrippableWithHTMLTreeBuild
er(InsertedNodes& insertedNodes) |
| 619 { | 622 { |
| 620 RefPtr<Node> pastEndNode = insertedNodes.pastLastLeaf(); | 623 RefPtr<Node> pastEndNode = insertedNodes.pastLastLeaf(); |
| 621 RefPtr<Node> next; | 624 RefPtr<Node> next; |
| 622 for (RefPtr<Node> node = insertedNodes.firstNodeInserted(); node && node !=
pastEndNode; node = next) { | 625 for (RefPtr<Node> node = insertedNodes.firstNodeInserted(); node && node !=
pastEndNode; node = next) { |
| 623 next = NodeTraversal::next(node.get()); | 626 next = NodeTraversal::next(node.get()); |
| 624 | 627 |
| 625 if (!node->isHTMLElement()) | 628 if (!node->isHTMLElement()) |
| 626 continue; | 629 continue; |
| 627 | 630 |
| 628 if (isProhibitedParagraphChild(toHTMLElement(node.get())->localName()))
{ | 631 if (isProhibitedParagraphChild(toHTMLElement(node.get())->tagQName())) { |
| 629 if (HTMLElement* paragraphElement = toHTMLElement(enclosingNodeWithT
ag(positionInParentBeforeNode(node.get()), pTag))) | 632 if (HTMLElement* paragraphElement = toHTMLElement(enclosingNodeWithT
ag(positionInParentBeforeNode(node.get()), pTag))) |
| 630 moveNodeOutOfAncestor(node, paragraphElement); | 633 moveNodeOutOfAncestor(node, paragraphElement); |
| 631 } | 634 } |
| 632 | 635 |
| 633 if (isHeaderElement(node.get())) { | 636 if (isHeaderElement(node.get())) { |
| 634 if (HTMLElement* headerElement = static_cast<HTMLElement*>(highestEn
closingNodeOfType(positionInParentBeforeNode(node.get()), isHeaderElement))) | 637 if (HTMLElement* headerElement = static_cast<HTMLElement*>(highestEn
closingNodeOfType(positionInParentBeforeNode(node.get()), isHeaderElement))) |
| 635 moveNodeOutOfAncestor(node, headerElement); | 638 moveNodeOutOfAncestor(node, headerElement); |
| 636 } | 639 } |
| 637 } | 640 } |
| 638 } | 641 } |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); | 1492 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); |
| 1490 | 1493 |
| 1491 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); | 1494 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); |
| 1492 | 1495 |
| 1493 setEndingSelection(selectionAfterReplace); | 1496 setEndingSelection(selectionAfterReplace); |
| 1494 | 1497 |
| 1495 return true; | 1498 return true; |
| 1496 } | 1499 } |
| 1497 | 1500 |
| 1498 } // namespace WebCore | 1501 } // namespace WebCore |
| OLD | NEW |