Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 SetNonDirectionalSelectionIfNeeded(selection, granularity, | 472 SetNonDirectionalSelectionIfNeeded(selection, granularity, |
| 473 kDoNotAdjustEndpoints, handle_visibility); | 473 kDoNotAdjustEndpoints, handle_visibility); |
| 474 | 474 |
| 475 return true; | 475 return true; |
| 476 } | 476 } |
| 477 | 477 |
| 478 bool SelectionController::SelectClosestWordFromHitTestResult( | 478 bool SelectionController::SelectClosestWordFromHitTestResult( |
| 479 const HitTestResult& result, | 479 const HitTestResult& result, |
| 480 AppendTrailingWhitespace append_trailing_whitespace, | 480 AppendTrailingWhitespace append_trailing_whitespace, |
| 481 SelectInputEventType select_input_event_type) { | 481 SelectInputEventType select_input_event_type) { |
| 482 Node* inner_node = result.InnerNode(); | 482 Node* const inner_node = result.InnerNode(); |
| 483 VisibleSelectionInFlatTree new_selection; | |
| 484 | 483 |
| 485 if (!inner_node || !inner_node->GetLayoutObject() || | 484 if (!inner_node || !inner_node->GetLayoutObject() || |
| 486 !inner_node->GetLayoutObject()->IsSelectable()) | 485 !inner_node->GetLayoutObject()->IsSelectable()) |
| 487 return false; | 486 return false; |
| 488 | 487 |
| 489 // Special-case image local offset to always be zero, to avoid triggering | 488 // Special-case image local offset to always be zero, to avoid triggering |
| 490 // LayoutReplaced::positionFromPoint's advancement of the position at the | 489 // LayoutReplaced::positionFromPoint's advancement of the position at the |
| 491 // mid-point of the the image (which was intended for mouse-drag selection | 490 // mid-point of the the image (which was intended for mouse-drag selection |
| 492 // and isn't desirable for touch). | 491 // and isn't desirable for touch). |
| 493 HitTestResult adjusted_hit_test_result = result; | 492 HitTestResult adjusted_hit_test_result = result; |
| 494 if (select_input_event_type == SelectInputEventType::kTouch && | 493 if (select_input_event_type == SelectInputEventType::kTouch && |
| 495 result.GetImage()) | 494 result.GetImage()) |
| 496 adjusted_hit_test_result.SetNodeAndPosition(result.InnerNode(), | 495 adjusted_hit_test_result.SetNodeAndPosition(result.InnerNode(), |
| 497 LayoutPoint(0, 0)); | 496 LayoutPoint(0, 0)); |
| 498 | 497 |
| 499 const VisiblePositionInFlatTree& pos = | 498 const VisiblePositionInFlatTree& pos = |
| 500 VisiblePositionOfHitTestResult(adjusted_hit_test_result); | 499 VisiblePositionOfHitTestResult(adjusted_hit_test_result); |
| 501 if (pos.IsNotNull()) { | 500 VisibleSelectionInFlatTree new_selection = |
| 502 new_selection = | 501 pos.IsNotNull() |
| 503 CreateVisibleSelection(SelectionInFlatTree::Builder() | 502 ? CreateVisibleSelection(SelectionInFlatTree::Builder() |
| 504 .Collapse(pos.ToPositionWithAffinity()) | 503 .Collapse(pos.ToPositionWithAffinity()) |
| 505 .SetGranularity(kWordGranularity) | 504 .SetGranularity(kWordGranularity) |
| 506 .Build()); | 505 .Build()) |
| 507 } | 506 : VisibleSelectionInFlatTree(); |
| 508 | 507 |
| 509 HandleVisibility visibility = HandleVisibility::kNotVisible; | 508 HandleVisibility visibility = HandleVisibility::kNotVisible; |
| 510 if (select_input_event_type == SelectInputEventType::kTouch) { | 509 if (select_input_event_type == SelectInputEventType::kTouch) { |
| 511 // If node doesn't have text except space, tab or line break, do not | 510 // If node doesn't have text except space, tab or line break, do not |
| 512 // select that 'empty' area. | 511 // select that 'empty' area. |
| 513 EphemeralRangeInFlatTree range(new_selection.Start(), new_selection.End()); | 512 EphemeralRangeInFlatTree range(new_selection.Start(), new_selection.End()); |
| 514 const String& str = PlainText( | 513 const String& str = PlainText( |
| 515 range, | 514 range, |
| 516 TextIteratorBehavior::Builder() | 515 TextIteratorBehavior::Builder() |
| 517 .SetEmitsObjectReplacementCharacter(HasEditableStyle(*inner_node)) | 516 .SetEmitsObjectReplacementCharacter(HasEditableStyle(*inner_node)) |
| 518 .Build()); | 517 .Build()); |
| 519 if (str.IsEmpty() || str.SimplifyWhiteSpace().ContainsOnlyWhitespace()) | 518 if (str.IsEmpty() || str.SimplifyWhiteSpace().ContainsOnlyWhitespace()) |
| 520 return false; | 519 return false; |
| 521 | 520 |
| 522 if (new_selection.RootEditableElement() && | 521 if (new_selection.RootEditableElement() && |
| 523 pos.DeepEquivalent() == VisiblePositionInFlatTree::LastPositionInNode( | 522 pos.DeepEquivalent() == VisiblePositionInFlatTree::LastPositionInNode( |
| 524 *new_selection.RootEditableElement()) | 523 *new_selection.RootEditableElement()) |
| 525 .DeepEquivalent()) | 524 .DeepEquivalent()) |
| 526 return false; | 525 return false; |
| 527 | 526 |
| 528 visibility = HandleVisibility::kVisible; | 527 visibility = HandleVisibility::kVisible; |
| 529 } | 528 } |
| 530 | 529 |
| 531 if (append_trailing_whitespace == AppendTrailingWhitespace::kShouldAppend) | 530 if (append_trailing_whitespace == AppendTrailingWhitespace::kShouldAppend) |
| 532 new_selection.AppendTrailingWhitespace(); | 531 new_selection.AppendTrailingWhitespace(); |
|
yoichio
2017/07/04 05:32:18
How about making AppendTrailingWhitespace() const
| |
| 533 | 532 |
| 534 return UpdateSelectionForMouseDownDispatchingSelectStart( | 533 return UpdateSelectionForMouseDownDispatchingSelectStart( |
| 535 inner_node, | 534 inner_node, |
| 536 ExpandSelectionToRespectUserSelectAll(inner_node, new_selection), | 535 ExpandSelectionToRespectUserSelectAll(inner_node, new_selection), |
| 537 kWordGranularity, visibility); | 536 kWordGranularity, visibility); |
| 538 } | 537 } |
| 539 | 538 |
| 540 void SelectionController::SelectClosestMisspellingFromHitTestResult( | 539 void SelectionController::SelectClosestMisspellingFromHitTestResult( |
| 541 const HitTestResult& result, | 540 const HitTestResult& result, |
| 542 AppendTrailingWhitespace append_trailing_whitespace) { | 541 AppendTrailingWhitespace append_trailing_whitespace) { |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 | 1212 |
| 1214 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) { | 1213 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 1215 bool is_mouse_down_on_link_or_image = | 1214 bool is_mouse_down_on_link_or_image = |
| 1216 event.IsOverLink() || event.GetHitTestResult().GetImage(); | 1215 event.IsOverLink() || event.GetHitTestResult().GetImage(); |
| 1217 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) != | 1216 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) != |
| 1218 0 && | 1217 0 && |
| 1219 !is_mouse_down_on_link_or_image; | 1218 !is_mouse_down_on_link_or_image; |
| 1220 } | 1219 } |
| 1221 | 1220 |
| 1222 } // namespace blink | 1221 } // namespace blink |
| OLD | NEW |