OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 { | 286 { |
287 applyCommandToComposite(InsertParagraphSeparatorCommand::create(document(),
useDefaultParagraphElement, pasteBlockqutoeIntoUnquotedArea)); | 287 applyCommandToComposite(InsertParagraphSeparatorCommand::create(document(),
useDefaultParagraphElement, pasteBlockqutoeIntoUnquotedArea)); |
288 } | 288 } |
289 | 289 |
290 bool CompositeEditCommand::isRemovableBlock(const Node* node) | 290 bool CompositeEditCommand::isRemovableBlock(const Node* node) |
291 { | 291 { |
292 ASSERT(node); | 292 ASSERT(node); |
293 if (!isHTMLDivElement(*node)) | 293 if (!isHTMLDivElement(*node)) |
294 return false; | 294 return false; |
295 | 295 |
296 Node* parentNode = node->parentNode(); | 296 ContainerNode* parentNode = node->parentNode(); |
297 if (parentNode && parentNode->firstChild() != parentNode->lastChild()) | 297 if (parentNode && parentNode->firstChild() != parentNode->lastChild()) |
298 return false; | 298 return false; |
299 | 299 |
300 if (!toElement(node)->hasAttributes()) | 300 if (!toElement(node)->hasAttributes()) |
301 return true; | 301 return true; |
302 | 302 |
303 return false; | 303 return false; |
304 } | 304 } |
305 | 305 |
306 void CompositeEditCommand::insertNodeBefore(PassRefPtrWillBeRawPtr<Node> insertC
hild, PassRefPtrWillBeRawPtr<Node> refChild, ShouldAssumeContentIsAlwaysEditable
shouldAssumeContentIsAlwaysEditable) | 306 void CompositeEditCommand::insertNodeBefore(PassRefPtrWillBeRawPtr<Node> insertC
hild, PassRefPtrWillBeRawPtr<Node> refChild, ShouldAssumeContentIsAlwaysEditable
shouldAssumeContentIsAlwaysEditable) |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 878 |
879 // We are certain that the position is at a line break, but it may be a br o
r a preserved newline. | 879 // We are certain that the position is at a line break, but it may be a br o
r a preserved newline. |
880 if (isHTMLBRElement(*p.anchorNode())) { | 880 if (isHTMLBRElement(*p.anchorNode())) { |
881 removeNode(p.anchorNode()); | 881 removeNode(p.anchorNode()); |
882 return; | 882 return; |
883 } | 883 } |
884 | 884 |
885 deleteTextFromNode(toText(p.anchorNode()), p.offsetInContainerNode(), 1); | 885 deleteTextFromNode(toText(p.anchorNode()), p.offsetInContainerNode(), 1); |
886 } | 886 } |
887 | 887 |
888 PassRefPtrWillBeRawPtr<Node> CompositeEditCommand::insertNewDefaultParagraphElem
entAt(const Position& position) | 888 PassRefPtrWillBeRawPtr<Element> CompositeEditCommand::insertNewDefaultParagraphE
lementAt(const Position& position) |
889 { | 889 { |
890 RefPtrWillBeRawPtr<Element> paragraphElement = createDefaultParagraphElement
(document()); | 890 RefPtrWillBeRawPtr<Element> paragraphElement = createDefaultParagraphElement
(document()); |
891 paragraphElement->appendChild(createBreakElement(document())); | 891 paragraphElement->appendChild(createBreakElement(document())); |
892 insertNodeAt(paragraphElement, position); | 892 insertNodeAt(paragraphElement, position); |
893 return paragraphElement.release(); | 893 return paragraphElement.release(); |
894 } | 894 } |
895 | 895 |
896 // If the paragraph is not entirely within it's own block, create one and move t
he paragraph into | 896 // If the paragraph is not entirely within it's own block, create one and move t
he paragraph into |
897 // it, and return that block. Otherwise return 0. | 897 // it, and return that block. Otherwise return 0. |
898 PassRefPtrWillBeRawPtr<Node> CompositeEditCommand::moveParagraphContentsToNewBlo
ckIfNecessary(const Position& pos) | 898 PassRefPtrWillBeRawPtr<Element> CompositeEditCommand::moveParagraphContentsToNew
BlockIfNecessary(const Position& pos) |
899 { | 899 { |
900 if (pos.isNull()) | 900 if (pos.isNull()) |
901 return nullptr; | 901 return nullptr; |
902 | 902 |
903 document().updateLayoutIgnorePendingStylesheets(); | 903 document().updateLayoutIgnorePendingStylesheets(); |
904 | 904 |
905 // It's strange that this function is responsible for verifying that pos has
not been invalidated | 905 // It's strange that this function is responsible for verifying that pos has
not been invalidated |
906 // by an earlier call to this function. The caller, applyBlockStyle, should
do this. | 906 // by an earlier call to this function. The caller, applyBlockStyle, should
do this. |
907 VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY); | 907 VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY); |
908 VisiblePosition visibleParagraphStart(startOfParagraph(visiblePos)); | 908 VisiblePosition visibleParagraphStart(startOfParagraph(visiblePos)); |
(...skipping 30 matching lines...) Expand all Loading... |
939 return nullptr; | 939 return nullptr; |
940 } else if (isEndOfEditableOrNonEditableContent(visibleEnd)) { | 940 } else if (isEndOfEditableOrNonEditableContent(visibleEnd)) { |
941 // At the end of the editable region. We can bail here as well. | 941 // At the end of the editable region. We can bail here as well. |
942 return nullptr; | 942 return nullptr; |
943 } | 943 } |
944 } | 944 } |
945 | 945 |
946 if (visibleParagraphEnd.isNull()) | 946 if (visibleParagraphEnd.isNull()) |
947 return nullptr; | 947 return nullptr; |
948 | 948 |
949 RefPtrWillBeRawPtr<Node> newBlock = insertNewDefaultParagraphElementAt(upstr
eamStart); | 949 RefPtrWillBeRawPtr<Element> newBlock = insertNewDefaultParagraphElementAt(up
streamStart); |
950 | 950 |
951 bool endWasBr = isHTMLBRElement(*visibleParagraphEnd.deepEquivalent().deprec
atedNode()); | 951 bool endWasBr = isHTMLBRElement(*visibleParagraphEnd.deepEquivalent().deprec
atedNode()); |
952 | 952 |
953 moveParagraphs(visibleParagraphStart, visibleParagraphEnd, VisiblePosition(f
irstPositionInNode(newBlock.get()))); | 953 moveParagraphs(visibleParagraphStart, visibleParagraphEnd, VisiblePosition(f
irstPositionInNode(newBlock.get()))); |
954 | 954 |
955 if (newBlock->lastChild() && isHTMLBRElement(*newBlock->lastChild()) && !end
WasBr) | 955 if (newBlock->lastChild() && isHTMLBRElement(*newBlock->lastChild()) && !end
WasBr) |
956 removeNode(newBlock->lastChild()); | 956 removeNode(newBlock->lastChild()); |
957 | 957 |
958 return newBlock.release(); | 958 return newBlock.release(); |
959 } | 959 } |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 } | 1492 } |
1493 | 1493 |
1494 void CompositeEditCommand::trace(Visitor* visitor) | 1494 void CompositeEditCommand::trace(Visitor* visitor) |
1495 { | 1495 { |
1496 visitor->trace(m_commands); | 1496 visitor->trace(m_commands); |
1497 visitor->trace(m_composition); | 1497 visitor->trace(m_composition); |
1498 EditCommand::trace(visitor); | 1498 EditCommand::trace(visitor); |
1499 } | 1499 } |
1500 | 1500 |
1501 } // namespace WebCore | 1501 } // namespace WebCore |
OLD | NEW |