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

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

Issue 2102913002: Remove style spans to follow the styles of the block element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use of assert_selection() 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"
38 #include "core/dom/Text.h" 39 #include "core/dom/Text.h"
39 #include "core/editing/EditingUtilities.h" 40 #include "core/editing/EditingUtilities.h"
40 #include "core/editing/FrameSelection.h" 41 #include "core/editing/FrameSelection.h"
41 #include "core/editing/VisibleUnits.h" 42 #include "core/editing/VisibleUnits.h"
42 #include "core/editing/commands/ApplyStyleCommand.h" 43 #include "core/editing/commands/ApplyStyleCommand.h"
43 #include "core/editing/commands/BreakBlockquoteCommand.h" 44 #include "core/editing/commands/BreakBlockquoteCommand.h"
44 #include "core/editing/commands/SimplifyMarkupCommand.h" 45 #include "core/editing/commands/SimplifyMarkupCommand.h"
45 #include "core/editing/commands/SmartReplace.h" 46 #include "core/editing/commands/SmartReplace.h"
46 #include "core/editing/iterators/TextIterator.h" 47 #include "core/editing/iterators/TextIterator.h"
47 #include "core/editing/serializers/HTMLInterchange.h" 48 #include "core/editing/serializers/HTMLInterchange.h"
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 || isHTMLStyleElement(*node) 788 || isHTMLStyleElement(*node)
788 || isHTMLTitleElement(*node)) { 789 || isHTMLTitleElement(*node)) {
789 next = NodeTraversal::nextSkippingChildren(*node); 790 next = NodeTraversal::nextSkippingChildren(*node);
790 fragment.removeNode(node); 791 fragment.removeNode(node);
791 } else { 792 } else {
792 next = NodeTraversal::next(*node); 793 next = NodeTraversal::next(*node);
793 } 794 }
794 } 795 }
795 } 796 }
796 797
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
797 // Remove style spans before insertion if they are unnecessary. It's faster bec ause we'll 815 // Remove style spans before insertion if they are unnecessary. It's faster bec ause we'll
798 // avoid doing a layout. 816 // avoid doing a layout.
799 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos) 817 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos)
800 { 818 {
801 Node* topNode = fragment.firstChild(); 819 Node* topNode = fragment.firstChild();
802 if (!isHTMLSpanElement(topNode)) 820 if (!isHTMLSpanElement(topNode))
803 return false; 821 return false;
804 822
805 // Handling the case where we are doing Paste as Quotation or pasting into q uoted content is more complicated (see handleStyleSpans) 823 // Handling the case where we are doing Paste as Quotation or pasting into q uoted content is more complicated (see handleStyleSpans)
806 // and doesn't receive the optimization. 824 // and doesn't receive the optimization.
807 if (isMailPasteAsQuotationHTMLBlockQuoteElement(topNode) || enclosingNodeOfT ype(firstPositionInOrBeforeNode(topNode), isMailHTMLBlockquoteElement, CanCrossE ditingBoundary)) 825 if (isMailPasteAsQuotationHTMLBlockQuoteElement(topNode) || enclosingNodeOfT ype(firstPositionInOrBeforeNode(topNode), isMailHTMLBlockquoteElement, CanCrossE ditingBoundary))
808 return false; 826 return false;
809 827
810 // Remove style spans to follow the styles of list item when |fragment| beco mes a list item. 828 // Remove style spans to follow the styles of parent block element when |fra gment| becomes a part of it.
811 // See bug http://crbug.com/335955. 829 // See bugs http://crbug.com/226941 and http://crbug.com/335955.
812 HTMLSpanElement* wrappingStyleSpan = toHTMLSpanElement(topNode); 830 HTMLSpanElement* wrappingStyleSpan = toHTMLSpanElement(topNode);
813 if (isListItem(enclosingBlock(insertionPos.anchorNode()))) { 831 const Node* node = 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)) {
814 fragment.removeNodePreservingChildren(wrappingStyleSpan); 841 fragment.removeNodePreservingChildren(wrappingStyleSpan);
815 return true; 842 return true;
816 } 843 }
817 844
818 // Either there are no style spans in the fragment or a WebKit client has ad ded content to the fragment 845 // Either there are no style spans in the fragment or a WebKit client has ad ded content to the fragment
819 // before inserting it. Look for and handle style spans after insertion. 846 // before inserting it. Look for and handle style spans after insertion.
820 if (!isLegacyAppleHTMLSpanElement(topNode)) 847 if (!isLegacyAppleHTMLSpanElement(topNode))
821 return false; 848 return false;
822 849
823 EditingStyle* styleAtInsertionPos = EditingStyle::create(insertionPos.parent AnchoredEquivalent()); 850 EditingStyle* styleAtInsertionPos = EditingStyle::create(insertionPos.parent AnchoredEquivalent());
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 visitor->trace(m_startOfInsertedContent); 1756 visitor->trace(m_startOfInsertedContent);
1730 visitor->trace(m_endOfInsertedContent); 1757 visitor->trace(m_endOfInsertedContent);
1731 visitor->trace(m_insertionStyle); 1758 visitor->trace(m_insertionStyle);
1732 visitor->trace(m_documentFragment); 1759 visitor->trace(m_documentFragment);
1733 visitor->trace(m_startOfInsertedRange); 1760 visitor->trace(m_startOfInsertedRange);
1734 visitor->trace(m_endOfInsertedRange); 1761 visitor->trace(m_endOfInsertedRange);
1735 CompositeEditCommand::trace(visitor); 1762 CompositeEditCommand::trace(visitor);
1736 } 1763 }
1737 1764
1738 } // namespace blink 1765 } // 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