Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ApplyBlockElementCommand.cpp

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 // When a selection ends at the start of a paragraph, we rarely paint 67 // When a selection ends at the start of a paragraph, we rarely paint
68 // the selection gap before that paragraph, because there often is no gap. 68 // the selection gap before that paragraph, because there often is no gap.
69 // In a case like this, it's not obvious to the user that the selection 69 // In a case like this, it's not obvious to the user that the selection
70 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent 70 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent
71 // operated on that paragraph. 71 // operated on that paragraph.
72 // FIXME: We paint the gap before some paragraphs that are indented with lef t 72 // FIXME: We paint the gap before some paragraphs that are indented with lef t
73 // margin/padding, but not others. We should make the gap painting more 73 // margin/padding, but not others. We should make the gap painting more
74 // consistent and then use a left margin/padding rule here. 74 // consistent and then use a left margin/padding rule here.
75 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraphDeprecated(visibleEnd)) { 75 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraphDeprecated(visibleEnd)) {
76 VisibleSelection newSelection(visibleStart, previousPositionOf(visibleEn d, CannotCrossEditingBoundary), endingSelection().isDirectional()); 76 VisibleSelection newSelection = createVisibleSelectionDeprecated(visible Start, previousPositionOf(visibleEnd, CannotCrossEditingBoundary), endingSelecti on().isDirectional());
77 if (newSelection.isNone()) 77 if (newSelection.isNone())
78 return; 78 return;
79 setEndingSelection(newSelection); 79 setEndingSelection(newSelection);
80 } 80 }
81 81
82 VisibleSelection selection = selectionForParagraphIteration(endingSelection( )); 82 VisibleSelection selection = selectionForParagraphIteration(endingSelection( ));
83 VisiblePosition startOfSelection = selection.visibleStartDeprecated(); 83 VisiblePosition startOfSelection = selection.visibleStartDeprecated();
84 VisiblePosition endOfSelection = selection.visibleEndDeprecated(); 84 VisiblePosition endOfSelection = selection.visibleEndDeprecated();
85 DCHECK(!startOfSelection.isNull()); 85 DCHECK(!startOfSelection.isNull());
86 DCHECK(!endOfSelection.isNull()); 86 DCHECK(!endOfSelection.isNull());
87 ContainerNode* startScope = nullptr; 87 ContainerNode* startScope = nullptr;
88 int startIndex = indexForVisiblePosition(startOfSelection, startScope); 88 int startIndex = indexForVisiblePosition(startOfSelection, startScope);
89 ContainerNode* endScope = nullptr; 89 ContainerNode* endScope = nullptr;
90 int endIndex = indexForVisiblePosition(endOfSelection, endScope); 90 int endIndex = indexForVisiblePosition(endOfSelection, endScope);
91 91
92 formatSelection(startOfSelection, endOfSelection, editingState); 92 formatSelection(startOfSelection, endOfSelection, editingState);
93 if (editingState->isAborted()) 93 if (editingState->isAborted())
94 return; 94 return;
95 95
96 document().updateStyleAndLayoutIgnorePendingStylesheets(); 96 document().updateStyleAndLayoutIgnorePendingStylesheets();
97 97
98 DCHECK_EQ(startScope, endScope); 98 DCHECK_EQ(startScope, endScope);
99 DCHECK_GE(startIndex, 0); 99 DCHECK_GE(startIndex, 0);
100 DCHECK_LE(startIndex, endIndex); 100 DCHECK_LE(startIndex, endIndex);
101 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { 101 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) {
102 VisiblePosition start(visiblePositionForIndex(startIndex, startScope)); 102 VisiblePosition start(visiblePositionForIndex(startIndex, startScope));
103 VisiblePosition end(visiblePositionForIndex(endIndex, endScope)); 103 VisiblePosition end(visiblePositionForIndex(endIndex, endScope));
104 if (start.isNotNull() && end.isNotNull()) 104 if (start.isNotNull() && end.isNotNull())
105 setEndingSelection(VisibleSelection(start, end, endingSelection().is Directional())); 105 setEndingSelection(createVisibleSelectionDeprecated(start, end, endi ngSelection().isDirectional()));
106 } 106 }
107 } 107 }
108 108
109 static bool isAtUnsplittableElement(const Position& pos) 109 static bool isAtUnsplittableElement(const Position& pos)
110 { 110 {
111 Node* node = pos.anchorNode(); 111 Node* node = pos.anchorNode();
112 return node == rootEditableElementOf(pos) || node == enclosingNodeOfType(pos , &isTableCell); 112 return node == rootEditableElementOf(pos) || node == enclosingNodeOfType(pos , &isTableCell);
113 } 113 }
114 114
115 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel ection, const VisiblePosition& endOfSelection, EditingState* editingState) 115 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel ection, const VisiblePosition& endOfSelection, EditingState* editingState)
116 { 116 {
117 // Special case empty unsplittable elements because there's nothing to split 117 // Special case empty unsplittable elements because there's nothing to split
118 // and there's nothing to move. 118 // and there's nothing to move.
119 Position start = mostForwardCaretPosition(startOfSelection.deepEquivalent()) ; 119 Position start = mostForwardCaretPosition(startOfSelection.deepEquivalent()) ;
120 if (isAtUnsplittableElement(start)) { 120 if (isAtUnsplittableElement(start)) {
121 HTMLElement* blockquote = createBlockElement(); 121 HTMLElement* blockquote = createBlockElement();
122 insertNodeAt(blockquote, start, editingState); 122 insertNodeAt(blockquote, start, editingState);
123 if (editingState->isAborted()) 123 if (editingState->isAborted())
124 return; 124 return;
125 HTMLBRElement* placeholder = HTMLBRElement::create(document()); 125 HTMLBRElement* placeholder = HTMLBRElement::create(document());
126 appendNode(placeholder, blockquote, editingState); 126 appendNode(placeholder, blockquote, editingState);
127 if (editingState->isAborted()) 127 if (editingState->isAborted())
128 return; 128 return;
129 setEndingSelection(VisibleSelection(Position::beforeNode(placeholder), T extAffinity::Downstream, endingSelection().isDirectional())); 129 setEndingSelection(createVisibleSelectionDeprecated(Position::beforeNode (placeholder), TextAffinity::Downstream, endingSelection().isDirectional()));
130 return; 130 return;
131 } 131 }
132 132
133 HTMLElement* blockquoteForNextIndent = nullptr; 133 HTMLElement* blockquoteForNextIndent = nullptr;
134 VisiblePosition endOfCurrentParagraph = endOfParagraphDeprecated(startOfSele ction); 134 VisiblePosition endOfCurrentParagraph = endOfParagraphDeprecated(startOfSele ction);
135 VisiblePosition endOfLastParagraph = endOfParagraphDeprecated(endOfSelection ); 135 VisiblePosition endOfLastParagraph = endOfParagraphDeprecated(endOfSelection );
136 VisiblePosition endAfterSelection = endOfParagraphDeprecated(nextPositionOf( endOfLastParagraph)); 136 VisiblePosition endAfterSelection = endOfParagraphDeprecated(nextPositionOf( endOfLastParagraph));
137 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent(); 137 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent();
138 138
139 bool atEnd = false; 139 bool atEnd = false;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return element; 306 return element;
307 } 307 }
308 308
309 DEFINE_TRACE(ApplyBlockElementCommand) 309 DEFINE_TRACE(ApplyBlockElementCommand)
310 { 310 {
311 visitor->trace(m_endOfLastParagraph); 311 visitor->trace(m_endOfLastParagraph);
312 CompositeEditCommand::trace(visitor); 312 CompositeEditCommand::trace(visitor);
313 } 313 }
314 314
315 } // namespace blink 315 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698