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

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

Issue 2212293002: Use LayoutObject::selectionState() to check whether selection contains node or not (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-08-08T11:10:01 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/PerformanceTests/DOM/remove_child_with_selection.html ('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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // the selection in the document that created the fragment needs no adjustme nt. 412 // the selection in the document that created the fragment needs no adjustme nt.
413 if (isNone() || !node.inActiveDocument()) 413 if (isNone() || !node.inActiveDocument())
414 return; 414 return;
415 415
416 respondToNodeModification(node, removingNodeRemovesPosition(node, selection( ).base()), removingNodeRemovesPosition(node, selection().extent()), 416 respondToNodeModification(node, removingNodeRemovesPosition(node, selection( ).base()), removingNodeRemovesPosition(node, selection().extent()),
417 removingNodeRemovesPosition(node, selection().start()), removingNodeRemo vesPosition(node, selection().end())); 417 removingNodeRemovesPosition(node, selection().start()), removingNodeRemo vesPosition(node, selection().end()));
418 418
419 m_frameCaret->nodeWillBeRemoved(node); 419 m_frameCaret->nodeWillBeRemoved(node);
420 } 420 }
421 421
422 static bool intersectsNode(const VisibleSelection& selection, Node* node) 422 static SelectionState selectionStateOf(const Node& node)
423 { 423 {
424 if (selection.isNone()) 424 const LayoutObject* layoutObject = node.layoutObject();
425 return false; 425 if (!layoutObject)
426 Position start = selection.start().parentAnchoredEquivalent(); 426 return SelectionNone;
427 Position end = selection.end().parentAnchoredEquivalent(); 427 return layoutObject->getSelectionState();
428 TrackExceptionState exceptionState;
429 // TODO(yosin) We should avoid to use |Range::intersectsNode()|.
430 return Range::intersectsNode(node, start, end, exceptionState) && !exception State.hadException();
431 } 428 }
432 429
433 void FrameSelection::respondToNodeModification(Node& node, bool baseRemoved, boo l extentRemoved, bool startRemoved, bool endRemoved) 430 void FrameSelection::respondToNodeModification(Node& node, bool baseRemoved, boo l extentRemoved, bool startRemoved, bool endRemoved)
434 { 431 {
435 DCHECK(node.document().isActive()) << node; 432 DCHECK(node.document().isActive()) << node;
436 433
437 bool clearLayoutTreeSelection = false; 434 bool clearLayoutTreeSelection = false;
438 bool clearDOMTreeSelection = false; 435 bool clearDOMTreeSelection = false;
439 436
440 if (startRemoved || endRemoved) { 437 if (startRemoved || endRemoved) {
(...skipping 16 matching lines...) Expand all
457 clearLayoutTreeSelection = true; 454 clearLayoutTreeSelection = true;
458 } else if (baseRemoved || extentRemoved) { 455 } else if (baseRemoved || extentRemoved) {
459 // The base and/or extent are about to be removed, but the start and end aren't. 456 // The base and/or extent are about to be removed, but the start and end aren't.
460 // Change the base and extent to the start and end, but don't re-validat e the 457 // Change the base and extent to the start and end, but don't re-validat e the
461 // selection, since doing so could move the start and end into the node 458 // selection, since doing so could move the start and end into the node
462 // that is about to be removed. 459 // that is about to be removed.
463 if (selection().isBaseFirst()) 460 if (selection().isBaseFirst())
464 m_selectionEditor->setWithoutValidation(selection().start(), selecti on().end()); 461 m_selectionEditor->setWithoutValidation(selection().start(), selecti on().end());
465 else 462 else
466 m_selectionEditor->setWithoutValidation(selection().end(), selection ().start()); 463 m_selectionEditor->setWithoutValidation(selection().end(), selection ().start());
467 } else if (intersectsNode(selection(), &node)) { 464 } else if (selectionStateOf(node) != SelectionNone) {
468 // If we did nothing here, when this node's layoutObject was destroyed, the rect that it 465 // When node to be removed is part of selection, we invalidate
469 // occupied would be invalidated, but, selection gaps that change as a r esult of 466 // selection to paint again.
470 // the removal wouldn't be invalidated. 467 // TODO(yosin): We should paint changed area only rather than whole
471 // FIXME: Don't do so much unnecessary invalidation. 468 // selected range.
472 clearLayoutTreeSelection = true; 469 clearLayoutTreeSelection = true;
473 } 470 }
474 471
475 if (clearLayoutTreeSelection) 472 if (clearLayoutTreeSelection)
476 selection().start().document()->layoutViewItem().clearSelection(); 473 selection().start().document()->layoutViewItem().clearSelection();
477 474
478 if (clearDOMTreeSelection) 475 if (clearDOMTreeSelection)
479 setSelection(VisibleSelection(), DoNotSetFocus); 476 setSelection(VisibleSelection(), DoNotSetFocus);
480 m_frameCaret->setCaretRectNeedsUpdate(); 477 m_frameCaret->setCaretRectNeedsUpdate();
481 478
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 1385
1389 void showTree(const blink::FrameSelection* sel) 1386 void showTree(const blink::FrameSelection* sel)
1390 { 1387 {
1391 if (sel) 1388 if (sel)
1392 sel->showTreeForThis(); 1389 sel->showTreeForThis();
1393 else 1390 else
1394 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1391 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1395 } 1392 }
1396 1393
1397 #endif 1394 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/PerformanceTests/DOM/remove_child_with_selection.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698