Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: Source/core/editing/ReplaceSelectionCommand.cpp

Issue 15622005: Introduce LiteralSet (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Cleaned Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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/TableSet.h"
63 #include "wtf/Vector.h"
63 64
64 namespace WebCore { 65 namespace WebCore {
65 66
66 using namespace HTMLNames; 67 using namespace HTMLNames;
67 68
68 enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment }; 69 enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };
69 70
70 // --- ReplacementFragment helper class 71 // --- ReplacementFragment helper class
71 72
72 class ReplacementFragment { 73 class ReplacementFragment {
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 552
552 // Mutate using the CSSOM wrapper so we get the same event behavior as a script. 553 // Mutate using the CSSOM wrapper so we get the same event behavior as a script.
553 if (isBlock(element)) 554 if (isBlock(element))
554 element->style()->setPropertyInternal(CSSPropertyDisplay, "inlin e", false, IGNORE_EXCEPTION); 555 element->style()->setPropertyInternal(CSSPropertyDisplay, "inlin e", false, IGNORE_EXCEPTION);
555 if (element->renderer() && element->renderer()->style()->isFloating( )) 556 if (element->renderer() && element->renderer()->style()->isFloating( ))
556 element->style()->setPropertyInternal(CSSPropertyFloat, "none", false, IGNORE_EXCEPTION); 557 element->style()->setPropertyInternal(CSSPropertyFloat, "none", false, IGNORE_EXCEPTION);
557 } 558 }
558 } 559 }
559 } 560 }
560 561
561 static bool isProhibitedParagraphChild(const AtomicString& name) 562 static bool isProhibitedParagraphChild(const QualifiedName& name)
562 { 563 {
563 // https://dvcs.w3.org/hg/editing/raw-file/57abe6d3cb60/editing.html#prohibi ted-paragraph-child 564 // https://dvcs.w3.org/hg/editing/raw-file/57abe6d3cb60/editing.html#prohibi ted-paragraph-child
564 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, elements, ()); 565 DEFINE_STATIC_LOCAL(TableSet<const QualifiedName*>, elements, (lessThanByLoc alNameImplAddress));
565 if (elements.isEmpty()) { 566 if (elements.isEmpty()) {
566 elements.add(addressTag.localName()); 567 static const QualifiedName* elementNames[] = {
eseidel 2013/05/22 00:40:14 Why not just make this AtomicString-based? If you
abarth-chromium 2013/05/22 00:58:25 The table needs to be computable by the linker. W
567 elements.add(articleTag.localName()); 568 &addressTag,
568 elements.add(asideTag.localName()); 569 &articleTag,
569 elements.add(blockquoteTag.localName()); 570 &asideTag,
570 elements.add(captionTag.localName()); 571 &blockquoteTag,
571 elements.add(centerTag.localName()); 572 &captionTag,
572 elements.add(colTag.localName()); 573 &centerTag,
573 elements.add(colgroupTag.localName()); 574 &colTag,
574 elements.add(ddTag.localName()); 575 &colgroupTag,
575 elements.add(detailsTag.localName()); 576 &ddTag,
576 elements.add(dirTag.localName()); 577 &detailsTag,
577 elements.add(divTag.localName()); 578 &dirTag,
578 elements.add(dlTag.localName()); 579 &divTag,
579 elements.add(dtTag.localName()); 580 &dlTag,
580 elements.add(fieldsetTag.localName()); 581 &dtTag,
581 elements.add(figcaptionTag.localName()); 582 &fieldsetTag,
582 elements.add(figureTag.localName()); 583 &figcaptionTag,
583 elements.add(footerTag.localName()); 584 &figureTag,
584 elements.add(formTag.localName()); 585 &footerTag,
585 elements.add(h1Tag.localName()); 586 &formTag,
586 elements.add(h2Tag.localName()); 587 &h1Tag,
587 elements.add(h3Tag.localName()); 588 &h2Tag,
588 elements.add(h4Tag.localName()); 589 &h3Tag,
589 elements.add(h5Tag.localName()); 590 &h4Tag,
590 elements.add(h6Tag.localName()); 591 &h5Tag,
591 elements.add(headerTag.localName()); 592 &h6Tag,
592 elements.add(hgroupTag.localName()); 593 &headerTag,
593 elements.add(hrTag.localName()); 594 &hgroupTag,
594 elements.add(liTag.localName()); 595 &hrTag,
595 elements.add(listingTag.localName()); 596 &liTag,
596 elements.add(mainTag.localName()); // Missing in the specification. 597 &listingTag,
597 elements.add(menuTag.localName()); 598 &mainTag, // Missing in the specification.
598 elements.add(navTag.localName()); 599 &menuTag,
599 elements.add(olTag.localName()); 600 &navTag,
600 elements.add(pTag.localName()); 601 &olTag,
601 elements.add(plaintextTag.localName()); 602 &pTag,
602 elements.add(preTag.localName()); 603 &plaintextTag,
603 elements.add(sectionTag.localName()); 604 &preTag,
604 elements.add(summaryTag.localName()); 605 &sectionTag,
605 elements.add(tableTag.localName()); 606 &summaryTag,
606 elements.add(tbodyTag.localName()); 607 &tableTag,
607 elements.add(tdTag.localName()); 608 &tbodyTag,
608 elements.add(tfootTag.localName()); 609 &tdTag,
609 elements.add(thTag.localName()); 610 &tfootTag,
610 elements.add(theadTag.localName()); 611 &thTag,
611 elements.add(trTag.localName()); 612 &theadTag,
612 elements.add(ulTag.localName()); 613 &trTag,
613 elements.add(xmpTag.localName()); 614 &ulTag,
615 &xmpTag,
616 };
617 elements.init(elementNames, WTF_ARRAY_LENGTH(elementNames));
614 } 618 }
615 return elements.contains(name); 619 return elements.contains(&name);
616 } 620 }
617 621
618 void ReplaceSelectionCommand::makeInsertedContentRoundTrippableWithHTMLTreeBuild er(InsertedNodes& insertedNodes) 622 void ReplaceSelectionCommand::makeInsertedContentRoundTrippableWithHTMLTreeBuild er(InsertedNodes& insertedNodes)
619 { 623 {
620 RefPtr<Node> pastEndNode = insertedNodes.pastLastLeaf(); 624 RefPtr<Node> pastEndNode = insertedNodes.pastLastLeaf();
621 RefPtr<Node> next; 625 RefPtr<Node> next;
622 for (RefPtr<Node> node = insertedNodes.firstNodeInserted(); node && node != pastEndNode; node = next) { 626 for (RefPtr<Node> node = insertedNodes.firstNodeInserted(); node && node != pastEndNode; node = next) {
623 next = NodeTraversal::next(node.get()); 627 next = NodeTraversal::next(node.get());
624 628
625 if (!node->isHTMLElement()) 629 if (!node->isHTMLElement())
626 continue; 630 continue;
627 631
628 if (isProhibitedParagraphChild(toHTMLElement(node.get())->localName())) { 632 if (isProhibitedParagraphChild(toHTMLElement(node.get())->tagQName())) {
eseidel 2013/05/22 00:40:14 Is this intentional?
abarth-chromium 2013/05/22 00:58:25 Yes. We need to pass a const QualifiedName* to co
629 if (HTMLElement* paragraphElement = toHTMLElement(enclosingNodeWithT ag(positionInParentBeforeNode(node.get()), pTag))) 633 if (HTMLElement* paragraphElement = toHTMLElement(enclosingNodeWithT ag(positionInParentBeforeNode(node.get()), pTag)))
630 moveNodeOutOfAncestor(node, paragraphElement); 634 moveNodeOutOfAncestor(node, paragraphElement);
631 } 635 }
632 636
633 if (isHeaderElement(node.get())) { 637 if (isHeaderElement(node.get())) {
634 if (HTMLElement* headerElement = static_cast<HTMLElement*>(highestEn closingNodeOfType(positionInParentBeforeNode(node.get()), isHeaderElement))) 638 if (HTMLElement* headerElement = static_cast<HTMLElement*>(highestEn closingNodeOfType(positionInParentBeforeNode(node.get()), isHeaderElement)))
635 moveNodeOutOfAncestor(node, headerElement); 639 moveNodeOutOfAncestor(node, headerElement);
636 } 640 }
637 } 641 }
638 } 642 }
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); 1493 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get());
1490 1494
1491 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en d); 1495 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en d);
1492 1496
1493 setEndingSelection(selectionAfterReplace); 1497 setEndingSelection(selectionAfterReplace);
1494 1498
1495 return true; 1499 return true;
1496 } 1500 }
1497 1501
1498 } // namespace WebCore 1502 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698