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

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

Issue 2135993003: Add null check to fix crash in blink::ComputedStyle::display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use of the short form for running the insertHTML command 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
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 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 } 793 }
794 } 794 }
795 } 795 }
796 796
797 static bool followBlockElementStyle(const Node* node) 797 static bool followBlockElementStyle(const Node* node)
798 { 798 {
799 if (!node->isHTMLElement()) 799 if (!node->isHTMLElement())
800 return false; 800 return false;
801 801
802 const HTMLElement& element = toHTMLElement(*node); 802 const HTMLElement& element = toHTMLElement(*node);
803 return element.computedStyle()->display() == LIST_ITEM 803 return isListItem(node)
804 || element.computedStyle()->display() == TABLE_CELL 804 || isTableCell(node)
805 || element.hasTagName(preTag) 805 || element.hasTagName(preTag)
806 || element.hasTagName(h1Tag) 806 || element.hasTagName(h1Tag)
807 || element.hasTagName(h2Tag) 807 || element.hasTagName(h2Tag)
808 || element.hasTagName(h3Tag) 808 || element.hasTagName(h3Tag)
809 || element.hasTagName(h4Tag) 809 || element.hasTagName(h4Tag)
810 || element.hasTagName(h5Tag) 810 || element.hasTagName(h5Tag)
811 || element.hasTagName(h6Tag); 811 || element.hasTagName(h6Tag);
812 } 812 }
813 813
814 // Remove style spans before insertion if they are unnecessary. It's faster bec ause we'll 814 // Remove style spans before insertion if they are unnecessary. It's faster bec ause we'll
815 // avoid doing a layout. 815 // avoid doing a layout.
816 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos) 816 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos)
817 { 817 {
818 Node* topNode = fragment.firstChild(); 818 Node* topNode = fragment.firstChild();
819 if (!isHTMLSpanElement(topNode)) 819 if (!isHTMLSpanElement(topNode))
820 return false; 820 return false;
821 821
822 // Handling the case where we are doing Paste as Quotation or pasting into q uoted content is more complicated (see handleStyleSpans) 822 // Handling the case where we are doing Paste as Quotation or pasting into q uoted content is more complicated (see handleStyleSpans)
823 // and doesn't receive the optimization. 823 // and doesn't receive the optimization.
824 if (isMailPasteAsQuotationHTMLBlockQuoteElement(topNode) || enclosingNodeOfT ype(firstPositionInOrBeforeNode(topNode), isMailHTMLBlockquoteElement, CanCrossE ditingBoundary)) 824 if (isMailPasteAsQuotationHTMLBlockQuoteElement(topNode) || enclosingNodeOfT ype(firstPositionInOrBeforeNode(topNode), isMailHTMLBlockquoteElement, CanCrossE ditingBoundary))
825 return false; 825 return false;
826 826
827 // Remove style spans to follow the styles of parent block element when |fra gment| becomes a part of it. 827 // Remove style spans to follow the styles of parent block element when |fra gment| becomes a part of it.
828 // See bugs http://crbug.com/226941 and http://crbug.com/335955. 828 // See bugs http://crbug.com/226941 and http://crbug.com/335955.
829 HTMLSpanElement* wrappingStyleSpan = toHTMLSpanElement(topNode); 829 HTMLSpanElement* wrappingStyleSpan = toHTMLSpanElement(topNode);
830 const Node* node = insertionPos.anchorNode(); 830 const Node* node = insertionPos.anchorNode();
831 // |node| can be an inline element like <br> under <li> 831 // |node| can be an inline element like <br> under <li>
832 // e.g.) editing/execCommand/switch-list-type.html 832 // e.g.) editing/execCommand/switch-list-type.html
833 // editing/deleting/backspace-merge-into-block.html 833 // editing/deleting/backspace-merge-into-block.html
834 if (node->computedStyle()->display() == INLINE) { 834 if (isInline(node)) {
835 node = enclosingBlock(insertionPos.anchorNode()); 835 node = enclosingBlock(insertionPos.anchorNode());
836 if (!node) 836 if (!node)
837 return false; 837 return false;
838 } 838 }
839 839
840 if (followBlockElementStyle(node)) { 840 if (followBlockElementStyle(node)) {
841 fragment.removeNodePreservingChildren(wrappingStyleSpan); 841 fragment.removeNodePreservingChildren(wrappingStyleSpan);
842 return true; 842 return true;
843 } 843 }
844 844
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 visitor->trace(m_startOfInsertedContent); 1756 visitor->trace(m_startOfInsertedContent);
1757 visitor->trace(m_endOfInsertedContent); 1757 visitor->trace(m_endOfInsertedContent);
1758 visitor->trace(m_insertionStyle); 1758 visitor->trace(m_insertionStyle);
1759 visitor->trace(m_documentFragment); 1759 visitor->trace(m_documentFragment);
1760 visitor->trace(m_startOfInsertedRange); 1760 visitor->trace(m_startOfInsertedRange);
1761 visitor->trace(m_endOfInsertedRange); 1761 visitor->trace(m_endOfInsertedRange);
1762 CompositeEditCommand::trace(visitor); 1762 CompositeEditCommand::trace(visitor);
1763 } 1763 }
1764 1764
1765 } // namespace blink 1765 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698