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

Side by Side Diff: Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp

Issue 1293593004: Introduce enum class TextAffinity as replacement of enum EAffinity (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-19T18:09:55 Created 5 years, 4 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) 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return parent.release(); 149 return parent.release();
150 } 150 }
151 151
152 void InsertParagraphSeparatorCommand::doApply() 152 void InsertParagraphSeparatorCommand::doApply()
153 { 153 {
154 if (!endingSelection().isNonOrphanedCaretOrRange()) 154 if (!endingSelection().isNonOrphanedCaretOrRange())
155 return; 155 return;
156 156
157 Position insertionPosition = endingSelection().start(); 157 Position insertionPosition = endingSelection().start();
158 158
159 EAffinity affinity = endingSelection().affinity(); 159 TextAffinity affinity = endingSelection().affinity();
160 160
161 // Delete the current selection. 161 // Delete the current selection.
162 if (endingSelection().isRange()) { 162 if (endingSelection().isRange()) {
163 calculateStyleBeforeInsertion(insertionPosition); 163 calculateStyleBeforeInsertion(insertionPosition);
164 deleteSelection(false, true); 164 deleteSelection(false, true);
165 insertionPosition = endingSelection().start(); 165 insertionPosition = endingSelection().start();
166 affinity = endingSelection().affinity(); 166 affinity = endingSelection().affinity();
167 } 167 }
168 168
169 // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enc losingBlock. 169 // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enc losingBlock.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 252
253 // Recreate the same structure in the new paragraph. 253 // Recreate the same structure in the new paragraph.
254 254
255 WillBeHeapVector<RefPtrWillBeMember<Element>> ancestors; 255 WillBeHeapVector<RefPtrWillBeMember<Element>> ancestors;
256 getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).anchor Node(), startBlock.get(), ancestors); 256 getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).anchor Node(), startBlock.get(), ancestors);
257 RefPtrWillBeRawPtr<Element> parent = cloneHierarchyUnderNewBlock(ancesto rs, blockToInsert); 257 RefPtrWillBeRawPtr<Element> parent = cloneHierarchyUnderNewBlock(ancesto rs, blockToInsert);
258 258
259 appendBlockPlaceholder(parent); 259 appendBlockPlaceholder(parent);
260 260
261 setEndingSelection(VisibleSelection(firstPositionInNode(parent.get()), D OWNSTREAM, endingSelection().isDirectional())); 261 setEndingSelection(VisibleSelection(firstPositionInNode(parent.get()), T extAffinity::Downstream, endingSelection().isDirectional()));
262 return; 262 return;
263 } 263 }
264 264
265 265
266 //--------------------------------------------------------------------- 266 //---------------------------------------------------------------------
267 // Handle case when position is in the first visible position in its block, and 267 // Handle case when position is in the first visible position in its block, and
268 // similar case where previous position is in another, presumeably nested, b lock. 268 // similar case where previous position is in another, presumeably nested, b lock.
269 if (isFirstInBlock || !inSameBlock(visiblePos, visiblePos.previous())) { 269 if (isFirstInBlock || !inSameBlock(visiblePos, visiblePos.previous())) {
270 Node* refNode = nullptr; 270 Node* refNode = nullptr;
271 insertionPosition = positionOutsideTabSpan(insertionPosition); 271 insertionPosition = positionOutsideTabSpan(insertionPosition);
(...skipping 24 matching lines...) Expand all
296 insertNodeBefore(blockToInsert, refNode); 296 insertNodeBefore(blockToInsert, refNode);
297 297
298 // Recreate the same structure in the new paragraph. 298 // Recreate the same structure in the new paragraph.
299 299
300 WillBeHeapVector<RefPtrWillBeMember<Element>> ancestors; 300 WillBeHeapVector<RefPtrWillBeMember<Element>> ancestors;
301 getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(positionO utsideTabSpan(insertionPosition)).anchorNode(), startBlock.get(), ancestors); 301 getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(positionO utsideTabSpan(insertionPosition)).anchorNode(), startBlock.get(), ancestors);
302 302
303 appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, blockToIns ert)); 303 appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, blockToIns ert));
304 304
305 // In this case, we need to set the new ending selection. 305 // In this case, we need to set the new ending selection.
306 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, endin gSelection().isDirectional())); 306 setEndingSelection(VisibleSelection(insertionPosition, TextAffinity::Dow nstream, endingSelection().isDirectional()));
307 return; 307 return;
308 } 308 }
309 309
310 //--------------------------------------------------------------------- 310 //---------------------------------------------------------------------
311 // Handle the (more complicated) general case, 311 // Handle the (more complicated) general case,
312 312
313 // All of the content in the current block after visiblePos is 313 // All of the content in the current block after visiblePos is
314 // about to be wrapped in a new paragraph element. Add a br before 314 // about to be wrapped in a new paragraph element. Add a br before
315 // it if visiblePos is at the start of a paragraph so that the 315 // it if visiblePos is at the start of a paragraph so that the
316 // content will move down a line. 316 // content will move down a line.
317 if (isStartOfParagraph(visiblePos)) { 317 if (isStartOfParagraph(visiblePos)) {
318 RefPtrWillBeRawPtr<HTMLBRElement> br = createBreakElement(document()); 318 RefPtrWillBeRawPtr<HTMLBRElement> br = createBreakElement(document());
319 insertNodeAt(br.get(), insertionPosition); 319 insertNodeAt(br.get(), insertionPosition);
320 insertionPosition = positionInParentAfterNode(*br); 320 insertionPosition = positionInParentAfterNode(*br);
321 // If the insertion point is a break element, there is nothing else 321 // If the insertion point is a break element, there is nothing else
322 // we need to do. 322 // we need to do.
323 if (visiblePos.deepEquivalent().anchorNode()->layoutObject()->isBR()) { 323 if (visiblePos.deepEquivalent().anchorNode()->layoutObject()->isBR()) {
324 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, e ndingSelection().isDirectional())); 324 setEndingSelection(VisibleSelection(insertionPosition, TextAffinity: :Downstream, endingSelection().isDirectional()));
325 return; 325 return;
326 } 326 }
327 } 327 }
328 328
329 // Move downstream. Typing style code will take care of carrying along the 329 // Move downstream. Typing style code will take care of carrying along the
330 // style of the upstream position. 330 // style of the upstream position.
331 insertionPosition = insertionPosition.downstream(); 331 insertionPosition = insertionPosition.downstream();
332 332
333 // At this point, the insertionPosition's node could be a container, and we want to make sure we include 333 // At this point, the insertionPosition's node could be a container, and we want to make sure we include
334 // all of the correct nodes when building the ancestor list. So this needs to be the deepest representation of the position 334 // all of the correct nodes when building the ancestor list. So this needs to be the deepest representation of the position
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // use |VisiblePosition::characterAfter()|. 421 // use |VisiblePosition::characterAfter()|.
422 if (!isRenderedCharacter(positionAfterSplit)) { 422 if (!isRenderedCharacter(positionAfterSplit)) {
423 // Clear out all whitespace and insert one non-breaking space 423 // Clear out all whitespace and insert one non-breaking space
424 ASSERT(!positionAfterSplit.computeContainerNode()->layoutObject() || positionAfterSplit.computeContainerNode()->layoutObject()->style()->collapseWhi teSpace()); 424 ASSERT(!positionAfterSplit.computeContainerNode()->layoutObject() || positionAfterSplit.computeContainerNode()->layoutObject()->style()->collapseWhi teSpace());
425 deleteInsignificantTextDownstream(positionAfterSplit); 425 deleteInsignificantTextDownstream(positionAfterSplit);
426 if (positionAfterSplit.anchorNode()->isTextNode()) 426 if (positionAfterSplit.anchorNode()->isTextNode())
427 insertTextIntoNode(toText(positionAfterSplit.computeContainerNod e()), 0, nonBreakingSpaceString()); 427 insertTextIntoNode(toText(positionAfterSplit.computeContainerNod e()), 0, nonBreakingSpaceString());
428 } 428 }
429 } 429 }
430 430
431 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get()) , DOWNSTREAM, endingSelection().isDirectional())); 431 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get()) , TextAffinity::Downstream, endingSelection().isDirectional()));
432 applyStyleAfterInsertion(startBlock.get()); 432 applyStyleAfterInsertion(startBlock.get());
433 } 433 }
434 434
435 DEFINE_TRACE(InsertParagraphSeparatorCommand) 435 DEFINE_TRACE(InsertParagraphSeparatorCommand)
436 { 436 {
437 visitor->trace(m_style); 437 visitor->trace(m_style);
438 CompositeEditCommand::trace(visitor); 438 CompositeEditCommand::trace(visitor);
439 } 439 }
440 440
441 441
442 } // namespace blink 442 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698