| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 5 * Copyright (C) 2015 Google Inc. All rights reserved. | 5 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 return; | 354 return; |
| 355 | 355 |
| 356 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H
itTestRequest::Move); | 356 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H
itTestRequest::Move); |
| 357 HitTestResult result(request, view->rootFrameToContents(lastKnownMousePositi
on)); | 357 HitTestResult result(request, view->rootFrameToContents(lastKnownMousePositi
on)); |
| 358 layoutObject->hitTest(result); | 358 layoutObject->hitTest(result); |
| 359 updateSelectionForMouseDrag(result, mousePressNode, dragStartPos, lastKnownM
ousePosition); | 359 updateSelectionForMouseDrag(result, mousePressNode, dragStartPos, lastKnownM
ousePosition); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void SelectionController::updateSelectionForMouseDrag(const HitTestResult& hitTe
stResult, Node* mousePressNode, const LayoutPoint& dragStartPos, const IntPoint&
lastKnownMousePosition) | 362 void SelectionController::updateSelectionForMouseDrag(const HitTestResult& hitTe
stResult, Node* mousePressNode, const LayoutPoint& dragStartPos, const IntPoint&
lastKnownMousePosition) |
| 363 { | 363 { |
| 364 updateSelectionForMouseDragAlgorithm<VisibleSelection::InDOMTree>(hitTestRes
ult, mousePressNode, dragStartPos, lastKnownMousePosition); |
| 365 } |
| 366 |
| 367 template <typename Strategy> |
| 368 void SelectionController::updateSelectionForMouseDragAlgorithm(const HitTestResu
lt& hitTestResult, Node* mousePressNode, const LayoutPoint& dragStartPos, const
IntPoint& lastKnownMousePosition) |
| 369 { |
| 370 using PositionType = typename Strategy::PositionType; |
| 371 |
| 364 if (!m_mouseDownMayStartSelect) | 372 if (!m_mouseDownMayStartSelect) |
| 365 return; | 373 return; |
| 366 | 374 |
| 367 Node* target = hitTestResult.innerNode(); | 375 Node* target = hitTestResult.innerNode(); |
| 368 if (!target) | 376 if (!target) |
| 369 return; | 377 return; |
| 370 | 378 |
| 371 VisiblePosition targetPosition = m_frame->selection().selection().visiblePos
itionRespectingEditingBoundary(hitTestResult.localPoint(), target); | 379 VisiblePosition targetPosition = m_frame->selection().selection().visiblePos
itionRespectingEditingBoundary(hitTestResult.localPoint(), target); |
| 372 // Don't modify the selection if we're not on a node. | 380 // Don't modify the selection if we're not on a node. |
| 373 if (targetPosition.isNull()) | 381 if (targetPosition.isNull()) |
| 374 return; | 382 return; |
| 375 | 383 |
| 376 // Restart the selection if this is the first mouse move. This work is usual
ly | 384 // Restart the selection if this is the first mouse move. This work is usual
ly |
| 377 // done in handleMousePressEvent, but not if the mouse press was on an exist
ing selection. | 385 // done in handleMousePressEvent, but not if the mouse press was on an exist
ing selection. |
| 378 VisibleSelection newSelection = m_frame->selection().selection(); | 386 VisibleSelection newSelection = m_frame->selection().selection(); |
| 379 | 387 |
| 380 // Special case to limit selection to the containing block for SVG text. | 388 // Special case to limit selection to the containing block for SVG text. |
| 381 // FIXME: Isn't there a better non-SVG-specific way to do this? | 389 // FIXME: Isn't there a better non-SVG-specific way to do this? |
| 382 if (Node* selectionBaseNode = newSelection.base().deprecatedNode()) { | 390 if (Node* selectionBaseNode = Strategy::selectionBase(newSelection).deprecat
edNode()) { |
| 383 if (LayoutObject* selectionBaseLayoutObject = selectionBaseNode->layoutO
bject()) { | 391 if (LayoutObject* selectionBaseLayoutObject = selectionBaseNode->layoutO
bject()) { |
| 384 if (selectionBaseLayoutObject->isSVGText()) { | 392 if (selectionBaseLayoutObject->isSVGText()) { |
| 385 if (target->layoutObject()->containingBlock() != selectionBaseLa
youtObject->containingBlock()) | 393 if (target->layoutObject()->containingBlock() != selectionBaseLa
youtObject->containingBlock()) |
| 386 return; | 394 return; |
| 387 } | 395 } |
| 388 } | 396 } |
| 389 } | 397 } |
| 390 | 398 |
| 391 if (m_selectionInitiationState == HaveNotStartedSelection && !dispatchSelect
Start(target)) | 399 if (m_selectionInitiationState == HaveNotStartedSelection && !dispatchSelect
Start(target)) |
| 392 return; | 400 return; |
| 393 | 401 |
| 394 if (m_selectionInitiationState != ExtendedSelection) { | 402 if (m_selectionInitiationState != ExtendedSelection) { |
| 395 // Always extend selection here because it's caused by a mouse drag | 403 // Always extend selection here because it's caused by a mouse drag |
| 396 m_selectionInitiationState = ExtendedSelection; | 404 m_selectionInitiationState = ExtendedSelection; |
| 397 newSelection = VisibleSelection(targetPosition); | 405 newSelection = VisibleSelection(targetPosition); |
| 398 } | 406 } |
| 399 | 407 |
| 400 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { | 408 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { |
| 401 Node* rootUserSelectAllForMousePressNode = Position::rootUserSelectAllFo
rNode(mousePressNode); | 409 Node* rootUserSelectAllForMousePressNode = Position::rootUserSelectAllFo
rNode(mousePressNode); |
| 402 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress
Node == Position::rootUserSelectAllForNode(target)) { | 410 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress
Node == Position::rootUserSelectAllForNode(target)) { |
| 403 newSelection.setBase(positionBeforeNode(rootUserSelectAllForMousePre
ssNode).upstream(CanCrossEditingBoundary)); | 411 newSelection.setBase(PositionType::beforeNode(rootUserSelectAllForMo
usePressNode).upstream(CanCrossEditingBoundary)); |
| 404 newSelection.setExtent(positionAfterNode(rootUserSelectAllForMousePr
essNode).downstream(CanCrossEditingBoundary)); | 412 newSelection.setExtent(PositionType::afterNode(rootUserSelectAllForM
ousePressNode).downstream(CanCrossEditingBoundary)); |
| 405 } else { | 413 } else { |
| 406 // Reset base for user select all when base is inside user-select-al
l area and extent < base. | 414 // Reset base for user select all when base is inside user-select-al
l area and extent < base. |
| 407 if (rootUserSelectAllForMousePressNode && comparePositions(target->l
ayoutObject()->positionForPoint(hitTestResult.localPoint()), mousePressNode->lay
outObject()->positionForPoint(dragStartPos)) < 0) | 415 if (rootUserSelectAllForMousePressNode) { |
| 408 newSelection.setBase(positionAfterNode(rootUserSelectAllForMouse
PressNode).downstream(CanCrossEditingBoundary)); | 416 PositionType eventPosition = Strategy::toPositionType(target->la
youtObject()->positionForPoint(hitTestResult.localPoint()).position()); |
| 417 PositionType dragStartPosition = Strategy::toPositionType(mouseP
ressNode->layoutObject()->positionForPoint(dragStartPos).position()); |
| 418 if (eventPosition.compareTo(dragStartPosition) < 0) |
| 419 newSelection.setBase(PositionType::afterNode(rootUserSelectA
llForMousePressNode).downstream(CanCrossEditingBoundary)); |
| 420 } |
| 409 | 421 |
| 410 Node* rootUserSelectAllForTarget = Position::rootUserSelectAllForNod
e(target); | 422 Node* rootUserSelectAllForTarget = Position::rootUserSelectAllForNod
e(target); |
| 411 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() &&
comparePositions(target->layoutObject()->positionForPoint(hitTestResult.localPoi
nt()), mousePressNode->layoutObject()->positionForPoint(dragStartPos)) < 0) | 423 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() &&
Strategy::toPositionType(target->layoutObject()->positionForPoint(hitTestResult.
localPoint()).position()).compareTo(Strategy::toPositionType(mousePressNode->lay
outObject()->positionForPoint(dragStartPos).position())) < 0) |
| 412 newSelection.setExtent(positionBeforeNode(rootUserSelectAllForTa
rget).upstream(CanCrossEditingBoundary)); | 424 newSelection.setExtent(PositionType::beforeNode(rootUserSelectAl
lForTarget).upstream(CanCrossEditingBoundary)); |
| 413 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject(
)) | 425 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject(
)) |
| 414 newSelection.setExtent(positionAfterNode(rootUserSelectAllForTar
get).downstream(CanCrossEditingBoundary)); | 426 newSelection.setExtent(PositionType::afterNode(rootUserSelectAll
ForTarget).downstream(CanCrossEditingBoundary)); |
| 415 else | 427 else |
| 416 newSelection.setExtent(targetPosition); | 428 newSelection.setExtent(targetPosition); |
| 417 } | 429 } |
| 418 } else { | 430 } else { |
| 419 newSelection.setExtent(targetPosition); | 431 newSelection.setExtent(targetPosition); |
| 420 } | 432 } |
| 421 | 433 |
| 422 if (m_frame->selection().granularity() != CharacterGranularity) | 434 if (m_frame->selection().granularity() != CharacterGranularity) |
| 423 newSelection.expandUsingGranularity(m_frame->selection().granularity()); | 435 newSelection.expandUsingGranularity(m_frame->selection().granularity()); |
| 424 | 436 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 { | 577 { |
| 566 return m_mouseDownMayStartSelect; | 578 return m_mouseDownMayStartSelect; |
| 567 } | 579 } |
| 568 | 580 |
| 569 bool SelectionController::mouseDownWasSingleClickInSelection() const | 581 bool SelectionController::mouseDownWasSingleClickInSelection() const |
| 570 { | 582 { |
| 571 return m_mouseDownWasSingleClickInSelection; | 583 return m_mouseDownWasSingleClickInSelection; |
| 572 } | 584 } |
| 573 | 585 |
| 574 } // namespace blink | 586 } // namespace blink |
| OLD | NEW |