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

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

Issue 2964863003: Refactor SelectionController::SelectClosestWordFromHitTestResult() (Closed)
Patch Set: 2017-07-04T18:47:54 const VisbileSelectionInFlatTree Created 3 years, 5 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 | « no previous file | 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) 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 selection_state_ = SelectionState::kPlacedCaret; 483 selection_state_ = SelectionState::kPlacedCaret;
484 SetNonDirectionalSelectionIfNeeded(selection, kCharacterGranularity, 484 SetNonDirectionalSelectionIfNeeded(selection, kCharacterGranularity,
485 kDoNotAdjustEndpoints, handle_visibility); 485 kDoNotAdjustEndpoints, handle_visibility);
486 return true; 486 return true;
487 } 487 }
488 488
489 bool SelectionController::SelectClosestWordFromHitTestResult( 489 bool SelectionController::SelectClosestWordFromHitTestResult(
490 const HitTestResult& result, 490 const HitTestResult& result,
491 AppendTrailingWhitespace append_trailing_whitespace, 491 AppendTrailingWhitespace append_trailing_whitespace,
492 SelectInputEventType select_input_event_type) { 492 SelectInputEventType select_input_event_type) {
493 Node* inner_node = result.InnerNode(); 493 Node* const inner_node = result.InnerNode();
494 VisibleSelectionInFlatTree new_selection;
495 494
496 if (!inner_node || !inner_node->GetLayoutObject() || 495 if (!inner_node || !inner_node->GetLayoutObject() ||
497 !inner_node->GetLayoutObject()->IsSelectable()) 496 !inner_node->GetLayoutObject()->IsSelectable())
498 return false; 497 return false;
499 498
500 // Special-case image local offset to always be zero, to avoid triggering 499 // Special-case image local offset to always be zero, to avoid triggering
501 // LayoutReplaced::positionFromPoint's advancement of the position at the 500 // LayoutReplaced::positionFromPoint's advancement of the position at the
502 // mid-point of the the image (which was intended for mouse-drag selection 501 // mid-point of the the image (which was intended for mouse-drag selection
503 // and isn't desirable for touch). 502 // and isn't desirable for touch).
504 HitTestResult adjusted_hit_test_result = result; 503 HitTestResult adjusted_hit_test_result = result;
505 if (select_input_event_type == SelectInputEventType::kTouch && 504 if (select_input_event_type == SelectInputEventType::kTouch &&
506 result.GetImage()) 505 result.GetImage())
507 adjusted_hit_test_result.SetNodeAndPosition(result.InnerNode(), 506 adjusted_hit_test_result.SetNodeAndPosition(result.InnerNode(),
508 LayoutPoint(0, 0)); 507 LayoutPoint(0, 0));
509 508
510 const VisiblePositionInFlatTree& pos = 509 const VisiblePositionInFlatTree& pos =
511 VisiblePositionOfHitTestResult(adjusted_hit_test_result); 510 VisiblePositionOfHitTestResult(adjusted_hit_test_result);
512 if (pos.IsNotNull()) { 511 const VisibleSelectionInFlatTree& new_selection =
513 new_selection = 512 pos.IsNotNull()
514 CreateVisibleSelection(SelectionInFlatTree::Builder() 513 ? CreateVisibleSelection(SelectionInFlatTree::Builder()
515 .Collapse(pos.ToPositionWithAffinity()) 514 .Collapse(pos.ToPositionWithAffinity())
516 .SetGranularity(kWordGranularity) 515 .SetGranularity(kWordGranularity)
517 .Build()); 516 .Build())
518 } 517 : VisibleSelectionInFlatTree();
519 518
520 HandleVisibility visibility = HandleVisibility::kNotVisible; 519 HandleVisibility visibility = HandleVisibility::kNotVisible;
521 if (select_input_event_type == SelectInputEventType::kTouch) { 520 if (select_input_event_type == SelectInputEventType::kTouch) {
522 // If node doesn't have text except space, tab or line break, do not 521 // If node doesn't have text except space, tab or line break, do not
523 // select that 'empty' area. 522 // select that 'empty' area.
524 EphemeralRangeInFlatTree range(new_selection.Start(), new_selection.End()); 523 EphemeralRangeInFlatTree range(new_selection.Start(), new_selection.End());
525 const String& str = PlainText( 524 const String& str = PlainText(
526 range, 525 range,
527 TextIteratorBehavior::Builder() 526 TextIteratorBehavior::Builder()
528 .SetEmitsObjectReplacementCharacter(HasEditableStyle(*inner_node)) 527 .SetEmitsObjectReplacementCharacter(HasEditableStyle(*inner_node))
529 .Build()); 528 .Build());
530 if (str.IsEmpty() || str.SimplifyWhiteSpace().ContainsOnlyWhitespace()) 529 if (str.IsEmpty() || str.SimplifyWhiteSpace().ContainsOnlyWhitespace())
531 return false; 530 return false;
532 531
533 if (new_selection.RootEditableElement() && 532 if (new_selection.RootEditableElement() &&
534 pos.DeepEquivalent() == VisiblePositionInFlatTree::LastPositionInNode( 533 pos.DeepEquivalent() == VisiblePositionInFlatTree::LastPositionInNode(
535 *new_selection.RootEditableElement()) 534 *new_selection.RootEditableElement())
536 .DeepEquivalent()) 535 .DeepEquivalent())
537 return false; 536 return false;
538 537
539 visibility = HandleVisibility::kVisible; 538 visibility = HandleVisibility::kVisible;
540 } 539 }
541 540
542 if (append_trailing_whitespace == AppendTrailingWhitespace::kShouldAppend) 541 const VisibleSelectionInFlatTree& adjusted_selection =
543 new_selection = new_selection.AppendTrailingWhitespace(); 542 append_trailing_whitespace == AppendTrailingWhitespace::kShouldAppend
543 ? new_selection.AppendTrailingWhitespace()
544 : new_selection;
544 545
545 return UpdateSelectionForMouseDownDispatchingSelectStart( 546 return UpdateSelectionForMouseDownDispatchingSelectStart(
546 inner_node, 547 inner_node,
547 ExpandSelectionToRespectUserSelectAll(inner_node, new_selection), 548 ExpandSelectionToRespectUserSelectAll(inner_node, adjusted_selection),
548 kWordGranularity, visibility); 549 kWordGranularity, visibility);
549 } 550 }
550 551
551 void SelectionController::SelectClosestMisspellingFromHitTestResult( 552 void SelectionController::SelectClosestMisspellingFromHitTestResult(
552 const HitTestResult& result, 553 const HitTestResult& result,
553 AppendTrailingWhitespace append_trailing_whitespace) { 554 AppendTrailingWhitespace append_trailing_whitespace) {
554 Node* inner_node = result.InnerNode(); 555 Node* inner_node = result.InnerNode();
555 556
556 if (!inner_node || !inner_node->GetLayoutObject()) 557 if (!inner_node || !inner_node->GetLayoutObject())
557 return; 558 return;
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1226
1226 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) { 1227 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) {
1227 bool is_mouse_down_on_link_or_image = 1228 bool is_mouse_down_on_link_or_image =
1228 event.IsOverLink() || event.GetHitTestResult().GetImage(); 1229 event.IsOverLink() || event.GetHitTestResult().GetImage();
1229 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) != 1230 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) !=
1230 0 && 1231 0 &&
1231 !is_mouse_down_on_link_or_image; 1232 !is_mouse_down_on_link_or_image;
1232 } 1233 }
1233 1234
1234 } // namespace blink 1235 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698