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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 if (startNode != editableRoot) { | 772 if (startNode != editableRoot) { |
773 while (editableRoot && startNode->parentNode() != editableRoot && isNode
VisiblyContainedWithin(*startNode->parentNode(), *range)) | 773 while (editableRoot && startNode->parentNode() != editableRoot && isNode
VisiblyContainedWithin(*startNode->parentNode(), *range)) |
774 startNode = startNode->parentNode(); | 774 startNode = startNode->parentNode(); |
775 } | 775 } |
776 | 776 |
777 applyInlineStyleToNodeRange(style, startNode, pastEndNode, editingState); | 777 applyInlineStyleToNodeRange(style, startNode, pastEndNode, editingState); |
778 } | 778 } |
779 | 779 |
780 static bool containsNonEditableRegion(Node& node) | 780 static bool containsNonEditableRegion(Node& node) |
781 { | 781 { |
782 if (!node.hasEditableStyle()) | 782 if (!hasEditableStyle(node)) |
783 return true; | 783 return true; |
784 | 784 |
785 Node* sibling = NodeTraversal::nextSkippingChildren(node); | 785 Node* sibling = NodeTraversal::nextSkippingChildren(node); |
786 for (Node* descendent = node.firstChild(); descendent && descendent != sibli
ng; descendent = NodeTraversal::next(*descendent)) { | 786 for (Node* descendent = node.firstChild(); descendent && descendent != sibli
ng; descendent = NodeTraversal::next(*descendent)) { |
787 if (!descendent->hasEditableStyle()) | 787 if (!hasEditableStyle(*descendent)) |
788 return true; | 788 return true; |
789 } | 789 } |
790 | 790 |
791 return false; | 791 return false; |
792 } | 792 } |
793 | 793 |
794 class InlineRunToApplyStyle { | 794 class InlineRunToApplyStyle { |
795 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 795 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
796 public: | 796 public: |
797 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode) | 797 InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 if (m_removeOnly) | 835 if (m_removeOnly) |
836 return; | 836 return; |
837 | 837 |
838 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 838 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
839 | 839 |
840 HeapVector<InlineRunToApplyStyle> runs; | 840 HeapVector<InlineRunToApplyStyle> runs; |
841 Node* node = startNode; | 841 Node* node = startNode; |
842 for (Node* next; node && node != pastEndNode; node = next) { | 842 for (Node* next; node && node != pastEndNode; node = next) { |
843 next = NodeTraversal::next(*node); | 843 next = NodeTraversal::next(*node); |
844 | 844 |
845 if (!node->layoutObject() || !node->hasEditableStyle()) | 845 if (!node->layoutObject() || !hasEditableStyle(*node)) |
846 continue; | 846 continue; |
847 | 847 |
848 if (!node->layoutObjectIsRichlyEditable() && node->isHTMLElement()) { | 848 if (!layoutObjectIsRichlyEditable(*node) && node->isHTMLElement()) { |
849 HTMLElement* element = toHTMLElement(node); | 849 HTMLElement* element = toHTMLElement(node); |
850 // This is a plaintext-only region. Only proceed if it's fully selec
ted. | 850 // This is a plaintext-only region. Only proceed if it's fully selec
ted. |
851 // pastEndNode is the node after the last fully selected node, so if
it's inside node then | 851 // pastEndNode is the node after the last fully selected node, so if
it's inside node then |
852 // node isn't fully selected. | 852 // node isn't fully selected. |
853 if (pastEndNode && pastEndNode->isDescendantOf(element)) | 853 if (pastEndNode && pastEndNode->isDescendantOf(element)) |
854 break; | 854 break; |
855 // Add to this element's inline style and skip over its contents. | 855 // Add to this element's inline style and skip over its contents. |
856 next = NodeTraversal::nextSkippingChildren(*node); | 856 next = NodeTraversal::nextSkippingChildren(*node); |
857 if (!style->style()) | 857 if (!style->style()) |
858 continue; | 858 continue; |
859 MutableStylePropertySet* inlineStyle = copyStyleOrCreateEmpty(elemen
t->inlineStyle()); | 859 MutableStylePropertySet* inlineStyle = copyStyleOrCreateEmpty(elemen
t->inlineStyle()); |
860 inlineStyle->mergeAndOverrideOnConflict(style->style()); | 860 inlineStyle->mergeAndOverrideOnConflict(style->style()); |
861 setNodeAttribute(element, styleAttr, AtomicString(inlineStyle->asTex
t())); | 861 setNodeAttribute(element, styleAttr, AtomicString(inlineStyle->asTex
t())); |
862 continue; | 862 continue; |
863 } | 863 } |
864 | 864 |
865 if (isEnclosingBlock(node)) | 865 if (isEnclosingBlock(node)) |
866 continue; | 866 continue; |
867 | 867 |
868 if (node->hasChildren()) { | 868 if (node->hasChildren()) { |
869 if (node->contains(pastEndNode) || containsNonEditableRegion(*node)
|| !node->parentNode()->hasEditableStyle()) | 869 if (node->contains(pastEndNode) || containsNonEditableRegion(*node)
|| !hasEditableStyle(*node->parentNode())) |
870 continue; | 870 continue; |
871 if (editingIgnoresContent(node)) { | 871 if (editingIgnoresContent(node)) { |
872 next = NodeTraversal::nextSkippingChildren(*node); | 872 next = NodeTraversal::nextSkippingChildren(*node); |
873 continue; | 873 continue; |
874 } | 874 } |
875 } | 875 } |
876 | 876 |
877 Node* runStart = node; | 877 Node* runStart = node; |
878 Node* runEnd = node; | 878 Node* runEnd = node; |
879 Node* sibling = node->nextSibling(); | 879 Node* sibling = node->nextSibling(); |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 if (editingState->isAborted()) | 1484 if (editingState->isAborted()) |
1485 return; | 1485 return; |
1486 } | 1486 } |
1487 if (node == endNode) | 1487 if (node == endNode) |
1488 break; | 1488 break; |
1489 node = next; | 1489 node = next; |
1490 } | 1490 } |
1491 | 1491 |
1492 Node* nextSibling = element->nextSibling(); | 1492 Node* nextSibling = element->nextSibling(); |
1493 Node* previousSibling = element->previousSibling(); | 1493 Node* previousSibling = element->previousSibling(); |
1494 if (nextSibling && nextSibling->isElementNode() && nextSibling->hasEditableS
tyle() | 1494 if (nextSibling && nextSibling->isElementNode() && hasEditableStyle(*nextSib
ling) |
1495 && areIdenticalElements(*element, toElement(*nextSibling))) { | 1495 && areIdenticalElements(*element, toElement(*nextSibling))) { |
1496 mergeIdenticalElements(element, toElement(nextSibling), editingState); | 1496 mergeIdenticalElements(element, toElement(nextSibling), editingState); |
1497 if (editingState->isAborted()) | 1497 if (editingState->isAborted()) |
1498 return; | 1498 return; |
1499 } | 1499 } |
1500 | 1500 |
1501 if (previousSibling && previousSibling->isElementNode() && previousSibling->
hasEditableStyle()) { | 1501 if (previousSibling && previousSibling->isElementNode() && hasEditableStyle(
*previousSibling)) { |
1502 Node* mergedElement = previousSibling->nextSibling(); | 1502 Node* mergedElement = previousSibling->nextSibling(); |
1503 if (mergedElement->isElementNode() && mergedElement->hasEditableStyle() | 1503 if (mergedElement->isElementNode() && hasEditableStyle(*mergedElement) |
1504 && areIdenticalElements(toElement(*previousSibling), toElement(*merg
edElement))) { | 1504 && areIdenticalElements(toElement(*previousSibling), toElement(*merg
edElement))) { |
1505 mergeIdenticalElements(toElement(previousSibling), toElement(mergedE
lement), editingState); | 1505 mergeIdenticalElements(toElement(previousSibling), toElement(mergedE
lement), editingState); |
1506 if (editingState->isAborted()) | 1506 if (editingState->isAborted()) |
1507 return; | 1507 return; |
1508 } | 1508 } |
1509 } | 1509 } |
1510 | 1510 |
1511 // FIXME: We should probably call updateStartEnd if the start or end was in
the node | 1511 // FIXME: We should probably call updateStartEnd if the start or end was in
the node |
1512 // range so that the endingSelection() is canonicalized. See the comments a
t the end of | 1512 // range so that the endingSelection() is canonicalized. See the comments a
t the end of |
1513 // VisibleSelection::validate(). | 1513 // VisibleSelection::validate(). |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 DEFINE_TRACE(ApplyStyleCommand) | 1731 DEFINE_TRACE(ApplyStyleCommand) |
1732 { | 1732 { |
1733 visitor->trace(m_style); | 1733 visitor->trace(m_style); |
1734 visitor->trace(m_start); | 1734 visitor->trace(m_start); |
1735 visitor->trace(m_end); | 1735 visitor->trace(m_end); |
1736 visitor->trace(m_styledInlineElement); | 1736 visitor->trace(m_styledInlineElement); |
1737 CompositeEditCommand::trace(visitor); | 1737 CompositeEditCommand::trace(visitor); |
1738 } | 1738 } |
1739 | 1739 |
1740 } // namespace blink | 1740 } // namespace blink |
OLD | NEW |