| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && | 78 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && |
| 79 isStartOfParagraph(visibleEnd)) { | 79 isStartOfParagraph(visibleEnd)) { |
| 80 const Position& newEnd = | 80 const Position& newEnd = |
| 81 previousPositionOf(visibleEnd, CannotCrossEditingBoundary) | 81 previousPositionOf(visibleEnd, CannotCrossEditingBoundary) |
| 82 .deepEquivalent(); | 82 .deepEquivalent(); |
| 83 SelectionInDOMTree::Builder builder; | 83 SelectionInDOMTree::Builder builder; |
| 84 builder.collapse(visibleStart.toPositionWithAffinity()); | 84 builder.collapse(visibleStart.toPositionWithAffinity()); |
| 85 if (newEnd.isNotNull()) | 85 if (newEnd.isNotNull()) |
| 86 builder.extend(newEnd); | 86 builder.extend(newEnd); |
| 87 builder.setIsDirectional(endingSelection().isDirectional()); | 87 builder.setIsDirectional(endingSelection().isDirectional()); |
| 88 const VisibleSelection newSelection = | 88 const SelectionInDOMTree& newSelection = builder.build(); |
| 89 createVisibleSelection(builder.build()); | |
| 90 if (newSelection.isNone()) | 89 if (newSelection.isNone()) |
| 91 return; | 90 return; |
| 92 setEndingSelection(newSelection); | 91 setEndingSelection(newSelection); |
| 93 } | 92 } |
| 94 | 93 |
| 95 VisibleSelection selection = | 94 VisibleSelection selection = |
| 96 selectionForParagraphIteration(endingSelection()); | 95 selectionForParagraphIteration(endingSelection()); |
| 97 VisiblePosition startOfSelection = selection.visibleStart(); | 96 VisiblePosition startOfSelection = selection.visibleStart(); |
| 98 VisiblePosition endOfSelection = selection.visibleEnd(); | 97 VisiblePosition endOfSelection = selection.visibleEnd(); |
| 99 DCHECK(!startOfSelection.isNull()); | 98 DCHECK(!startOfSelection.isNull()); |
| 100 DCHECK(!endOfSelection.isNull()); | 99 DCHECK(!endOfSelection.isNull()); |
| 101 ContainerNode* startScope = nullptr; | 100 ContainerNode* startScope = nullptr; |
| 102 int startIndex = indexForVisiblePosition(startOfSelection, startScope); | 101 int startIndex = indexForVisiblePosition(startOfSelection, startScope); |
| 103 ContainerNode* endScope = nullptr; | 102 ContainerNode* endScope = nullptr; |
| 104 int endIndex = indexForVisiblePosition(endOfSelection, endScope); | 103 int endIndex = indexForVisiblePosition(endOfSelection, endScope); |
| 105 | 104 |
| 106 formatSelection(startOfSelection, endOfSelection, editingState); | 105 formatSelection(startOfSelection, endOfSelection, editingState); |
| 107 if (editingState->isAborted()) | 106 if (editingState->isAborted()) |
| 108 return; | 107 return; |
| 109 | 108 |
| 110 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 109 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 111 | 110 |
| 112 DCHECK_EQ(startScope, endScope); | 111 DCHECK_EQ(startScope, endScope); |
| 113 DCHECK_GE(startIndex, 0); | 112 DCHECK_GE(startIndex, 0); |
| 114 DCHECK_LE(startIndex, endIndex); | 113 DCHECK_LE(startIndex, endIndex); |
| 115 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { | 114 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { |
| 116 VisiblePosition start(visiblePositionForIndex(startIndex, startScope)); | 115 VisiblePosition start(visiblePositionForIndex(startIndex, startScope)); |
| 117 VisiblePosition end(visiblePositionForIndex(endIndex, endScope)); | 116 VisiblePosition end(visiblePositionForIndex(endIndex, endScope)); |
| 118 if (start.isNotNull() && end.isNotNull()) { | 117 if (start.isNotNull() && end.isNotNull()) { |
| 119 setEndingSelection(createVisibleSelection( | 118 setEndingSelection( |
| 120 SelectionInDOMTree::Builder() | 119 SelectionInDOMTree::Builder() |
| 121 .collapse(start.toPositionWithAffinity()) | 120 .collapse(start.toPositionWithAffinity()) |
| 122 .extend(end.deepEquivalent()) | 121 .extend(end.deepEquivalent()) |
| 123 .setIsDirectional(endingSelection().isDirectional()) | 122 .setIsDirectional(endingSelection().isDirectional()) |
| 124 .build())); | 123 .build()); |
| 125 } | 124 } |
| 126 } | 125 } |
| 127 } | 126 } |
| 128 | 127 |
| 129 static bool isAtUnsplittableElement(const Position& pos) { | 128 static bool isAtUnsplittableElement(const Position& pos) { |
| 130 Node* node = pos.anchorNode(); | 129 Node* node = pos.anchorNode(); |
| 131 return node == rootEditableElementOf(pos) || | 130 return node == rootEditableElementOf(pos) || |
| 132 node == enclosingNodeOfType(pos, &isTableCell); | 131 node == enclosingNodeOfType(pos, &isTableCell); |
| 133 } | 132 } |
| 134 | 133 |
| 135 void ApplyBlockElementCommand::formatSelection( | 134 void ApplyBlockElementCommand::formatSelection( |
| 136 const VisiblePosition& startOfSelection, | 135 const VisiblePosition& startOfSelection, |
| 137 const VisiblePosition& endOfSelection, | 136 const VisiblePosition& endOfSelection, |
| 138 EditingState* editingState) { | 137 EditingState* editingState) { |
| 139 // Special case empty unsplittable elements because there's nothing to split | 138 // Special case empty unsplittable elements because there's nothing to split |
| 140 // and there's nothing to move. | 139 // and there's nothing to move. |
| 141 const Position& caretPosition = | 140 const Position& caretPosition = |
| 142 mostForwardCaretPosition(startOfSelection.deepEquivalent()); | 141 mostForwardCaretPosition(startOfSelection.deepEquivalent()); |
| 143 if (isAtUnsplittableElement(caretPosition)) { | 142 if (isAtUnsplittableElement(caretPosition)) { |
| 144 HTMLElement* blockquote = createBlockElement(); | 143 HTMLElement* blockquote = createBlockElement(); |
| 145 insertNodeAt(blockquote, caretPosition, editingState); | 144 insertNodeAt(blockquote, caretPosition, editingState); |
| 146 if (editingState->isAborted()) | 145 if (editingState->isAborted()) |
| 147 return; | 146 return; |
| 148 HTMLBRElement* placeholder = HTMLBRElement::create(document()); | 147 HTMLBRElement* placeholder = HTMLBRElement::create(document()); |
| 149 appendNode(placeholder, blockquote, editingState); | 148 appendNode(placeholder, blockquote, editingState); |
| 150 if (editingState->isAborted()) | 149 if (editingState->isAborted()) |
| 151 return; | 150 return; |
| 152 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 151 setEndingSelection(SelectionInDOMTree::Builder() |
| 153 setEndingSelection(createVisibleSelection( | 152 .collapse(Position::beforeNode(placeholder)) |
| 154 SelectionInDOMTree::Builder() | 153 .setIsDirectional(endingSelection().isDirectional()) |
| 155 .collapse(Position::beforeNode(placeholder)) | 154 .build()); |
| 156 .setIsDirectional(endingSelection().isDirectional()) | |
| 157 .build())); | |
| 158 return; | 155 return; |
| 159 } | 156 } |
| 160 | 157 |
| 161 HTMLElement* blockquoteForNextIndent = nullptr; | 158 HTMLElement* blockquoteForNextIndent = nullptr; |
| 162 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); | 159 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); |
| 163 const VisiblePosition& visibleEndOfLastParagraph = | 160 const VisiblePosition& visibleEndOfLastParagraph = |
| 164 endOfParagraph(endOfSelection); | 161 endOfParagraph(endOfSelection); |
| 165 const Position& endOfNextLastParagraph = | 162 const Position& endOfNextLastParagraph = |
| 166 endOfParagraph(nextPositionOf(visibleEndOfLastParagraph)) | 163 endOfParagraph(nextPositionOf(visibleEndOfLastParagraph)) |
| 167 .deepEquivalent(); | 164 .deepEquivalent(); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 if (m_inlineStyle.length()) | 406 if (m_inlineStyle.length()) |
| 410 element->setAttribute(styleAttr, m_inlineStyle); | 407 element->setAttribute(styleAttr, m_inlineStyle); |
| 411 return element; | 408 return element; |
| 412 } | 409 } |
| 413 | 410 |
| 414 DEFINE_TRACE(ApplyBlockElementCommand) { | 411 DEFINE_TRACE(ApplyBlockElementCommand) { |
| 415 CompositeEditCommand::trace(visitor); | 412 CompositeEditCommand::trace(visitor); |
| 416 } | 413 } |
| 417 | 414 |
| 418 } // namespace blink | 415 } // namespace blink |
| OLD | NEW |