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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 bool ApplyStyleCommand::shouldApplyInlineStyleToRun(EditingStyle* style, Node* r
unStart, Node* pastEndNode) | 841 bool ApplyStyleCommand::shouldApplyInlineStyleToRun(EditingStyle* style, Node* r
unStart, Node* pastEndNode) |
842 { | 842 { |
843 ASSERT(style && runStart); | 843 ASSERT(style && runStart); |
844 | 844 |
845 for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversa
l::next(*node)) { | 845 for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversa
l::next(*node)) { |
846 if (node->hasChildren()) | 846 if (node->hasChildren()) |
847 continue; | 847 continue; |
848 // We don't consider m_isInlineElementToRemoveFunction here because we n
ever apply style when m_isInlineElementToRemoveFunction is specified | 848 // We don't consider m_isInlineElementToRemoveFunction here because we n
ever apply style when m_isInlineElementToRemoveFunction is specified |
849 if (!style->styleIsPresentInComputedStyleOfNode(node)) | 849 if (!style->styleIsPresentInComputedStyleOfNode(node)) |
850 return true; | 850 return true; |
851 if (m_styledInlineElement && !enclosingNodeWithTag(positionBeforeNode(*n
ode), m_styledInlineElement->tagQName())) | 851 if (m_styledInlineElement && !enclosingNodeWithTag(positionBeforeNode(no
de), m_styledInlineElement->tagQName())) |
852 return true; | 852 return true; |
853 } | 853 } |
854 return false; | 854 return false; |
855 } | 855 } |
856 | 856 |
857 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style,
RefPtr<Node>& runStart, RefPtr<Node>& runEnd, PassRefPtr<Node> pastEndNode) | 857 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style,
RefPtr<Node>& runStart, RefPtr<Node>& runEnd, PassRefPtr<Node> pastEndNode) |
858 { | 858 { |
859 ASSERT(runStart && runEnd); | 859 ASSERT(runStart && runEnd); |
860 RefPtr<Node> next = runStart; | 860 RefPtr<Node> next = runStart; |
861 for (RefPtr<Node> node = next; node && node->inDocument() && node != pastEnd
Node; node = next) { | 861 for (RefPtr<Node> node = next; node && node->inDocument() && node != pastEnd
Node; node = next) { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 { | 1206 { |
1207 ASSERT(start.containerNode()->isTextNode()); | 1207 ASSERT(start.containerNode()->isTextNode()); |
1208 | 1208 |
1209 Position newEnd; | 1209 Position newEnd; |
1210 if (start.containerNode() == end.containerNode()) | 1210 if (start.containerNode() == end.containerNode()) |
1211 newEnd = Position(end.containerText(), end.offsetInContainerNode() - sta
rt.offsetInContainerNode()); | 1211 newEnd = Position(end.containerText(), end.offsetInContainerNode() - sta
rt.offsetInContainerNode()); |
1212 else | 1212 else |
1213 newEnd = end; | 1213 newEnd = end; |
1214 | 1214 |
1215 splitTextNodeContainingElement(start.containerText(), start.offsetInContaine
rNode()); | 1215 splitTextNodeContainingElement(start.containerText(), start.offsetInContaine
rNode()); |
1216 updateStartEnd(positionBeforeNode(*start.containerNode()), newEnd); | 1216 updateStartEnd(positionBeforeNode(start.containerNode()), newEnd); |
1217 } | 1217 } |
1218 | 1218 |
1219 void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Posit
ion& end) | 1219 void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Posit
ion& end) |
1220 { | 1220 { |
1221 ASSERT(end.containerNode()->isTextNode()); | 1221 ASSERT(end.containerNode()->isTextNode()); |
1222 | 1222 |
1223 bool shouldUpdateStart = start.containerNode() == end.containerNode(); | 1223 bool shouldUpdateStart = start.containerNode() == end.containerNode(); |
1224 splitTextNodeContainingElement(end.containerText(), end.offsetInContainerNod
e()); | 1224 splitTextNodeContainingElement(end.containerText(), end.offsetInContainerNod
e()); |
1225 | 1225 |
1226 Node* parentElement = end.containerNode()->parentNode(); | 1226 Node* parentElement = end.containerNode()->parentNode(); |
1227 if (!parentElement || !parentElement->previousSibling()) | 1227 if (!parentElement || !parentElement->previousSibling()) |
1228 return; | 1228 return; |
1229 Node* firstTextNode = parentElement->previousSibling()->lastChild(); | 1229 Node* firstTextNode = parentElement->previousSibling()->lastChild(); |
1230 if (!firstTextNode || !firstTextNode->isTextNode()) | 1230 if (!firstTextNode || !firstTextNode->isTextNode()) |
1231 return; | 1231 return; |
1232 | 1232 |
1233 Position newStart = shouldUpdateStart ? Position(toText(firstTextNode), star
t.offsetInContainerNode()) : start; | 1233 Position newStart = shouldUpdateStart ? Position(toText(firstTextNode), star
t.offsetInContainerNode()) : start; |
1234 updateStartEnd(newStart, positionAfterNode(*firstTextNode)); | 1234 updateStartEnd(newStart, positionAfterNode(firstTextNode)); |
1235 } | 1235 } |
1236 | 1236 |
1237 bool ApplyStyleCommand::shouldSplitTextElement(Element* element, EditingStyle* s
tyle) | 1237 bool ApplyStyleCommand::shouldSplitTextElement(Element* element, EditingStyle* s
tyle) |
1238 { | 1238 { |
1239 if (!element || !element->isHTMLElement()) | 1239 if (!element || !element->isHTMLElement()) |
1240 return false; | 1240 return false; |
1241 | 1241 |
1242 return shouldRemoveInlineStyleFromElement(style, toHTMLElement(element)); | 1242 return shouldRemoveInlineStyleFromElement(style, toHTMLElement(element)); |
1243 } | 1243 } |
1244 | 1244 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 StyleChange styleChange(style, positionToComputeInlineStyleChange(start, dum
myElement)); | 1392 StyleChange styleChange(style, positionToComputeInlineStyleChange(start, dum
myElement)); |
1393 | 1393 |
1394 if (dummyElement) | 1394 if (dummyElement) |
1395 removeNode(dummyElement); | 1395 removeNode(dummyElement); |
1396 | 1396 |
1397 applyInlineStyleChange(start, passedEnd, styleChange, addStyledElement); | 1397 applyInlineStyleChange(start, passedEnd, styleChange, addStyledElement); |
1398 } | 1398 } |
1399 | 1399 |
1400 Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node>
startNode, RefPtr<Node>& dummyElement) | 1400 Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node>
startNode, RefPtr<Node>& dummyElement) |
1401 { | 1401 { |
1402 ASSERT(startNode); | |
1403 // It's okay to obtain the style at the startNode because we've removed all
relevant styles from the current run. | 1402 // 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()) { | 1403 if (!startNode->isElementNode()) { |
1405 dummyElement = createStyleSpanElement(document()); | 1404 dummyElement = createStyleSpanElement(document()); |
1406 insertNodeAt(dummyElement, positionBeforeNode(*startNode)); | 1405 insertNodeAt(dummyElement, positionBeforeNode(startNode.get())); |
1407 return positionBeforeNode(*dummyElement); | 1406 return positionBeforeNode(dummyElement.get()); |
1408 } | 1407 } |
1409 | 1408 |
1410 return firstPositionInOrBeforeNode(startNode.get()); | 1409 return firstPositionInOrBeforeNode(startNode.get()); |
1411 } | 1410 } |
1412 | 1411 |
1413 void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
sRefPtr<Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledEl
ement) | 1412 void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
sRefPtr<Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledEl
ement) |
1414 { | 1413 { |
1415 RefPtr<Node> startNode = passedStart; | 1414 RefPtr<Node> startNode = passedStart; |
1416 RefPtr<Node> endNode = passedEnd; | 1415 RefPtr<Node> endNode = passedEnd; |
1417 ASSERT(startNode->inDocument()); | 1416 ASSERT(startNode->inDocument()); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 String textToMove = nextText->data(); | 1542 String textToMove = nextText->data(); |
1544 insertTextIntoNode(childText, childText->length(), textToMove); | 1543 insertTextIntoNode(childText, childText->length(), textToMove); |
1545 removeNode(next); | 1544 removeNode(next); |
1546 // don't move child node pointer. it may want to merge with more text no
des. | 1545 // don't move child node pointer. it may want to merge with more text no
des. |
1547 } | 1546 } |
1548 | 1547 |
1549 updateStartEnd(newStart, newEnd); | 1548 updateStartEnd(newStart, newEnd); |
1550 } | 1549 } |
1551 | 1550 |
1552 } | 1551 } |
OLD | NEW |