| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 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 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/dom/Text.h" | 30 #include "core/dom/Text.h" |
| 31 #include "core/editing/EditingStyle.h" | 31 #include "core/editing/EditingStyle.h" |
| 32 #include "core/editing/EditingUtilities.h" | 32 #include "core/editing/EditingUtilities.h" |
| 33 #include "core/editing/FrameSelection.h" | 33 #include "core/editing/FrameSelection.h" |
| 34 #include "core/editing/VisiblePosition.h" | 34 #include "core/editing/VisiblePosition.h" |
| 35 #include "core/editing/VisibleUnits.h" | 35 #include "core/editing/VisibleUnits.h" |
| 36 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
| 37 #include "core/html/HTMLBRElement.h" | 37 #include "core/html/HTMLBRElement.h" |
| 38 #include "core/html/HTMLElement.h" | 38 #include "core/html/HTMLElement.h" |
| 39 #include "core/html/HTMLTextFormControlElement.h" |
| 39 #include "core/layout/LayoutObject.h" | 40 #include "core/layout/LayoutObject.h" |
| 40 #include "core/layout/LayoutText.h" | 41 #include "core/layout/LayoutText.h" |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 using namespace HTMLNames; | 45 using namespace HTMLNames; |
| 45 | 46 |
| 46 InsertLineBreakCommand::InsertLineBreakCommand(Document& document) | 47 InsertLineBreakCommand::InsertLineBreakCommand(Document& document) |
| 47 : CompositeEditCommand(document) | 48 : CompositeEditCommand(document) |
| 48 { | 49 { |
| 49 } | 50 } |
| 50 | 51 |
| 51 bool InsertLineBreakCommand::preservesTypingStyle() const | 52 bool InsertLineBreakCommand::preservesTypingStyle() const |
| 52 { | 53 { |
| 53 return true; | 54 return true; |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Whether we should insert a break element or a '\n'. | 57 // Whether we should insert a break element or a '\n'. |
| 57 bool InsertLineBreakCommand::shouldUseBreakElement(const Position& insertionPos) | 58 bool InsertLineBreakCommand::shouldUseBreakElement(const Position& insertionPos) |
| 58 { | 59 { |
| 59 // An editing position like [input, 0] actually refers to the position befor
e | 60 // An editing position like [input, 0] actually refers to the position befor
e |
| 60 // the input element, and in that case we need to check the input element's | 61 // the input element, and in that case we need to check the input element's |
| 61 // parent's layoutObject. | 62 // parent's layoutObject. |
| 62 Position p(insertionPos.parentAnchoredEquivalent()); | 63 Position p(insertionPos.parentAnchoredEquivalent()); |
| 63 return p.anchorNode()->layoutObject() && !p.anchorNode()->layoutObject()->st
yle()->preserveNewline(); | 64 return isRichlyEditablePosition(p) && p.anchorNode()->layoutObject() && !p.a
nchorNode()->layoutObject()->style()->preserveNewline(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void InsertLineBreakCommand::doApply(EditingState* editingState) | 67 void InsertLineBreakCommand::doApply(EditingState* editingState) |
| 67 { | 68 { |
| 68 deleteSelection(editingState); | 69 deleteSelection(editingState); |
| 69 if (editingState->isAborted()) | 70 if (editingState->isAborted()) |
| 70 return; | 71 return; |
| 71 VisibleSelection selection = endingSelection(); | 72 VisibleSelection selection = endingSelection(); |
| 72 if (!selection.isNonOrphanedCaretOrRange()) | 73 if (!selection.isNonOrphanedCaretOrRange()) |
| 73 return; | 74 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 95 // FIXME: Need to merge text nodes when inserting just after or before text. | 96 // FIXME: Need to merge text nodes when inserting just after or before text. |
| 96 | 97 |
| 97 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { | 98 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { |
| 98 bool needExtraLineBreak = !isHTMLHRElement(*pos.anchorNode()) && !isHTML
TableElement(*pos.anchorNode()); | 99 bool needExtraLineBreak = !isHTMLHRElement(*pos.anchorNode()) && !isHTML
TableElement(*pos.anchorNode()); |
| 99 | 100 |
| 100 insertNodeAt(nodeToInsert.get(), pos, editingState); | 101 insertNodeAt(nodeToInsert.get(), pos, editingState); |
| 101 if (editingState->isAborted()) | 102 if (editingState->isAborted()) |
| 102 return; | 103 return; |
| 103 | 104 |
| 104 if (needExtraLineBreak) { | 105 if (needExtraLineBreak) { |
| 105 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert, editi
ngState); | 106 RefPtrWillBeRawPtr<Node> extraNode; |
| 107 // TODO(tkent): Can we remove HTMLTextFormControlElement dependency? |
| 108 if (HTMLTextFormControlElement* textControl = enclosingTextFormContr
ol(nodeToInsert.get())) |
| 109 extraNode = textControl->createPlaceholderBreakElement(); |
| 110 else |
| 111 extraNode = nodeToInsert->cloneNode(false); |
| 112 insertNodeAfter(extraNode.get(), nodeToInsert, editingState); |
| 106 if (editingState->isAborted()) | 113 if (editingState->isAborted()) |
| 107 return; | 114 return; |
| 115 nodeToInsert = extraNode.release(); |
| 108 } | 116 } |
| 109 | 117 |
| 110 VisiblePosition endingPosition = createVisiblePosition(positionBeforeNod
e(nodeToInsert.get())); | 118 VisiblePosition endingPosition = createVisiblePosition(positionBeforeNod
e(nodeToInsert.get())); |
| 111 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); | 119 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); |
| 112 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { | 120 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { |
| 113 insertNodeAt(nodeToInsert.get(), pos, editingState); | 121 insertNodeAt(nodeToInsert.get(), pos, editingState); |
| 114 if (editingState->isAborted()) | 122 if (editingState->isAborted()) |
| 115 return; | 123 return; |
| 116 | 124 |
| 117 // Insert an extra br or '\n' if the just inserted one collapsed. | 125 // Insert an extra br or '\n' if the just inserted one collapsed. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // before the line break (if the line break is at the end of a block it
isn't selectable). | 188 // before the line break (if the line break is at the end of a block it
isn't selectable). |
| 181 // So, this next call sets the endingSelection() to a caret just after t
he line break | 189 // So, this next call sets the endingSelection() to a caret just after t
he line break |
| 182 // that we inserted, or just before it if it's at the end of a block. | 190 // that we inserted, or just before it if it's at the end of a block. |
| 183 setEndingSelection(endingSelection().visibleEnd()); | 191 setEndingSelection(endingSelection().visibleEnd()); |
| 184 } | 192 } |
| 185 | 193 |
| 186 rebalanceWhitespace(); | 194 rebalanceWhitespace(); |
| 187 } | 195 } |
| 188 | 196 |
| 189 } // namespace blink | 197 } // namespace blink |
| OLD | NEW |