| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 SelectionController::SelectionController(LocalFrame& frame) | 55 SelectionController::SelectionController(LocalFrame& frame) |
| 56 : m_frame(&frame), | 56 : m_frame(&frame), |
| 57 m_mouseDownMayStartSelect(false), | 57 m_mouseDownMayStartSelect(false), |
| 58 m_mouseDownWasSingleClickInSelection(false), | 58 m_mouseDownWasSingleClickInSelection(false), |
| 59 m_mouseDownAllowsMultiClick(false), | 59 m_mouseDownAllowsMultiClick(false), |
| 60 m_selectionState(SelectionState::HaveNotStartedSelection) {} | 60 m_selectionState(SelectionState::HaveNotStartedSelection) {} |
| 61 | 61 |
| 62 DEFINE_TRACE(SelectionController) { | 62 DEFINE_TRACE(SelectionController) { |
| 63 visitor->trace(m_frame); | 63 visitor->trace(m_frame); |
| 64 visitor->trace(m_originalBaseInFlatTree); |
| 64 } | 65 } |
| 65 | 66 |
| 66 namespace { | 67 namespace { |
| 67 | 68 |
| 68 void setSelectionIfNeeded(FrameSelection& selection, | 69 void setSelectionIfNeeded(FrameSelection& selection, |
| 69 const VisibleSelectionInFlatTree& newSelection) { | 70 const VisibleSelectionInFlatTree& newSelection) { |
| 70 if (selection.visibleSelection<EditingInFlatTreeStrategy>() == newSelection) | 71 if (selection.visibleSelection<EditingInFlatTreeStrategy>() == newSelection) |
| 71 return; | 72 return; |
| 72 selection.setSelection(newSelection); | 73 selection.setSelection(newSelection); |
| 73 } | 74 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 VisiblePositionInFlatTree visiblePositionOfHitTestResult( | 118 VisiblePositionInFlatTree visiblePositionOfHitTestResult( |
| 118 const HitTestResult& hitTestResult) { | 119 const HitTestResult& hitTestResult) { |
| 119 return createVisiblePosition(fromPositionInDOMTree<EditingInFlatTreeStrategy>( | 120 return createVisiblePosition(fromPositionInDOMTree<EditingInFlatTreeStrategy>( |
| 120 hitTestResult.innerNode()->layoutObject()->positionForPoint( | 121 hitTestResult.innerNode()->layoutObject()->positionForPoint( |
| 121 hitTestResult.localPoint()))); | 122 hitTestResult.localPoint()))); |
| 122 } | 123 } |
| 123 | 124 |
| 124 } // namespace | 125 } // namespace |
| 125 | 126 |
| 127 Document& SelectionController::document() const { |
| 128 DCHECK(m_frame->document()); |
| 129 return *m_frame->document(); |
| 130 } |
| 131 |
| 132 void SelectionController::documentDetached() { |
| 133 m_originalBaseInFlatTree = VisiblePositionInFlatTree(); |
| 134 } |
| 135 |
| 126 bool SelectionController::handleMousePressEventSingleClick( | 136 bool SelectionController::handleMousePressEventSingleClick( |
| 127 const MouseEventWithHitTestResults& event) { | 137 const MouseEventWithHitTestResults& event) { |
| 128 TRACE_EVENT0("blink", | 138 TRACE_EVENT0("blink", |
| 129 "SelectionController::handleMousePressEventSingleClick"); | 139 "SelectionController::handleMousePressEventSingleClick"); |
| 130 | 140 |
| 131 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); | 141 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); |
| 132 Node* innerNode = event.innerNode(); | 142 Node* innerNode = event.innerNode(); |
| 133 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) | 143 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) |
| 134 return false; | 144 return false; |
| 135 | 145 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 else | 335 else |
| 326 newSelection.setExtent(targetPosition); | 336 newSelection.setExtent(targetPosition); |
| 327 } | 337 } |
| 328 } else { | 338 } else { |
| 329 newSelection.setExtent(targetPosition); | 339 newSelection.setExtent(targetPosition); |
| 330 } | 340 } |
| 331 | 341 |
| 332 if (selection().granularity() != CharacterGranularity) | 342 if (selection().granularity() != CharacterGranularity) |
| 333 newSelection.expandUsingGranularity(selection().granularity()); | 343 newSelection.expandUsingGranularity(selection().granularity()); |
| 334 | 344 |
| 335 selection().setNonDirectionalSelectionIfNeeded( | 345 setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(), |
| 336 newSelection, selection().granularity(), | 346 AdjustEndpointsAtBidiBoundary); |
| 337 FrameSelection::AdjustEndpointsAtBidiBoundary); | |
| 338 } | 347 } |
| 339 | 348 |
| 340 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( | 349 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
| 341 Node* targetNode, | 350 Node* targetNode, |
| 342 const VisibleSelectionInFlatTree& selection, | 351 const VisibleSelectionInFlatTree& selection, |
| 343 TextGranularity granularity) { | 352 TextGranularity granularity) { |
| 344 if (targetNode && targetNode->layoutObject() && | 353 if (targetNode && targetNode->layoutObject() && |
| 345 !targetNode->layoutObject()->isSelectable()) | 354 !targetNode->layoutObject()->isSelectable()) |
| 346 return false; | 355 return false; |
| 347 | 356 |
| 348 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) | 357 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) |
| 349 return false; | 358 return false; |
| 350 | 359 |
| 351 // |dispatchSelectStart()| can change document hosted by |m_frame|. | 360 // |dispatchSelectStart()| can change document hosted by |m_frame|. |
| 352 if (!this->selection().isAvailable()) | 361 if (!this->selection().isAvailable()) |
| 353 return false; | 362 return false; |
| 354 | 363 |
| 355 if (!selection.isValidFor(this->selection().document())) | 364 if (!selection.isValidFor(this->selection().document())) |
| 356 return false; | 365 return false; |
| 357 | 366 |
| 358 if (selection.isRange()) { | 367 if (selection.isRange()) { |
| 359 m_selectionState = SelectionState::ExtendedSelection; | 368 m_selectionState = SelectionState::ExtendedSelection; |
| 360 } else { | 369 } else { |
| 361 granularity = CharacterGranularity; | 370 granularity = CharacterGranularity; |
| 362 m_selectionState = SelectionState::PlacedCaret; | 371 m_selectionState = SelectionState::PlacedCaret; |
| 363 } | 372 } |
| 364 | 373 |
| 365 this->selection().setNonDirectionalSelectionIfNeeded(selection, granularity); | 374 setNonDirectionalSelectionIfNeeded(selection, granularity, |
| 375 DoNotAdjustEndpoints); |
| 366 | 376 |
| 367 return true; | 377 return true; |
| 368 } | 378 } |
| 369 | 379 |
| 370 void SelectionController::selectClosestWordFromHitTestResult( | 380 void SelectionController::selectClosestWordFromHitTestResult( |
| 371 const HitTestResult& result, | 381 const HitTestResult& result, |
| 372 AppendTrailingWhitespace appendTrailingWhitespace, | 382 AppendTrailingWhitespace appendTrailingWhitespace, |
| 373 SelectInputEventType selectInputEventType) { | 383 SelectInputEventType selectInputEventType) { |
| 374 Node* innerNode = result.innerNode(); | 384 Node* innerNode = result.innerNode(); |
| 375 VisibleSelectionInFlatTree newSelection; | 385 VisibleSelectionInFlatTree newSelection; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 return event.event().altKey() && event.isOverLink(); | 865 return event.event().altKey() && event.isOverLink(); |
| 856 } | 866 } |
| 857 | 867 |
| 858 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { | 868 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 859 bool isMouseDownOnLinkOrImage = | 869 bool isMouseDownOnLinkOrImage = |
| 860 event.isOverLink() || event.hitTestResult().image(); | 870 event.isOverLink() || event.hitTestResult().image(); |
| 861 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; | 871 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; |
| 862 } | 872 } |
| 863 | 873 |
| 864 } // namespace blink | 874 } // namespace blink |
| OLD | NEW |