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

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

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation. Created 4 years, 8 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, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (attributes.isEmpty()) 79 if (attributes.isEmpty())
80 return true; 80 return true;
81 81
82 unsigned matchedAttributes = 0; 82 unsigned matchedAttributes = 0;
83 if (element->getAttribute(classAttr) == styleSpanClassString()) 83 if (element->getAttribute(classAttr) == styleSpanClassString())
84 matchedAttributes++; 84 matchedAttributes++;
85 if (element->hasAttribute(styleAttr) && (shouldStyleAttributeBeEmpty == Allo wNonEmptyStyleAttribute 85 if (element->hasAttribute(styleAttr) && (shouldStyleAttributeBeEmpty == Allo wNonEmptyStyleAttribute
86 || !element->inlineStyle() || element->inlineStyle()->isEmpty())) 86 || !element->inlineStyle() || element->inlineStyle()->isEmpty()))
87 matchedAttributes++; 87 matchedAttributes++;
88 88
89 ASSERT(matchedAttributes <= attributes.size()); 89 DCHECK_LE(matchedAttributes, attributes.size());
90 return matchedAttributes == attributes.size(); 90 return matchedAttributes == attributes.size();
91 } 91 }
92 92
93 bool isStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element) 93 bool isStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element)
94 { 94 {
95 if (!isHTMLSpanElement(element)) 95 if (!isHTMLSpanElement(element))
96 return false; 96 return false;
97 return hasNoAttributeOrOnlyStyleAttribute(toHTMLSpanElement(element), AllowN onEmptyStyleAttribute); 97 return hasNoAttributeOrOnlyStyleAttribute(toHTMLSpanElement(element), AllowN onEmptyStyleAttribute);
98 } 98 }
99 99
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 , m_end(mostBackwardCaretPosition(endingSelection().end())) 163 , m_end(mostBackwardCaretPosition(endingSelection().end()))
164 , m_useEndingSelection(true) 164 , m_useEndingSelection(true)
165 , m_styledInlineElement(nullptr) 165 , m_styledInlineElement(nullptr)
166 , m_removeOnly(true) 166 , m_removeOnly(true)
167 , m_isInlineElementToRemoveFunction(isInlineElementToRemoveFunction) 167 , m_isInlineElementToRemoveFunction(isInlineElementToRemoveFunction)
168 { 168 {
169 } 169 }
170 170
171 void ApplyStyleCommand::updateStartEnd(const Position& newStart, const Position& newEnd) 171 void ApplyStyleCommand::updateStartEnd(const Position& newStart, const Position& newEnd)
172 { 172 {
173 ASSERT(comparePositions(newEnd, newStart) >= 0); 173 DCHECK_GE(comparePositions(newEnd, newStart), 0);
174 174
175 if (!m_useEndingSelection && (newStart != m_start || newEnd != m_end)) 175 if (!m_useEndingSelection && (newStart != m_start || newEnd != m_end))
176 m_useEndingSelection = true; 176 m_useEndingSelection = true;
177 177
178 setEndingSelection(VisibleSelection(newStart, newEnd, VP_DEFAULT_AFFINITY, e ndingSelection().isDirectional())); 178 setEndingSelection(VisibleSelection(newStart, newEnd, VP_DEFAULT_AFFINITY, e ndingSelection().isDirectional()));
179 m_start = newStart; 179 m_start = newStart;
180 m_end = newEnd; 180 m_end = newEnd;
181 } 181 }
182 182
183 Position ApplyStyleCommand::startPosition() 183 Position ApplyStyleCommand::startPosition()
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 if (isValidCaretPositionInTextNode(end)) { 352 if (isValidCaretPositionInTextNode(end)) {
353 splitTextAtEnd(start, end); 353 splitTextAtEnd(start, end);
354 start = startPosition(); 354 start = startPosition();
355 end = endPosition(); 355 end = endPosition();
356 } 356 }
357 357
358 // Calculate loop end point. 358 // Calculate loop end point.
359 // If the end node is before the start node (can only happen if the end node is 359 // If the end node is before the start node (can only happen if the end node is
360 // an ancestor of the start node), we gather nodes up to the next sibling of the end node 360 // an ancestor of the start node), we gather nodes up to the next sibling of the end node
361 Node* beyondEnd; 361 Node* beyondEnd;
362 ASSERT(start.anchorNode()); 362 DCHECK(start.anchorNode());
363 ASSERT(end.anchorNode()); 363 DCHECK(end.anchorNode());
364 if (start.anchorNode()->isDescendantOf(end.anchorNode())) 364 if (start.anchorNode()->isDescendantOf(end.anchorNode()))
365 beyondEnd = NodeTraversal::nextSkippingChildren(*end.anchorNode()); 365 beyondEnd = NodeTraversal::nextSkippingChildren(*end.anchorNode());
366 else 366 else
367 beyondEnd = NodeTraversal::next(*end.anchorNode()); 367 beyondEnd = NodeTraversal::next(*end.anchorNode());
368 368
369 start = mostBackwardCaretPosition(start); // Move upstream to ensure we do n ot add redundant spans. 369 start = mostBackwardCaretPosition(start); // Move upstream to ensure we do n ot add redundant spans.
370 Node* startNode = start.anchorNode(); 370 Node* startNode = start.anchorNode();
371 ASSERT(startNode); 371 DCHECK(startNode);
372 372
373 // Make sure we're not already at the end or the next NodeTraversal::next() will traverse 373 // Make sure we're not already at the end or the next NodeTraversal::next() will traverse
374 // past it. 374 // past it.
375 if (startNode == beyondEnd) 375 if (startNode == beyondEnd)
376 return; 376 return;
377 377
378 if (startNode->isTextNode() && start.computeOffsetInContainerNode() >= caret MaxOffset(startNode)) { 378 if (startNode->isTextNode() && start.computeOffsetInContainerNode() >= caret MaxOffset(startNode)) {
379 // Move out of text node if range does not include its characters. 379 // Move out of text node if range does not include its characters.
380 startNode = NodeTraversal::next(*startNode); 380 startNode = NodeTraversal::next(*startNode);
381 if (!startNode) 381 if (!startNode)
382 return; 382 return;
383 } 383 }
384 384
385 // Store away font size before making any changes to the document. 385 // Store away font size before making any changes to the document.
386 // This ensures that changes to one node won't effect another. 386 // This ensures that changes to one node won't effect another.
387 HeapHashMap<Member<Node>, float> startingFontSizes; 387 HeapHashMap<Member<Node>, float> startingFontSizes;
388 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) { 388 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) {
389 ASSERT(node); 389 DCHECK(node);
390 startingFontSizes.set(node, computedFontSize(node)); 390 startingFontSizes.set(node, computedFontSize(node));
391 } 391 }
392 392
393 // These spans were added by us. If empty after font size changes, they can be removed. 393 // These spans were added by us. If empty after font size changes, they can be removed.
394 HeapVector<Member<HTMLElement>> unstyledSpans; 394 HeapVector<Member<HTMLElement>> unstyledSpans;
395 395
396 Node* lastStyledNode = nullptr; 396 Node* lastStyledNode = nullptr;
397 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) { 397 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) {
398 ASSERT(node); 398 DCHECK(node);
399 RawPtr<HTMLElement> element = nullptr; 399 RawPtr<HTMLElement> element = nullptr;
400 if (node->isHTMLElement()) { 400 if (node->isHTMLElement()) {
401 // Only work on fully selected nodes. 401 // Only work on fully selected nodes.
402 if (!elementFullySelected(toHTMLElement(*node), start, end)) 402 if (!elementFullySelected(toHTMLElement(*node), start, end))
403 continue; 403 continue;
404 element = toHTMLElement(node); 404 element = toHTMLElement(node);
405 } else if (node->isTextNode() && node->layoutObject() && node->parentNod e() != lastStyledNode) { 405 } else if (node->isTextNode() && node->layoutObject() && node->parentNod e() != lastStyledNode) {
406 // Last styled node was not parent node of this text node, but we wi sh to style this 406 // Last styled node was not parent node of this text node, but we wi sh to style this
407 // text node. To make this possible, add a style span to surround th is text node. 407 // text node. To make this possible, add a style span to surround th is text node.
408 RawPtr<HTMLSpanElement> span = HTMLSpanElement::create(document()); 408 RawPtr<HTMLSpanElement> span = HTMLSpanElement::create(document());
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 696
697 RawPtr<EditingStyle> styleToApply = style; 697 RawPtr<EditingStyle> styleToApply = style;
698 if (hasTextDirection) { 698 if (hasTextDirection) {
699 // Avoid applying the unicode-bidi and direction properties beneath ance stors that already have them. 699 // Avoid applying the unicode-bidi and direction properties beneath ance stors that already have them.
700 HTMLElement* embeddingStartElement = highestEmbeddingAncestor(start.anch orNode(), enclosingBlock(start.anchorNode())); 700 HTMLElement* embeddingStartElement = highestEmbeddingAncestor(start.anch orNode(), enclosingBlock(start.anchorNode()));
701 HTMLElement* embeddingEndElement = highestEmbeddingAncestor(end.anchorNo de(), enclosingBlock(end.anchorNode())); 701 HTMLElement* embeddingEndElement = highestEmbeddingAncestor(end.anchorNo de(), enclosingBlock(end.anchorNode()));
702 702
703 if (embeddingStartElement || embeddingEndElement) { 703 if (embeddingStartElement || embeddingEndElement) {
704 Position embeddingApplyStart = embeddingStartElement ? positionInPar entAfterNode(*embeddingStartElement) : start; 704 Position embeddingApplyStart = embeddingStartElement ? positionInPar entAfterNode(*embeddingStartElement) : start;
705 Position embeddingApplyEnd = embeddingEndElement ? positionInParentB eforeNode(*embeddingEndElement) : end; 705 Position embeddingApplyEnd = embeddingEndElement ? positionInParentB eforeNode(*embeddingEndElement) : end;
706 ASSERT(embeddingApplyStart.isNotNull() && embeddingApplyEnd.isNotNul l()); 706 DCHECK(embeddingApplyStart.isNotNull() && embeddingApplyEnd.isNotNul l());
707 707
708 if (!embeddingStyle) { 708 if (!embeddingStyle) {
709 styleWithoutEmbedding = style->copy(); 709 styleWithoutEmbedding = style->copy();
710 embeddingStyle = styleWithoutEmbedding->extractAndRemoveTextDire ction(); 710 embeddingStyle = styleWithoutEmbedding->extractAndRemoveTextDire ction();
711 } 711 }
712 fixRangeAndApplyInlineStyle(embeddingStyle.get(), embeddingApplyStar t, embeddingApplyEnd, editingState); 712 fixRangeAndApplyInlineStyle(embeddingStyle.get(), embeddingApplyStar t, embeddingApplyEnd, editingState);
713 if (editingState->isAborted()) 713 if (editingState->isAborted())
714 return; 714 return;
715 715
716 styleToApply = styleWithoutEmbedding; 716 styleToApply = styleWithoutEmbedding;
717 } 717 }
718 } 718 }
719 719
720 fixRangeAndApplyInlineStyle(styleToApply.get(), start, end, editingState); 720 fixRangeAndApplyInlineStyle(styleToApply.get(), start, end, editingState);
721 if (editingState->isAborted()) 721 if (editingState->isAborted())
722 return; 722 return;
723 723
724 // Remove dummy style spans created by splitting text elements. 724 // Remove dummy style spans created by splitting text elements.
725 cleanupUnstyledAppleStyleSpans(startDummySpanAncestor.get(), editingState); 725 cleanupUnstyledAppleStyleSpans(startDummySpanAncestor.get(), editingState);
726 if (editingState->isAborted()) 726 if (editingState->isAborted())
727 return; 727 return;
728 if (endDummySpanAncestor != startDummySpanAncestor) 728 if (endDummySpanAncestor != startDummySpanAncestor)
729 cleanupUnstyledAppleStyleSpans(endDummySpanAncestor.get(), editingState) ; 729 cleanupUnstyledAppleStyleSpans(endDummySpanAncestor.get(), editingState) ;
730 } 730 }
731 731
732 void ApplyStyleCommand::fixRangeAndApplyInlineStyle(EditingStyle* style, const P osition& start, const Position& end, EditingState* editingState) 732 void ApplyStyleCommand::fixRangeAndApplyInlineStyle(EditingStyle* style, const P osition& start, const Position& end, EditingState* editingState)
733 { 733 {
734 Node* startNode = start.anchorNode(); 734 Node* startNode = start.anchorNode();
735 ASSERT(startNode); 735 DCHECK(startNode);
736 736
737 if (start.computeEditingOffset() >= caretMaxOffset(start.anchorNode())) { 737 if (start.computeEditingOffset() >= caretMaxOffset(start.anchorNode())) {
738 startNode = NodeTraversal::next(*startNode); 738 startNode = NodeTraversal::next(*startNode);
739 if (!startNode || comparePositions(end, firstPositionInOrBeforeNode(star tNode)) < 0) 739 if (!startNode || comparePositions(end, firstPositionInOrBeforeNode(star tNode)) < 0)
740 return; 740 return;
741 } 741 }
742 742
743 Node* pastEndNode = end.anchorNode(); 743 Node* pastEndNode = end.anchorNode();
744 if (end.computeEditingOffset() >= caretMaxOffset(end.anchorNode())) 744 if (end.computeEditingOffset() >= caretMaxOffset(end.anchorNode()))
745 pastEndNode = NodeTraversal::nextSkippingChildren(*end.anchorNode()); 745 pastEndNode = NodeTraversal::nextSkippingChildren(*end.anchorNode());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 } 777 }
778 778
779 class InlineRunToApplyStyle { 779 class InlineRunToApplyStyle {
780 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 780 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
781 public: 781 public:
782 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode) 782 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode)
783 : start(start) 783 : start(start)
784 , end(end) 784 , end(end)
785 , pastEndNode(pastEndNode) 785 , pastEndNode(pastEndNode)
786 { 786 {
787 ASSERT(start->parentNode() == end->parentNode()); 787 DCHECK_EQ(start->parentNode(), end->parentNode());
788 } 788 }
789 789
790 bool startAndEndAreStillInDocument() 790 bool startAndEndAreStillInDocument()
791 { 791 {
792 return start && end && start->inShadowIncludingDocument() && end->inShad owIncludingDocument(); 792 return start && end && start->inShadowIncludingDocument() && end->inShad owIncludingDocument();
793 } 793 }
794 794
795 DEFINE_INLINE_TRACE() 795 DEFINE_INLINE_TRACE()
796 { 796 {
797 visitor->trace(start); 797 visitor->trace(start);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 861
862 Node* runStart = node.get(); 862 Node* runStart = node.get();
863 Node* runEnd = node.get(); 863 Node* runEnd = node.get();
864 Node* sibling = node->nextSibling(); 864 Node* sibling = node->nextSibling();
865 while (sibling && sibling != pastEndNode && !sibling->contains(pastEndNo de.get()) 865 while (sibling && sibling != pastEndNode && !sibling->contains(pastEndNo de.get())
866 && (!isEnclosingBlock(sibling) || isHTMLBRElement(*sibling)) 866 && (!isEnclosingBlock(sibling) || isHTMLBRElement(*sibling))
867 && !containsNonEditableRegion(*sibling)) { 867 && !containsNonEditableRegion(*sibling)) {
868 runEnd = sibling; 868 runEnd = sibling;
869 sibling = runEnd->nextSibling(); 869 sibling = runEnd->nextSibling();
870 } 870 }
871 ASSERT(runEnd); 871 DCHECK(runEnd);
872 next = NodeTraversal::nextSkippingChildren(*runEnd); 872 next = NodeTraversal::nextSkippingChildren(*runEnd);
873 873
874 Node* pastEndNode = NodeTraversal::nextSkippingChildren(*runEnd); 874 Node* pastEndNode = NodeTraversal::nextSkippingChildren(*runEnd);
875 if (!shouldApplyInlineStyleToRun(style, runStart, pastEndNode)) 875 if (!shouldApplyInlineStyleToRun(style, runStart, pastEndNode))
876 continue; 876 continue;
877 877
878 runs.append(InlineRunToApplyStyle(runStart, runEnd, pastEndNode)); 878 runs.append(InlineRunToApplyStyle(runStart, runEnd, pastEndNode));
879 } 879 }
880 880
881 for (auto& run : runs) { 881 for (auto& run : runs) {
(...skipping 29 matching lines...) Expand all
911 } 911 }
912 912
913 bool ApplyStyleCommand::isStyledInlineElementToRemove(Element* element) const 913 bool ApplyStyleCommand::isStyledInlineElementToRemove(Element* element) const
914 { 914 {
915 return (m_styledInlineElement && element->hasTagName(m_styledInlineElement-> tagQName())) 915 return (m_styledInlineElement && element->hasTagName(m_styledInlineElement-> tagQName()))
916 || (m_isInlineElementToRemoveFunction && m_isInlineElementToRemoveFuncti on(element)); 916 || (m_isInlineElementToRemoveFunction && m_isInlineElementToRemoveFuncti on(element));
917 } 917 }
918 918
919 bool ApplyStyleCommand::shouldApplyInlineStyleToRun(EditingStyle* style, Node* r unStart, Node* pastEndNode) 919 bool ApplyStyleCommand::shouldApplyInlineStyleToRun(EditingStyle* style, Node* r unStart, Node* pastEndNode)
920 { 920 {
921 ASSERT(style && runStart); 921 DCHECK(style && runStart);
922 922
923 for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversa l::next(*node)) { 923 for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversa l::next(*node)) {
924 if (node->hasChildren()) 924 if (node->hasChildren())
925 continue; 925 continue;
926 // We don't consider m_isInlineElementToRemoveFunction here because we n ever apply style when m_isInlineElementToRemoveFunction is specified 926 // We don't consider m_isInlineElementToRemoveFunction here because we n ever apply style when m_isInlineElementToRemoveFunction is specified
927 if (!style->styleIsPresentInComputedStyleOfNode(node)) 927 if (!style->styleIsPresentInComputedStyleOfNode(node))
928 return true; 928 return true;
929 if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode (node), m_styledInlineElement->tagQName())) 929 if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode (node), m_styledInlineElement->tagQName()))
930 return true; 930 return true;
931 } 931 }
932 return false; 932 return false;
933 } 933 }
934 934
935 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style, Member<Node>& runStart, Member<Node>& runEnd, RawPtr<Node> pastEndNode, Editing State* editingState) 935 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style, Member<Node>& runStart, Member<Node>& runEnd, RawPtr<Node> pastEndNode, Editing State* editingState)
936 { 936 {
937 ASSERT(runStart && runEnd); 937 DCHECK(runStart && runEnd);
938 RawPtr<Node> next = runStart; 938 RawPtr<Node> next = runStart;
939 for (RawPtr<Node> node = next; node && node->inShadowIncludingDocument() && node != pastEndNode; node = next) { 939 for (RawPtr<Node> node = next; node && node->inShadowIncludingDocument() && node != pastEndNode; node = next) {
940 if (editingIgnoresContent(node.get())) { 940 if (editingIgnoresContent(node.get())) {
941 ASSERT(!node->contains(pastEndNode.get())); 941 DCHECK(!node->contains(pastEndNode.get()));
942 next = NodeTraversal::nextSkippingChildren(*node); 942 next = NodeTraversal::nextSkippingChildren(*node);
943 } else { 943 } else {
944 next = NodeTraversal::next(*node); 944 next = NodeTraversal::next(*node);
945 } 945 }
946 if (!node->isHTMLElement()) 946 if (!node->isHTMLElement())
947 continue; 947 continue;
948 948
949 HTMLElement& element = toHTMLElement(*node); 949 HTMLElement& element = toHTMLElement(*node);
950 RawPtr<Node> previousSibling = element.previousSibling(); 950 RawPtr<Node> previousSibling = element.previousSibling();
951 RawPtr<Node> nextSibling = element.nextSibling(); 951 RawPtr<Node> nextSibling = element.nextSibling();
952 RawPtr<ContainerNode> parent = element.parentNode(); 952 RawPtr<ContainerNode> parent = element.parentNode();
953 removeInlineStyleFromElement(style, &element, editingState, RemoveAlways ); 953 removeInlineStyleFromElement(style, &element, editingState, RemoveAlways );
954 if (editingState->isAborted()) 954 if (editingState->isAborted())
955 return; 955 return;
956 if (!element.inShadowIncludingDocument()) { 956 if (!element.inShadowIncludingDocument()) {
957 // FIXME: We might need to update the start and the end of current s election here but need a test. 957 // FIXME: We might need to update the start and the end of current s election here but need a test.
958 if (runStart == element) 958 if (runStart == element)
959 runStart = previousSibling ? previousSibling->nextSibling() : pa rent->firstChild(); 959 runStart = previousSibling ? previousSibling->nextSibling() : pa rent->firstChild();
960 if (runEnd == element) 960 if (runEnd == element)
961 runEnd = nextSibling ? nextSibling->previousSibling() : parent-> lastChild(); 961 runEnd = nextSibling ? nextSibling->previousSibling() : parent-> lastChild();
962 } 962 }
963 } 963 }
964 } 964 }
965 965
966 bool ApplyStyleCommand::removeInlineStyleFromElement(EditingStyle* style, RawPtr <HTMLElement> element, EditingState* editingState, InlineStyleRemovalMode mode, EditingStyle* extractedStyle) 966 bool ApplyStyleCommand::removeInlineStyleFromElement(EditingStyle* style, RawPtr <HTMLElement> element, EditingState* editingState, InlineStyleRemovalMode mode, EditingStyle* extractedStyle)
967 { 967 {
968 ASSERT(element); 968 DCHECK(element);
969 969
970 if (!element->parentNode() || !element->parentNode()->isContentEditable(Node ::UserSelectAllIsAlwaysNonEditable)) 970 if (!element->parentNode() || !element->parentNode()->isContentEditable(Node ::UserSelectAllIsAlwaysNonEditable))
971 return false; 971 return false;
972 972
973 if (isStyledInlineElementToRemove(element.get())) { 973 if (isStyledInlineElementToRemove(element.get())) {
974 if (mode == RemoveNone) 974 if (mode == RemoveNone)
975 return true; 975 return true;
976 if (extractedStyle) 976 if (extractedStyle)
977 extractedStyle->mergeInlineStyleOfElement(element.get(), EditingStyl e::OverrideValues); 977 extractedStyle->mergeInlineStyleOfElement(element.get(), EditingStyl e::OverrideValues);
978 removeNodePreservingChildren(element, editingState); 978 removeNodePreservingChildren(element, editingState);
(...skipping 22 matching lines...) Expand all
1001 void ApplyStyleCommand::replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement* elem, EditingState* editingState) 1001 void ApplyStyleCommand::replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement* elem, EditingState* editingState)
1002 { 1002 {
1003 if (hasNoAttributeOrOnlyStyleAttribute(elem, StyleAttributeShouldBeEmpty)) 1003 if (hasNoAttributeOrOnlyStyleAttribute(elem, StyleAttributeShouldBeEmpty))
1004 removeNodePreservingChildren(elem, editingState); 1004 removeNodePreservingChildren(elem, editingState);
1005 else 1005 else
1006 replaceElementWithSpanPreservingChildrenAndAttributes(elem); 1006 replaceElementWithSpanPreservingChildrenAndAttributes(elem);
1007 } 1007 }
1008 1008
1009 bool ApplyStyleCommand::removeImplicitlyStyledElement(EditingStyle* style, HTMLE lement* element, InlineStyleRemovalMode mode, EditingStyle* extractedStyle, Edit ingState* editingState) 1009 bool ApplyStyleCommand::removeImplicitlyStyledElement(EditingStyle* style, HTMLE lement* element, InlineStyleRemovalMode mode, EditingStyle* extractedStyle, Edit ingState* editingState)
1010 { 1010 {
1011 ASSERT(style); 1011 DCHECK(style);
1012 if (mode == RemoveNone) { 1012 if (mode == RemoveNone) {
1013 ASSERT(!extractedStyle); 1013 DCHECK(!extractedStyle);
1014 return style->conflictsWithImplicitStyleOfElement(element) || style->con flictsWithImplicitStyleOfAttributes(element); 1014 return style->conflictsWithImplicitStyleOfElement(element) || style->con flictsWithImplicitStyleOfAttributes(element);
1015 } 1015 }
1016 1016
1017 ASSERT(mode == RemoveIfNeeded || mode == RemoveAlways); 1017 DCHECK(mode == RemoveIfNeeded || mode == RemoveAlways);
1018 if (style->conflictsWithImplicitStyleOfElement(element, extractedStyle, mode == RemoveAlways ? EditingStyle::ExtractMatchingStyle : EditingStyle::DoNotExtra ctMatchingStyle)) { 1018 if (style->conflictsWithImplicitStyleOfElement(element, extractedStyle, mode == RemoveAlways ? EditingStyle::ExtractMatchingStyle : EditingStyle::DoNotExtra ctMatchingStyle)) {
1019 replaceWithSpanOrRemoveIfWithoutAttributes(element, editingState); 1019 replaceWithSpanOrRemoveIfWithoutAttributes(element, editingState);
1020 if (editingState->isAborted()) 1020 if (editingState->isAborted())
1021 return false; 1021 return false;
1022 return true; 1022 return true;
1023 } 1023 }
1024 1024
1025 // unicode-bidi and direction are pushed down separately so don't push down with other styles 1025 // unicode-bidi and direction are pushed down separately so don't push down with other styles
1026 Vector<QualifiedName> attributes; 1026 Vector<QualifiedName> attributes;
1027 if (!style->extractConflictingImplicitStyleOfAttributes(element, extractedSt yle ? EditingStyle::PreserveWritingDirection : EditingStyle::DoNotPreserveWritin gDirection, 1027 if (!style->extractConflictingImplicitStyleOfAttributes(element, extractedSt yle ? EditingStyle::PreserveWritingDirection : EditingStyle::DoNotPreserveWritin gDirection,
1028 extractedStyle, attributes, mode == RemoveAlways ? EditingStyle::Extract MatchingStyle : EditingStyle::DoNotExtractMatchingStyle)) 1028 extractedStyle, attributes, mode == RemoveAlways ? EditingStyle::Extract MatchingStyle : EditingStyle::DoNotExtractMatchingStyle))
1029 return false; 1029 return false;
1030 1030
1031 for (const auto& attribute : attributes) 1031 for (const auto& attribute : attributes)
1032 removeElementAttribute(element, attribute); 1032 removeElementAttribute(element, attribute);
1033 1033
1034 if (isEmptyFontTag(element) || isSpanWithoutAttributesOrUnstyledStyleSpan(el ement)) { 1034 if (isEmptyFontTag(element) || isSpanWithoutAttributesOrUnstyledStyleSpan(el ement)) {
1035 removeNodePreservingChildren(element, editingState); 1035 removeNodePreservingChildren(element, editingState);
1036 if (editingState->isAborted()) 1036 if (editingState->isAborted())
1037 return false; 1037 return false;
1038 } 1038 }
1039 1039
1040 return true; 1040 return true;
1041 } 1041 }
1042 1042
1043 bool ApplyStyleCommand::removeCSSStyle(EditingStyle* style, HTMLElement* element , EditingState* editingState, InlineStyleRemovalMode mode, EditingStyle* extract edStyle) 1043 bool ApplyStyleCommand::removeCSSStyle(EditingStyle* style, HTMLElement* element , EditingState* editingState, InlineStyleRemovalMode mode, EditingStyle* extract edStyle)
1044 { 1044 {
1045 ASSERT(style); 1045 DCHECK(style);
1046 ASSERT(element); 1046 DCHECK(element);
1047 1047
1048 if (mode == RemoveNone) 1048 if (mode == RemoveNone)
1049 return style->conflictsWithInlineStyleOfElement(element); 1049 return style->conflictsWithInlineStyleOfElement(element);
1050 1050
1051 Vector<CSSPropertyID> properties; 1051 Vector<CSSPropertyID> properties;
1052 if (!style->conflictsWithInlineStyleOfElement(element, extractedStyle, prope rties)) 1052 if (!style->conflictsWithInlineStyleOfElement(element, extractedStyle, prope rties))
1053 return false; 1053 return false;
1054 1054
1055 // FIXME: We should use a mass-removal function here but we don't have an un doable one yet. 1055 // FIXME: We should use a mass-removal function here but we don't have an un doable one yet.
1056 for (const auto& property : properties) 1056 for (const auto& property : properties)
(...skipping 20 matching lines...) Expand all
1077 // also stop at the unsplittable element to be consistent with other UAs 1077 // also stop at the unsplittable element to be consistent with other UAs
1078 if (n == unsplittableElement) 1078 if (n == unsplittableElement)
1079 break; 1079 break;
1080 } 1080 }
1081 1081
1082 return result; 1082 return result;
1083 } 1083 }
1084 1084
1085 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty le, EditingState* editingState) 1085 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty le, EditingState* editingState)
1086 { 1086 {
1087 ASSERT(node); 1087 DCHECK(node);
1088 1088
1089 node->document().updateLayoutTree(); 1089 node->document().updateLayoutTree();
1090 1090
1091 if (!style || style->isEmpty() || !node->layoutObject() || isHTMLIFrameEleme nt(*node)) 1091 if (!style || style->isEmpty() || !node->layoutObject() || isHTMLIFrameEleme nt(*node))
1092 return; 1092 return;
1093 1093
1094 RawPtr<EditingStyle> newInlineStyle = style; 1094 RawPtr<EditingStyle> newInlineStyle = style;
1095 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { 1095 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) {
1096 newInlineStyle = style->copy(); 1096 newInlineStyle = style->copy();
1097 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt yle::OverrideValues); 1097 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt yle::OverrideValues);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 // We found the next node for the outer loop (contains targetNode) 1171 // We found the next node for the outer loop (contains targetNode)
1172 // When reached targetNode, stop the outer loop upon the completion of the current inner loop 1172 // When reached targetNode, stop the outer loop upon the completion of the current inner loop
1173 if (child == targetNode || child->contains(targetNode)) 1173 if (child == targetNode || child->contains(targetNode))
1174 current = child; 1174 current = child;
1175 } 1175 }
1176 } 1176 }
1177 } 1177 }
1178 1178
1179 void ApplyStyleCommand::removeInlineStyle(EditingStyle* style, const Position &s tart, const Position &end, EditingState* editingState) 1179 void ApplyStyleCommand::removeInlineStyle(EditingStyle* style, const Position &s tart, const Position &end, EditingState* editingState)
1180 { 1180 {
1181 ASSERT(start.isNotNull()); 1181 DCHECK(start.isNotNull());
1182 ASSERT(end.isNotNull()); 1182 DCHECK(end.isNotNull());
1183 ASSERT(start.inShadowIncludingDocument()); 1183 DCHECK(start.inShadowIncludingDocument());
1184 ASSERT(end.inShadowIncludingDocument()); 1184 DCHECK(end.inShadowIncludingDocument());
1185 ASSERT(Position::commonAncestorTreeScope(start, end)); 1185 DCHECK(Position::commonAncestorTreeScope(start, end));
1186 ASSERT(comparePositions(start, end) <= 0); 1186 DCHECK_LE(comparePositions(start, end), 0);
1187 // FIXME: We should assert that start/end are not in the middle of a text no de. 1187 // FIXME: We should assert that start/end are not in the middle of a text no de.
1188 1188
1189 Position pushDownStart = mostForwardCaretPosition(start); 1189 Position pushDownStart = mostForwardCaretPosition(start);
1190 // If the pushDownStart is at the end of a text node, then this node is not fully selected. 1190 // If the pushDownStart is at the end of a text node, then this node is not fully selected.
1191 // Move it to the next deep quivalent position to avoid removing the style f rom this node. 1191 // Move it to the next deep quivalent position to avoid removing the style f rom this node.
1192 // e.g. if pushDownStart was at Position("hello", 5) in <b>hello<div>world</ div></b>, we want Position("world", 0) instead. 1192 // e.g. if pushDownStart was at Position("hello", 5) in <b>hello<div>world</ div></b>, we want Position("world", 0) instead.
1193 Node* pushDownStartContainer = pushDownStart.computeContainerNode(); 1193 Node* pushDownStartContainer = pushDownStart.computeContainerNode();
1194 if (pushDownStartContainer && pushDownStartContainer->isTextNode() 1194 if (pushDownStartContainer && pushDownStartContainer->isTextNode()
1195 && pushDownStart.computeOffsetInContainerNode() == pushDownStartContaine r->maxCharacterOffset()) 1195 && pushDownStart.computeOffsetInContainerNode() == pushDownStartContaine r->maxCharacterOffset())
1196 pushDownStart = nextVisuallyDistinctCandidate(pushDownStart); 1196 pushDownStart = nextVisuallyDistinctCandidate(pushDownStart);
(...skipping 21 matching lines...) Expand all
1218 1218
1219 // Current ending selection resetting algorithm assumes |start| and |end| 1219 // Current ending selection resetting algorithm assumes |start| and |end|
1220 // are in a same DOM tree even if they are not in document. 1220 // are in a same DOM tree even if they are not in document.
1221 if (!Position::commonAncestorTreeScope(start, end)) 1221 if (!Position::commonAncestorTreeScope(start, end))
1222 return; 1222 return;
1223 1223
1224 RawPtr<Node> node = start.anchorNode(); 1224 RawPtr<Node> node = start.anchorNode();
1225 while (node) { 1225 while (node) {
1226 RawPtr<Node> next = nullptr; 1226 RawPtr<Node> next = nullptr;
1227 if (editingIgnoresContent(node.get())) { 1227 if (editingIgnoresContent(node.get())) {
1228 ASSERT(node == end.anchorNode() || !node->contains(end.anchorNode()) ); 1228 DCHECK(node == end.anchorNode() || !node->contains(end.anchorNode()) );
1229 next = NodeTraversal::nextSkippingChildren(*node); 1229 next = NodeTraversal::nextSkippingChildren(*node);
1230 } else { 1230 } else {
1231 next = NodeTraversal::next(*node); 1231 next = NodeTraversal::next(*node);
1232 } 1232 }
1233 if (node->isHTMLElement() && elementFullySelected(toHTMLElement(*node), start, end)) { 1233 if (node->isHTMLElement() && elementFullySelected(toHTMLElement(*node), start, end)) {
1234 RawPtr<HTMLElement> elem = toHTMLElement(node); 1234 RawPtr<HTMLElement> elem = toHTMLElement(node);
1235 RawPtr<Node> prev = NodeTraversal::previousPostOrder(*elem); 1235 RawPtr<Node> prev = NodeTraversal::previousPostOrder(*elem);
1236 RawPtr<Node> next = NodeTraversal::next(*elem); 1236 RawPtr<Node> next = NodeTraversal::next(*elem);
1237 RawPtr<EditingStyle> styleToPushDown = nullptr; 1237 RawPtr<EditingStyle> styleToPushDown = nullptr;
1238 RawPtr<Node> childNode = nullptr; 1238 RawPtr<Node> childNode = nullptr;
1239 if (isStyledInlineElementToRemove(elem.get())) { 1239 if (isStyledInlineElementToRemove(elem.get())) {
1240 styleToPushDown = EditingStyle::create(); 1240 styleToPushDown = EditingStyle::create();
1241 childNode = elem->firstChild(); 1241 childNode = elem->firstChild();
1242 } 1242 }
1243 1243
1244 removeInlineStyleFromElement(style, elem.get(), editingState, Remove IfNeeded, styleToPushDown.get()); 1244 removeInlineStyleFromElement(style, elem.get(), editingState, Remove IfNeeded, styleToPushDown.get());
1245 if (editingState->isAborted()) 1245 if (editingState->isAborted())
1246 return; 1246 return;
1247 if (!elem->inShadowIncludingDocument()) { 1247 if (!elem->inShadowIncludingDocument()) {
1248 if (s.anchorNode() == elem) { 1248 if (s.anchorNode() == elem) {
1249 // Since elem must have been fully selected, and it is at th e start 1249 // Since elem must have been fully selected, and it is at th e start
1250 // of the selection, it is clear we can set the new s offset to 0. 1250 // of the selection, it is clear we can set the new s offset to 0.
1251 ASSERT(s.isBeforeAnchor() || s.isBeforeChildren() || s.offse tInContainerNode() <= 0); 1251 DCHECK(s.isBeforeAnchor() || s.isBeforeChildren() || s.offse tInContainerNode() <= 0);
1252 s = firstPositionInOrBeforeNode(next.get()); 1252 s = firstPositionInOrBeforeNode(next.get());
1253 } 1253 }
1254 if (e.anchorNode() == elem) { 1254 if (e.anchorNode() == elem) {
1255 // Since elem must have been fully selected, and it is at th e end 1255 // Since elem must have been fully selected, and it is at th e end
1256 // of the selection, it is clear we can set the new e offset to 1256 // of the selection, it is clear we can set the new e offset to
1257 // the max range offset of prev. 1257 // the max range offset of prev.
1258 ASSERT(s.isAfterAnchor() || !offsetIsBeforeLastNodeOffset(s. offsetInContainerNode(), s.computeContainerNode())); 1258 DCHECK(s.isAfterAnchor() || !offsetIsBeforeLastNodeOffset(s. offsetInContainerNode(), s.computeContainerNode()));
1259 e = lastPositionInOrAfterNode(prev.get()); 1259 e = lastPositionInOrAfterNode(prev.get());
1260 } 1260 }
1261 } 1261 }
1262 1262
1263 if (styleToPushDown) { 1263 if (styleToPushDown) {
1264 for (; childNode; childNode = childNode->nextSibling()) { 1264 for (; childNode; childNode = childNode->nextSibling()) {
1265 applyInlineStyleToPushDown(childNode.get(), styleToPushDown. get(), editingState); 1265 applyInlineStyleToPushDown(childNode.get(), styleToPushDown. get(), editingState);
1266 if (editingState->isAborted()) 1266 if (editingState->isAborted())
1267 return; 1267 return;
1268 } 1268 }
(...skipping 11 matching lines...) Expand all
1280 { 1280 {
1281 // The tree may have changed and Position::upstream() relies on an up-to-dat e layout. 1281 // The tree may have changed and Position::upstream() relies on an up-to-dat e layout.
1282 element.document().updateLayoutIgnorePendingStylesheets(); 1282 element.document().updateLayoutIgnorePendingStylesheets();
1283 1283
1284 return comparePositions(firstPositionInOrBeforeNode(&element), start) >= 0 1284 return comparePositions(firstPositionInOrBeforeNode(&element), start) >= 0
1285 && comparePositions(mostBackwardCaretPosition(lastPositionInOrAfterNode( &element)), end) <= 0; 1285 && comparePositions(mostBackwardCaretPosition(lastPositionInOrAfterNode( &element)), end) <= 0;
1286 } 1286 }
1287 1287
1288 void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position& end) 1288 void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position& end)
1289 { 1289 {
1290 ASSERT(start.computeContainerNode()->isTextNode()); 1290 DCHECK(start.computeContainerNode()->isTextNode());
1291 1291
1292 Position newEnd; 1292 Position newEnd;
1293 if (end.isOffsetInAnchor() && start.computeContainerNode() == end.computeCon tainerNode()) 1293 if (end.isOffsetInAnchor() && start.computeContainerNode() == end.computeCon tainerNode())
1294 newEnd = Position(end.computeContainerNode(), end.offsetInContainerNode( ) - start.offsetInContainerNode()); 1294 newEnd = Position(end.computeContainerNode(), end.offsetInContainerNode( ) - start.offsetInContainerNode());
1295 else 1295 else
1296 newEnd = end; 1296 newEnd = end;
1297 1297
1298 RawPtr<Text> text = toText(start.computeContainerNode()); 1298 RawPtr<Text> text = toText(start.computeContainerNode());
1299 splitTextNode(text, start.offsetInContainerNode()); 1299 splitTextNode(text, start.offsetInContainerNode());
1300 updateStartEnd(firstPositionInNode(text.get()), newEnd); 1300 updateStartEnd(firstPositionInNode(text.get()), newEnd);
1301 } 1301 }
1302 1302
1303 void ApplyStyleCommand::splitTextAtEnd(const Position& start, const Position& en d) 1303 void ApplyStyleCommand::splitTextAtEnd(const Position& start, const Position& en d)
1304 { 1304 {
1305 ASSERT(end.computeContainerNode()->isTextNode()); 1305 DCHECK(end.computeContainerNode()->isTextNode());
1306 1306
1307 bool shouldUpdateStart = start.isOffsetInAnchor() && start.computeContainerN ode() == end.computeContainerNode(); 1307 bool shouldUpdateStart = start.isOffsetInAnchor() && start.computeContainerN ode() == end.computeContainerNode();
1308 Text* text = toText(end.anchorNode()); 1308 Text* text = toText(end.anchorNode());
1309 splitTextNode(text, end.offsetInContainerNode()); 1309 splitTextNode(text, end.offsetInContainerNode());
1310 1310
1311 Node* prevNode = text->previousSibling(); 1311 Node* prevNode = text->previousSibling();
1312 if (!prevNode || !prevNode->isTextNode()) 1312 if (!prevNode || !prevNode->isTextNode())
1313 return; 1313 return;
1314 1314
1315 Position newStart = shouldUpdateStart ? Position(toText(prevNode), start.off setInContainerNode()) : start; 1315 Position newStart = shouldUpdateStart ? Position(toText(prevNode), start.off setInContainerNode()) : start;
1316 updateStartEnd(newStart, lastPositionInNode(prevNode)); 1316 updateStartEnd(newStart, lastPositionInNode(prevNode));
1317 } 1317 }
1318 1318
1319 void ApplyStyleCommand::splitTextElementAtStart(const Position& start, const Pos ition& end) 1319 void ApplyStyleCommand::splitTextElementAtStart(const Position& start, const Pos ition& end)
1320 { 1320 {
1321 ASSERT(start.computeContainerNode()->isTextNode()); 1321 DCHECK(start.computeContainerNode()->isTextNode());
1322 1322
1323 Position newEnd; 1323 Position newEnd;
1324 if (start.computeContainerNode() == end.computeContainerNode()) 1324 if (start.computeContainerNode() == end.computeContainerNode())
1325 newEnd = Position(end.computeContainerNode(), end.offsetInContainerNode( ) - start.offsetInContainerNode()); 1325 newEnd = Position(end.computeContainerNode(), end.offsetInContainerNode( ) - start.offsetInContainerNode());
1326 else 1326 else
1327 newEnd = end; 1327 newEnd = end;
1328 1328
1329 splitTextNodeContainingElement(toText(start.computeContainerNode()), start.o ffsetInContainerNode()); 1329 splitTextNodeContainingElement(toText(start.computeContainerNode()), start.o ffsetInContainerNode());
1330 updateStartEnd(positionBeforeNode(start.computeContainerNode()), newEnd); 1330 updateStartEnd(positionBeforeNode(start.computeContainerNode()), newEnd);
1331 } 1331 }
1332 1332
1333 void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Posit ion& end) 1333 void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Posit ion& end)
1334 { 1334 {
1335 ASSERT(end.computeContainerNode()->isTextNode()); 1335 DCHECK(end.computeContainerNode()->isTextNode());
1336 1336
1337 bool shouldUpdateStart = start.computeContainerNode() == end.computeContaine rNode(); 1337 bool shouldUpdateStart = start.computeContainerNode() == end.computeContaine rNode();
1338 splitTextNodeContainingElement(toText(end.computeContainerNode()), end.offse tInContainerNode()); 1338 splitTextNodeContainingElement(toText(end.computeContainerNode()), end.offse tInContainerNode());
1339 1339
1340 Node* parentElement = end.computeContainerNode()->parentNode(); 1340 Node* parentElement = end.computeContainerNode()->parentNode();
1341 if (!parentElement || !parentElement->previousSibling()) 1341 if (!parentElement || !parentElement->previousSibling())
1342 return; 1342 return;
1343 Node* firstTextNode = parentElement->previousSibling()->lastChild(); 1343 Node* firstTextNode = parentElement->previousSibling()->lastChild();
1344 if (!firstTextNode || !firstTextNode->isTextNode()) 1344 if (!firstTextNode || !firstTextNode->isTextNode())
1345 return; 1345 return;
1346 1346
1347 Position newStart = shouldUpdateStart ? Position(toText(firstTextNode), star t.offsetInContainerNode()) : start; 1347 Position newStart = shouldUpdateStart ? Position(toText(firstTextNode), star t.offsetInContainerNode()) : start;
1348 updateStartEnd(newStart, positionAfterNode(firstTextNode)); 1348 updateStartEnd(newStart, positionAfterNode(firstTextNode));
1349 } 1349 }
1350 1350
1351 bool ApplyStyleCommand::shouldSplitTextElement(Element* element, EditingStyle* s tyle) 1351 bool ApplyStyleCommand::shouldSplitTextElement(Element* element, EditingStyle* s tyle)
1352 { 1352 {
1353 if (!element || !element->isHTMLElement()) 1353 if (!element || !element->isHTMLElement())
1354 return false; 1354 return false;
1355 1355
1356 return shouldRemoveInlineStyleFromElement(style, toHTMLElement(element)); 1356 return shouldRemoveInlineStyleFromElement(style, toHTMLElement(element));
1357 } 1357 }
1358 1358
1359 bool ApplyStyleCommand::isValidCaretPositionInTextNode(const Position& position) 1359 bool ApplyStyleCommand::isValidCaretPositionInTextNode(const Position& position)
1360 { 1360 {
1361 ASSERT(position.isNotNull()); 1361 DCHECK(position.isNotNull());
1362 1362
1363 Node* node = position.computeContainerNode(); 1363 Node* node = position.computeContainerNode();
1364 if (!position.isOffsetInAnchor() || !node->isTextNode()) 1364 if (!position.isOffsetInAnchor() || !node->isTextNode())
1365 return false; 1365 return false;
1366 int offsetInText = position.offsetInContainerNode(); 1366 int offsetInText = position.offsetInContainerNode();
1367 return offsetInText > caretMinOffset(node) && offsetInText < caretMaxOffset( node); 1367 return offsetInText > caretMinOffset(node) && offsetInText < caretMaxOffset( node);
1368 } 1368 }
1369 1369
1370 bool ApplyStyleCommand::mergeStartWithPreviousIfIdentical(const Position& start, const Position& end, EditingState* editingState) 1370 bool ApplyStyleCommand::mergeStartWithPreviousIfIdentical(const Position& start, const Position& end, EditingState* editingState)
1371 { 1371 {
(...skipping 13 matching lines...) Expand all
1385 1385
1386 if (!startNode->isElementNode()) 1386 if (!startNode->isElementNode())
1387 return false; 1387 return false;
1388 1388
1389 Node* previousSibling = startNode->previousSibling(); 1389 Node* previousSibling = startNode->previousSibling();
1390 1390
1391 if (previousSibling && areIdenticalElements(*startNode, *previousSibling)) { 1391 if (previousSibling && areIdenticalElements(*startNode, *previousSibling)) {
1392 Element* previousElement = toElement(previousSibling); 1392 Element* previousElement = toElement(previousSibling);
1393 Element* element = toElement(startNode); 1393 Element* element = toElement(startNode);
1394 Node* startChild = element->firstChild(); 1394 Node* startChild = element->firstChild();
1395 ASSERT(startChild); 1395 DCHECK(startChild);
1396 mergeIdenticalElements(previousElement, element, editingState); 1396 mergeIdenticalElements(previousElement, element, editingState);
1397 if (editingState->isAborted()) 1397 if (editingState->isAborted())
1398 return false; 1398 return false;
1399 1399
1400 int startOffsetAdjustment = startChild->nodeIndex(); 1400 int startOffsetAdjustment = startChild->nodeIndex();
1401 int endOffsetAdjustment = startNode == end.anchorNode() ? startOffsetAdj ustment : 0; 1401 int endOffsetAdjustment = startNode == end.anchorNode() ? startOffsetAdj ustment : 0;
1402 updateStartEnd(Position(startNode, startOffsetAdjustment), 1402 updateStartEnd(Position(startNode, startOffsetAdjustment),
1403 Position(end.anchorNode(), end.computeEditingOffset() + endOffsetAdj ustment)); 1403 Position(end.anchorNode(), end.computeEditingOffset() + endOffsetAdj ustment));
1404 return true; 1404 return true;
1405 } 1405 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 updateStartEnd(shouldUpdateStart ? Position(nextElement, start.offsetInC ontainerNode()) : start, 1440 updateStartEnd(shouldUpdateStart ? Position(nextElement, start.offsetInC ontainerNode()) : start,
1441 Position(nextElement, endOffset)); 1441 Position(nextElement, endOffset));
1442 return true; 1442 return true;
1443 } 1443 }
1444 1444
1445 return false; 1445 return false;
1446 } 1446 }
1447 1447
1448 void ApplyStyleCommand::surroundNodeRangeWithElement(RawPtr<Node> passedStartNod e, RawPtr<Node> endNode, RawPtr<Element> elementToInsert, EditingState* editingS tate) 1448 void ApplyStyleCommand::surroundNodeRangeWithElement(RawPtr<Node> passedStartNod e, RawPtr<Node> endNode, RawPtr<Element> elementToInsert, EditingState* editingS tate)
1449 { 1449 {
1450 ASSERT(passedStartNode); 1450 DCHECK(passedStartNode);
1451 ASSERT(endNode); 1451 DCHECK(endNode);
1452 ASSERT(elementToInsert); 1452 DCHECK(elementToInsert);
1453 RawPtr<Node> node = passedStartNode; 1453 RawPtr<Node> node = passedStartNode;
1454 RawPtr<Element> element = elementToInsert; 1454 RawPtr<Element> element = elementToInsert;
1455 1455
1456 insertNodeBefore(element, node, editingState); 1456 insertNodeBefore(element, node, editingState);
1457 if (editingState->isAborted()) 1457 if (editingState->isAborted())
1458 return; 1458 return;
1459 1459
1460 while (node) { 1460 while (node) {
1461 RawPtr<Node> next = node->nextSibling(); 1461 RawPtr<Node> next = node->nextSibling();
1462 if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)) { 1462 if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 return positionBeforeNode(dummyElement.get()); 1545 return positionBeforeNode(dummyElement.get());
1546 } 1546 }
1547 1547
1548 return firstPositionInOrBeforeNode(startNode.get()); 1548 return firstPositionInOrBeforeNode(startNode.get());
1549 } 1549 }
1550 1550
1551 void ApplyStyleCommand::applyInlineStyleChange(RawPtr<Node> passedStart, RawPtr< Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledElement, E ditingState* editingState) 1551 void ApplyStyleCommand::applyInlineStyleChange(RawPtr<Node> passedStart, RawPtr< Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledElement, E ditingState* editingState)
1552 { 1552 {
1553 RawPtr<Node> startNode = passedStart; 1553 RawPtr<Node> startNode = passedStart;
1554 RawPtr<Node> endNode = passedEnd; 1554 RawPtr<Node> endNode = passedEnd;
1555 ASSERT(startNode->inShadowIncludingDocument()); 1555 DCHECK(startNode->inShadowIncludingDocument());
1556 ASSERT(endNode->inShadowIncludingDocument()); 1556 DCHECK(endNode->inShadowIncludingDocument());
1557 1557
1558 // Find appropriate font and span elements top-down. 1558 // Find appropriate font and span elements top-down.
1559 HTMLFontElement* fontContainer = nullptr; 1559 HTMLFontElement* fontContainer = nullptr;
1560 HTMLElement* styleContainer = nullptr; 1560 HTMLElement* styleContainer = nullptr;
1561 for (Node* container = startNode.get(); container && startNode == endNode; c ontainer = container->firstChild()) { 1561 for (Node* container = startNode.get(); container && startNode == endNode; c ontainer = container->firstChild()) {
1562 if (isHTMLFontElement(*container)) 1562 if (isHTMLFontElement(*container))
1563 fontContainer = toHTMLFontElement(container); 1563 fontContainer = toHTMLFontElement(container);
1564 bool styleContainerIsNotSpan = !isHTMLSpanElement(styleContainer); 1564 bool styleContainerIsNotSpan = !isHTMLSpanElement(styleContainer);
1565 if (container->isHTMLElement()) { 1565 if (container->isHTMLElement()) {
1566 HTMLElement* containerElement = toHTMLElement(container); 1566 HTMLElement* containerElement = toHTMLElement(container);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 return 0; 1662 return 0;
1663 1663
1664 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::create(nod e); 1664 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::create(nod e);
1665 if (!style) 1665 if (!style)
1666 return 0; 1666 return 0;
1667 1667
1668 CSSPrimitiveValue* value = toCSSPrimitiveValue(style->getPropertyCSSValue(CS SPropertyFontSize)); 1668 CSSPrimitiveValue* value = toCSSPrimitiveValue(style->getPropertyCSSValue(CS SPropertyFontSize));
1669 if (!value) 1669 if (!value)
1670 return 0; 1670 return 0;
1671 1671
1672 ASSERT(value->typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Pixels) ; 1672 DCHECK(value->typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Pixels) ;
1673 return value->getFloatValue(); 1673 return value->getFloatValue();
1674 } 1674 }
1675 1675
1676 void ApplyStyleCommand::joinChildTextNodes(ContainerNode* node, const Position& start, const Position& end) 1676 void ApplyStyleCommand::joinChildTextNodes(ContainerNode* node, const Position& start, const Position& end)
1677 { 1677 {
1678 if (!node) 1678 if (!node)
1679 return; 1679 return;
1680 1680
1681 Position newStart = start; 1681 Position newStart = start;
1682 Position newEnd = end; 1682 Position newEnd = end;
(...skipping 30 matching lines...) Expand all
1713 DEFINE_TRACE(ApplyStyleCommand) 1713 DEFINE_TRACE(ApplyStyleCommand)
1714 { 1714 {
1715 visitor->trace(m_style); 1715 visitor->trace(m_style);
1716 visitor->trace(m_start); 1716 visitor->trace(m_start);
1717 visitor->trace(m_end); 1717 visitor->trace(m_end);
1718 visitor->trace(m_styledInlineElement); 1718 visitor->trace(m_styledInlineElement);
1719 CompositeEditCommand::trace(visitor); 1719 CompositeEditCommand::trace(visitor);
1720 } 1720 }
1721 1721
1722 } // namespace blink 1722 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698