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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp

Issue 2109973002: Revert of Remove style spans to follow the styles of the block element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/deleting/merge-paragraph-from-p-with-style-3-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17 matching lines...) Expand all
28 28
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "core/CSSPropertyNames.h" 30 #include "core/CSSPropertyNames.h"
31 #include "core/HTMLNames.h" 31 #include "core/HTMLNames.h"
32 #include "core/InputTypeNames.h" 32 #include "core/InputTypeNames.h"
33 #include "core/css/CSSStyleDeclaration.h" 33 #include "core/css/CSSStyleDeclaration.h"
34 #include "core/css/StylePropertySet.h" 34 #include "core/css/StylePropertySet.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/DocumentFragment.h" 36 #include "core/dom/DocumentFragment.h"
37 #include "core/dom/Element.h" 37 #include "core/dom/Element.h"
38 #include "core/dom/NodeComputedStyle.h"
39 #include "core/dom/Text.h" 38 #include "core/dom/Text.h"
40 #include "core/editing/EditingUtilities.h" 39 #include "core/editing/EditingUtilities.h"
41 #include "core/editing/FrameSelection.h" 40 #include "core/editing/FrameSelection.h"
42 #include "core/editing/VisibleUnits.h" 41 #include "core/editing/VisibleUnits.h"
43 #include "core/editing/commands/ApplyStyleCommand.h" 42 #include "core/editing/commands/ApplyStyleCommand.h"
44 #include "core/editing/commands/BreakBlockquoteCommand.h" 43 #include "core/editing/commands/BreakBlockquoteCommand.h"
45 #include "core/editing/commands/SimplifyMarkupCommand.h" 44 #include "core/editing/commands/SimplifyMarkupCommand.h"
46 #include "core/editing/commands/SmartReplace.h" 45 #include "core/editing/commands/SmartReplace.h"
47 #include "core/editing/iterators/TextIterator.h" 46 #include "core/editing/iterators/TextIterator.h"
48 #include "core/editing/serializers/HTMLInterchange.h" 47 #include "core/editing/serializers/HTMLInterchange.h"
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 || isHTMLStyleElement(*node) 787 || isHTMLStyleElement(*node)
789 || isHTMLTitleElement(*node)) { 788 || isHTMLTitleElement(*node)) {
790 next = NodeTraversal::nextSkippingChildren(*node); 789 next = NodeTraversal::nextSkippingChildren(*node);
791 fragment.removeNode(node); 790 fragment.removeNode(node);
792 } else { 791 } else {
793 next = NodeTraversal::next(*node); 792 next = NodeTraversal::next(*node);
794 } 793 }
795 } 794 }
796 } 795 }
797 796
798 static bool followBlockElementStyle(const Node* node)
799 {
800 if (!node->isHTMLElement())
801 return false;
802
803 const HTMLElement& element = toHTMLElement(*node);
804 return element.computedStyle()->display() == LIST_ITEM
805 || element.computedStyle()->display() == TABLE_CELL
806 || element.hasTagName(preTag)
807 || element.hasTagName(h1Tag)
808 || element.hasTagName(h2Tag)
809 || element.hasTagName(h3Tag)
810 || element.hasTagName(h4Tag)
811 || element.hasTagName(h5Tag)
812 || element.hasTagName(h6Tag);
813 }
814
815 // Remove style spans before insertion if they are unnecessary. It's faster bec ause we'll 797 // Remove style spans before insertion if they are unnecessary. It's faster bec ause we'll
816 // avoid doing a layout. 798 // avoid doing a layout.
817 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos) 799 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos)
818 { 800 {
819 Node* topNode = fragment.firstChild(); 801 Node* topNode = fragment.firstChild();
820 if (!isHTMLSpanElement(topNode)) 802 if (!isHTMLSpanElement(topNode))
821 return false; 803 return false;
822 804
823 // Handling the case where we are doing Paste as Quotation or pasting into q uoted content is more complicated (see handleStyleSpans) 805 // Handling the case where we are doing Paste as Quotation or pasting into q uoted content is more complicated (see handleStyleSpans)
824 // and doesn't receive the optimization. 806 // and doesn't receive the optimization.
825 if (isMailPasteAsQuotationHTMLBlockQuoteElement(topNode) || enclosingNodeOfT ype(firstPositionInOrBeforeNode(topNode), isMailHTMLBlockquoteElement, CanCrossE ditingBoundary)) 807 if (isMailPasteAsQuotationHTMLBlockQuoteElement(topNode) || enclosingNodeOfT ype(firstPositionInOrBeforeNode(topNode), isMailHTMLBlockquoteElement, CanCrossE ditingBoundary))
826 return false; 808 return false;
827 809
828 // Remove style spans to follow the styles of parent block element when |fra gment| becomes a part of it. 810 // Remove style spans to follow the styles of list item when |fragment| beco mes a list item.
829 // See bugs http://crbug.com/226941 and http://crbug.com/335955. 811 // See bug http://crbug.com/335955.
830 HTMLSpanElement* wrappingStyleSpan = toHTMLSpanElement(topNode); 812 HTMLSpanElement* wrappingStyleSpan = toHTMLSpanElement(topNode);
831 const Node* node = insertionPos.anchorNode(); 813 if (isListItem(enclosingBlock(insertionPos.anchorNode()))) {
832 // |node| can be an inline element like <br> under <li>
833 // e.g.) editing/execCommand/switch-list-type.html
834 // editing/deleting/backspace-merge-into-block.html
835 if (node->computedStyle()->display() == INLINE) {
836 if (!(node = enclosingBlock(insertionPos.anchorNode())))
837 return false;
838 }
839
840 if (followBlockElementStyle(node)) {
841 fragment.removeNodePreservingChildren(wrappingStyleSpan); 814 fragment.removeNodePreservingChildren(wrappingStyleSpan);
842 return true; 815 return true;
843 } 816 }
844 817
845 // Either there are no style spans in the fragment or a WebKit client has ad ded content to the fragment 818 // Either there are no style spans in the fragment or a WebKit client has ad ded content to the fragment
846 // before inserting it. Look for and handle style spans after insertion. 819 // before inserting it. Look for and handle style spans after insertion.
847 if (!isLegacyAppleHTMLSpanElement(topNode)) 820 if (!isLegacyAppleHTMLSpanElement(topNode))
848 return false; 821 return false;
849 822
850 EditingStyle* styleAtInsertionPos = EditingStyle::create(insertionPos.parent AnchoredEquivalent()); 823 EditingStyle* styleAtInsertionPos = EditingStyle::create(insertionPos.parent AnchoredEquivalent());
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 visitor->trace(m_startOfInsertedContent); 1729 visitor->trace(m_startOfInsertedContent);
1757 visitor->trace(m_endOfInsertedContent); 1730 visitor->trace(m_endOfInsertedContent);
1758 visitor->trace(m_insertionStyle); 1731 visitor->trace(m_insertionStyle);
1759 visitor->trace(m_documentFragment); 1732 visitor->trace(m_documentFragment);
1760 visitor->trace(m_startOfInsertedRange); 1733 visitor->trace(m_startOfInsertedRange);
1761 visitor->trace(m_endOfInsertedRange); 1734 visitor->trace(m_endOfInsertedRange);
1762 CompositeEditCommand::trace(visitor); 1735 CompositeEditCommand::trace(visitor);
1763 } 1736 }
1764 1737
1765 } // namespace blink 1738 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/deleting/merge-paragraph-from-p-with-style-3-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698