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 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 25 matching lines...) Expand all Loading... | |
| 199 if (visiblePos.isNull()) { | 201 if (visiblePos.isNull()) { |
| 200 newSelection = VisibleSelectionInFlatTree(); | 202 newSelection = VisibleSelectionInFlatTree(); |
| 201 } else { | 203 } else { |
| 202 SelectionInFlatTree::Builder builder; | 204 SelectionInFlatTree::Builder builder; |
| 203 builder.collapse(visiblePos.toPositionWithAffinity()); | 205 builder.collapse(visiblePos.toPositionWithAffinity()); |
| 204 newSelection = expandSelectionToRespectUserSelectAll( | 206 newSelection = expandSelectionToRespectUserSelectAll( |
| 205 innerNode, createVisibleSelection(builder.build())); | 207 innerNode, createVisibleSelection(builder.build())); |
| 206 } | 208 } |
| 207 } | 209 } |
| 208 | 210 |
| 211 bool isHandleVisible = false; | |
| 212 if (newSelection.isContentEditable()) { | |
| 213 bool isTextBoxEmpty = | |
| 214 VisibleSelection::selectionFromContentsOfNode(innerNode).isCaret(); | |
|
yosin_UTC9
2016/10/19 06:33:05
nit: VisibleSelection::selectionFromContentsOfNode
amaralp
2016/10/21 03:47:18
Done.
| |
| 215 bool notLeftClick = event.event().pointerProperties().button != | |
|
yosin_UTC9
2016/10/19 06:33:05
nit: s/bool/const bool/
amaralp
2016/10/21 03:47:18
Done.
| |
| 216 WebPointerProperties::Button::Left; | |
| 217 if (!isTextBoxEmpty || notLeftClick) | |
| 218 isHandleVisible = event.event().fromTouch(); | |
| 219 } | |
| 220 | |
| 209 // Updating the selection is considered side-effect of the event and so it | 221 // Updating the selection is considered side-effect of the event and so it |
| 210 // doesn't impact the handled state. | 222 // doesn't impact the handled state. |
| 211 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, | 223 updateSelectionForMouseDownDispatchingSelectStart( |
| 212 granularity); | 224 innerNode, newSelection, granularity, isHandleVisible |
| 225 ? HandleVisibility::Visible | |
| 226 : HandleVisibility::NotVisible); | |
| 213 return false; | 227 return false; |
| 214 } | 228 } |
| 215 | 229 |
| 216 void SelectionController::updateSelectionForMouseDrag( | 230 void SelectionController::updateSelectionForMouseDrag( |
| 217 const HitTestResult& hitTestResult, | 231 const HitTestResult& hitTestResult, |
| 218 Node* mousePressNode, | 232 Node* mousePressNode, |
| 219 const LayoutPoint& dragStartPos, | 233 const LayoutPoint& dragStartPos, |
| 220 const IntPoint& lastKnownMousePosition) { | 234 const IntPoint& lastKnownMousePosition) { |
| 221 if (!m_mouseDownMayStartSelect) | 235 if (!m_mouseDownMayStartSelect) |
| 222 return; | 236 return; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 newSelection.expandUsingGranularity(selection().granularity()); | 346 newSelection.expandUsingGranularity(selection().granularity()); |
| 333 | 347 |
| 334 selection().setNonDirectionalSelectionIfNeeded( | 348 selection().setNonDirectionalSelectionIfNeeded( |
| 335 newSelection, selection().granularity(), | 349 newSelection, selection().granularity(), |
| 336 FrameSelection::AdjustEndpointsAtBidiBoundary); | 350 FrameSelection::AdjustEndpointsAtBidiBoundary); |
| 337 } | 351 } |
| 338 | 352 |
| 339 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( | 353 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
| 340 Node* targetNode, | 354 Node* targetNode, |
| 341 const VisibleSelectionInFlatTree& selection, | 355 const VisibleSelectionInFlatTree& selection, |
| 342 TextGranularity granularity) { | 356 TextGranularity granularity, |
| 357 HandleVisibility visibility) { | |
| 343 if (targetNode && targetNode->layoutObject() && | 358 if (targetNode && targetNode->layoutObject() && |
| 344 !targetNode->layoutObject()->isSelectable()) | 359 !targetNode->layoutObject()->isSelectable()) |
| 345 return false; | 360 return false; |
| 346 | 361 |
| 347 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) | 362 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) |
| 348 return false; | 363 return false; |
| 349 | 364 |
| 350 // |dispatchSelectStart()| can change document hosted by |m_frame|. | 365 // |dispatchSelectStart()| can change document hosted by |m_frame|. |
| 351 if (!this->selection().isAvailable()) | 366 if (!this->selection().isAvailable()) |
| 352 return false; | 367 return false; |
| 353 | 368 |
| 354 if (!selection.isValidFor(this->selection().document())) | 369 if (!selection.isValidFor(this->selection().document())) |
| 355 return false; | 370 return false; |
| 356 | 371 |
| 357 if (selection.isRange()) { | 372 if (selection.isRange()) { |
| 358 m_selectionState = SelectionState::ExtendedSelection; | 373 m_selectionState = SelectionState::ExtendedSelection; |
| 359 } else { | 374 } else { |
| 360 granularity = CharacterGranularity; | 375 granularity = CharacterGranularity; |
| 361 m_selectionState = SelectionState::PlacedCaret; | 376 m_selectionState = SelectionState::PlacedCaret; |
| 362 } | 377 } |
| 363 | 378 |
| 364 this->selection().setNonDirectionalSelectionIfNeeded(selection, granularity); | 379 this->selection().setNonDirectionalSelectionIfNeeded( |
| 380 selection, granularity, FrameSelection::DoNotAdjustEndpoints, visibility); | |
| 365 | 381 |
| 366 return true; | 382 return true; |
| 367 } | 383 } |
| 368 | 384 |
| 369 void SelectionController::selectClosestWordFromHitTestResult( | 385 void SelectionController::selectClosestWordFromHitTestResult( |
| 370 const HitTestResult& result, | 386 const HitTestResult& result, |
| 371 AppendTrailingWhitespace appendTrailingWhitespace, | 387 AppendTrailingWhitespace appendTrailingWhitespace, |
| 372 SelectInputEventType selectInputEventType) { | 388 SelectInputEventType selectInputEventType) { |
| 373 Node* innerNode = result.innerNode(); | 389 Node* innerNode = result.innerNode(); |
| 374 VisibleSelectionInFlatTree newSelection; | 390 VisibleSelectionInFlatTree newSelection; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 387 | 403 |
| 388 const VisiblePositionInFlatTree& pos = | 404 const VisiblePositionInFlatTree& pos = |
| 389 visiblePositionOfHitTestResult(adjustedHitTestResult); | 405 visiblePositionOfHitTestResult(adjustedHitTestResult); |
| 390 if (pos.isNotNull()) { | 406 if (pos.isNotNull()) { |
| 391 SelectionInFlatTree::Builder builder; | 407 SelectionInFlatTree::Builder builder; |
| 392 builder.collapse(pos.toPositionWithAffinity()); | 408 builder.collapse(pos.toPositionWithAffinity()); |
| 393 newSelection = createVisibleSelection(builder.build()); | 409 newSelection = createVisibleSelection(builder.build()); |
| 394 newSelection.expandUsingGranularity(WordGranularity); | 410 newSelection.expandUsingGranularity(WordGranularity); |
| 395 } | 411 } |
| 396 | 412 |
| 413 HandleVisibility visibility = HandleVisibility::NotVisible; | |
|
yosin_UTC9
2016/10/19 06:33:05
Better to use |handleVisibility|, name |visibility
amaralp
2016/10/21 03:47:18
Done.
| |
| 397 if (selectInputEventType == SelectInputEventType::Touch) { | 414 if (selectInputEventType == SelectInputEventType::Touch) { |
| 398 // If node doesn't have text except space, tab or line break, do not | 415 // If node doesn't have text except space, tab or line break, do not |
| 399 // select that 'empty' area. | 416 // select that 'empty' area. |
| 400 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); | 417 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); |
| 401 const String& str = | 418 const String& str = |
| 402 plainText(range, hasEditableStyle(*innerNode) | 419 plainText(range, hasEditableStyle(*innerNode) |
| 403 ? TextIteratorEmitsObjectReplacementCharacter | 420 ? TextIteratorEmitsObjectReplacementCharacter |
| 404 : TextIteratorDefaultBehavior); | 421 : TextIteratorDefaultBehavior); |
| 405 if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace()) | 422 if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace()) |
| 406 return; | 423 return; |
| 407 | 424 |
| 408 if (newSelection.rootEditableElement() && | 425 if (newSelection.rootEditableElement() && |
| 409 pos.deepEquivalent() == | 426 pos.deepEquivalent() == |
| 410 VisiblePositionInFlatTree::lastPositionInNode( | 427 VisiblePositionInFlatTree::lastPositionInNode( |
| 411 newSelection.rootEditableElement()) | 428 newSelection.rootEditableElement()) |
| 412 .deepEquivalent()) | 429 .deepEquivalent()) |
| 413 return; | 430 return; |
| 431 visibility = HandleVisibility::Visible; | |
| 414 } | 432 } |
| 415 | 433 |
| 416 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && | 434 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && |
| 417 newSelection.isRange()) | 435 newSelection.isRange()) |
| 418 newSelection.appendTrailingWhitespace(); | 436 newSelection.appendTrailingWhitespace(); |
| 419 | 437 |
| 420 updateSelectionForMouseDownDispatchingSelectStart( | 438 updateSelectionForMouseDownDispatchingSelectStart( |
| 421 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 439 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 422 WordGranularity); | 440 WordGranularity, visibility); |
| 423 } | 441 } |
| 424 | 442 |
| 425 void SelectionController::selectClosestMisspellingFromHitTestResult( | 443 void SelectionController::selectClosestMisspellingFromHitTestResult( |
| 426 const HitTestResult& result, | 444 const HitTestResult& result, |
| 427 AppendTrailingWhitespace appendTrailingWhitespace) { | 445 AppendTrailingWhitespace appendTrailingWhitespace) { |
| 428 Node* innerNode = result.innerNode(); | 446 Node* innerNode = result.innerNode(); |
| 429 VisibleSelectionInFlatTree newSelection; | 447 VisibleSelectionInFlatTree newSelection; |
| 430 | 448 |
| 431 if (!innerNode || !innerNode->layoutObject()) | 449 if (!innerNode || !innerNode->layoutObject()) |
| 432 return; | 450 return; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 446 newSelection = createVisibleSelection(start, end); | 464 newSelection = createVisibleSelection(start, end); |
| 447 } | 465 } |
| 448 } | 466 } |
| 449 | 467 |
| 450 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && | 468 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && |
| 451 newSelection.isRange()) | 469 newSelection.isRange()) |
| 452 newSelection.appendTrailingWhitespace(); | 470 newSelection.appendTrailingWhitespace(); |
| 453 | 471 |
| 454 updateSelectionForMouseDownDispatchingSelectStart( | 472 updateSelectionForMouseDownDispatchingSelectStart( |
| 455 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 473 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 456 WordGranularity); | 474 WordGranularity, HandleVisibility::NotVisible); |
| 457 } | 475 } |
| 458 | 476 |
| 459 void SelectionController::selectClosestWordFromMouseEvent( | 477 void SelectionController::selectClosestWordFromMouseEvent( |
| 460 const MouseEventWithHitTestResults& result) { | 478 const MouseEventWithHitTestResults& result) { |
| 461 if (!m_mouseDownMayStartSelect) | 479 if (!m_mouseDownMayStartSelect) |
| 462 return; | 480 return; |
| 463 | 481 |
| 464 AppendTrailingWhitespace appendTrailingWhitespace = | 482 AppendTrailingWhitespace appendTrailingWhitespace = |
| 465 (result.event().clickCount() == 2 && | 483 (result.event().clickCount() == 2 && |
| 466 m_frame->editor().isSelectTrailingWhitespaceEnabled()) | 484 m_frame->editor().isSelectTrailingWhitespaceEnabled()) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 Element* URLElement = result.hitTestResult().URLElement(); | 520 Element* URLElement = result.hitTestResult().URLElement(); |
| 503 const VisiblePositionInFlatTree pos = | 521 const VisiblePositionInFlatTree pos = |
| 504 visiblePositionOfHitTestResult(result.hitTestResult()); | 522 visiblePositionOfHitTestResult(result.hitTestResult()); |
| 505 if (pos.isNotNull() && | 523 if (pos.isNotNull() && |
| 506 pos.deepEquivalent().anchorNode()->isDescendantOf(URLElement)) | 524 pos.deepEquivalent().anchorNode()->isDescendantOf(URLElement)) |
| 507 newSelection = | 525 newSelection = |
| 508 VisibleSelectionInFlatTree::selectionFromContentsOfNode(URLElement); | 526 VisibleSelectionInFlatTree::selectionFromContentsOfNode(URLElement); |
| 509 | 527 |
| 510 updateSelectionForMouseDownDispatchingSelectStart( | 528 updateSelectionForMouseDownDispatchingSelectStart( |
| 511 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 529 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 512 WordGranularity); | 530 WordGranularity, HandleVisibility::NotVisible); |
| 513 } | 531 } |
| 514 | 532 |
| 515 bool SelectionController::handleMousePressEventDoubleClick( | 533 bool SelectionController::handleMousePressEventDoubleClick( |
| 516 const MouseEventWithHitTestResults& event) { | 534 const MouseEventWithHitTestResults& event) { |
| 517 TRACE_EVENT0("blink", | 535 TRACE_EVENT0("blink", |
| 518 "SelectionController::handleMousePressEventDoubleClick"); | 536 "SelectionController::handleMousePressEventDoubleClick"); |
| 519 | 537 |
| 520 if (!selection().isAvailable()) | 538 if (!selection().isAvailable()) |
| 521 return false; | 539 return false; |
| 522 | 540 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 VisibleSelectionInFlatTree newSelection; | 582 VisibleSelectionInFlatTree newSelection; |
| 565 const VisiblePositionInFlatTree& pos = | 583 const VisiblePositionInFlatTree& pos = |
| 566 visiblePositionOfHitTestResult(event.hitTestResult()); | 584 visiblePositionOfHitTestResult(event.hitTestResult()); |
| 567 if (pos.isNotNull()) { | 585 if (pos.isNotNull()) { |
| 568 SelectionInFlatTree::Builder builder; | 586 SelectionInFlatTree::Builder builder; |
| 569 builder.collapse(pos.toPositionWithAffinity()); | 587 builder.collapse(pos.toPositionWithAffinity()); |
| 570 newSelection = createVisibleSelection(builder.build()); | 588 newSelection = createVisibleSelection(builder.build()); |
| 571 newSelection.expandUsingGranularity(ParagraphGranularity); | 589 newSelection.expandUsingGranularity(ParagraphGranularity); |
| 572 } | 590 } |
| 573 | 591 |
| 592 bool isHandleVisible = event.event().fromTouch() && newSelection.isRange(); | |
| 593 | |
| 574 return updateSelectionForMouseDownDispatchingSelectStart( | 594 return updateSelectionForMouseDownDispatchingSelectStart( |
| 575 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 595 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 576 ParagraphGranularity); | 596 ParagraphGranularity, isHandleVisible ? HandleVisibility::Visible |
| 597 : HandleVisibility::NotVisible); | |
| 577 } | 598 } |
| 578 | 599 |
| 579 void SelectionController::handleMousePressEvent( | 600 void SelectionController::handleMousePressEvent( |
| 580 const MouseEventWithHitTestResults& event) { | 601 const MouseEventWithHitTestResults& event) { |
| 581 // If we got the event back, that must mean it wasn't prevented, | 602 // If we got the event back, that must mean it wasn't prevented, |
| 582 // so it's allowed to start a drag or selection if it wasn't in a scrollbar. | 603 // so it's allowed to start a drag or selection if it wasn't in a scrollbar. |
| 583 m_mouseDownMayStartSelect = | 604 m_mouseDownMayStartSelect = |
| 584 (canMouseDownStartSelect(event.innerNode()) || isLinkSelection(event)) && | 605 (canMouseDownStartSelect(event.innerNode()) || isLinkSelection(event)) && |
| 585 !event.scrollbar(); | 606 !event.scrollbar(); |
| 586 m_mouseDownWasSingleClickInSelection = false; | 607 m_mouseDownWasSingleClickInSelection = false; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 pos.deepEquivalent().parentAnchoredEquivalent()), | 785 pos.deepEquivalent().parentAnchoredEquivalent()), |
| 765 DocumentMarker::MisspellingMarkers()) | 786 DocumentMarker::MisspellingMarkers()) |
| 766 .size() > 0; | 787 .size() > 0; |
| 767 } | 788 } |
| 768 | 789 |
| 769 void SelectionController::sendContextMenuEvent( | 790 void SelectionController::sendContextMenuEvent( |
| 770 const MouseEventWithHitTestResults& mev, | 791 const MouseEventWithHitTestResults& mev, |
| 771 const LayoutPoint& position) { | 792 const LayoutPoint& position) { |
| 772 if (!selection().isAvailable()) | 793 if (!selection().isAvailable()) |
| 773 return; | 794 return; |
| 774 if (selection().contains(position) || mev.scrollbar() || | 795 if (selection().contains(mev.hitTestResult()) || mev.scrollbar() || |
| 775 // FIXME: In the editable case, word selection sometimes selects content | 796 // FIXME: In the editable case, word selection sometimes selects content |
| 776 // that isn't underneath the mouse. | 797 // that isn't underneath the mouse. |
| 777 // If the selection is non-editable, we do word selection to make it | 798 // If the selection is non-editable, we do word selection to make it |
| 778 // easier to use the contextual menu items available for text selections. | 799 // easier to use the contextual menu items available for text selections. |
| 779 // But only if we're above text. | 800 // But only if we're above text. |
| 780 !(selection().isContentEditable() || | 801 !(selection().isContentEditable() || |
| 781 (mev.innerNode() && mev.innerNode()->isTextNode()))) | 802 (mev.innerNode() && mev.innerNode()->isTextNode()))) |
| 782 return; | 803 return; |
| 783 | 804 |
| 784 // Context menu events are always allowed to perform a selection. | 805 // Context menu events are always allowed to perform a selection. |
| 785 AutoReset<bool> mouseDownMayStartSelectChange(&m_mouseDownMayStartSelect, | 806 AutoReset<bool> mouseDownMayStartSelectChange(&m_mouseDownMayStartSelect, |
| 786 true); | 807 true); |
| 787 | 808 |
| 788 if (hitTestResultIsMisspelled(mev.hitTestResult())) | 809 if (hitTestResultIsMisspelled(mev.hitTestResult())) |
| 789 return selectClosestMisspellingFromMouseEvent(mev); | 810 return selectClosestMisspellingFromMouseEvent(mev); |
| 790 | 811 |
| 791 if (!m_frame->editor().behavior().shouldSelectOnContextualMenuClick()) | 812 if (!m_frame->editor().behavior().shouldSelectOnContextualMenuClick()) |
| 792 return; | 813 return; |
| 793 | 814 |
| 794 selectClosestWordOrLinkFromMouseEvent(mev); | 815 selectClosestWordOrLinkFromMouseEvent(mev); |
| 795 } | 816 } |
| 796 | 817 |
| 797 void SelectionController::passMousePressEventToSubframe( | 818 void SelectionController::passMousePressEventToSubframe( |
| 798 const MouseEventWithHitTestResults& mev) { | 819 const MouseEventWithHitTestResults& mev) { |
| 799 // If we're clicking into a frame that is selected, the frame will appear | 820 // If we're clicking into a frame that is selected, the frame will appear |
| 800 // greyed out even though we're clicking on the selection. This looks | 821 // greyed out even though we're clicking on the selection. This looks |
| 801 // really strange (having the whole frame be greyed out), so we deselect the | 822 // really strange (having the whole frame be greyed out), so we deselect the |
| 802 // selection. | 823 // selection. |
| 803 IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position()); | 824 if (!selection().contains(mev.hitTestResult())) |
| 804 if (!selection().contains(p)) | |
| 805 return; | 825 return; |
| 806 | 826 |
| 807 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 827 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 808 // needs to be audited. See http://crbug.com/590369 for more details. | 828 // needs to be audited. See http://crbug.com/590369 for more details. |
| 809 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 829 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 810 | 830 |
| 811 const VisiblePositionInFlatTree& visiblePos = | 831 const VisiblePositionInFlatTree& visiblePos = |
| 812 visiblePositionOfHitTestResult(mev.hitTestResult()); | 832 visiblePositionOfHitTestResult(mev.hitTestResult()); |
| 813 if (visiblePos.isNull()) { | 833 if (visiblePos.isNull()) { |
| 814 selection().setSelection(VisibleSelectionInFlatTree()); | 834 selection().setSelection(VisibleSelectionInFlatTree()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 return event.event().altKey() && event.isOverLink(); | 872 return event.event().altKey() && event.isOverLink(); |
| 853 } | 873 } |
| 854 | 874 |
| 855 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { | 875 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 856 bool isMouseDownOnLinkOrImage = | 876 bool isMouseDownOnLinkOrImage = |
| 857 event.isOverLink() || event.hitTestResult().image(); | 877 event.isOverLink() || event.hitTestResult().image(); |
| 858 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; | 878 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; |
| 859 } | 879 } |
| 860 | 880 |
| 861 } // namespace blink | 881 } // namespace blink |
| OLD | NEW |