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

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

Powered by Google App Engine
This is Rietveld 408576698