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

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

Issue 2221783003: Introduce FrameSelection::nodeChildrenWillBeRemoved() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-08-10T10:37:48 Created 4 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (position.anchorNode() == node) 399 if (position.anchorNode() == node)
400 return true; 400 return true;
401 401
402 if (!node.isElementNode()) 402 if (!node.isElementNode())
403 return false; 403 return false;
404 404
405 Element& element = toElement(node); 405 Element& element = toElement(node);
406 return element.isShadowIncludingInclusiveAncestorOf(position.anchorNode()); 406 return element.isShadowIncludingInclusiveAncestorOf(position.anchorNode());
407 } 407 }
408 408
409 static Position computePositionForChildrenRemoval(const Position& position, Cont ainerNode& container)
410 {
411 Node* node = position.computeContainerNode();
412 if (container.containsIncludingHostElements(*node))
413 return Position::firstPositionInNode(&container);
414 return position;
415 }
416
417 void FrameSelection::nodeChildrenWillBeRemoved(ContainerNode& container)
418 {
419 if (isNone() || !container.inActiveDocument())
420 return;
421 const Position& oldStart = selection().start();
422 const Position& newStart = computePositionForChildrenRemoval(oldStart, conta iner);
423 const Position& oldEnd = selection().end();
424 const Position& newEnd = computePositionForChildrenRemoval(oldEnd, container );
425 const Position& oldBase = selection().base();
426 const Position& newBase = computePositionForChildrenRemoval(oldBase, contain er);
427 const Position& oldExtent = selection().extent();
428 const Position& newExtent = computePositionForChildrenRemoval(oldExtent, con tainer);
429 if (newStart == oldStart && newEnd == oldEnd && newBase == oldBase && newExt ent == oldExtent)
430 return;
431 if (selection().isBaseFirst())
432 m_selectionEditor->setWithoutValidation(newStart, newEnd);
433 else
434 m_selectionEditor->setWithoutValidation(newEnd, newStart);
435 m_frameCaret->setCaretRectNeedsUpdate();
436 if (document().isRunningExecCommand())
437 return;
438 TypingCommand::closeTyping(m_frame);
439 }
440
409 void FrameSelection::nodeWillBeRemoved(Node& node) 441 void FrameSelection::nodeWillBeRemoved(Node& node)
410 { 442 {
411 // There can't be a selection inside a fragment, so if a fragment's node is being removed, 443 // There can't be a selection inside a fragment, so if a fragment's node is being removed,
412 // the selection in the document that created the fragment needs no adjustme nt. 444 // the selection in the document that created the fragment needs no adjustme nt.
413 if (isNone() || !node.inActiveDocument()) 445 if (isNone() || !node.inActiveDocument())
414 return; 446 return;
415 447
416 respondToNodeModification(node, removingNodeRemovesPosition(node, selection( ).base()), removingNodeRemovesPosition(node, selection().extent()), 448 respondToNodeModification(node, removingNodeRemovesPosition(node, selection( ).base()), removingNodeRemovesPosition(node, selection().extent()),
417 removingNodeRemovesPosition(node, selection().start()), removingNodeRemo vesPosition(node, selection().end())); 449 removingNodeRemovesPosition(node, selection().start()), removingNodeRemo vesPosition(node, selection().end()));
418 450
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 1417
1386 void showTree(const blink::FrameSelection* sel) 1418 void showTree(const blink::FrameSelection* sel)
1387 { 1419 {
1388 if (sel) 1420 if (sel)
1389 sel->showTreeForThis(); 1421 sel->showTreeForThis();
1390 else 1422 else
1391 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1423 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1392 } 1424 }
1393 1425
1394 #endif 1426 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698