OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005 Apple Computer, 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 19 matching lines...) Expand all Loading... |
30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
31 #include "core/dom/DocumentFragment.h" | 31 #include "core/dom/DocumentFragment.h" |
32 #include "core/dom/DocumentMarkerController.h" | 32 #include "core/dom/DocumentMarkerController.h" |
33 #include "core/dom/Element.h" | 33 #include "core/dom/Element.h" |
34 #include "core/dom/NodeTraversal.h" | 34 #include "core/dom/NodeTraversal.h" |
35 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
36 #include "core/editing/EditingBoundary.h" | 36 #include "core/editing/EditingBoundary.h" |
37 #include "core/editing/Editor.h" | 37 #include "core/editing/Editor.h" |
38 #include "core/editing/VisibleUnits.h" | 38 #include "core/editing/VisibleUnits.h" |
39 #include "core/editing/htmlediting.h" | 39 #include "core/editing/htmlediting.h" |
40 #include "core/html/HTMLInputElement.h" | 40 #include "core/html/HTMLTextFormControlElement.h" |
41 #include "core/html/HTMLTextAreaElement.h" | |
42 #include "core/page/EditorClient.h" | 41 #include "core/page/EditorClient.h" |
43 #include "core/page/Frame.h" | 42 #include "core/page/Frame.h" |
44 #include "core/rendering/RenderTableCell.h" | 43 #include "core/rendering/RenderTableCell.h" |
45 | 44 |
46 namespace WebCore { | 45 namespace WebCore { |
47 | 46 |
48 using namespace HTMLNames; | 47 using namespace HTMLNames; |
49 | 48 |
50 static bool isTableRow(const Node* node) | 49 static bool isTableRow(const Node* node) |
51 { | 50 { |
(...skipping 11 matching lines...) Expand all Loading... |
63 if (!isTableRow(row)) | 62 if (!isTableRow(row)) |
64 return false; | 63 return false; |
65 | 64 |
66 for (Node* child = row->firstChild(); child; child = child->nextSibling()) | 65 for (Node* child = row->firstChild(); child; child = child->nextSibling()) |
67 if (isTableCell(child) && !isTableCellEmpty(child)) | 66 if (isTableCell(child) && !isTableCellEmpty(child)) |
68 return false; | 67 return false; |
69 | 68 |
70 return true; | 69 return true; |
71 } | 70 } |
72 | 71 |
| 72 static bool shouldNotHavePlaceholder(HTMLTextFormControlElement* textControl) |
| 73 { |
| 74 if (!textControl) |
| 75 return false; |
| 76 |
| 77 Node* textElement = textControl->innerTextElement(); |
| 78 if (!textElement) |
| 79 return false; |
| 80 |
| 81 // When text control is empty, we don't need to have placeholder. |
| 82 if (!textElement->firstChild()) |
| 83 return true; |
| 84 |
| 85 // Text control ends with placeholder. |
| 86 return textElement->lastChild()->hasTagName(brTag); |
| 87 } |
| 88 |
73 DeleteSelectionCommand::DeleteSelectionCommand(Document *document, bool smartDel
ete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, b
ool sanitizeMarkup) | 89 DeleteSelectionCommand::DeleteSelectionCommand(Document *document, bool smartDel
ete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, b
ool sanitizeMarkup) |
74 : CompositeEditCommand(document) | 90 : CompositeEditCommand(document) |
75 , m_hasSelectionToDelete(false) | 91 , m_hasSelectionToDelete(false) |
76 , m_smartDelete(smartDelete) | 92 , m_smartDelete(smartDelete) |
77 , m_mergeBlocksAfterDelete(mergeBlocksAfterDelete) | 93 , m_mergeBlocksAfterDelete(mergeBlocksAfterDelete) |
78 , m_needPlaceholder(false) | 94 , m_needPlaceholder(false) |
79 , m_replace(replace) | 95 , m_replace(replace) |
80 , m_expandForSpecialElements(expandForSpecialElements) | 96 , m_expandForSpecialElements(expandForSpecialElements) |
81 , m_pruneStartBlockIfNecessary(false) | 97 , m_pruneStartBlockIfNecessary(false) |
82 , m_startsAtEmptyLine(false) | 98 , m_startsAtEmptyLine(false) |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 && !lineBreakExistsAtVisiblePosition(m_selectionToDelete.visibleEnd(
)); | 811 && !lineBreakExistsAtVisiblePosition(m_selectionToDelete.visibleEnd(
)); |
796 if (m_needPlaceholder) { | 812 if (m_needPlaceholder) { |
797 // Don't need a placeholder when deleting a selection that starts just b
efore a table | 813 // Don't need a placeholder when deleting a selection that starts just b
efore a table |
798 // and ends inside it (we do need placeholders to hold open empty cells,
but that's | 814 // and ends inside it (we do need placeholders to hold open empty cells,
but that's |
799 // handled elsewhere). | 815 // handled elsewhere). |
800 if (Node* table = isLastPositionBeforeTable(m_selectionToDelete.visibleS
tart())) | 816 if (Node* table = isLastPositionBeforeTable(m_selectionToDelete.visibleS
tart())) |
801 if (m_selectionToDelete.end().deprecatedNode()->isDescendantOf(table
)) | 817 if (m_selectionToDelete.end().deprecatedNode()->isDescendantOf(table
)) |
802 m_needPlaceholder = false; | 818 m_needPlaceholder = false; |
803 } | 819 } |
804 | 820 |
805 | 821 |
| 822 RefPtr<HTMLTextFormControlElement> textControl = enclosingTextFormControl(m_
selectionToDelete.start()); |
| 823 |
806 // set up our state | 824 // set up our state |
807 initializePositionData(); | 825 initializePositionData(); |
808 | 826 |
809 // Delete any text that may hinder our ability to fixup whitespace after the
delete | 827 // Delete any text that may hinder our ability to fixup whitespace after the
delete |
810 deleteInsignificantTextDownstream(m_trailingWhitespace); | 828 deleteInsignificantTextDownstream(m_trailingWhitespace); |
811 | 829 |
812 saveTypingStyleState(); | 830 saveTypingStyleState(); |
813 | 831 |
814 // deleting just a BR is handled specially, at least because we do not | 832 // deleting just a BR is handled specially, at least because we do not |
815 // want to replace it with a placeholder BR! | 833 // want to replace it with a placeholder BR! |
816 if (handleSpecialCaseBRDelete()) { | 834 if (handleSpecialCaseBRDelete()) { |
817 calculateTypingStyleAfterDelete(); | 835 calculateTypingStyleAfterDelete(); |
818 setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSe
lection().isDirectional())); | 836 setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSe
lection().isDirectional())); |
819 clearTransientState(); | 837 clearTransientState(); |
820 rebalanceWhitespace(); | 838 rebalanceWhitespace(); |
821 return; | 839 return; |
822 } | 840 } |
823 | 841 |
824 handleGeneralDelete(); | 842 handleGeneralDelete(); |
825 | 843 |
826 fixupWhitespace(); | 844 fixupWhitespace(); |
827 | 845 |
828 mergeParagraphs(); | 846 mergeParagraphs(); |
829 | 847 |
830 removePreviouslySelectedEmptyTableRows(); | 848 removePreviouslySelectedEmptyTableRows(); |
831 | 849 |
| 850 if (m_needPlaceholder && shouldNotHavePlaceholder(textControl.get())) |
| 851 m_needPlaceholder = false; |
| 852 |
832 RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(document()
).get() : 0; | 853 RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(document()
).get() : 0; |
833 | 854 |
834 if (placeholder) { | 855 if (placeholder) { |
835 if (m_sanitizeMarkup) | 856 if (m_sanitizeMarkup) |
836 removeRedundantBlocks(); | 857 removeRedundantBlocks(); |
837 insertNodeAt(placeholder.get(), m_endingPosition); | 858 insertNodeAt(placeholder.get(), m_endingPosition); |
838 } | 859 } |
839 | 860 |
840 rebalanceWhitespaceAt(m_endingPosition); | 861 rebalanceWhitespaceAt(m_endingPosition); |
841 | 862 |
(...skipping 13 matching lines...) Expand all Loading... |
855 | 876 |
856 // Normally deletion doesn't preserve the typing style that was present before i
t. For example, | 877 // Normally deletion doesn't preserve the typing style that was present before i
t. For example, |
857 // type a character, Bold, then delete the character and start typing. The Bold
typing style shouldn't | 878 // type a character, Bold, then delete the character and start typing. The Bold
typing style shouldn't |
858 // stick around. Deletion should preserve a typing style that *it* sets, howeve
r. | 879 // stick around. Deletion should preserve a typing style that *it* sets, howeve
r. |
859 bool DeleteSelectionCommand::preservesTypingStyle() const | 880 bool DeleteSelectionCommand::preservesTypingStyle() const |
860 { | 881 { |
861 return m_typingStyle; | 882 return m_typingStyle; |
862 } | 883 } |
863 | 884 |
864 } // namespace WebCore | 885 } // namespace WebCore |
OLD | NEW |