| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // When a selection ends at the start of a paragraph, we rarely paint | 70 // When a selection ends at the start of a paragraph, we rarely paint |
| 71 // the selection gap before that paragraph, because there often is no gap. | 71 // the selection gap before that paragraph, because there often is no gap. |
| 72 // In a case like this, it's not obvious to the user that the selection | 72 // In a case like this, it's not obvious to the user that the selection |
| 73 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent | 73 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent |
| 74 // operated on that paragraph. | 74 // operated on that paragraph. |
| 75 // FIXME: We paint the gap before some paragraphs that are indented with left | 75 // FIXME: We paint the gap before some paragraphs that are indented with left |
| 76 // margin/padding, but not others. We should make the gap painting more | 76 // margin/padding, but not others. We should make the gap painting more |
| 77 // consistent and then use a left margin/padding rule here. | 77 // consistent and then use a left margin/padding rule here. |
| 78 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && | 78 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && |
| 79 isStartOfParagraph(visibleEnd)) { | 79 isStartOfParagraph(visibleEnd)) { |
| 80 VisibleSelection newSelection = createVisibleSelection( | 80 const Position& newEnd = |
| 81 visibleStart, | 81 previousPositionOf(visibleEnd, CannotCrossEditingBoundary) |
| 82 previousPositionOf(visibleEnd, CannotCrossEditingBoundary), | 82 .deepEquivalent(); |
| 83 endingSelection().isDirectional()); | 83 SelectionInDOMTree::Builder builder; |
| 84 builder.collapse(visibleStart.toPositionWithAffinity()); |
| 85 if (newEnd.isNotNull()) |
| 86 builder.extend(newEnd); |
| 87 builder.setIsDirectional(endingSelection().isDirectional()); |
| 88 const VisibleSelection newSelection = |
| 89 createVisibleSelection(builder.build()); |
| 84 if (newSelection.isNone()) | 90 if (newSelection.isNone()) |
| 85 return; | 91 return; |
| 86 setEndingSelection(newSelection); | 92 setEndingSelection(newSelection); |
| 87 } | 93 } |
| 88 | 94 |
| 89 VisibleSelection selection = | 95 VisibleSelection selection = |
| 90 selectionForParagraphIteration(endingSelection()); | 96 selectionForParagraphIteration(endingSelection()); |
| 91 VisiblePosition startOfSelection = selection.visibleStart(); | 97 VisiblePosition startOfSelection = selection.visibleStart(); |
| 92 VisiblePosition endOfSelection = selection.visibleEnd(); | 98 VisiblePosition endOfSelection = selection.visibleEnd(); |
| 93 DCHECK(!startOfSelection.isNull()); | 99 DCHECK(!startOfSelection.isNull()); |
| 94 DCHECK(!endOfSelection.isNull()); | 100 DCHECK(!endOfSelection.isNull()); |
| 95 ContainerNode* startScope = nullptr; | 101 ContainerNode* startScope = nullptr; |
| 96 int startIndex = indexForVisiblePosition(startOfSelection, startScope); | 102 int startIndex = indexForVisiblePosition(startOfSelection, startScope); |
| 97 ContainerNode* endScope = nullptr; | 103 ContainerNode* endScope = nullptr; |
| 98 int endIndex = indexForVisiblePosition(endOfSelection, endScope); | 104 int endIndex = indexForVisiblePosition(endOfSelection, endScope); |
| 99 | 105 |
| 100 formatSelection(startOfSelection, endOfSelection, editingState); | 106 formatSelection(startOfSelection, endOfSelection, editingState); |
| 101 if (editingState->isAborted()) | 107 if (editingState->isAborted()) |
| 102 return; | 108 return; |
| 103 | 109 |
| 104 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 110 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 105 | 111 |
| 106 DCHECK_EQ(startScope, endScope); | 112 DCHECK_EQ(startScope, endScope); |
| 107 DCHECK_GE(startIndex, 0); | 113 DCHECK_GE(startIndex, 0); |
| 108 DCHECK_LE(startIndex, endIndex); | 114 DCHECK_LE(startIndex, endIndex); |
| 109 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { | 115 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { |
| 110 VisiblePosition start(visiblePositionForIndex(startIndex, startScope)); | 116 VisiblePosition start(visiblePositionForIndex(startIndex, startScope)); |
| 111 VisiblePosition end(visiblePositionForIndex(endIndex, endScope)); | 117 VisiblePosition end(visiblePositionForIndex(endIndex, endScope)); |
| 112 if (start.isNotNull() && end.isNotNull()) | 118 if (start.isNotNull() && end.isNotNull()) { |
| 113 setEndingSelection(createVisibleSelection( | 119 setEndingSelection(createVisibleSelection( |
| 114 start, end, endingSelection().isDirectional())); | 120 SelectionInDOMTree::Builder() |
| 121 .collapse(start.toPositionWithAffinity()) |
| 122 .extend(end.deepEquivalent()) |
| 123 .setIsDirectional(endingSelection().isDirectional()) |
| 124 .build())); |
| 125 } |
| 115 } | 126 } |
| 116 } | 127 } |
| 117 | 128 |
| 118 static bool isAtUnsplittableElement(const Position& pos) { | 129 static bool isAtUnsplittableElement(const Position& pos) { |
| 119 Node* node = pos.anchorNode(); | 130 Node* node = pos.anchorNode(); |
| 120 return node == rootEditableElementOf(pos) || | 131 return node == rootEditableElementOf(pos) || |
| 121 node == enclosingNodeOfType(pos, &isTableCell); | 132 node == enclosingNodeOfType(pos, &isTableCell); |
| 122 } | 133 } |
| 123 | 134 |
| 124 void ApplyBlockElementCommand::formatSelection( | 135 void ApplyBlockElementCommand::formatSelection( |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 element->setAttribute(styleAttr, m_inlineStyle); | 392 element->setAttribute(styleAttr, m_inlineStyle); |
| 382 return element; | 393 return element; |
| 383 } | 394 } |
| 384 | 395 |
| 385 DEFINE_TRACE(ApplyBlockElementCommand) { | 396 DEFINE_TRACE(ApplyBlockElementCommand) { |
| 386 visitor->trace(m_endOfLastParagraph); | 397 visitor->trace(m_endOfLastParagraph); |
| 387 CompositeEditCommand::trace(visitor); | 398 CompositeEditCommand::trace(visitor); |
| 388 } | 399 } |
| 389 | 400 |
| 390 } // namespace blink | 401 } // namespace blink |
| OLD | NEW |