| OLD | NEW |
| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 RefPtr<Element> fontNode = createHTMLElement(document, fontTag); | 109 RefPtr<Element> fontNode = createHTMLElement(document, fontTag); |
| 110 return fontNode.release(); | 110 return fontNode.release(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 PassRefPtr<HTMLElement> createStyleSpanElement(Document* document) | 113 PassRefPtr<HTMLElement> createStyleSpanElement(Document* document) |
| 114 { | 114 { |
| 115 RefPtr<HTMLElement> styleElement = createHTMLElement(document, spanTag); | 115 RefPtr<HTMLElement> styleElement = createHTMLElement(document, spanTag); |
| 116 return styleElement.release(); | 116 return styleElement.release(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 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) |
| 120 : CompositeEditCommand(document) | 120 : CompositeEditCommand(document) |
| 121 , m_style(style->copy()) | 121 , m_style(style->copy()) |
| 122 , m_editingAction(editingAction) | 122 , m_editingAction(editingAction) |
| 123 , m_propertyLevel(propertyLevel) | 123 , m_propertyLevel(propertyLevel) |
| 124 , m_start(endingSelection().start().downstream()) | 124 , m_start(endingSelection().start().downstream()) |
| 125 , m_end(endingSelection().end().upstream()) | 125 , m_end(endingSelection().end().upstream()) |
| 126 , m_useEndingSelection(true) | 126 , m_useEndingSelection(true) |
| 127 , m_styledInlineElement(0) | 127 , m_styledInlineElement(0) |
| 128 , m_removeOnly(false) | 128 , m_removeOnly(false) |
| 129 , m_isInlineElementToRemoveFunction(0) | 129 , m_isInlineElementToRemoveFunction(0) |
| 130 { | 130 { |
| 131 } | 131 } |
| 132 | 132 |
| 133 ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* sty
le, const Position& start, const Position& end, EditAction editingAction, EPrope
rtyLevel propertyLevel) | 133 ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* sty
le, const Position& start, const Position& end, EditAction editingAction, EPrope
rtyLevel propertyLevel) |
| 134 : CompositeEditCommand(document) | 134 : CompositeEditCommand(document) |
| 135 , m_style(style->copy()) | 135 , m_style(style->copy()) |
| 136 , m_editingAction(editingAction) | 136 , m_editingAction(editingAction) |
| 137 , m_propertyLevel(propertyLevel) | 137 , m_propertyLevel(propertyLevel) |
| 138 , m_start(start) | 138 , m_start(start) |
| 139 , m_end(end) | 139 , m_end(end) |
| 140 , m_useEndingSelection(false) | 140 , m_useEndingSelection(false) |
| 141 , m_styledInlineElement(0) | 141 , m_styledInlineElement(0) |
| 142 , m_removeOnly(false) | 142 , m_removeOnly(false) |
| 143 , m_isInlineElementToRemoveFunction(0) | 143 , m_isInlineElementToRemoveFunction(0) |
| 144 { | 144 { |
| 145 } | 145 } |
| 146 | 146 |
| 147 ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnl
y, EditAction editingAction) | 147 ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnl
y, EditAction editingAction) |
| 148 : CompositeEditCommand(&element->document()) | 148 : CompositeEditCommand(element->document()) |
| 149 , m_style(EditingStyle::create()) | 149 , m_style(EditingStyle::create()) |
| 150 , m_editingAction(editingAction) | 150 , m_editingAction(editingAction) |
| 151 , m_propertyLevel(PropertyDefault) | 151 , m_propertyLevel(PropertyDefault) |
| 152 , m_start(endingSelection().start().downstream()) | 152 , m_start(endingSelection().start().downstream()) |
| 153 , m_end(endingSelection().end().upstream()) | 153 , m_end(endingSelection().end().upstream()) |
| 154 , m_useEndingSelection(true) | 154 , m_useEndingSelection(true) |
| 155 , m_styledInlineElement(element) | 155 , m_styledInlineElement(element) |
| 156 , m_removeOnly(removeOnly) | 156 , m_removeOnly(removeOnly) |
| 157 , m_isInlineElementToRemoveFunction(0) | 157 , m_isInlineElementToRemoveFunction(0) |
| 158 { | 158 { |
| 159 } | 159 } |
| 160 | 160 |
| 161 ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* sty
le, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction
editingAction) | 161 ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* sty
le, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction
editingAction) |
| 162 : CompositeEditCommand(document) | 162 : CompositeEditCommand(document) |
| 163 , m_style(style->copy()) | 163 , m_style(style->copy()) |
| 164 , m_editingAction(editingAction) | 164 , m_editingAction(editingAction) |
| 165 , m_propertyLevel(PropertyDefault) | 165 , m_propertyLevel(PropertyDefault) |
| 166 , m_start(endingSelection().start().downstream()) | 166 , m_start(endingSelection().start().downstream()) |
| 167 , m_end(endingSelection().end().upstream()) | 167 , m_end(endingSelection().end().upstream()) |
| 168 , m_useEndingSelection(true) | 168 , m_useEndingSelection(true) |
| 169 , m_styledInlineElement(0) | 169 , m_styledInlineElement(0) |
| 170 , m_removeOnly(true) | 170 , m_removeOnly(true) |
| 171 , m_isInlineElementToRemoveFunction(isInlineElementToRemoveFunction) | 171 , m_isInlineElementToRemoveFunction(isInlineElementToRemoveFunction) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 EditAction ApplyStyleCommand::editingAction() const | 225 EditAction ApplyStyleCommand::editingAction() const |
| 226 { | 226 { |
| 227 return m_editingAction; | 227 return m_editingAction; |
| 228 } | 228 } |
| 229 | 229 |
| 230 void ApplyStyleCommand::applyBlockStyle(EditingStyle *style) | 230 void ApplyStyleCommand::applyBlockStyle(EditingStyle *style) |
| 231 { | 231 { |
| 232 // update document layout once before removing styles | 232 // update document layout once before removing styles |
| 233 // so that we avoid the expense of updating before each and every call | 233 // so that we avoid the expense of updating before each and every call |
| 234 // to check a computed style | 234 // to check a computed style |
| 235 document()->updateLayoutIgnorePendingStylesheets(); | 235 document().updateLayoutIgnorePendingStylesheets(); |
| 236 | 236 |
| 237 // get positions we want to use for applying style | 237 // get positions we want to use for applying style |
| 238 Position start = startPosition(); | 238 Position start = startPosition(); |
| 239 Position end = endPosition(); | 239 Position end = endPosition(); |
| 240 if (comparePositions(end, start) < 0) { | 240 if (comparePositions(end, start) < 0) { |
| 241 Position swap = start; | 241 Position swap = start; |
| 242 start = end; | 242 start = end; |
| 243 end = swap; | 243 end = swap; |
| 244 } | 244 } |
| 245 | 245 |
| 246 VisiblePosition visibleStart(start); | 246 VisiblePosition visibleStart(start); |
| 247 VisiblePosition visibleEnd(end); | 247 VisiblePosition visibleEnd(end); |
| 248 | 248 |
| 249 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull()
|| visibleEnd.isOrphan()) | 249 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull()
|| visibleEnd.isOrphan()) |
| 250 return; | 250 return; |
| 251 | 251 |
| 252 // Save and restore the selection endpoints using their indices in the docum
ent, since | 252 // Save and restore the selection endpoints using their indices in the docum
ent, since |
| 253 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint
s. | 253 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint
s. |
| 254 // Calculate start and end indices from the start of the tree that they're i
n. | 254 // Calculate start and end indices from the start of the tree that they're i
n. |
| 255 Node* scope = highestAncestor(visibleStart.deepEquivalent().deprecatedNode()
); | 255 Node* scope = highestAncestor(visibleStart.deepEquivalent().deprecatedNode()
); |
| 256 RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(sco
pe), visibleStart.deepEquivalent().parentAnchoredEquivalent()); | 256 RefPtr<Range> startRange = Range::create(&document(), firstPositionInNode(sc
ope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); |
| 257 RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope
), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); | 257 RefPtr<Range> endRange = Range::create(&document(), firstPositionInNode(scop
e), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); |
| 258 int startIndex = TextIterator::rangeLength(startRange.get(), true); | 258 int startIndex = TextIterator::rangeLength(startRange.get(), true); |
| 259 int endIndex = TextIterator::rangeLength(endRange.get(), true); | 259 int endIndex = TextIterator::rangeLength(endRange.get(), true); |
| 260 | 260 |
| 261 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); | 261 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); |
| 262 VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next()); | 262 VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next()); |
| 263 VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next()); | 263 VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next()); |
| 264 while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) { | 264 while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) { |
| 265 StyleChange styleChange(style, paragraphStart.deepEquivalent()); | 265 StyleChange styleChange(style, paragraphStart.deepEquivalent()); |
| 266 if (styleChange.cssStyle().length() || m_removeOnly) { | 266 if (styleChange.cssStyle().length() || m_removeOnly) { |
| 267 RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent().
deprecatedNode()); | 267 RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent().
deprecatedNode()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(n
ode)) { | 372 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(n
ode)) { |
| 373 RefPtr<HTMLElement> element; | 373 RefPtr<HTMLElement> element; |
| 374 if (node->isHTMLElement()) { | 374 if (node->isHTMLElement()) { |
| 375 // Only work on fully selected nodes. | 375 // Only work on fully selected nodes. |
| 376 if (!nodeFullySelected(node, start, end)) | 376 if (!nodeFullySelected(node, start, end)) |
| 377 continue; | 377 continue; |
| 378 element = toHTMLElement(node); | 378 element = toHTMLElement(node); |
| 379 } else if (node->isTextNode() && node->renderer() && node->parentNode()
!= lastStyledNode) { | 379 } else if (node->isTextNode() && node->renderer() && node->parentNode()
!= lastStyledNode) { |
| 380 // Last styled node was not parent node of this text node, but we wi
sh to style this | 380 // Last styled node was not parent node of this text node, but we wi
sh to style this |
| 381 // text node. To make this possible, add a style span to surround th
is text node. | 381 // text node. To make this possible, add a style span to surround th
is text node. |
| 382 RefPtr<HTMLElement> span = createStyleSpanElement(document()); | 382 RefPtr<HTMLElement> span = createStyleSpanElement(&document()); |
| 383 surroundNodeRangeWithElement(node, node, span.get()); | 383 surroundNodeRangeWithElement(node, node, span.get()); |
| 384 element = span.release(); | 384 element = span.release(); |
| 385 } else { | 385 } else { |
| 386 // Only handle HTML elements and text nodes. | 386 // Only handle HTML elements and text nodes. |
| 387 continue; | 387 continue; |
| 388 } | 388 } |
| 389 lastStyledNode = node; | 389 lastStyledNode = node; |
| 390 | 390 |
| 391 RefPtr<MutableStylePropertySet> inlineStyle = copyStyleOrCreateEmpty(ele
ment->inlineStyle()); | 391 RefPtr<MutableStylePropertySet> inlineStyle = copyStyleOrCreateEmpty(ele
ment->inlineStyle()); |
| 392 float currentFontSize = computedFontSize(node); | 392 float currentFontSize = computedFontSize(node); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 536 } |
| 537 | 537 |
| 538 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style) | 538 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style) |
| 539 { | 539 { |
| 540 RefPtr<Node> startDummySpanAncestor = 0; | 540 RefPtr<Node> startDummySpanAncestor = 0; |
| 541 RefPtr<Node> endDummySpanAncestor = 0; | 541 RefPtr<Node> endDummySpanAncestor = 0; |
| 542 | 542 |
| 543 // update document layout once before removing styles | 543 // update document layout once before removing styles |
| 544 // so that we avoid the expense of updating before each and every call | 544 // so that we avoid the expense of updating before each and every call |
| 545 // to check a computed style | 545 // to check a computed style |
| 546 document()->updateLayoutIgnorePendingStylesheets(); | 546 document().updateLayoutIgnorePendingStylesheets(); |
| 547 | 547 |
| 548 // adjust to the positions we want to use for applying style | 548 // adjust to the positions we want to use for applying style |
| 549 Position start = startPosition(); | 549 Position start = startPosition(); |
| 550 Position end = endPosition(); | 550 Position end = endPosition(); |
| 551 | 551 |
| 552 if (start.isNull() || end.isNull()) | 552 if (start.isNull() || end.isNull()) |
| 553 return; | 553 return; |
| 554 | 554 |
| 555 if (comparePositions(end, start) < 0) { | 555 if (comparePositions(end, start) < 0) { |
| 556 Position swap = start; | 556 Position swap = start; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 630 |
| 631 if (splitEnd) { | 631 if (splitEnd) { |
| 632 mergeEndWithNextIfIdentical(start, end); | 632 mergeEndWithNextIfIdentical(start, end); |
| 633 start = startPosition(); | 633 start = startPosition(); |
| 634 end = endPosition(); | 634 end = endPosition(); |
| 635 } | 635 } |
| 636 | 636 |
| 637 // update document layout once before running the rest of the function | 637 // update document layout once before running the rest of the function |
| 638 // so that we avoid the expense of updating before each and every call | 638 // so that we avoid the expense of updating before each and every call |
| 639 // to check a computed style | 639 // to check a computed style |
| 640 document()->updateLayoutIgnorePendingStylesheets(); | 640 document().updateLayoutIgnorePendingStylesheets(); |
| 641 | 641 |
| 642 RefPtr<EditingStyle> styleToApply = style; | 642 RefPtr<EditingStyle> styleToApply = style; |
| 643 if (hasTextDirection) { | 643 if (hasTextDirection) { |
| 644 // Avoid applying the unicode-bidi and direction properties beneath ance
stors that already have them. | 644 // Avoid applying the unicode-bidi and direction properties beneath ance
stors that already have them. |
| 645 Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode
(), enclosingBlock(start.deprecatedNode())); | 645 Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode
(), enclosingBlock(start.deprecatedNode())); |
| 646 Node* embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(),
enclosingBlock(end.deprecatedNode())); | 646 Node* embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(),
enclosingBlock(end.deprecatedNode())); |
| 647 | 647 |
| 648 if (embeddingStartNode || embeddingEndNode) { | 648 if (embeddingStartNode || embeddingEndNode) { |
| 649 Position embeddingApplyStart = embeddingStartNode ? positionInParent
AfterNode(embeddingStartNode) : start; | 649 Position embeddingApplyStart = embeddingStartNode ? positionInParent
AfterNode(embeddingStartNode) : start; |
| 650 Position embeddingApplyEnd = embeddingEndNode ? positionInParentBefo
reNode(embeddingEndNode) : end; | 650 Position embeddingApplyEnd = embeddingEndNode ? positionInParentBefo
reNode(embeddingEndNode) : end; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 Position positionForStyleComputation; | 734 Position positionForStyleComputation; |
| 735 RefPtr<Node> dummyElement; | 735 RefPtr<Node> dummyElement; |
| 736 StyleChange change; | 736 StyleChange change; |
| 737 }; | 737 }; |
| 738 | 738 |
| 739 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRef
Ptr<Node> startNode, PassRefPtr<Node> pastEndNode) | 739 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRef
Ptr<Node> startNode, PassRefPtr<Node> pastEndNode) |
| 740 { | 740 { |
| 741 if (m_removeOnly) | 741 if (m_removeOnly) |
| 742 return; | 742 return; |
| 743 | 743 |
| 744 document()->updateLayoutIgnorePendingStylesheets(); | 744 document().updateLayoutIgnorePendingStylesheets(); |
| 745 | 745 |
| 746 Vector<InlineRunToApplyStyle> runs; | 746 Vector<InlineRunToApplyStyle> runs; |
| 747 RefPtr<Node> node = startNode; | 747 RefPtr<Node> node = startNode; |
| 748 for (RefPtr<Node> next; node && node != pastEndNode; node = next) { | 748 for (RefPtr<Node> next; node && node != pastEndNode; node = next) { |
| 749 next = NodeTraversal::next(node.get()); | 749 next = NodeTraversal::next(node.get()); |
| 750 | 750 |
| 751 if (!node->renderer() || !node->rendererIsEditable()) | 751 if (!node->renderer() || !node->rendererIsEditable()) |
| 752 continue; | 752 continue; |
| 753 | 753 |
| 754 if (!node->rendererIsRichlyEditable() && node->isHTMLElement()) { | 754 if (!node->rendererIsRichlyEditable() && node->isHTMLElement()) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 continue; | 794 continue; |
| 795 | 795 |
| 796 runs.append(InlineRunToApplyStyle(runStart, runEnd, pastEndNode)); | 796 runs.append(InlineRunToApplyStyle(runStart, runEnd, pastEndNode)); |
| 797 } | 797 } |
| 798 | 798 |
| 799 for (size_t i = 0; i < runs.size(); i++) { | 799 for (size_t i = 0; i < runs.size(); i++) { |
| 800 removeConflictingInlineStyleFromRun(style, runs[i].start, runs[i].end, r
uns[i].pastEndNode); | 800 removeConflictingInlineStyleFromRun(style, runs[i].start, runs[i].end, r
uns[i].pastEndNode); |
| 801 runs[i].positionForStyleComputation = positionToComputeInlineStyleChange
(runs[i].start, runs[i].dummyElement); | 801 runs[i].positionForStyleComputation = positionToComputeInlineStyleChange
(runs[i].start, runs[i].dummyElement); |
| 802 } | 802 } |
| 803 | 803 |
| 804 document()->updateLayoutIgnorePendingStylesheets(); | 804 document().updateLayoutIgnorePendingStylesheets(); |
| 805 | 805 |
| 806 for (size_t i = 0; i < runs.size(); i++) | 806 for (size_t i = 0; i < runs.size(); i++) |
| 807 runs[i].change = StyleChange(style, runs[i].positionForStyleComputation)
; | 807 runs[i].change = StyleChange(style, runs[i].positionForStyleComputation)
; |
| 808 | 808 |
| 809 for (size_t i = 0; i < runs.size(); i++) { | 809 for (size_t i = 0; i < runs.size(); i++) { |
| 810 InlineRunToApplyStyle& run = runs[i]; | 810 InlineRunToApplyStyle& run = runs[i]; |
| 811 if (run.dummyElement) | 811 if (run.dummyElement) |
| 812 removeNode(run.dummyElement); | 812 removeNode(run.dummyElement); |
| 813 if (run.startAndEndAreStillInDocument()) | 813 if (run.startAndEndAreStillInDocument()) |
| 814 applyInlineStyleChange(run.start.release(), run.end.release(), run.c
hange, AddStyledElement); | 814 applyInlineStyleChange(run.start.release(), run.end.release(), run.c
hange, AddStyledElement); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 removeNode(dummyElement); | 1397 removeNode(dummyElement); |
| 1398 | 1398 |
| 1399 applyInlineStyleChange(start, passedEnd, styleChange, addStyledElement); | 1399 applyInlineStyleChange(start, passedEnd, styleChange, addStyledElement); |
| 1400 } | 1400 } |
| 1401 | 1401 |
| 1402 Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node>
startNode, RefPtr<Node>& dummyElement) | 1402 Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node>
startNode, RefPtr<Node>& dummyElement) |
| 1403 { | 1403 { |
| 1404 // It's okay to obtain the style at the startNode because we've removed all
relevant styles from the current run. | 1404 // It's okay to obtain the style at the startNode because we've removed all
relevant styles from the current run. |
| 1405 Position positionForStyleComparison; | 1405 Position positionForStyleComparison; |
| 1406 if (!startNode->isElementNode()) { | 1406 if (!startNode->isElementNode()) { |
| 1407 dummyElement = createStyleSpanElement(document()); | 1407 dummyElement = createStyleSpanElement(&document()); |
| 1408 insertNodeAt(dummyElement, positionBeforeNode(startNode.get())); | 1408 insertNodeAt(dummyElement, positionBeforeNode(startNode.get())); |
| 1409 return positionBeforeNode(dummyElement.get()); | 1409 return positionBeforeNode(dummyElement.get()); |
| 1410 } | 1410 } |
| 1411 | 1411 |
| 1412 return firstPositionInOrBeforeNode(startNode.get()); | 1412 return firstPositionInOrBeforeNode(startNode.get()); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
sRefPtr<Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledEl
ement) | 1415 void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
sRefPtr<Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledEl
ement) |
| 1416 { | 1416 { |
| 1417 RefPtr<Node> startNode = passedStart; | 1417 RefPtr<Node> startNode = passedStart; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1437 // Font tags need to go outside of CSS so that CSS font sizes override leagc
y font sizes. | 1437 // Font tags need to go outside of CSS so that CSS font sizes override leagc
y font sizes. |
| 1438 if (styleChange.applyFontColor() || styleChange.applyFontFace() || styleChan
ge.applyFontSize()) { | 1438 if (styleChange.applyFontColor() || styleChange.applyFontFace() || styleChan
ge.applyFontSize()) { |
| 1439 if (fontContainer) { | 1439 if (fontContainer) { |
| 1440 if (styleChange.applyFontColor()) | 1440 if (styleChange.applyFontColor()) |
| 1441 setNodeAttribute(fontContainer, colorAttr, styleChange.fontColor
()); | 1441 setNodeAttribute(fontContainer, colorAttr, styleChange.fontColor
()); |
| 1442 if (styleChange.applyFontFace()) | 1442 if (styleChange.applyFontFace()) |
| 1443 setNodeAttribute(fontContainer, faceAttr, styleChange.fontFace()
); | 1443 setNodeAttribute(fontContainer, faceAttr, styleChange.fontFace()
); |
| 1444 if (styleChange.applyFontSize()) | 1444 if (styleChange.applyFontSize()) |
| 1445 setNodeAttribute(fontContainer, sizeAttr, styleChange.fontSize()
); | 1445 setNodeAttribute(fontContainer, sizeAttr, styleChange.fontSize()
); |
| 1446 } else { | 1446 } else { |
| 1447 RefPtr<Element> fontElement = createFontElement(document()); | 1447 RefPtr<Element> fontElement = createFontElement(&document()); |
| 1448 if (styleChange.applyFontColor()) | 1448 if (styleChange.applyFontColor()) |
| 1449 fontElement->setAttribute(colorAttr, styleChange.fontColor()); | 1449 fontElement->setAttribute(colorAttr, styleChange.fontColor()); |
| 1450 if (styleChange.applyFontFace()) | 1450 if (styleChange.applyFontFace()) |
| 1451 fontElement->setAttribute(faceAttr, styleChange.fontFace()); | 1451 fontElement->setAttribute(faceAttr, styleChange.fontFace()); |
| 1452 if (styleChange.applyFontSize()) | 1452 if (styleChange.applyFontSize()) |
| 1453 fontElement->setAttribute(sizeAttr, styleChange.fontSize()); | 1453 fontElement->setAttribute(sizeAttr, styleChange.fontSize()); |
| 1454 surroundNodeRangeWithElement(startNode, endNode, fontElement.get()); | 1454 surroundNodeRangeWithElement(startNode, endNode, fontElement.get()); |
| 1455 } | 1455 } |
| 1456 } | 1456 } |
| 1457 | 1457 |
| 1458 if (styleChange.cssStyle().length()) { | 1458 if (styleChange.cssStyle().length()) { |
| 1459 if (styleContainer) { | 1459 if (styleContainer) { |
| 1460 if (const StylePropertySet* existingStyle = styleContainer->inlineSt
yle()) { | 1460 if (const StylePropertySet* existingStyle = styleContainer->inlineSt
yle()) { |
| 1461 String existingText = existingStyle->asText(); | 1461 String existingText = existingStyle->asText(); |
| 1462 StringBuilder cssText; | 1462 StringBuilder cssText; |
| 1463 cssText.append(existingText); | 1463 cssText.append(existingText); |
| 1464 if (!existingText.isEmpty()) | 1464 if (!existingText.isEmpty()) |
| 1465 cssText.append(' '); | 1465 cssText.append(' '); |
| 1466 cssText.append(styleChange.cssStyle()); | 1466 cssText.append(styleChange.cssStyle()); |
| 1467 setNodeAttribute(styleContainer, styleAttr, cssText.toString()); | 1467 setNodeAttribute(styleContainer, styleAttr, cssText.toString()); |
| 1468 } else | 1468 } else |
| 1469 setNodeAttribute(styleContainer, styleAttr, styleChange.cssStyle
()); | 1469 setNodeAttribute(styleContainer, styleAttr, styleChange.cssStyle
()); |
| 1470 } else { | 1470 } else { |
| 1471 RefPtr<Element> styleElement = createStyleSpanElement(document()); | 1471 RefPtr<Element> styleElement = createStyleSpanElement(&document()); |
| 1472 styleElement->setAttribute(styleAttr, styleChange.cssStyle()); | 1472 styleElement->setAttribute(styleAttr, styleChange.cssStyle()); |
| 1473 surroundNodeRangeWithElement(startNode, endNode, styleElement.releas
e()); | 1473 surroundNodeRangeWithElement(startNode, endNode, styleElement.releas
e()); |
| 1474 } | 1474 } |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 if (styleChange.applyBold()) | 1477 if (styleChange.applyBold()) |
| 1478 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum
ent(), bTag)); | 1478 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&docu
ment(), bTag)); |
| 1479 | 1479 |
| 1480 if (styleChange.applyItalic()) | 1480 if (styleChange.applyItalic()) |
| 1481 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum
ent(), iTag)); | 1481 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&docu
ment(), iTag)); |
| 1482 | 1482 |
| 1483 if (styleChange.applyUnderline()) | 1483 if (styleChange.applyUnderline()) |
| 1484 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum
ent(), uTag)); | 1484 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&docu
ment(), uTag)); |
| 1485 | 1485 |
| 1486 if (styleChange.applyLineThrough()) | 1486 if (styleChange.applyLineThrough()) |
| 1487 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum
ent(), strikeTag)); | 1487 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&docu
ment(), strikeTag)); |
| 1488 | 1488 |
| 1489 if (styleChange.applySubscript()) | 1489 if (styleChange.applySubscript()) |
| 1490 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum
ent(), subTag)); | 1490 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&docu
ment(), subTag)); |
| 1491 else if (styleChange.applySuperscript()) | 1491 else if (styleChange.applySuperscript()) |
| 1492 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(docum
ent(), supTag)); | 1492 surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&docu
ment(), supTag)); |
| 1493 | 1493 |
| 1494 if (m_styledInlineElement && addStyledElement == AddStyledElement) | 1494 if (m_styledInlineElement && addStyledElement == AddStyledElement) |
| 1495 surroundNodeRangeWithElement(startNode, endNode, m_styledInlineElement->
cloneElementWithoutChildren()); | 1495 surroundNodeRangeWithElement(startNode, endNode, m_styledInlineElement->
cloneElementWithoutChildren()); |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 float ApplyStyleCommand::computedFontSize(Node* node) | 1498 float ApplyStyleCommand::computedFontSize(Node* node) |
| 1499 { | 1499 { |
| 1500 if (!node) | 1500 if (!node) |
| 1501 return 0; | 1501 return 0; |
| 1502 | 1502 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 String textToMove = nextText->data(); | 1541 String textToMove = nextText->data(); |
| 1542 insertTextIntoNode(childText, childText->length(), textToMove); | 1542 insertTextIntoNode(childText, childText->length(), textToMove); |
| 1543 removeNode(next); | 1543 removeNode(next); |
| 1544 // don't move child node pointer. it may want to merge with more text no
des. | 1544 // don't move child node pointer. it may want to merge with more text no
des. |
| 1545 } | 1545 } |
| 1546 | 1546 |
| 1547 updateStartEnd(newStart, newEnd); | 1547 updateStartEnd(newStart, newEnd); |
| 1548 } | 1548 } |
| 1549 | 1549 |
| 1550 } | 1550 } |
| OLD | NEW |