| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 newSelection = createVisibleSelection( | 189 newSelection = createVisibleSelection( |
| 190 SelectionInFlatTree::Builder() | 190 SelectionInFlatTree::Builder() |
| 191 .collapse(distanceToStart <= distanceToEnd ? end : start) | 191 .collapse(distanceToStart <= distanceToEnd ? end : start) |
| 192 .extend(pos) | 192 .extend(pos) |
| 193 .build()); | 193 .build()); |
| 194 } | 194 } |
| 195 } else { | 195 } else { |
| 196 newSelection.setExtent(pos); | 196 newSelection.setExtent(pos); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // TODO(yosin): We should have |newBase| and |newExtent| instead of |
| 200 // |newSelection|. |
| 199 if (selection().granularity() != CharacterGranularity) { | 201 if (selection().granularity() != CharacterGranularity) { |
| 200 granularity = selection().granularity(); | 202 granularity = selection().granularity(); |
| 201 newSelection.expandUsingGranularity(selection().granularity()); | 203 newSelection = createVisibleSelection( |
| 204 SelectionInFlatTree::Builder() |
| 205 .setBaseAndExtent(newSelection.base(), newSelection.extent()) |
| 206 .setGranularity(granularity) |
| 207 .build()); |
| 202 } | 208 } |
| 203 } else if (m_selectionState != SelectionState::ExtendedSelection) { | 209 } else if (m_selectionState != SelectionState::ExtendedSelection) { |
| 204 if (visiblePos.isNull()) { | 210 if (visiblePos.isNull()) { |
| 205 newSelection = VisibleSelectionInFlatTree(); | 211 newSelection = VisibleSelectionInFlatTree(); |
| 206 } else { | 212 } else { |
| 207 SelectionInFlatTree::Builder builder; | 213 SelectionInFlatTree::Builder builder; |
| 208 builder.collapse(visiblePos.toPositionWithAffinity()); | 214 builder.collapse(visiblePos.toPositionWithAffinity()); |
| 209 newSelection = expandSelectionToRespectUserSelectAll( | 215 newSelection = expandSelectionToRespectUserSelectAll( |
| 210 innerNode, createVisibleSelection(builder.build())); | 216 innerNode, createVisibleSelection(builder.build())); |
| 211 } | 217 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 newSelection.setExtent(mostForwardCaretPosition( | 332 newSelection.setExtent(mostForwardCaretPosition( |
| 327 PositionInFlatTree::afterNode(rootUserSelectAllForTarget), | 333 PositionInFlatTree::afterNode(rootUserSelectAllForTarget), |
| 328 CanCrossEditingBoundary)); | 334 CanCrossEditingBoundary)); |
| 329 else | 335 else |
| 330 newSelection.setExtent(targetPosition); | 336 newSelection.setExtent(targetPosition); |
| 331 } | 337 } |
| 332 } else { | 338 } else { |
| 333 newSelection.setExtent(targetPosition); | 339 newSelection.setExtent(targetPosition); |
| 334 } | 340 } |
| 335 | 341 |
| 336 if (selection().granularity() != CharacterGranularity) | 342 // TODO(yosin): We should have |newBase| and |newExtent| instead of |
| 337 newSelection.expandUsingGranularity(selection().granularity()); | 343 // |newSelection|. |
| 344 if (selection().granularity() != CharacterGranularity) { |
| 345 newSelection = createVisibleSelection( |
| 346 SelectionInFlatTree::Builder() |
| 347 .setBaseAndExtent(newSelection.base(), newSelection.extent()) |
| 348 .setGranularity(selection().granularity()) |
| 349 .build()); |
| 350 } |
| 338 | 351 |
| 339 setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(), | 352 setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(), |
| 340 AdjustEndpointsAtBidiBoundary); | 353 AdjustEndpointsAtBidiBoundary); |
| 341 } | 354 } |
| 342 | 355 |
| 343 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( | 356 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
| 344 Node* targetNode, | 357 Node* targetNode, |
| 345 const VisibleSelectionInFlatTree& selection, | 358 const VisibleSelectionInFlatTree& selection, |
| 346 TextGranularity granularity) { | 359 TextGranularity granularity) { |
| 347 if (targetNode && targetNode->layoutObject() && | 360 if (targetNode && targetNode->layoutObject() && |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 // mid-point of the the image (which was intended for mouse-drag selection | 399 // mid-point of the the image (which was intended for mouse-drag selection |
| 387 // and isn't desirable for touch). | 400 // and isn't desirable for touch). |
| 388 HitTestResult adjustedHitTestResult = result; | 401 HitTestResult adjustedHitTestResult = result; |
| 389 if (selectInputEventType == SelectInputEventType::Touch && result.image()) | 402 if (selectInputEventType == SelectInputEventType::Touch && result.image()) |
| 390 adjustedHitTestResult.setNodeAndPosition(result.innerNode(), | 403 adjustedHitTestResult.setNodeAndPosition(result.innerNode(), |
| 391 LayoutPoint(0, 0)); | 404 LayoutPoint(0, 0)); |
| 392 | 405 |
| 393 const VisiblePositionInFlatTree& pos = | 406 const VisiblePositionInFlatTree& pos = |
| 394 visiblePositionOfHitTestResult(adjustedHitTestResult); | 407 visiblePositionOfHitTestResult(adjustedHitTestResult); |
| 395 if (pos.isNotNull()) { | 408 if (pos.isNotNull()) { |
| 396 SelectionInFlatTree::Builder builder; | 409 newSelection = |
| 397 builder.collapse(pos.toPositionWithAffinity()); | 410 createVisibleSelection(SelectionInFlatTree::Builder() |
| 398 newSelection = createVisibleSelection(builder.build()); | 411 .collapse(pos.toPositionWithAffinity()) |
| 399 newSelection.expandUsingGranularity(WordGranularity); | 412 .setGranularity(WordGranularity) |
| 413 .build()); |
| 400 } | 414 } |
| 401 | 415 |
| 402 if (selectInputEventType == SelectInputEventType::Touch) { | 416 if (selectInputEventType == SelectInputEventType::Touch) { |
| 403 // If node doesn't have text except space, tab or line break, do not | 417 // If node doesn't have text except space, tab or line break, do not |
| 404 // select that 'empty' area. | 418 // select that 'empty' area. |
| 405 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); | 419 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); |
| 406 const String& str = | 420 const String& str = |
| 407 plainText(range, hasEditableStyle(*innerNode) | 421 plainText(range, hasEditableStyle(*innerNode) |
| 408 ? TextIteratorEmitsObjectReplacementCharacter | 422 ? TextIteratorEmitsObjectReplacementCharacter |
| 409 : TextIteratorDefaultBehavior); | 423 : TextIteratorDefaultBehavior); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 return false; | 682 return false; |
| 669 | 683 |
| 670 Node* innerNode = event.innerNode(); | 684 Node* innerNode = event.innerNode(); |
| 671 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) | 685 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) |
| 672 return false; | 686 return false; |
| 673 | 687 |
| 674 VisibleSelectionInFlatTree newSelection; | 688 VisibleSelectionInFlatTree newSelection; |
| 675 const VisiblePositionInFlatTree& pos = | 689 const VisiblePositionInFlatTree& pos = |
| 676 visiblePositionOfHitTestResult(event.hitTestResult()); | 690 visiblePositionOfHitTestResult(event.hitTestResult()); |
| 677 if (pos.isNotNull()) { | 691 if (pos.isNotNull()) { |
| 678 SelectionInFlatTree::Builder builder; | 692 newSelection = |
| 679 builder.collapse(pos.toPositionWithAffinity()); | 693 createVisibleSelection(SelectionInFlatTree::Builder() |
| 680 newSelection = createVisibleSelection(builder.build()); | 694 .collapse(pos.toPositionWithAffinity()) |
| 681 newSelection.expandUsingGranularity(ParagraphGranularity); | 695 .setGranularity(ParagraphGranularity) |
| 696 .build()); |
| 682 } | 697 } |
| 683 | 698 |
| 684 return updateSelectionForMouseDownDispatchingSelectStart( | 699 return updateSelectionForMouseDownDispatchingSelectStart( |
| 685 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 700 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 686 ParagraphGranularity); | 701 ParagraphGranularity); |
| 687 } | 702 } |
| 688 | 703 |
| 689 void SelectionController::handleMousePressEvent( | 704 void SelectionController::handleMousePressEvent( |
| 690 const MouseEventWithHitTestResults& event) { | 705 const MouseEventWithHitTestResults& event) { |
| 691 // If we got the event back, that must mean it wasn't prevented, | 706 // If we got the event back, that must mean it wasn't prevented, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 return event.event().altKey() && event.isOverLink(); | 981 return event.event().altKey() && event.isOverLink(); |
| 967 } | 982 } |
| 968 | 983 |
| 969 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { | 984 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 970 bool isMouseDownOnLinkOrImage = | 985 bool isMouseDownOnLinkOrImage = |
| 971 event.isOverLink() || event.hitTestResult().image(); | 986 event.isOverLink() || event.hitTestResult().image(); |
| 972 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; | 987 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; |
| 973 } | 988 } |
| 974 | 989 |
| 975 } // namespace blink | 990 } // namespace blink |
| OLD | NEW |