| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); | 134 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); |
| 135 Node* innerNode = event.innerNode(); | 135 Node* innerNode = event.innerNode(); |
| 136 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) | 136 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) |
| 137 return false; | 137 return false; |
| 138 | 138 |
| 139 // Extend the selection if the Shift key is down, unless the click is in a | 139 // Extend the selection if the Shift key is down, unless the click is in a |
| 140 // link or image. | 140 // link or image. |
| 141 bool extendSelection = isExtendingSelection(event); | 141 bool extendSelection = isExtendingSelection(event); |
| 142 | 142 |
| 143 // Don't restart the selection when the mouse is pressed on an | |
| 144 // existing selection so we can allow for text dragging. | |
| 145 if (FrameView* view = m_frame->view()) { | |
| 146 LayoutPoint vPoint = view->rootFrameToContents(event.event().position()); | |
| 147 if (!extendSelection && selection().contains(vPoint)) { | |
| 148 m_mouseDownWasSingleClickInSelection = true; | |
| 149 return false; | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 VisiblePositionInFlatTree visiblePos = | 143 VisiblePositionInFlatTree visiblePos = |
| 154 visiblePositionOfHitTestResult(event.hitTestResult()); | 144 visiblePositionOfHitTestResult(event.hitTestResult()); |
| 155 if (visiblePos.isNull()) | 145 if (visiblePos.isNull()) |
| 156 visiblePos = createVisiblePosition( | 146 visiblePos = createVisiblePosition( |
| 157 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)); | 147 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)); |
| 158 PositionInFlatTree pos = visiblePos.deepEquivalent(); | 148 PositionInFlatTree pos = visiblePos.deepEquivalent(); |
| 159 | 149 |
| 160 VisibleSelectionInFlatTree newSelection = | 150 VisibleSelectionInFlatTree newSelection = |
| 161 selection().visibleSelection<EditingInFlatTreeStrategy>(); | 151 selection().visibleSelection<EditingInFlatTreeStrategy>(); |
| 162 TextGranularity granularity = CharacterGranularity; | 152 TextGranularity granularity = CharacterGranularity; |
| 163 | 153 |
| 154 // Don't restart the selection when the mouse is pressed on an |
| 155 // existing selection so we can allow for text dragging. |
| 156 if (!extendSelection && selection().contains(event.hitTestResult())) { |
| 157 m_mouseDownWasSingleClickInSelection = true; |
| 158 if (!event.event().fromTouch()) |
| 159 return false; |
| 160 |
| 161 if (!selection().isHandleVisible()) { |
| 162 updateSelectionForMouseDownDispatchingSelectStart( |
| 163 innerNode, newSelection, granularity, HandleVisibility::Visible); |
| 164 return false; |
| 165 } |
| 166 } |
| 167 |
| 164 if (extendSelection && !newSelection.isNone()) { | 168 if (extendSelection && !newSelection.isNone()) { |
| 165 // Note: "fast/events/shift-click-user-select-none.html" makes | |
| 166 // |pos.isNull()| true. | |
| 167 SelectionInFlatTree::Builder builder; | 169 SelectionInFlatTree::Builder builder; |
| 168 if (pos.isNotNull()) | 170 if (pos.isNotNull()) |
| 169 builder.collapse(pos); | 171 builder.collapse(pos); |
| 170 const VisibleSelectionInFlatTree& selectionInUserSelectAll = | 172 const VisibleSelectionInFlatTree& selectionInUserSelectAll = |
| 171 expandSelectionToRespectUserSelectAll( | 173 expandSelectionToRespectUserSelectAll( |
| 172 innerNode, createVisibleSelection(builder.build())); | 174 innerNode, createVisibleSelection(builder.build())); |
| 173 if (selectionInUserSelectAll.isRange()) { | 175 if (selectionInUserSelectAll.isRange()) { |
| 174 if (selectionInUserSelectAll.start().compareTo(newSelection.start()) < 0) | 176 if (selectionInUserSelectAll.start().compareTo(newSelection.start()) < 0) |
| 175 pos = selectionInUserSelectAll.start(); | 177 pos = selectionInUserSelectAll.start(); |
| 176 else if (newSelection.end().compareTo(selectionInUserSelectAll.end()) < 0) | 178 else if (newSelection.end().compareTo(selectionInUserSelectAll.end()) < 0) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 203 if (visiblePos.isNull()) { | 205 if (visiblePos.isNull()) { |
| 204 newSelection = VisibleSelectionInFlatTree(); | 206 newSelection = VisibleSelectionInFlatTree(); |
| 205 } else { | 207 } else { |
| 206 SelectionInFlatTree::Builder builder; | 208 SelectionInFlatTree::Builder builder; |
| 207 builder.collapse(visiblePos.toPositionWithAffinity()); | 209 builder.collapse(visiblePos.toPositionWithAffinity()); |
| 208 newSelection = expandSelectionToRespectUserSelectAll( | 210 newSelection = expandSelectionToRespectUserSelectAll( |
| 209 innerNode, createVisibleSelection(builder.build())); | 211 innerNode, createVisibleSelection(builder.build())); |
| 210 } | 212 } |
| 211 } | 213 } |
| 212 | 214 |
| 215 bool isHandleVisible = false; |
| 216 if (newSelection.isContentEditable()) { |
| 217 const bool isTextBoxEmpty = |
| 218 createVisibleSelection(SelectionInFlatTree::Builder() |
| 219 .selectAllChildren(*innerNode) |
| 220 .build()) |
| 221 .isCaret(); |
| 222 const bool notLeftClick = event.event().pointerProperties().button != |
| 223 WebPointerProperties::Button::Left; |
| 224 if (!isTextBoxEmpty || notLeftClick) |
| 225 isHandleVisible = event.event().fromTouch(); |
| 226 } |
| 227 |
| 213 // Updating the selection is considered side-effect of the event and so it | 228 // Updating the selection is considered side-effect of the event and so it |
| 214 // doesn't impact the handled state. | 229 // doesn't impact the handled state. |
| 215 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, | 230 updateSelectionForMouseDownDispatchingSelectStart( |
| 216 granularity); | 231 innerNode, newSelection, granularity, isHandleVisible |
| 232 ? HandleVisibility::Visible |
| 233 : HandleVisibility::NotVisible); |
| 217 return false; | 234 return false; |
| 218 } | 235 } |
| 219 | 236 |
| 220 void SelectionController::updateSelectionForMouseDrag( | 237 void SelectionController::updateSelectionForMouseDrag( |
| 221 const HitTestResult& hitTestResult, | 238 const HitTestResult& hitTestResult, |
| 222 Node* mousePressNode, | 239 Node* mousePressNode, |
| 223 const LayoutPoint& dragStartPos, | 240 const LayoutPoint& dragStartPos, |
| 224 const IntPoint& lastKnownMousePosition) { | 241 const IntPoint& lastKnownMousePosition) { |
| 225 if (!m_mouseDownMayStartSelect) | 242 if (!m_mouseDownMayStartSelect) |
| 226 return; | 243 return; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 newSelection.setExtent(targetPosition); | 346 newSelection.setExtent(targetPosition); |
| 330 } | 347 } |
| 331 } else { | 348 } else { |
| 332 newSelection.setExtent(targetPosition); | 349 newSelection.setExtent(targetPosition); |
| 333 } | 350 } |
| 334 | 351 |
| 335 if (selection().granularity() != CharacterGranularity) | 352 if (selection().granularity() != CharacterGranularity) |
| 336 newSelection.expandUsingGranularity(selection().granularity()); | 353 newSelection.expandUsingGranularity(selection().granularity()); |
| 337 | 354 |
| 338 setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(), | 355 setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(), |
| 339 AdjustEndpointsAtBidiBoundary); | 356 AdjustEndpointsAtBidiBoundary, |
| 357 HandleVisibility::NotVisible); |
| 340 } | 358 } |
| 341 | 359 |
| 342 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( | 360 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
| 343 Node* targetNode, | 361 Node* targetNode, |
| 344 const VisibleSelectionInFlatTree& selection, | 362 const VisibleSelectionInFlatTree& selection, |
| 345 TextGranularity granularity) { | 363 TextGranularity granularity, |
| 364 HandleVisibility handleVisibility) { |
| 346 if (targetNode && targetNode->layoutObject() && | 365 if (targetNode && targetNode->layoutObject() && |
| 347 !targetNode->layoutObject()->isSelectable()) | 366 !targetNode->layoutObject()->isSelectable()) |
| 348 return false; | 367 return false; |
| 349 | 368 |
| 350 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) | 369 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) |
| 351 return false; | 370 return false; |
| 352 | 371 |
| 353 // |dispatchSelectStart()| can change document hosted by |m_frame|. | 372 // |dispatchSelectStart()| can change document hosted by |m_frame|. |
| 354 if (!this->selection().isAvailable()) | 373 if (!this->selection().isAvailable()) |
| 355 return false; | 374 return false; |
| 356 | 375 |
| 357 if (!selection.isValidFor(this->selection().document())) | 376 if (!selection.isValidFor(this->selection().document())) |
| 358 return false; | 377 return false; |
| 359 | 378 |
| 360 if (selection.isRange()) { | 379 if (selection.isRange()) { |
| 361 m_selectionState = SelectionState::ExtendedSelection; | 380 m_selectionState = SelectionState::ExtendedSelection; |
| 362 } else { | 381 } else { |
| 363 granularity = CharacterGranularity; | 382 granularity = CharacterGranularity; |
| 364 m_selectionState = SelectionState::PlacedCaret; | 383 m_selectionState = SelectionState::PlacedCaret; |
| 365 } | 384 } |
| 366 | 385 |
| 367 setNonDirectionalSelectionIfNeeded(selection, granularity, | 386 setNonDirectionalSelectionIfNeeded(selection, granularity, |
| 368 DoNotAdjustEndpoints); | 387 DoNotAdjustEndpoints, handleVisibility); |
| 369 | 388 |
| 370 return true; | 389 return true; |
| 371 } | 390 } |
| 372 | 391 |
| 373 void SelectionController::selectClosestWordFromHitTestResult( | 392 void SelectionController::selectClosestWordFromHitTestResult( |
| 374 const HitTestResult& result, | 393 const HitTestResult& result, |
| 375 AppendTrailingWhitespace appendTrailingWhitespace, | 394 AppendTrailingWhitespace appendTrailingWhitespace, |
| 376 SelectInputEventType selectInputEventType) { | 395 SelectInputEventType selectInputEventType) { |
| 377 Node* innerNode = result.innerNode(); | 396 Node* innerNode = result.innerNode(); |
| 378 VisibleSelectionInFlatTree newSelection; | 397 VisibleSelectionInFlatTree newSelection; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 391 | 410 |
| 392 const VisiblePositionInFlatTree& pos = | 411 const VisiblePositionInFlatTree& pos = |
| 393 visiblePositionOfHitTestResult(adjustedHitTestResult); | 412 visiblePositionOfHitTestResult(adjustedHitTestResult); |
| 394 if (pos.isNotNull()) { | 413 if (pos.isNotNull()) { |
| 395 SelectionInFlatTree::Builder builder; | 414 SelectionInFlatTree::Builder builder; |
| 396 builder.collapse(pos.toPositionWithAffinity()); | 415 builder.collapse(pos.toPositionWithAffinity()); |
| 397 newSelection = createVisibleSelection(builder.build()); | 416 newSelection = createVisibleSelection(builder.build()); |
| 398 newSelection.expandUsingGranularity(WordGranularity); | 417 newSelection.expandUsingGranularity(WordGranularity); |
| 399 } | 418 } |
| 400 | 419 |
| 420 HandleVisibility visibility = HandleVisibility::NotVisible; |
| 401 if (selectInputEventType == SelectInputEventType::Touch) { | 421 if (selectInputEventType == SelectInputEventType::Touch) { |
| 402 // If node doesn't have text except space, tab or line break, do not | 422 // If node doesn't have text except space, tab or line break, do not |
| 403 // select that 'empty' area. | 423 // select that 'empty' area. |
| 404 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); | 424 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); |
| 405 const String& str = | 425 const String& str = |
| 406 plainText(range, hasEditableStyle(*innerNode) | 426 plainText(range, hasEditableStyle(*innerNode) |
| 407 ? TextIteratorEmitsObjectReplacementCharacter | 427 ? TextIteratorEmitsObjectReplacementCharacter |
| 408 : TextIteratorDefaultBehavior); | 428 : TextIteratorDefaultBehavior); |
| 409 if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace()) | 429 if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace()) |
| 410 return; | 430 return; |
| 411 | 431 |
| 412 if (newSelection.rootEditableElement() && | 432 if (newSelection.rootEditableElement() && |
| 413 pos.deepEquivalent() == | 433 pos.deepEquivalent() == |
| 414 VisiblePositionInFlatTree::lastPositionInNode( | 434 VisiblePositionInFlatTree::lastPositionInNode( |
| 415 newSelection.rootEditableElement()) | 435 newSelection.rootEditableElement()) |
| 416 .deepEquivalent()) | 436 .deepEquivalent()) |
| 417 return; | 437 return; |
| 438 visibility = HandleVisibility::Visible; |
| 418 } | 439 } |
| 419 | 440 |
| 420 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && | 441 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && |
| 421 newSelection.isRange()) | 442 newSelection.isRange()) |
| 422 newSelection.appendTrailingWhitespace(); | 443 newSelection.appendTrailingWhitespace(); |
| 423 | 444 |
| 424 updateSelectionForMouseDownDispatchingSelectStart( | 445 updateSelectionForMouseDownDispatchingSelectStart( |
| 425 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 446 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 426 WordGranularity); | 447 WordGranularity, visibility); |
| 427 } | 448 } |
| 428 | 449 |
| 429 void SelectionController::selectClosestMisspellingFromHitTestResult( | 450 void SelectionController::selectClosestMisspellingFromHitTestResult( |
| 430 const HitTestResult& result, | 451 const HitTestResult& result, |
| 431 AppendTrailingWhitespace appendTrailingWhitespace) { | 452 AppendTrailingWhitespace appendTrailingWhitespace) { |
| 432 Node* innerNode = result.innerNode(); | 453 Node* innerNode = result.innerNode(); |
| 433 VisibleSelectionInFlatTree newSelection; | 454 VisibleSelectionInFlatTree newSelection; |
| 434 | 455 |
| 435 if (!innerNode || !innerNode->layoutObject()) | 456 if (!innerNode || !innerNode->layoutObject()) |
| 436 return; | 457 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 451 SelectionInFlatTree::Builder().collapse(start).extend(end).build()); | 472 SelectionInFlatTree::Builder().collapse(start).extend(end).build()); |
| 452 } | 473 } |
| 453 } | 474 } |
| 454 | 475 |
| 455 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && | 476 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && |
| 456 newSelection.isRange()) | 477 newSelection.isRange()) |
| 457 newSelection.appendTrailingWhitespace(); | 478 newSelection.appendTrailingWhitespace(); |
| 458 | 479 |
| 459 updateSelectionForMouseDownDispatchingSelectStart( | 480 updateSelectionForMouseDownDispatchingSelectStart( |
| 460 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 481 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 461 WordGranularity); | 482 WordGranularity, HandleVisibility::NotVisible); |
| 462 } | 483 } |
| 463 | 484 |
| 464 void SelectionController::selectClosestWordFromMouseEvent( | 485 void SelectionController::selectClosestWordFromMouseEvent( |
| 465 const MouseEventWithHitTestResults& result) { | 486 const MouseEventWithHitTestResults& result) { |
| 466 if (!m_mouseDownMayStartSelect) | 487 if (!m_mouseDownMayStartSelect) |
| 467 return; | 488 return; |
| 468 | 489 |
| 469 AppendTrailingWhitespace appendTrailingWhitespace = | 490 AppendTrailingWhitespace appendTrailingWhitespace = |
| 470 (result.event().clickCount() == 2 && | 491 (result.event().clickCount() == 2 && |
| 471 m_frame->editor().isSelectTrailingWhitespaceEnabled()) | 492 m_frame->editor().isSelectTrailingWhitespaceEnabled()) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 const VisiblePositionInFlatTree pos = | 529 const VisiblePositionInFlatTree pos = |
| 509 visiblePositionOfHitTestResult(result.hitTestResult()); | 530 visiblePositionOfHitTestResult(result.hitTestResult()); |
| 510 if (pos.isNotNull() && | 531 if (pos.isNotNull() && |
| 511 pos.deepEquivalent().anchorNode()->isDescendantOf(URLElement)) { | 532 pos.deepEquivalent().anchorNode()->isDescendantOf(URLElement)) { |
| 512 newSelection = createVisibleSelection( | 533 newSelection = createVisibleSelection( |
| 513 SelectionInFlatTree::Builder().selectAllChildren(*URLElement).build()); | 534 SelectionInFlatTree::Builder().selectAllChildren(*URLElement).build()); |
| 514 } | 535 } |
| 515 | 536 |
| 516 updateSelectionForMouseDownDispatchingSelectStart( | 537 updateSelectionForMouseDownDispatchingSelectStart( |
| 517 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 538 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 518 WordGranularity); | 539 WordGranularity, HandleVisibility::NotVisible); |
| 519 } | 540 } |
| 520 | 541 |
| 521 bool SelectionController::handleMousePressEventDoubleClick( | 542 bool SelectionController::handleMousePressEventDoubleClick( |
| 522 const MouseEventWithHitTestResults& event) { | 543 const MouseEventWithHitTestResults& event) { |
| 523 TRACE_EVENT0("blink", | 544 TRACE_EVENT0("blink", |
| 524 "SelectionController::handleMousePressEventDoubleClick"); | 545 "SelectionController::handleMousePressEventDoubleClick"); |
| 525 | 546 |
| 526 if (!selection().isAvailable()) | 547 if (!selection().isAvailable()) |
| 527 return false; | 548 return false; |
| 528 | 549 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 VisibleSelectionInFlatTree newSelection; | 591 VisibleSelectionInFlatTree newSelection; |
| 571 const VisiblePositionInFlatTree& pos = | 592 const VisiblePositionInFlatTree& pos = |
| 572 visiblePositionOfHitTestResult(event.hitTestResult()); | 593 visiblePositionOfHitTestResult(event.hitTestResult()); |
| 573 if (pos.isNotNull()) { | 594 if (pos.isNotNull()) { |
| 574 SelectionInFlatTree::Builder builder; | 595 SelectionInFlatTree::Builder builder; |
| 575 builder.collapse(pos.toPositionWithAffinity()); | 596 builder.collapse(pos.toPositionWithAffinity()); |
| 576 newSelection = createVisibleSelection(builder.build()); | 597 newSelection = createVisibleSelection(builder.build()); |
| 577 newSelection.expandUsingGranularity(ParagraphGranularity); | 598 newSelection.expandUsingGranularity(ParagraphGranularity); |
| 578 } | 599 } |
| 579 | 600 |
| 601 bool isHandleVisible = event.event().fromTouch() && newSelection.isRange(); |
| 602 |
| 580 return updateSelectionForMouseDownDispatchingSelectStart( | 603 return updateSelectionForMouseDownDispatchingSelectStart( |
| 581 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 604 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 582 ParagraphGranularity); | 605 ParagraphGranularity, isHandleVisible ? HandleVisibility::Visible |
| 606 : HandleVisibility::NotVisible); |
| 583 } | 607 } |
| 584 | 608 |
| 585 void SelectionController::handleMousePressEvent( | 609 void SelectionController::handleMousePressEvent( |
| 586 const MouseEventWithHitTestResults& event) { | 610 const MouseEventWithHitTestResults& event) { |
| 587 // If we got the event back, that must mean it wasn't prevented, | 611 // If we got the event back, that must mean it wasn't prevented, |
| 588 // so it's allowed to start a drag or selection if it wasn't in a scrollbar. | 612 // so it's allowed to start a drag or selection if it wasn't in a scrollbar. |
| 589 m_mouseDownMayStartSelect = | 613 m_mouseDownMayStartSelect = |
| 590 (canMouseDownStartSelect(event.innerNode()) || isLinkSelection(event)) && | 614 (canMouseDownStartSelect(event.innerNode()) || isLinkSelection(event)) && |
| 591 !event.scrollbar(); | 615 !event.scrollbar(); |
| 592 m_mouseDownWasSingleClickInSelection = false; | 616 m_mouseDownWasSingleClickInSelection = false; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 pos.deepEquivalent().parentAnchoredEquivalent()), | 797 pos.deepEquivalent().parentAnchoredEquivalent()), |
| 774 DocumentMarker::MisspellingMarkers()) | 798 DocumentMarker::MisspellingMarkers()) |
| 775 .size() > 0; | 799 .size() > 0; |
| 776 } | 800 } |
| 777 | 801 |
| 778 void SelectionController::sendContextMenuEvent( | 802 void SelectionController::sendContextMenuEvent( |
| 779 const MouseEventWithHitTestResults& mev, | 803 const MouseEventWithHitTestResults& mev, |
| 780 const LayoutPoint& position) { | 804 const LayoutPoint& position) { |
| 781 if (!selection().isAvailable()) | 805 if (!selection().isAvailable()) |
| 782 return; | 806 return; |
| 783 if (selection().contains(position) || mev.scrollbar() || | 807 if (selection().contains(mev.hitTestResult()) || mev.scrollbar() || |
| 784 // FIXME: In the editable case, word selection sometimes selects content | 808 // FIXME: In the editable case, word selection sometimes selects content |
| 785 // that isn't underneath the mouse. | 809 // that isn't underneath the mouse. |
| 786 // If the selection is non-editable, we do word selection to make it | 810 // If the selection is non-editable, we do word selection to make it |
| 787 // easier to use the contextual menu items available for text selections. | 811 // easier to use the contextual menu items available for text selections. |
| 788 // But only if we're above text. | 812 // But only if we're above text. |
| 789 !(selection().isContentEditable() || | 813 !(selection().isContentEditable() || |
| 790 (mev.innerNode() && mev.innerNode()->isTextNode()))) | 814 (mev.innerNode() && mev.innerNode()->isTextNode()))) |
| 791 return; | 815 return; |
| 792 | 816 |
| 793 // Context menu events are always allowed to perform a selection. | 817 // Context menu events are always allowed to perform a selection. |
| 794 AutoReset<bool> mouseDownMayStartSelectChange(&m_mouseDownMayStartSelect, | 818 AutoReset<bool> mouseDownMayStartSelectChange(&m_mouseDownMayStartSelect, |
| 795 true); | 819 true); |
| 796 | 820 |
| 797 if (hitTestResultIsMisspelled(mev.hitTestResult())) | 821 if (hitTestResultIsMisspelled(mev.hitTestResult())) |
| 798 return selectClosestMisspellingFromMouseEvent(mev); | 822 return selectClosestMisspellingFromMouseEvent(mev); |
| 799 | 823 |
| 800 if (!m_frame->editor().behavior().shouldSelectOnContextualMenuClick()) | 824 if (!m_frame->editor().behavior().shouldSelectOnContextualMenuClick()) |
| 801 return; | 825 return; |
| 802 | 826 |
| 803 selectClosestWordOrLinkFromMouseEvent(mev); | 827 selectClosestWordOrLinkFromMouseEvent(mev); |
| 804 } | 828 } |
| 805 | 829 |
| 806 void SelectionController::passMousePressEventToSubframe( | 830 void SelectionController::passMousePressEventToSubframe( |
| 807 const MouseEventWithHitTestResults& mev) { | 831 const MouseEventWithHitTestResults& mev) { |
| 808 // If we're clicking into a frame that is selected, the frame will appear | 832 // If we're clicking into a frame that is selected, the frame will appear |
| 809 // greyed out even though we're clicking on the selection. This looks | 833 // greyed out even though we're clicking on the selection. This looks |
| 810 // really strange (having the whole frame be greyed out), so we deselect the | 834 // really strange (having the whole frame be greyed out), so we deselect the |
| 811 // selection. | 835 // selection. |
| 812 IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position()); | 836 if (!selection().contains(mev.hitTestResult())) |
| 813 if (!selection().contains(p)) | |
| 814 return; | 837 return; |
| 815 | 838 |
| 816 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 839 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 817 // needs to be audited. See http://crbug.com/590369 for more details. | 840 // needs to be audited. See http://crbug.com/590369 for more details. |
| 818 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 841 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 819 | 842 |
| 820 const VisiblePositionInFlatTree& visiblePos = | 843 const VisiblePositionInFlatTree& visiblePos = |
| 821 visiblePositionOfHitTestResult(mev.hitTestResult()); | 844 visiblePositionOfHitTestResult(mev.hitTestResult()); |
| 822 if (visiblePos.isNull()) { | 845 if (visiblePos.isNull()) { |
| 823 selection().setSelection(VisibleSelectionInFlatTree()); | 846 selection().setSelection(VisibleSelectionInFlatTree()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 return event.event().altKey() && event.isOverLink(); | 884 return event.event().altKey() && event.isOverLink(); |
| 862 } | 885 } |
| 863 | 886 |
| 864 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { | 887 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 865 bool isMouseDownOnLinkOrImage = | 888 bool isMouseDownOnLinkOrImage = |
| 866 event.isOverLink() || event.hitTestResult().image(); | 889 event.isOverLink() || event.hitTestResult().image(); |
| 867 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; | 890 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; |
| 868 } | 891 } |
| 869 | 892 |
| 870 } // namespace blink | 893 } // namespace blink |
| OLD | NEW |