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

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

Issue 299353004: Oilpan: move editing objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Make test wrapper class finalized Created 6 years, 6 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 | « Source/core/editing/ApplyStyleCommand.h ('k') | Source/core/editing/BreakBlockquoteCommand.h » ('j') | 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, 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 99 }
100 100
101 bool isEmptyFontTag(const Element* element, ShouldStyleAttributeBeEmpty shouldSt yleAttributeBeEmpty) 101 bool isEmptyFontTag(const Element* element, ShouldStyleAttributeBeEmpty shouldSt yleAttributeBeEmpty)
102 { 102 {
103 if (!isHTMLFontElement(element)) 103 if (!isHTMLFontElement(element))
104 return false; 104 return false;
105 105
106 return hasNoAttributeOrOnlyStyleAttribute(toHTMLElement(element), shouldStyl eAttributeBeEmpty); 106 return hasNoAttributeOrOnlyStyleAttribute(toHTMLElement(element), shouldStyl eAttributeBeEmpty);
107 } 107 }
108 108
109 static PassRefPtr<Element> createFontElement(Document& document) 109 static PassRefPtrWillBeRawPtr<Element> createFontElement(Document& document)
110 { 110 {
111 RefPtr<Element> fontNode = createHTMLElement(document, fontTag); 111 return createHTMLElement(document, fontTag);
112 return fontNode.release();
113 } 112 }
114 113
115 PassRefPtrWillBeRawPtr<HTMLElement> createStyleSpanElement(Document& document) 114 PassRefPtrWillBeRawPtr<HTMLElement> createStyleSpanElement(Document& document)
116 { 115 {
117 RefPtrWillBeRawPtr<HTMLElement> styleElement = createHTMLElement(document, s panTag); 116 return createHTMLElement(document, spanTag);
118 return styleElement.release();
119 } 117 }
120 118
121 ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* sty le, EditAction editingAction, EPropertyLevel propertyLevel) 119 ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* sty le, EditAction editingAction, EPropertyLevel propertyLevel)
122 : CompositeEditCommand(document) 120 : CompositeEditCommand(document)
123 , m_style(style->copy()) 121 , m_style(style->copy())
124 , m_editingAction(editingAction) 122 , m_editingAction(editingAction)
125 , m_propertyLevel(propertyLevel) 123 , m_propertyLevel(propertyLevel)
126 , m_start(endingSelection().start().downstream()) 124 , m_start(endingSelection().start().downstream())
127 , m_end(endingSelection().end().upstream()) 125 , m_end(endingSelection().end().upstream())
128 , m_useEndingSelection(true) 126 , m_useEndingSelection(true)
(...skipping 10 matching lines...) Expand all
139 , m_propertyLevel(propertyLevel) 137 , m_propertyLevel(propertyLevel)
140 , m_start(start) 138 , m_start(start)
141 , m_end(end) 139 , m_end(end)
142 , m_useEndingSelection(false) 140 , m_useEndingSelection(false)
143 , m_styledInlineElement(nullptr) 141 , m_styledInlineElement(nullptr)
144 , m_removeOnly(false) 142 , m_removeOnly(false)
145 , m_isInlineElementToRemoveFunction(0) 143 , m_isInlineElementToRemoveFunction(0)
146 { 144 {
147 } 145 }
148 146
149 ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnl y, EditAction editingAction) 147 ApplyStyleCommand::ApplyStyleCommand(PassRefPtrWillBeRawPtr<Element> element, bo ol removeOnly, EditAction editingAction)
150 : CompositeEditCommand(element->document()) 148 : CompositeEditCommand(element->document())
151 , m_style(EditingStyle::create()) 149 , m_style(EditingStyle::create())
152 , m_editingAction(editingAction) 150 , m_editingAction(editingAction)
153 , m_propertyLevel(PropertyDefault) 151 , m_propertyLevel(PropertyDefault)
154 , m_start(endingSelection().start().downstream()) 152 , m_start(endingSelection().start().downstream())
155 , m_end(endingSelection().end().upstream()) 153 , m_end(endingSelection().end().upstream())
156 , m_useEndingSelection(true) 154 , m_useEndingSelection(true)
157 , m_styledInlineElement(element) 155 , m_styledInlineElement(element)
158 , m_removeOnly(removeOnly) 156 , m_removeOnly(removeOnly)
159 , m_isInlineElementToRemoveFunction(0) 157 , m_isInlineElementToRemoveFunction(0)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 return endingSelection().end(); 198 return endingSelection().end();
201 199
202 return m_end; 200 return m_end;
203 } 201 }
204 202
205 void ApplyStyleCommand::doApply() 203 void ApplyStyleCommand::doApply()
206 { 204 {
207 switch (m_propertyLevel) { 205 switch (m_propertyLevel) {
208 case PropertyDefault: { 206 case PropertyDefault: {
209 // Apply the block-centric properties of the style. 207 // Apply the block-centric properties of the style.
210 RefPtr<EditingStyle> blockStyle = m_style->extractAndRemoveBlockProperti es(); 208 RefPtrWillBeRawPtr<EditingStyle> blockStyle = m_style->extractAndRemoveB lockProperties();
211 if (!blockStyle->isEmpty()) 209 if (!blockStyle->isEmpty())
212 applyBlockStyle(blockStyle.get()); 210 applyBlockStyle(blockStyle.get());
213 // Apply any remaining styles to the inline elements. 211 // Apply any remaining styles to the inline elements.
214 if (!m_style->isEmpty() || m_styledInlineElement || m_isInlineElementToR emoveFunction) { 212 if (!m_style->isEmpty() || m_styledInlineElement || m_isInlineElementToR emoveFunction) {
215 applyRelativeFontStyleChange(m_style.get()); 213 applyRelativeFontStyleChange(m_style.get());
216 applyInlineStyle(m_style.get()); 214 applyInlineStyle(m_style.get());
217 } 215 }
218 break; 216 break;
219 } 217 }
220 case ForceBlockProperties: 218 case ForceBlockProperties:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 RefPtrWillBeRawPtr<Range> endRange = Range::create(document(), firstPosition InNode(&scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 257 RefPtrWillBeRawPtr<Range> endRange = Range::create(document(), firstPosition InNode(&scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
260 int startIndex = TextIterator::rangeLength(startRange.get(), true); 258 int startIndex = TextIterator::rangeLength(startRange.get(), true);
261 int endIndex = TextIterator::rangeLength(endRange.get(), true); 259 int endIndex = TextIterator::rangeLength(endRange.get(), true);
262 260
263 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); 261 VisiblePosition paragraphStart(startOfParagraph(visibleStart));
264 VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next()); 262 VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next());
265 VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next()); 263 VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next());
266 while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) { 264 while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) {
267 StyleChange styleChange(style, paragraphStart.deepEquivalent()); 265 StyleChange styleChange(style, paragraphStart.deepEquivalent());
268 if (styleChange.cssStyle().length() || m_removeOnly) { 266 if (styleChange.cssStyle().length() || m_removeOnly) {
269 RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent(). deprecatedNode()); 267 RefPtrWillBeRawPtr<Node> block = enclosingBlock(paragraphStart.deepE quivalent().deprecatedNode());
270 if (!m_removeOnly) { 268 if (!m_removeOnly) {
271 RefPtr<Node> newBlock = moveParagraphContentsToNewBlockIfNecessa ry(paragraphStart.deepEquivalent()); 269 RefPtrWillBeRawPtr<Node> newBlock = moveParagraphContentsToNewBl ockIfNecessary(paragraphStart.deepEquivalent());
272 if (newBlock) 270 if (newBlock)
273 block = newBlock; 271 block = newBlock;
274 } 272 }
275 ASSERT(!block || block->isHTMLElement()); 273 ASSERT(!block || block->isHTMLElement());
276 if (block && block->isHTMLElement()) { 274 if (block && block->isHTMLElement()) {
277 removeCSSStyle(style, toHTMLElement(block)); 275 removeCSSStyle(style, toHTMLElement(block));
278 if (!m_removeOnly) 276 if (!m_removeOnly)
279 addBlockStyle(styleChange, toHTMLElement(block)); 277 addBlockStyle(styleChange, toHTMLElement(block));
280 } 278 }
281 279
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 && EditingStyle::create(highestAncestorWithUnicodeBidi, EditingStyle::Al lProperties)->textDirection(highestAncestorDirection) 481 && EditingStyle::create(highestAncestorWithUnicodeBidi, EditingStyle::Al lProperties)->textDirection(highestAncestorDirection)
484 && highestAncestorDirection == allowedDirection) { 482 && highestAncestorDirection == allowedDirection) {
485 if (!nextHighestAncestorWithUnicodeBidi) 483 if (!nextHighestAncestorWithUnicodeBidi)
486 return toHTMLElement(highestAncestorWithUnicodeBidi); 484 return toHTMLElement(highestAncestorWithUnicodeBidi);
487 485
488 unsplitAncestor = toHTMLElement(highestAncestorWithUnicodeBidi); 486 unsplitAncestor = toHTMLElement(highestAncestorWithUnicodeBidi);
489 highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi; 487 highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi;
490 } 488 }
491 489
492 // Split every ancestor through highest ancestor with embedding. 490 // Split every ancestor through highest ancestor with embedding.
493 RefPtr<Node> currentNode = node; 491 RefPtrWillBeRawPtr<Node> currentNode = node;
494 while (currentNode) { 492 while (currentNode) {
495 RefPtr<Element> parent = toElement(currentNode->parentNode()); 493 RefPtrWillBeRawPtr<Element> parent = toElement(currentNode->parentNode() );
496 if (before ? currentNode->previousSibling() : currentNode->nextSibling() ) 494 if (before ? currentNode->previousSibling() : currentNode->nextSibling() )
497 splitElement(parent, before ? currentNode : currentNode->nextSibling ()); 495 splitElement(parent, before ? currentNode.get() : currentNode->nextS ibling());
498 if (parent == highestAncestorWithUnicodeBidi) 496 if (parent == highestAncestorWithUnicodeBidi)
499 break; 497 break;
500 currentNode = parent; 498 currentNode = parent;
501 } 499 }
502 return unsplitAncestor; 500 return unsplitAncestor;
503 } 501 }
504 502
505 void ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsp litAncestor) 503 void ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsp litAncestor)
506 { 504 {
507 Node* block = enclosingBlock(node); 505 Node* block = enclosingBlock(node);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 for (Node* n = startNode; n && n != enclosingNode; n = n->parentNode()) { 539 for (Node* n = startNode; n && n != enclosingNode; n = n->parentNode()) {
542 if (n->isHTMLElement() && getIdentifierValue(CSSComputedStyleDeclaration ::create(n).get(), CSSPropertyUnicodeBidi) == CSSValueEmbed) 540 if (n->isHTMLElement() && getIdentifierValue(CSSComputedStyleDeclaration ::create(n).get(), CSSPropertyUnicodeBidi) == CSSValueEmbed)
543 return n; 541 return n;
544 } 542 }
545 543
546 return 0; 544 return 0;
547 } 545 }
548 546
549 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style) 547 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
550 { 548 {
551 RefPtr<Node> startDummySpanAncestor = nullptr; 549 RefPtrWillBeRawPtr<Node> startDummySpanAncestor = nullptr;
552 RefPtr<Node> endDummySpanAncestor = nullptr; 550 RefPtrWillBeRawPtr<Node> endDummySpanAncestor = nullptr;
553 551
554 // update document layout once before removing styles 552 // update document layout once before removing styles
555 // so that we avoid the expense of updating before each and every call 553 // so that we avoid the expense of updating before each and every call
556 // to check a computed style 554 // to check a computed style
557 document().updateLayoutIgnorePendingStylesheets(); 555 document().updateLayoutIgnorePendingStylesheets();
558 556
559 // adjust to the positions we want to use for applying style 557 // adjust to the positions we want to use for applying style
560 Position start = startPosition(); 558 Position start = startPosition();
561 Position end = endPosition(); 559 Position end = endPosition();
562 560
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 592 }
595 593
596 // Remove style from the selection. 594 // Remove style from the selection.
597 // Use the upstream position of the start for removing style. 595 // Use the upstream position of the start for removing style.
598 // This will ensure we remove all traces of the relevant styles from the sel ection 596 // This will ensure we remove all traces of the relevant styles from the sel ection
599 // and prevent us from adding redundant ones, as described in: 597 // and prevent us from adding redundant ones, as described in:
600 // <rdar://problem/3724344> Bolding and unbolding creates extraneous tags 598 // <rdar://problem/3724344> Bolding and unbolding creates extraneous tags
601 Position removeStart = start.upstream(); 599 Position removeStart = start.upstream();
602 WritingDirection textDirection = NaturalWritingDirection; 600 WritingDirection textDirection = NaturalWritingDirection;
603 bool hasTextDirection = style->textDirection(textDirection); 601 bool hasTextDirection = style->textDirection(textDirection);
604 RefPtr<EditingStyle> styleWithoutEmbedding; 602 RefPtrWillBeRawPtr<EditingStyle> styleWithoutEmbedding = nullptr;
605 RefPtr<EditingStyle> embeddingStyle; 603 RefPtrWillBeRawPtr<EditingStyle> embeddingStyle = nullptr;
606 if (hasTextDirection) { 604 if (hasTextDirection) {
607 // Leave alone an ancestor that provides the desired single level embedd ing, if there is one. 605 // Leave alone an ancestor that provides the desired single level embedd ing, if there is one.
608 HTMLElement* startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start. deprecatedNode(), true, textDirection); 606 HTMLElement* startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start. deprecatedNode(), true, textDirection);
609 HTMLElement* endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.depr ecatedNode(), false, textDirection); 607 HTMLElement* endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.depr ecatedNode(), false, textDirection);
610 removeEmbeddingUpToEnclosingBlock(start.deprecatedNode(), startUnsplitAn cestor); 608 removeEmbeddingUpToEnclosingBlock(start.deprecatedNode(), startUnsplitAn cestor);
611 removeEmbeddingUpToEnclosingBlock(end.deprecatedNode(), endUnsplitAncest or); 609 removeEmbeddingUpToEnclosingBlock(end.deprecatedNode(), endUnsplitAncest or);
612 610
613 // Avoid removing the dir attribute and the unicode-bidi and direction p roperties from the unsplit ancestors. 611 // Avoid removing the dir attribute and the unicode-bidi and direction p roperties from the unsplit ancestors.
614 Position embeddingRemoveStart = removeStart; 612 Position embeddingRemoveStart = removeStart;
615 if (startUnsplitAncestor && nodeFullySelected(startUnsplitAncestor, remo veStart, end)) 613 if (startUnsplitAncestor && nodeFullySelected(startUnsplitAncestor, remo veStart, end))
(...skipping 27 matching lines...) Expand all
643 mergeEndWithNextIfIdentical(start, end); 641 mergeEndWithNextIfIdentical(start, end);
644 start = startPosition(); 642 start = startPosition();
645 end = endPosition(); 643 end = endPosition();
646 } 644 }
647 645
648 // update document layout once before running the rest of the function 646 // update document layout once before running the rest of the function
649 // so that we avoid the expense of updating before each and every call 647 // so that we avoid the expense of updating before each and every call
650 // to check a computed style 648 // to check a computed style
651 document().updateLayoutIgnorePendingStylesheets(); 649 document().updateLayoutIgnorePendingStylesheets();
652 650
653 RefPtr<EditingStyle> styleToApply = style; 651 RefPtrWillBeRawPtr<EditingStyle> styleToApply = style;
654 if (hasTextDirection) { 652 if (hasTextDirection) {
655 // Avoid applying the unicode-bidi and direction properties beneath ance stors that already have them. 653 // Avoid applying the unicode-bidi and direction properties beneath ance stors that already have them.
656 Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode (), enclosingBlock(start.deprecatedNode())); 654 Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode (), enclosingBlock(start.deprecatedNode()));
657 Node* embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(), enclosingBlock(end.deprecatedNode())); 655 Node* embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(), enclosingBlock(end.deprecatedNode()));
658 656
659 if (embeddingStartNode || embeddingEndNode) { 657 if (embeddingStartNode || embeddingEndNode) {
660 Position embeddingApplyStart = embeddingStartNode ? positionInParent AfterNode(*embeddingStartNode) : start; 658 Position embeddingApplyStart = embeddingStartNode ? positionInParent AfterNode(*embeddingStartNode) : start;
661 Position embeddingApplyEnd = embeddingEndNode ? positionInParentBefo reNode(*embeddingEndNode) : end; 659 Position embeddingApplyEnd = embeddingEndNode ? positionInParentBefo reNode(*embeddingEndNode) : end;
662 ASSERT(embeddingApplyStart.isNotNull() && embeddingApplyEnd.isNotNul l()); 660 ASSERT(embeddingApplyStart.isNotNull() && embeddingApplyEnd.isNotNul l());
663 661
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 717
720 Node* sibling = NodeTraversal::nextSkippingChildren(node); 718 Node* sibling = NodeTraversal::nextSkippingChildren(node);
721 for (Node* descendent = node.firstChild(); descendent && descendent != sibli ng; descendent = NodeTraversal::next(*descendent)) { 719 for (Node* descendent = node.firstChild(); descendent && descendent != sibli ng; descendent = NodeTraversal::next(*descendent)) {
722 if (!descendent->rendererIsEditable()) 720 if (!descendent->rendererIsEditable())
723 return true; 721 return true;
724 } 722 }
725 723
726 return false; 724 return false;
727 } 725 }
728 726
729 struct InlineRunToApplyStyle { 727 class InlineRunToApplyStyle {
728 ALLOW_ONLY_INLINE_ALLOCATION();
729 public:
730 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode) 730 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode)
731 : start(start) 731 : start(start)
732 , end(end) 732 , end(end)
733 , pastEndNode(pastEndNode) 733 , pastEndNode(pastEndNode)
734 { 734 {
735 ASSERT(start->parentNode() == end->parentNode()); 735 ASSERT(start->parentNode() == end->parentNode());
736 } 736 }
737 737
738 bool startAndEndAreStillInDocument() 738 bool startAndEndAreStillInDocument()
739 { 739 {
740 return start && end && start->inDocument() && end->inDocument(); 740 return start && end && start->inDocument() && end->inDocument();
741 } 741 }
742 742
743 RefPtr<Node> start; 743 void trace(Visitor* visitor)
744 RefPtr<Node> end; 744 {
745 RefPtr<Node> pastEndNode; 745 visitor->trace(start);
746 visitor->trace(end);
747 visitor->trace(pastEndNode);
748 visitor->trace(positionForStyleComputation);
749 visitor->trace(dummyElement);
750 }
751
752 RefPtrWillBeMember<Node> start;
753 RefPtrWillBeMember<Node> end;
754 RefPtrWillBeMember<Node> pastEndNode;
746 Position positionForStyleComputation; 755 Position positionForStyleComputation;
747 RefPtr<Node> dummyElement; 756 RefPtrWillBeMember<Node> dummyElement;
748 StyleChange change; 757 StyleChange change;
749 }; 758 };
750 759
751 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRef Ptr<Node> startNode, PassRefPtr<Node> pastEndNode) 760 } // namespace WebCore
761
762 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(WebCore::InlineRunToApplyStyle);
763
764 namespace WebCore {
765
766 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRef PtrWillBeRawPtr<Node> startNode, PassRefPtrWillBeRawPtr<Node> pastEndNode)
752 { 767 {
753 if (m_removeOnly) 768 if (m_removeOnly)
754 return; 769 return;
755 770
756 document().updateLayoutIgnorePendingStylesheets(); 771 document().updateLayoutIgnorePendingStylesheets();
757 772
758 Vector<InlineRunToApplyStyle> runs; 773 WillBeHeapVector<InlineRunToApplyStyle> runs;
759 RefPtr<Node> node = startNode; 774 RefPtrWillBeRawPtr<Node> node = startNode;
760 for (RefPtr<Node> next; node && node != pastEndNode; node = next) { 775 for (RefPtrWillBeRawPtr<Node> next; node && node != pastEndNode; node = next ) {
761 next = NodeTraversal::next(*node); 776 next = NodeTraversal::next(*node);
762 777
763 if (!node->renderer() || !node->rendererIsEditable()) 778 if (!node->renderer() || !node->rendererIsEditable())
764 continue; 779 continue;
765 780
766 if (!node->rendererIsRichlyEditable() && node->isHTMLElement()) { 781 if (!node->rendererIsRichlyEditable() && node->isHTMLElement()) {
767 // This is a plaintext-only region. Only proceed if it's fully selec ted. 782 // This is a plaintext-only region. Only proceed if it's fully selec ted.
768 // pastEndNode is the node after the last fully selected node, so if it's inside node then 783 // pastEndNode is the node after the last fully selected node, so if it's inside node then
769 // node isn't fully selected. 784 // node isn't fully selected.
770 if (pastEndNode && pastEndNode->isDescendantOf(node.get())) 785 if (pastEndNode && pastEndNode->isDescendantOf(node.get()))
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 833 }
819 834
820 document().updateLayoutIgnorePendingStylesheets(); 835 document().updateLayoutIgnorePendingStylesheets();
821 836
822 for (size_t i = 0; i < runs.size(); i++) { 837 for (size_t i = 0; i < runs.size(); i++) {
823 if (runs[i].positionForStyleComputation.isNotNull()) 838 if (runs[i].positionForStyleComputation.isNotNull())
824 runs[i].change = StyleChange(style, runs[i].positionForStyleComputat ion); 839 runs[i].change = StyleChange(style, runs[i].positionForStyleComputat ion);
825 } 840 }
826 841
827 for (size_t i = 0; i < runs.size(); i++) { 842 for (size_t i = 0; i < runs.size(); i++) {
828 InlineRunToApplyStyle& run = runs[i]; 843 InlineRunToApplyStyle run = runs[i];
829 if (run.dummyElement) 844 if (run.dummyElement)
830 removeNode(run.dummyElement); 845 removeNode(run.dummyElement);
831 if (run.startAndEndAreStillInDocument()) 846 if (run.startAndEndAreStillInDocument())
832 applyInlineStyleChange(run.start.release(), run.end.release(), run.c hange, AddStyledElement); 847 applyInlineStyleChange(run.start.release(), run.end.release(), run.c hange, AddStyledElement);
833 } 848 }
834 } 849 }
835 850
836 bool ApplyStyleCommand::isStyledInlineElementToRemove(Element* element) const 851 bool ApplyStyleCommand::isStyledInlineElementToRemove(Element* element) const
837 { 852 {
838 return (m_styledInlineElement && element->hasTagName(m_styledInlineElement-> tagQName())) 853 return (m_styledInlineElement && element->hasTagName(m_styledInlineElement-> tagQName()))
839 || (m_isInlineElementToRemoveFunction && m_isInlineElementToRemoveFuncti on(element)); 854 || (m_isInlineElementToRemoveFunction && m_isInlineElementToRemoveFuncti on(element));
840 } 855 }
841 856
842 bool ApplyStyleCommand::shouldApplyInlineStyleToRun(EditingStyle* style, Node* r unStart, Node* pastEndNode) 857 bool ApplyStyleCommand::shouldApplyInlineStyleToRun(EditingStyle* style, Node* r unStart, Node* pastEndNode)
843 { 858 {
844 ASSERT(style && runStart); 859 ASSERT(style && runStart);
845 860
846 for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversa l::next(*node)) { 861 for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversa l::next(*node)) {
847 if (node->hasChildren()) 862 if (node->hasChildren())
848 continue; 863 continue;
849 // We don't consider m_isInlineElementToRemoveFunction here because we n ever apply style when m_isInlineElementToRemoveFunction is specified 864 // We don't consider m_isInlineElementToRemoveFunction here because we n ever apply style when m_isInlineElementToRemoveFunction is specified
850 if (!style->styleIsPresentInComputedStyleOfNode(node)) 865 if (!style->styleIsPresentInComputedStyleOfNode(node))
851 return true; 866 return true;
852 if (m_styledInlineElement && !enclosingNodeWithTag(positionBeforeNode(no de), m_styledInlineElement->tagQName())) 867 if (m_styledInlineElement && !enclosingNodeWithTag(positionBeforeNode(no de), m_styledInlineElement->tagQName()))
853 return true; 868 return true;
854 } 869 }
855 return false; 870 return false;
856 } 871 }
857 872
858 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style, RefPtr<Node>& runStart, RefPtr<Node>& runEnd, PassRefPtr<Node> pastEndNode) 873 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style, RefPtrWillBeMember<Node>& runStart, RefPtrWillBeMember<Node>& runEnd, PassRefPt rWillBeRawPtr<Node> pastEndNode)
859 { 874 {
860 ASSERT(runStart && runEnd); 875 ASSERT(runStart && runEnd);
861 RefPtr<Node> next = runStart; 876 RefPtrWillBeRawPtr<Node> next = runStart;
862 for (RefPtr<Node> node = next; node && node->inDocument() && node != pastEnd Node; node = next) { 877 for (RefPtrWillBeRawPtr<Node> node = next; node && node->inDocument() && nod e != pastEndNode; node = next) {
863 if (editingIgnoresContent(node.get())) { 878 if (editingIgnoresContent(node.get())) {
864 ASSERT(!node->contains(pastEndNode.get())); 879 ASSERT(!node->contains(pastEndNode.get()));
865 next = NodeTraversal::nextSkippingChildren(*node); 880 next = NodeTraversal::nextSkippingChildren(*node);
866 } else { 881 } else {
867 next = NodeTraversal::next(*node); 882 next = NodeTraversal::next(*node);
868 } 883 }
869 if (!node->isHTMLElement()) 884 if (!node->isHTMLElement())
870 continue; 885 continue;
871 886
872 RefPtr<Node> previousSibling = node->previousSibling(); 887 RefPtrWillBeRawPtr<Node> previousSibling = node->previousSibling();
873 RefPtr<Node> nextSibling = node->nextSibling(); 888 RefPtrWillBeRawPtr<Node> nextSibling = node->nextSibling();
874 RefPtr<ContainerNode> parent = node->parentNode(); 889 RefPtrWillBeRawPtr<ContainerNode> parent = node->parentNode();
875 removeInlineStyleFromElement(style, toHTMLElement(node), RemoveAlways); 890 removeInlineStyleFromElement(style, toHTMLElement(node), RemoveAlways);
876 if (!node->inDocument()) { 891 if (!node->inDocument()) {
877 // FIXME: We might need to update the start and the end of current s election here but need a test. 892 // FIXME: We might need to update the start and the end of current s election here but need a test.
878 if (runStart == node) 893 if (runStart == node)
879 runStart = previousSibling ? previousSibling->nextSibling() : pa rent->firstChild(); 894 runStart = previousSibling ? previousSibling->nextSibling() : pa rent->firstChild();
880 if (runEnd == node) 895 if (runEnd == node)
881 runEnd = nextSibling ? nextSibling->previousSibling() : parent-> lastChild(); 896 runEnd = nextSibling ? nextSibling->previousSibling() : parent-> lastChild();
882 } 897 }
883 } 898 }
884 } 899 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 1010
996 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty le) 1011 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty le)
997 { 1012 {
998 ASSERT(node); 1013 ASSERT(node);
999 1014
1000 node->document().updateRenderTreeIfNeeded(); 1015 node->document().updateRenderTreeIfNeeded();
1001 1016
1002 if (!style || style->isEmpty() || !node->renderer() || isHTMLIFrameElement(* node)) 1017 if (!style || style->isEmpty() || !node->renderer() || isHTMLIFrameElement(* node))
1003 return; 1018 return;
1004 1019
1005 RefPtr<EditingStyle> newInlineStyle = style; 1020 RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = style;
1006 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { 1021 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) {
1007 newInlineStyle = style->copy(); 1022 newInlineStyle = style->copy();
1008 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt yle::OverrideValues); 1023 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt yle::OverrideValues);
1009 } 1024 }
1010 1025
1011 // Since addInlineStyleIfNeeded can't add styles to block-flow render object s, add style attribute instead. 1026 // Since addInlineStyleIfNeeded can't add styles to block-flow render object s, add style attribute instead.
1012 // FIXME: applyInlineStyleToRange should be used here instead. 1027 // FIXME: applyInlineStyleToRange should be used here instead.
1013 if ((node->renderer()->isRenderBlockFlow() || node->hasChildren()) && node-> isHTMLElement()) { 1028 if ((node->renderer()->isRenderBlockFlow() || node->hasChildren()) && node-> isHTMLElement()) {
1014 setNodeAttribute(toHTMLElement(node), styleAttr, AtomicString(newInlineS tyle->style()->asText())); 1029 setNodeAttribute(toHTMLElement(node), styleAttr, AtomicString(newInlineS tyle->style()->asText()));
1015 return; 1030 return;
1016 } 1031 }
1017 1032
1018 if (node->renderer()->isText() && toRenderText(node->renderer())->isAllColla psibleWhitespace()) 1033 if (node->renderer()->isText() && toRenderText(node->renderer())->isAllColla psibleWhitespace())
1019 return; 1034 return;
1020 1035
1021 // We can't wrap node with the styled element here because new styled elemen t will never be removed if we did. 1036 // We can't wrap node with the styled element here because new styled elemen t will never be removed if we did.
1022 // If we modified the child pointer in pushDownInlineStyleAroundNode to poin t to new style element 1037 // If we modified the child pointer in pushDownInlineStyleAroundNode to poin t to new style element
1023 // then we fall into an infinite loop where we keep removing and adding styl ed element wrapping node. 1038 // then we fall into an infinite loop where we keep removing and adding styl ed element wrapping node.
1024 addInlineStyleIfNeeded(newInlineStyle.get(), node, node, DoNotAddStyledEleme nt); 1039 addInlineStyleIfNeeded(newInlineStyle.get(), node, node, DoNotAddStyledEleme nt);
1025 } 1040 }
1026 1041
1027 void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node* targetNode) 1042 void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node* targetNode)
1028 { 1043 {
1029 HTMLElement* highestAncestor = highestAncestorWithConflictingInlineStyle(sty le, targetNode); 1044 HTMLElement* highestAncestor = highestAncestorWithConflictingInlineStyle(sty le, targetNode);
1030 if (!highestAncestor) 1045 if (!highestAncestor)
1031 return; 1046 return;
1032 1047
1033 // The outer loop is traversing the tree vertically from highestAncestor to targetNode 1048 // The outer loop is traversing the tree vertically from highestAncestor to targetNode
1034 RefPtr<Node> current = highestAncestor; 1049 RefPtrWillBeRawPtr<Node> current = highestAncestor;
1035 // Along the way, styled elements that contain targetNode are removed and ac cumulated into elementsToPushDown. 1050 // Along the way, styled elements that contain targetNode are removed and ac cumulated into elementsToPushDown.
1036 // Each child of the removed element, exclusing ancestors of targetNode, is then wrapped by clones of elements in elementsToPushDown. 1051 // Each child of the removed element, exclusing ancestors of targetNode, is then wrapped by clones of elements in elementsToPushDown.
1037 Vector<RefPtr<Element> > elementsToPushDown; 1052 WillBeHeapVector<RefPtrWillBeMember<Element> > elementsToPushDown;
1038 while (current && current != targetNode && current->contains(targetNode)) { 1053 while (current && current != targetNode && current->contains(targetNode)) {
1039 NodeVector currentChildren; 1054 NodeVector currentChildren;
1040 getChildNodes(*current, currentChildren); 1055 getChildNodes(*current, currentChildren);
1041 RefPtr<Element> styledElement; 1056 RefPtrWillBeRawPtr<Element> styledElement = nullptr;
1042 if (current->isStyledElement() && isStyledInlineElementToRemove(toElemen t(current))) { 1057 if (current->isStyledElement() && isStyledInlineElementToRemove(toElemen t(current))) {
1043 styledElement = toElement(current); 1058 styledElement = toElement(current);
1044 elementsToPushDown.append(styledElement); 1059 elementsToPushDown.append(styledElement);
1045 } 1060 }
1046 1061
1047 RefPtr<EditingStyle> styleToPushDown = EditingStyle::create(); 1062 RefPtrWillBeRawPtr<EditingStyle> styleToPushDown = EditingStyle::create( );
1048 if (current->isHTMLElement()) 1063 if (current->isHTMLElement())
1049 removeInlineStyleFromElement(style, toHTMLElement(current), RemoveIf Needed, styleToPushDown.get()); 1064 removeInlineStyleFromElement(style, toHTMLElement(current), RemoveIf Needed, styleToPushDown.get());
1050 1065
1051 // The inner loop will go through children on each level 1066 // The inner loop will go through children on each level
1052 // FIXME: we should aggregate inline child elements together so that we don't wrap each child separately. 1067 // FIXME: we should aggregate inline child elements together so that we don't wrap each child separately.
1053 for (size_t i = 0; i < currentChildren.size(); ++i) { 1068 for (size_t i = 0; i < currentChildren.size(); ++i) {
1054 Node* child = currentChildren[i].get(); 1069 Node* child = currentChildren[i].get();
1055 if (!child->parentNode()) 1070 if (!child->parentNode())
1056 continue; 1071 continue;
1057 if (!child->contains(targetNode) && elementsToPushDown.size()) { 1072 if (!child->contains(targetNode) && elementsToPushDown.size()) {
1058 for (size_t i = 0; i < elementsToPushDown.size(); i++) { 1073 for (size_t i = 0; i < elementsToPushDown.size(); i++) {
1059 RefPtr<Element> wrapper = elementsToPushDown[i]->cloneElemen tWithoutChildren(); 1074 RefPtrWillBeRawPtr<Element> wrapper = elementsToPushDown[i]- >cloneElementWithoutChildren();
1060 wrapper->removeAttribute(styleAttr); 1075 wrapper->removeAttribute(styleAttr);
1061 surroundNodeRangeWithElement(child, child, wrapper); 1076 surroundNodeRangeWithElement(child, child, wrapper);
1062 } 1077 }
1063 } 1078 }
1064 1079
1065 // Apply style to all nodes containing targetNode and their siblings but NOT to targetNode 1080 // Apply style to all nodes containing targetNode and their siblings but NOT to targetNode
1066 // But if we've removed styledElement then go ahead and always apply the style. 1081 // But if we've removed styledElement then go ahead and always apply the style.
1067 if (child != targetNode || styledElement) 1082 if (child != targetNode || styledElement)
1068 applyInlineStyleToPushDown(child, styleToPushDown.get()); 1083 applyInlineStyleToPushDown(child, styleToPushDown.get());
1069 1084
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 pushDownInlineStyleAroundNode(style, pushDownEnd.deprecatedNode()); 1118 pushDownInlineStyleAroundNode(style, pushDownEnd.deprecatedNode());
1104 1119
1105 // The s and e variables store the positions used to set the ending selectio n after style removal 1120 // The s and e variables store the positions used to set the ending selectio n after style removal
1106 // takes place. This will help callers to recognize when either the start no de or the end node 1121 // takes place. This will help callers to recognize when either the start no de or the end node
1107 // are removed from the document during the work of this function. 1122 // are removed from the document during the work of this function.
1108 // If pushDownInlineStyleAroundNode has pruned start.deprecatedNode() or end .deprecatedNode(), 1123 // If pushDownInlineStyleAroundNode has pruned start.deprecatedNode() or end .deprecatedNode(),
1109 // use pushDownStart or pushDownEnd instead, which pushDownInlineStyleAround Node won't prune. 1124 // use pushDownStart or pushDownEnd instead, which pushDownInlineStyleAround Node won't prune.
1110 Position s = start.isNull() || start.isOrphan() ? pushDownStart : start; 1125 Position s = start.isNull() || start.isOrphan() ? pushDownStart : start;
1111 Position e = end.isNull() || end.isOrphan() ? pushDownEnd : end; 1126 Position e = end.isNull() || end.isOrphan() ? pushDownEnd : end;
1112 1127
1113 RefPtr<Node> node = start.deprecatedNode(); 1128 RefPtrWillBeRawPtr<Node> node = start.deprecatedNode();
1114 while (node) { 1129 while (node) {
1115 RefPtr<Node> next; 1130 RefPtrWillBeRawPtr<Node> next = nullptr;
1116 if (editingIgnoresContent(node.get())) { 1131 if (editingIgnoresContent(node.get())) {
1117 ASSERT(node == end.deprecatedNode() || !node->contains(end.deprecate dNode())); 1132 ASSERT(node == end.deprecatedNode() || !node->contains(end.deprecate dNode()));
1118 next = NodeTraversal::nextSkippingChildren(*node); 1133 next = NodeTraversal::nextSkippingChildren(*node);
1119 } else { 1134 } else {
1120 next = NodeTraversal::next(*node); 1135 next = NodeTraversal::next(*node);
1121 } 1136 }
1122 if (node->isHTMLElement() && nodeFullySelected(node.get(), start, end)) { 1137 if (node->isHTMLElement() && nodeFullySelected(node.get(), start, end)) {
1123 RefPtrWillBeRawPtr<HTMLElement> elem = toHTMLElement(node); 1138 RefPtrWillBeRawPtr<HTMLElement> elem = toHTMLElement(node);
1124 RefPtr<Node> prev = NodeTraversal::previousPostOrder(*elem); 1139 RefPtrWillBeRawPtr<Node> prev = NodeTraversal::previousPostOrder(*el em);
1125 RefPtr<Node> next = NodeTraversal::next(*elem); 1140 RefPtrWillBeRawPtr<Node> next = NodeTraversal::next(*elem);
1126 RefPtr<EditingStyle> styleToPushDown; 1141 RefPtrWillBeRawPtr<EditingStyle> styleToPushDown = nullptr;
1127 RefPtr<Node> childNode; 1142 RefPtrWillBeRawPtr<Node> childNode = nullptr;
1128 if (isStyledInlineElementToRemove(elem.get())) { 1143 if (isStyledInlineElementToRemove(elem.get())) {
1129 styleToPushDown = EditingStyle::create(); 1144 styleToPushDown = EditingStyle::create();
1130 childNode = elem->firstChild(); 1145 childNode = elem->firstChild();
1131 } 1146 }
1132 1147
1133 removeInlineStyleFromElement(style, elem.get(), RemoveIfNeeded, styl eToPushDown.get()); 1148 removeInlineStyleFromElement(style, elem.get(), RemoveIfNeeded, styl eToPushDown.get());
1134 if (!elem->inDocument()) { 1149 if (!elem->inDocument()) {
1135 if (s.deprecatedNode() == elem) { 1150 if (s.deprecatedNode() == elem) {
1136 // Since elem must have been fully selected, and it is at th e start 1151 // Since elem must have been fully selected, and it is at th e start
1137 // of the selection, it is clear we can set the new s offset to 0. 1152 // of the selection, it is clear we can set the new s offset to 0.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 bool shouldUpdateStart = start.containerNode() == endNode; 1334 bool shouldUpdateStart = start.containerNode() == endNode;
1320 int endOffset = nextChild ? nextChild->nodeIndex() : nextElement->childN odes()->length(); 1335 int endOffset = nextChild ? nextChild->nodeIndex() : nextElement->childN odes()->length();
1321 updateStartEnd(shouldUpdateStart ? Position(nextElement, start.offsetInC ontainerNode(), Position::PositionIsOffsetInAnchor) : start, 1336 updateStartEnd(shouldUpdateStart ? Position(nextElement, start.offsetInC ontainerNode(), Position::PositionIsOffsetInAnchor) : start,
1322 Position(nextElement, endOffset, Position::PositionIsOffs etInAnchor)); 1337 Position(nextElement, endOffset, Position::PositionIsOffs etInAnchor));
1323 return true; 1338 return true;
1324 } 1339 }
1325 1340
1326 return false; 1341 return false;
1327 } 1342 }
1328 1343
1329 void ApplyStyleCommand::surroundNodeRangeWithElement(PassRefPtr<Node> passedStar tNode, PassRefPtr<Node> endNode, PassRefPtr<Element> elementToInsert) 1344 void ApplyStyleCommand::surroundNodeRangeWithElement(PassRefPtrWillBeRawPtr<Node > passedStartNode, PassRefPtrWillBeRawPtr<Node> endNode, PassRefPtrWillBeRawPtr< Element> elementToInsert)
1330 { 1345 {
1331 ASSERT(passedStartNode); 1346 ASSERT(passedStartNode);
1332 ASSERT(endNode); 1347 ASSERT(endNode);
1333 ASSERT(elementToInsert); 1348 ASSERT(elementToInsert);
1334 RefPtr<Node> node = passedStartNode; 1349 RefPtrWillBeRawPtr<Node> node = passedStartNode;
1335 RefPtr<Element> element = elementToInsert; 1350 RefPtrWillBeRawPtr<Element> element = elementToInsert;
1336 1351
1337 insertNodeBefore(element, node); 1352 insertNodeBefore(element, node);
1338 1353
1339 while (node) { 1354 while (node) {
1340 RefPtr<Node> next = node->nextSibling(); 1355 RefPtrWillBeRawPtr<Node> next = node->nextSibling();
1341 if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)) { 1356 if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)) {
1342 removeNode(node); 1357 removeNode(node);
1343 appendNode(node, element); 1358 appendNode(node, element);
1344 } 1359 }
1345 if (node == endNode) 1360 if (node == endNode)
1346 break; 1361 break;
1347 node = next; 1362 node = next;
1348 } 1363 }
1349 1364
1350 RefPtr<Node> nextSibling = element->nextSibling(); 1365 RefPtrWillBeRawPtr<Node> nextSibling = element->nextSibling();
1351 RefPtr<Node> previousSibling = element->previousSibling(); 1366 RefPtrWillBeRawPtr<Node> previousSibling = element->previousSibling();
1352 if (nextSibling && nextSibling->isElementNode() && nextSibling->rendererIsEd itable() 1367 if (nextSibling && nextSibling->isElementNode() && nextSibling->rendererIsEd itable()
1353 && areIdenticalElements(element.get(), toElement(nextSibling))) 1368 && areIdenticalElements(element.get(), toElement(nextSibling)))
1354 mergeIdenticalElements(element.get(), toElement(nextSibling)); 1369 mergeIdenticalElements(element.get(), toElement(nextSibling));
1355 1370
1356 if (previousSibling && previousSibling->isElementNode() && previousSibling-> rendererIsEditable()) { 1371 if (previousSibling && previousSibling->isElementNode() && previousSibling-> rendererIsEditable()) {
1357 Node* mergedElement = previousSibling->nextSibling(); 1372 Node* mergedElement = previousSibling->nextSibling();
1358 if (mergedElement->isElementNode() && mergedElement->rendererIsEditable( ) 1373 if (mergedElement->isElementNode() && mergedElement->rendererIsEditable( )
1359 && areIdenticalElements(toElement(previousSibling), toElement(merged Element))) 1374 && areIdenticalElements(toElement(previousSibling), toElement(merged Element)))
1360 mergeIdenticalElements(toElement(previousSibling), toElement(mergedE lement)); 1375 mergeIdenticalElements(toElement(previousSibling), toElement(mergedE lement));
1361 } 1376 }
(...skipping 14 matching lines...) Expand all
1376 StringBuilder cssText; 1391 StringBuilder cssText;
1377 cssText.append(cssStyle); 1392 cssText.append(cssStyle);
1378 if (const StylePropertySet* decl = block->inlineStyle()) { 1393 if (const StylePropertySet* decl = block->inlineStyle()) {
1379 if (!cssStyle.isEmpty()) 1394 if (!cssStyle.isEmpty())
1380 cssText.append(' '); 1395 cssText.append(' ');
1381 cssText.append(decl->asText()); 1396 cssText.append(decl->asText());
1382 } 1397 }
1383 setNodeAttribute(block, styleAttr, cssText.toAtomicString()); 1398 setNodeAttribute(block, styleAttr, cssText.toAtomicString());
1384 } 1399 }
1385 1400
1386 void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, PassRefPtr<N ode> passedStart, PassRefPtr<Node> passedEnd, EAddStyledElement addStyledElement ) 1401 void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, PassRefPtrWi llBeRawPtr<Node> passedStart, PassRefPtrWillBeRawPtr<Node> passedEnd, EAddStyled Element addStyledElement)
1387 { 1402 {
1388 if (!passedStart || !passedEnd || !passedStart->inDocument() || !passedEnd-> inDocument()) 1403 if (!passedStart || !passedEnd || !passedStart->inDocument() || !passedEnd-> inDocument())
1389 return; 1404 return;
1390 1405
1391 RefPtr<Node> start = passedStart; 1406 RefPtrWillBeRawPtr<Node> start = passedStart;
1392 RefPtr<Node> dummyElement; 1407 RefPtrWillBeMember<Node> dummyElement = nullptr;
1393 StyleChange styleChange(style, positionToComputeInlineStyleChange(start, dum myElement)); 1408 StyleChange styleChange(style, positionToComputeInlineStyleChange(start, dum myElement));
1394 1409
1395 if (dummyElement) 1410 if (dummyElement)
1396 removeNode(dummyElement); 1411 removeNode(dummyElement);
1397 1412
1398 applyInlineStyleChange(start, passedEnd, styleChange, addStyledElement); 1413 applyInlineStyleChange(start, passedEnd, styleChange, addStyledElement);
1399 } 1414 }
1400 1415
1401 Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node> startNode, RefPtr<Node>& dummyElement) 1416 Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtrWillBeR awPtr<Node> startNode, RefPtrWillBeMember<Node>& dummyElement)
1402 { 1417 {
1403 // It's okay to obtain the style at the startNode because we've removed all relevant styles from the current run. 1418 // It's okay to obtain the style at the startNode because we've removed all relevant styles from the current run.
1404 if (!startNode->isElementNode()) { 1419 if (!startNode->isElementNode()) {
1405 dummyElement = createStyleSpanElement(document()); 1420 dummyElement = createStyleSpanElement(document());
1406 insertNodeAt(dummyElement, positionBeforeNode(startNode.get())); 1421 insertNodeAt(dummyElement, positionBeforeNode(startNode.get()));
1407 return positionBeforeNode(dummyElement.get()); 1422 return positionBeforeNode(dummyElement.get());
1408 } 1423 }
1409 1424
1410 return firstPositionInOrBeforeNode(startNode.get()); 1425 return firstPositionInOrBeforeNode(startNode.get());
1411 } 1426 }
1412 1427
1413 void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas sRefPtr<Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledEl ement) 1428 void ApplyStyleCommand::applyInlineStyleChange(PassRefPtrWillBeRawPtr<Node> pass edStart, PassRefPtrWillBeRawPtr<Node> passedEnd, StyleChange& styleChange, EAddS tyledElement addStyledElement)
1414 { 1429 {
1415 RefPtr<Node> startNode = passedStart; 1430 RefPtrWillBeRawPtr<Node> startNode = passedStart;
1416 RefPtr<Node> endNode = passedEnd; 1431 RefPtrWillBeRawPtr<Node> endNode = passedEnd;
1417 ASSERT(startNode->inDocument()); 1432 ASSERT(startNode->inDocument());
1418 ASSERT(endNode->inDocument()); 1433 ASSERT(endNode->inDocument());
1419 1434
1420 // Find appropriate font and span elements top-down. 1435 // Find appropriate font and span elements top-down.
1421 HTMLElement* fontContainer = 0; 1436 HTMLElement* fontContainer = 0;
1422 HTMLElement* styleContainer = 0; 1437 HTMLElement* styleContainer = 0;
1423 for (Node* container = startNode.get(); container && startNode == endNode; c ontainer = container->firstChild()) { 1438 for (Node* container = startNode.get(); container && startNode == endNode; c ontainer = container->firstChild()) {
1424 if (isHTMLFontElement(*container)) 1439 if (isHTMLFontElement(*container))
1425 fontContainer = toHTMLElement(container); 1440 fontContainer = toHTMLElement(container);
1426 bool styleContainerIsNotSpan = !isHTMLSpanElement(styleContainer); 1441 bool styleContainerIsNotSpan = !isHTMLSpanElement(styleContainer);
(...skipping 11 matching lines...) Expand all
1438 // Font tags need to go outside of CSS so that CSS font sizes override leagc y font sizes. 1453 // Font tags need to go outside of CSS so that CSS font sizes override leagc y font sizes.
1439 if (styleChange.applyFontColor() || styleChange.applyFontFace() || styleChan ge.applyFontSize()) { 1454 if (styleChange.applyFontColor() || styleChange.applyFontFace() || styleChan ge.applyFontSize()) {
1440 if (fontContainer) { 1455 if (fontContainer) {
1441 if (styleChange.applyFontColor()) 1456 if (styleChange.applyFontColor())
1442 setNodeAttribute(fontContainer, colorAttr, AtomicString(styleCha nge.fontColor())); 1457 setNodeAttribute(fontContainer, colorAttr, AtomicString(styleCha nge.fontColor()));
1443 if (styleChange.applyFontFace()) 1458 if (styleChange.applyFontFace())
1444 setNodeAttribute(fontContainer, faceAttr, AtomicString(styleChan ge.fontFace())); 1459 setNodeAttribute(fontContainer, faceAttr, AtomicString(styleChan ge.fontFace()));
1445 if (styleChange.applyFontSize()) 1460 if (styleChange.applyFontSize())
1446 setNodeAttribute(fontContainer, sizeAttr, AtomicString(styleChan ge.fontSize())); 1461 setNodeAttribute(fontContainer, sizeAttr, AtomicString(styleChan ge.fontSize()));
1447 } else { 1462 } else {
1448 RefPtr<Element> fontElement = createFontElement(document()); 1463 RefPtrWillBeRawPtr<Element> fontElement = createFontElement(document ());
1449 if (styleChange.applyFontColor()) 1464 if (styleChange.applyFontColor())
1450 fontElement->setAttribute(colorAttr, AtomicString(styleChange.fo ntColor())); 1465 fontElement->setAttribute(colorAttr, AtomicString(styleChange.fo ntColor()));
1451 if (styleChange.applyFontFace()) 1466 if (styleChange.applyFontFace())
1452 fontElement->setAttribute(faceAttr, AtomicString(styleChange.fon tFace())); 1467 fontElement->setAttribute(faceAttr, AtomicString(styleChange.fon tFace()));
1453 if (styleChange.applyFontSize()) 1468 if (styleChange.applyFontSize())
1454 fontElement->setAttribute(sizeAttr, AtomicString(styleChange.fon tSize())); 1469 fontElement->setAttribute(sizeAttr, AtomicString(styleChange.fon tSize()));
1455 surroundNodeRangeWithElement(startNode, endNode, fontElement.get()); 1470 surroundNodeRangeWithElement(startNode, endNode, fontElement.get());
1456 } 1471 }
1457 } 1472 }
1458 1473
1459 if (styleChange.cssStyle().length()) { 1474 if (styleChange.cssStyle().length()) {
1460 if (styleContainer) { 1475 if (styleContainer) {
1461 if (const StylePropertySet* existingStyle = styleContainer->inlineSt yle()) { 1476 if (const StylePropertySet* existingStyle = styleContainer->inlineSt yle()) {
1462 String existingText = existingStyle->asText(); 1477 String existingText = existingStyle->asText();
1463 StringBuilder cssText; 1478 StringBuilder cssText;
1464 cssText.append(existingText); 1479 cssText.append(existingText);
1465 if (!existingText.isEmpty()) 1480 if (!existingText.isEmpty())
1466 cssText.append(' '); 1481 cssText.append(' ');
1467 cssText.append(styleChange.cssStyle()); 1482 cssText.append(styleChange.cssStyle());
1468 setNodeAttribute(styleContainer, styleAttr, cssText.toAtomicStri ng()); 1483 setNodeAttribute(styleContainer, styleAttr, cssText.toAtomicStri ng());
1469 } else { 1484 } else {
1470 setNodeAttribute(styleContainer, styleAttr, AtomicString(styleCh ange.cssStyle())); 1485 setNodeAttribute(styleContainer, styleAttr, AtomicString(styleCh ange.cssStyle()));
1471 } 1486 }
1472 } else { 1487 } else {
1473 RefPtr<Element> styleElement = createStyleSpanElement(document()); 1488 RefPtrWillBeRawPtr<Element> styleElement = createStyleSpanElement(do cument());
1474 styleElement->setAttribute(styleAttr, AtomicString(styleChange.cssSt yle())); 1489 styleElement->setAttribute(styleAttr, AtomicString(styleChange.cssSt yle()));
1475 surroundNodeRangeWithElement(startNode, endNode, styleElement.releas e()); 1490 surroundNodeRangeWithElement(startNode, endNode, styleElement.releas e());
1476 } 1491 }
1477 } 1492 }
1478 1493
1479 if (styleChange.applyBold()) 1494 if (styleChange.applyBold())
1480 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum ent(), bTag)); 1495 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum ent(), bTag));
1481 1496
1482 if (styleChange.applyItalic()) 1497 if (styleChange.applyItalic())
1483 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum ent(), iTag)); 1498 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum ent(), iTag));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 newEnd = Position(childText, childText->length() + end.offsetInConta inerNode()); 1557 newEnd = Position(childText, childText->length() + end.offsetInConta inerNode());
1543 String textToMove = nextText->data(); 1558 String textToMove = nextText->data();
1544 insertTextIntoNode(childText, childText->length(), textToMove); 1559 insertTextIntoNode(childText, childText->length(), textToMove);
1545 removeNode(next); 1560 removeNode(next);
1546 // don't move child node pointer. it may want to merge with more text no des. 1561 // don't move child node pointer. it may want to merge with more text no des.
1547 } 1562 }
1548 1563
1549 updateStartEnd(newStart, newEnd); 1564 updateStartEnd(newStart, newEnd);
1550 } 1565 }
1551 1566
1567 void ApplyStyleCommand::trace(Visitor* visitor)
1568 {
1569 visitor->trace(m_style);
1570 visitor->trace(m_start);
1571 visitor->trace(m_end);
1572 visitor->trace(m_styledInlineElement);
1573 CompositeEditCommand::trace(visitor);
1552 } 1574 }
1575
1576 }
OLDNEW
« no previous file with comments | « Source/core/editing/ApplyStyleCommand.h ('k') | Source/core/editing/BreakBlockquoteCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698