| 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 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode) | 782 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode) |
| 783 : start(start) | 783 : start(start) |
| 784 , end(end) | 784 , end(end) |
| 785 , pastEndNode(pastEndNode) | 785 , pastEndNode(pastEndNode) |
| 786 { | 786 { |
| 787 ASSERT(start->parentNode() == end->parentNode()); | 787 ASSERT(start->parentNode() == end->parentNode()); |
| 788 } | 788 } |
| 789 | 789 |
| 790 bool startAndEndAreStillInDocument() | 790 bool startAndEndAreStillInDocument() |
| 791 { | 791 { |
| 792 return start && end && start->inDocument() && end->inDocument(); | 792 return start && end && start->inShadowIncludingDocument() && end->inShad
owIncludingDocument(); |
| 793 } | 793 } |
| 794 | 794 |
| 795 DEFINE_INLINE_TRACE() | 795 DEFINE_INLINE_TRACE() |
| 796 { | 796 { |
| 797 visitor->trace(start); | 797 visitor->trace(start); |
| 798 visitor->trace(end); | 798 visitor->trace(end); |
| 799 visitor->trace(pastEndNode); | 799 visitor->trace(pastEndNode); |
| 800 visitor->trace(positionForStyleComputation); | 800 visitor->trace(positionForStyleComputation); |
| 801 visitor->trace(dummyElement); | 801 visitor->trace(dummyElement); |
| 802 } | 802 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode
(node), m_styledInlineElement->tagQName())) | 929 if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode
(node), m_styledInlineElement->tagQName())) |
| 930 return true; | 930 return true; |
| 931 } | 931 } |
| 932 return false; | 932 return false; |
| 933 } | 933 } |
| 934 | 934 |
| 935 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style,
Member<Node>& runStart, Member<Node>& runEnd, RawPtr<Node> pastEndNode, Editing
State* editingState) | 935 void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style,
Member<Node>& runStart, Member<Node>& runEnd, RawPtr<Node> pastEndNode, Editing
State* editingState) |
| 936 { | 936 { |
| 937 ASSERT(runStart && runEnd); | 937 ASSERT(runStart && runEnd); |
| 938 RawPtr<Node> next = runStart; | 938 RawPtr<Node> next = runStart; |
| 939 for (RawPtr<Node> node = next; node && node->inDocument() && node != pastEnd
Node; node = next) { | 939 for (RawPtr<Node> node = next; node && node->inShadowIncludingDocument() &&
node != pastEndNode; node = next) { |
| 940 if (editingIgnoresContent(node.get())) { | 940 if (editingIgnoresContent(node.get())) { |
| 941 ASSERT(!node->contains(pastEndNode.get())); | 941 ASSERT(!node->contains(pastEndNode.get())); |
| 942 next = NodeTraversal::nextSkippingChildren(*node); | 942 next = NodeTraversal::nextSkippingChildren(*node); |
| 943 } else { | 943 } else { |
| 944 next = NodeTraversal::next(*node); | 944 next = NodeTraversal::next(*node); |
| 945 } | 945 } |
| 946 if (!node->isHTMLElement()) | 946 if (!node->isHTMLElement()) |
| 947 continue; | 947 continue; |
| 948 | 948 |
| 949 HTMLElement& element = toHTMLElement(*node); | 949 HTMLElement& element = toHTMLElement(*node); |
| 950 RawPtr<Node> previousSibling = element.previousSibling(); | 950 RawPtr<Node> previousSibling = element.previousSibling(); |
| 951 RawPtr<Node> nextSibling = element.nextSibling(); | 951 RawPtr<Node> nextSibling = element.nextSibling(); |
| 952 RawPtr<ContainerNode> parent = element.parentNode(); | 952 RawPtr<ContainerNode> parent = element.parentNode(); |
| 953 removeInlineStyleFromElement(style, &element, editingState, RemoveAlways
); | 953 removeInlineStyleFromElement(style, &element, editingState, RemoveAlways
); |
| 954 if (editingState->isAborted()) | 954 if (editingState->isAborted()) |
| 955 return; | 955 return; |
| 956 if (!element.inDocument()) { | 956 if (!element.inShadowIncludingDocument()) { |
| 957 // FIXME: We might need to update the start and the end of current s
election here but need a test. | 957 // FIXME: We might need to update the start and the end of current s
election here but need a test. |
| 958 if (runStart == element) | 958 if (runStart == element) |
| 959 runStart = previousSibling ? previousSibling->nextSibling() : pa
rent->firstChild(); | 959 runStart = previousSibling ? previousSibling->nextSibling() : pa
rent->firstChild(); |
| 960 if (runEnd == element) | 960 if (runEnd == element) |
| 961 runEnd = nextSibling ? nextSibling->previousSibling() : parent->
lastChild(); | 961 runEnd = nextSibling ? nextSibling->previousSibling() : parent->
lastChild(); |
| 962 } | 962 } |
| 963 } | 963 } |
| 964 } | 964 } |
| 965 | 965 |
| 966 bool ApplyStyleCommand::removeInlineStyleFromElement(EditingStyle* style, RawPtr
<HTMLElement> element, EditingState* editingState, InlineStyleRemovalMode mode,
EditingStyle* extractedStyle) | 966 bool ApplyStyleCommand::removeInlineStyleFromElement(EditingStyle* style, RawPtr
<HTMLElement> element, EditingState* editingState, InlineStyleRemovalMode mode,
EditingStyle* extractedStyle) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 978 removeNodePreservingChildren(element, editingState); | 978 removeNodePreservingChildren(element, editingState); |
| 979 if (editingState->isAborted()) | 979 if (editingState->isAborted()) |
| 980 return false; | 980 return false; |
| 981 return true; | 981 return true; |
| 982 } | 982 } |
| 983 | 983 |
| 984 bool removed = removeImplicitlyStyledElement(style, element.get(), mode, ext
ractedStyle, editingState); | 984 bool removed = removeImplicitlyStyledElement(style, element.get(), mode, ext
ractedStyle, editingState); |
| 985 if (editingState->isAborted()) | 985 if (editingState->isAborted()) |
| 986 return false; | 986 return false; |
| 987 | 987 |
| 988 if (!element->inDocument()) | 988 if (!element->inShadowIncludingDocument()) |
| 989 return removed; | 989 return removed; |
| 990 | 990 |
| 991 // If the node was converted to a span, the span may still contain relevant | 991 // If the node was converted to a span, the span may still contain relevant |
| 992 // styles which must be removed (e.g. <b style='font-weight: bold'>) | 992 // styles which must be removed (e.g. <b style='font-weight: bold'>) |
| 993 if (removeCSSStyle(style, element.get(), editingState, mode, extractedStyle)
) | 993 if (removeCSSStyle(style, element.get(), editingState, mode, extractedStyle)
) |
| 994 removed = true; | 994 removed = true; |
| 995 if (editingState->isAborted()) | 995 if (editingState->isAborted()) |
| 996 return false; | 996 return false; |
| 997 | 997 |
| 998 return removed; | 998 return removed; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 if (child == targetNode || child->contains(targetNode)) | 1173 if (child == targetNode || child->contains(targetNode)) |
| 1174 current = child; | 1174 current = child; |
| 1175 } | 1175 } |
| 1176 } | 1176 } |
| 1177 } | 1177 } |
| 1178 | 1178 |
| 1179 void ApplyStyleCommand::removeInlineStyle(EditingStyle* style, const Position &s
tart, const Position &end, EditingState* editingState) | 1179 void ApplyStyleCommand::removeInlineStyle(EditingStyle* style, const Position &s
tart, const Position &end, EditingState* editingState) |
| 1180 { | 1180 { |
| 1181 ASSERT(start.isNotNull()); | 1181 ASSERT(start.isNotNull()); |
| 1182 ASSERT(end.isNotNull()); | 1182 ASSERT(end.isNotNull()); |
| 1183 ASSERT(start.inDocument()); | 1183 ASSERT(start.inShadowIncludingDocument()); |
| 1184 ASSERT(end.inDocument()); | 1184 ASSERT(end.inShadowIncludingDocument()); |
| 1185 ASSERT(Position::commonAncestorTreeScope(start, end)); | 1185 ASSERT(Position::commonAncestorTreeScope(start, end)); |
| 1186 ASSERT(comparePositions(start, end) <= 0); | 1186 ASSERT(comparePositions(start, end) <= 0); |
| 1187 // FIXME: We should assert that start/end are not in the middle of a text no
de. | 1187 // FIXME: We should assert that start/end are not in the middle of a text no
de. |
| 1188 | 1188 |
| 1189 Position pushDownStart = mostForwardCaretPosition(start); | 1189 Position pushDownStart = mostForwardCaretPosition(start); |
| 1190 // If the pushDownStart is at the end of a text node, then this node is not
fully selected. | 1190 // If the pushDownStart is at the end of a text node, then this node is not
fully selected. |
| 1191 // Move it to the next deep quivalent position to avoid removing the style f
rom this node. | 1191 // Move it to the next deep quivalent position to avoid removing the style f
rom this node. |
| 1192 // e.g. if pushDownStart was at Position("hello", 5) in <b>hello<div>world</
div></b>, we want Position("world", 0) instead. | 1192 // e.g. if pushDownStart was at Position("hello", 5) in <b>hello<div>world</
div></b>, we want Position("world", 0) instead. |
| 1193 Node* pushDownStartContainer = pushDownStart.computeContainerNode(); | 1193 Node* pushDownStartContainer = pushDownStart.computeContainerNode(); |
| 1194 if (pushDownStartContainer && pushDownStartContainer->isTextNode() | 1194 if (pushDownStartContainer && pushDownStartContainer->isTextNode() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 RawPtr<EditingStyle> styleToPushDown = nullptr; | 1237 RawPtr<EditingStyle> styleToPushDown = nullptr; |
| 1238 RawPtr<Node> childNode = nullptr; | 1238 RawPtr<Node> childNode = nullptr; |
| 1239 if (isStyledInlineElementToRemove(elem.get())) { | 1239 if (isStyledInlineElementToRemove(elem.get())) { |
| 1240 styleToPushDown = EditingStyle::create(); | 1240 styleToPushDown = EditingStyle::create(); |
| 1241 childNode = elem->firstChild(); | 1241 childNode = elem->firstChild(); |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 removeInlineStyleFromElement(style, elem.get(), editingState, Remove
IfNeeded, styleToPushDown.get()); | 1244 removeInlineStyleFromElement(style, elem.get(), editingState, Remove
IfNeeded, styleToPushDown.get()); |
| 1245 if (editingState->isAborted()) | 1245 if (editingState->isAborted()) |
| 1246 return; | 1246 return; |
| 1247 if (!elem->inDocument()) { | 1247 if (!elem->inShadowIncludingDocument()) { |
| 1248 if (s.anchorNode() == elem) { | 1248 if (s.anchorNode() == elem) { |
| 1249 // Since elem must have been fully selected, and it is at th
e start | 1249 // Since elem must have been fully selected, and it is at th
e start |
| 1250 // of the selection, it is clear we can set the new s offset
to 0. | 1250 // of the selection, it is clear we can set the new s offset
to 0. |
| 1251 ASSERT(s.isBeforeAnchor() || s.isBeforeChildren() || s.offse
tInContainerNode() <= 0); | 1251 ASSERT(s.isBeforeAnchor() || s.isBeforeChildren() || s.offse
tInContainerNode() <= 0); |
| 1252 s = firstPositionInOrBeforeNode(next.get()); | 1252 s = firstPositionInOrBeforeNode(next.get()); |
| 1253 } | 1253 } |
| 1254 if (e.anchorNode() == elem) { | 1254 if (e.anchorNode() == elem) { |
| 1255 // Since elem must have been fully selected, and it is at th
e end | 1255 // Since elem must have been fully selected, and it is at th
e end |
| 1256 // of the selection, it is clear we can set the new e offset
to | 1256 // of the selection, it is clear we can set the new e offset
to |
| 1257 // the max range offset of prev. | 1257 // the max range offset of prev. |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1509 if (const StylePropertySet* decl = block->inlineStyle()) { | 1509 if (const StylePropertySet* decl = block->inlineStyle()) { |
| 1510 if (!cssStyle.isEmpty()) | 1510 if (!cssStyle.isEmpty()) |
| 1511 cssText.append(' '); | 1511 cssText.append(' '); |
| 1512 cssText.append(decl->asText()); | 1512 cssText.append(decl->asText()); |
| 1513 } | 1513 } |
| 1514 setNodeAttribute(block, styleAttr, cssText.toAtomicString()); | 1514 setNodeAttribute(block, styleAttr, cssText.toAtomicString()); |
| 1515 } | 1515 } |
| 1516 | 1516 |
| 1517 void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, RawPtr<Node>
passedStart, RawPtr<Node> passedEnd, EditingState* editingState) | 1517 void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, RawPtr<Node>
passedStart, RawPtr<Node> passedEnd, EditingState* editingState) |
| 1518 { | 1518 { |
| 1519 if (!passedStart || !passedEnd || !passedStart->inDocument() || !passedEnd->
inDocument()) | 1519 if (!passedStart || !passedEnd || !passedStart->inShadowIncludingDocument()
|| !passedEnd->inShadowIncludingDocument()) |
| 1520 return; | 1520 return; |
| 1521 | 1521 |
| 1522 RawPtr<Node> start = passedStart; | 1522 RawPtr<Node> start = passedStart; |
| 1523 Member<HTMLSpanElement> dummyElement = nullptr; | 1523 Member<HTMLSpanElement> dummyElement = nullptr; |
| 1524 StyleChange styleChange(style, positionToComputeInlineStyleChange(start, dum
myElement, editingState)); | 1524 StyleChange styleChange(style, positionToComputeInlineStyleChange(start, dum
myElement, editingState)); |
| 1525 if (editingState->isAborted()) | 1525 if (editingState->isAborted()) |
| 1526 return; | 1526 return; |
| 1527 | 1527 |
| 1528 if (dummyElement) { | 1528 if (dummyElement) { |
| 1529 removeNode(dummyElement, editingState); | 1529 removeNode(dummyElement, editingState); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1545 return positionBeforeNode(dummyElement.get()); | 1545 return positionBeforeNode(dummyElement.get()); |
| 1546 } | 1546 } |
| 1547 | 1547 |
| 1548 return firstPositionInOrBeforeNode(startNode.get()); | 1548 return firstPositionInOrBeforeNode(startNode.get()); |
| 1549 } | 1549 } |
| 1550 | 1550 |
| 1551 void ApplyStyleCommand::applyInlineStyleChange(RawPtr<Node> passedStart, RawPtr<
Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledElement, E
ditingState* editingState) | 1551 void ApplyStyleCommand::applyInlineStyleChange(RawPtr<Node> passedStart, RawPtr<
Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledElement, E
ditingState* editingState) |
| 1552 { | 1552 { |
| 1553 RawPtr<Node> startNode = passedStart; | 1553 RawPtr<Node> startNode = passedStart; |
| 1554 RawPtr<Node> endNode = passedEnd; | 1554 RawPtr<Node> endNode = passedEnd; |
| 1555 ASSERT(startNode->inDocument()); | 1555 ASSERT(startNode->inShadowIncludingDocument()); |
| 1556 ASSERT(endNode->inDocument()); | 1556 ASSERT(endNode->inShadowIncludingDocument()); |
| 1557 | 1557 |
| 1558 // Find appropriate font and span elements top-down. | 1558 // Find appropriate font and span elements top-down. |
| 1559 HTMLFontElement* fontContainer = nullptr; | 1559 HTMLFontElement* fontContainer = nullptr; |
| 1560 HTMLElement* styleContainer = nullptr; | 1560 HTMLElement* styleContainer = nullptr; |
| 1561 for (Node* container = startNode.get(); container && startNode == endNode; c
ontainer = container->firstChild()) { | 1561 for (Node* container = startNode.get(); container && startNode == endNode; c
ontainer = container->firstChild()) { |
| 1562 if (isHTMLFontElement(*container)) | 1562 if (isHTMLFontElement(*container)) |
| 1563 fontContainer = toHTMLFontElement(container); | 1563 fontContainer = toHTMLFontElement(container); |
| 1564 bool styleContainerIsNotSpan = !isHTMLSpanElement(styleContainer); | 1564 bool styleContainerIsNotSpan = !isHTMLSpanElement(styleContainer); |
| 1565 if (container->isHTMLElement()) { | 1565 if (container->isHTMLElement()) { |
| 1566 HTMLElement* containerElement = toHTMLElement(container); | 1566 HTMLElement* containerElement = toHTMLElement(container); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 DEFINE_TRACE(ApplyStyleCommand) | 1713 DEFINE_TRACE(ApplyStyleCommand) |
| 1714 { | 1714 { |
| 1715 visitor->trace(m_style); | 1715 visitor->trace(m_style); |
| 1716 visitor->trace(m_start); | 1716 visitor->trace(m_start); |
| 1717 visitor->trace(m_end); | 1717 visitor->trace(m_end); |
| 1718 visitor->trace(m_styledInlineElement); | 1718 visitor->trace(m_styledInlineElement); |
| 1719 CompositeEditCommand::trace(visitor); | 1719 CompositeEditCommand::trace(visitor); |
| 1720 } | 1720 } |
| 1721 | 1721 |
| 1722 } // namespace blink | 1722 } // namespace blink |
| OLD | NEW |