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

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

Issue 2732963002: Make SelectionController::setNonDirectionalSelectionIfNeeded() to take SelectionInFlatTree (Closed)
Patch Set: 2017-03-06T18:46:44 Created 3 years, 9 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, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
6 * Copyright (C) 2015 Google Inc. All rights reserved. 6 * Copyright (C) 2015 Google Inc. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 basePosition = selection().computeVisibleSelectionInFlatTree().base(); 388 basePosition = selection().computeVisibleSelectionInFlatTree().base();
389 } 389 }
390 const SelectionInFlatTree& appliedSelection = applySelectAll( 390 const SelectionInFlatTree& appliedSelection = applySelectAll(
391 basePosition, targetPosition.deepEquivalent(), mousePressNode, 391 basePosition, targetPosition.deepEquivalent(), mousePressNode,
392 dragStartPos, target, hitTestResult.localPoint()); 392 dragStartPos, target, hitTestResult.localPoint());
393 SelectionInFlatTree::Builder builder(appliedSelection); 393 SelectionInFlatTree::Builder builder(appliedSelection);
394 394
395 if (selection().granularity() != CharacterGranularity) 395 if (selection().granularity() != CharacterGranularity)
396 builder.setGranularity(selection().granularity()); 396 builder.setGranularity(selection().granularity());
397 397
398 setNonDirectionalSelectionIfNeeded( 398 setNonDirectionalSelectionIfNeeded(builder.build(), selection().granularity(),
399 createVisibleSelection(builder.build()), selection().granularity(), 399 AdjustEndpointsAtBidiBoundary,
Xiaocheng 2017/03/06 19:04:31 Guess this canonicalization is important and shoul
400 AdjustEndpointsAtBidiBoundary, HandleVisibility::NotVisible); 400 HandleVisibility::NotVisible);
401 } 401 }
402 402
403 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( 403 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(
404 Node* targetNode, 404 Node* targetNode,
405 const VisibleSelectionInFlatTree& selection, 405 const VisibleSelectionInFlatTree& selection,
406 TextGranularity granularity, 406 TextGranularity granularity,
407 HandleVisibility handleVisibility) { 407 HandleVisibility handleVisibility) {
408 if (targetNode && targetNode->layoutObject() && 408 if (targetNode && targetNode->layoutObject() &&
409 !targetNode->layoutObject()->isSelectable()) 409 !targetNode->layoutObject()->isSelectable())
410 return false; 410 return false;
411 411
412 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) 412 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled)
413 return false; 413 return false;
414 414
415 // |dispatchSelectStart()| can change document hosted by |m_frame|. 415 // |dispatchSelectStart()| can change document hosted by |m_frame|.
416 if (!this->selection().isAvailable()) 416 if (!this->selection().isAvailable())
417 return false; 417 return false;
418 418
419 if (!selection.isValidFor(this->selection().document())) 419 if (!selection.isValidFor(this->selection().document()))
420 return false; 420 return false;
421 421
422 if (selection.isRange()) { 422 if (selection.isRange()) {
423 m_selectionState = SelectionState::ExtendedSelection; 423 m_selectionState = SelectionState::ExtendedSelection;
424 } else { 424 } else {
425 granularity = CharacterGranularity; 425 granularity = CharacterGranularity;
426 m_selectionState = SelectionState::PlacedCaret; 426 m_selectionState = SelectionState::PlacedCaret;
427 } 427 }
428 428
429 setNonDirectionalSelectionIfNeeded(selection, granularity, 429 setNonDirectionalSelectionIfNeeded(selection.asSelection(), granularity,
430 DoNotAdjustEndpoints, handleVisibility); 430 DoNotAdjustEndpoints, handleVisibility);
431 431
432 return true; 432 return true;
433 } 433 }
434 434
435 bool SelectionController::selectClosestWordFromHitTestResult( 435 bool SelectionController::selectClosestWordFromHitTestResult(
436 const HitTestResult& result, 436 const HitTestResult& result,
437 AppendTrailingWhitespace appendTrailingWhitespace, 437 AppendTrailingWhitespace appendTrailingWhitespace,
438 SelectInputEventType selectInputEventType) { 438 SelectInputEventType selectInputEventType) {
439 Node* innerNode = result.innerNode(); 439 Node* innerNode = result.innerNode();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 628
629 if (extent.atRightBoundaryOfBidiRun() && 629 if (extent.atRightBoundaryOfBidiRun() &&
630 extent.isEquivalent( 630 extent.isEquivalent(
631 base.rightBoundaryOfBidiRun(extent.bidiLevelOnLeft()))) { 631 base.rightBoundaryOfBidiRun(extent.bidiLevelOnLeft()))) {
632 visibleExtent = createVisiblePosition( 632 visibleExtent = createVisiblePosition(
633 toPositionInFlatTree(extent.positionAtRightBoundaryOfBiDiRun())); 633 toPositionInFlatTree(extent.positionAtRightBoundaryOfBiDiRun()));
634 return; 634 return;
635 } 635 }
636 } 636 }
637 637
638 // TODO(yosin): We should make |setNonDirectionalSelectionIfNeeded()| to take 638 // TODO(yosin): We should take |granularity| and |handleVisibility| from
639 // |SelectionInFlatTree| instead of |VisibleSelectionInFlatTree|. 639 // |newSelection|.
640 void SelectionController::setNonDirectionalSelectionIfNeeded( 640 void SelectionController::setNonDirectionalSelectionIfNeeded(
641 const VisibleSelectionInFlatTree& newSelection, 641 const SelectionInFlatTree& newSelection,
642 TextGranularity granularity, 642 TextGranularity granularity,
643 EndPointsAdjustmentMode endpointsAdjustmentMode, 643 EndPointsAdjustmentMode endpointsAdjustmentMode,
644 HandleVisibility handleVisibility) { 644 HandleVisibility handleVisibility) {
645 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 645 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
646 // needs to be audited. See http://crbug.com/590369 for more details. 646 // needs to be audited. See http://crbug.com/590369 for more details.
647 document().updateStyleAndLayoutIgnorePendingStylesheets(); 647 document().updateStyleAndLayoutIgnorePendingStylesheets();
648 648
649 const PositionInFlatTree& basePosition = 649 const PositionInFlatTree& basePosition =
650 m_originalBaseInFlatTree.deepEquivalent(); 650 m_originalBaseInFlatTree.deepEquivalent();
651 const VisiblePositionInFlatTree& originalBase = 651 const VisiblePositionInFlatTree& originalBase =
652 basePosition.isConnected() ? createVisiblePosition(basePosition) 652 basePosition.isConnected() ? createVisiblePosition(basePosition)
653 : VisiblePositionInFlatTree(); 653 : VisiblePositionInFlatTree();
654 const VisiblePositionInFlatTree& base = 654 const VisiblePositionInFlatTree& base =
655 originalBase.isNotNull() ? originalBase 655 originalBase.isNotNull() ? originalBase
656 : createVisiblePosition(newSelection.base()); 656 : createVisiblePosition(newSelection.base());
657 VisiblePositionInFlatTree newBase = base; 657 VisiblePositionInFlatTree newBase = base;
658 const VisiblePositionInFlatTree& extent = 658 const VisiblePositionInFlatTree& extent =
659 createVisiblePosition(newSelection.extent()); 659 createVisiblePosition(newSelection.extent());
660 VisiblePositionInFlatTree newExtent = extent; 660 VisiblePositionInFlatTree newExtent = extent;
661 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary) 661 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary)
662 adjustEndpointsAtBidiBoundary(newBase, newExtent); 662 adjustEndpointsAtBidiBoundary(newBase, newExtent);
663 663
664 SelectionInFlatTree::Builder builder(newSelection.asSelection()); 664 SelectionInFlatTree::Builder builder(newSelection);
665 if (newBase.deepEquivalent() != base.deepEquivalent() || 665 if (newBase.deepEquivalent() != base.deepEquivalent() ||
666 newExtent.deepEquivalent() != extent.deepEquivalent()) { 666 newExtent.deepEquivalent() != extent.deepEquivalent()) {
667 m_originalBaseInFlatTree = base; 667 m_originalBaseInFlatTree = base;
668 setContext(&document()); 668 setContext(&document());
669 builder.setBaseAndExtent(newBase.deepEquivalent(), 669 builder.setBaseAndExtent(newBase.deepEquivalent(),
670 newExtent.deepEquivalent()); 670 newExtent.deepEquivalent());
671 } else if (originalBase.isNotNull()) { 671 } else if (originalBase.isNotNull()) {
672 if (selection().computeVisibleSelectionInFlatTree().base() == 672 if (selection().computeVisibleSelectionInFlatTree().base() ==
673 newSelection.base()) { 673 newSelection.base()) {
674 builder.setBaseAndExtent(originalBase.deepEquivalent(), 674 builder.setBaseAndExtent(originalBase.deepEquivalent(),
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 1086
1087 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { 1087 bool isExtendingSelection(const MouseEventWithHitTestResults& event) {
1088 bool isMouseDownOnLinkOrImage = 1088 bool isMouseDownOnLinkOrImage =
1089 event.isOverLink() || event.hitTestResult().image(); 1089 event.isOverLink() || event.hitTestResult().image();
1090 return (event.event().modifiers() & WebInputEvent::Modifiers::ShiftKey) != 1090 return (event.event().modifiers() & WebInputEvent::Modifiers::ShiftKey) !=
1091 0 && 1091 0 &&
1092 !isMouseDownOnLinkOrImage; 1092 !isMouseDownOnLinkOrImage;
1093 } 1093 }
1094 1094
1095 } // namespace blink 1095 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698