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