| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 visiblePos = createVisiblePosition( | 151 visiblePos = createVisiblePosition( |
| 152 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)); | 152 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)); |
| 153 PositionInFlatTree pos = visiblePos.deepEquivalent(); | 153 PositionInFlatTree pos = visiblePos.deepEquivalent(); |
| 154 | 154 |
| 155 VisibleSelectionInFlatTree newSelection = | 155 VisibleSelectionInFlatTree newSelection = |
| 156 selection().visibleSelection<EditingInFlatTreeStrategy>(); | 156 selection().visibleSelection<EditingInFlatTreeStrategy>(); |
| 157 TextGranularity granularity = CharacterGranularity; | 157 TextGranularity granularity = CharacterGranularity; |
| 158 | 158 |
| 159 if (extendSelection && !newSelection.isNone()) { | 159 if (extendSelection && !newSelection.isNone()) { |
| 160 const VisibleSelectionInFlatTree selectionInUserSelectAll( | 160 const VisibleSelectionInFlatTree selectionInUserSelectAll( |
| 161 expandSelectionToRespectUserSelectAll( | 161 expandSelectionToRespectUserSelectAll(innerNode, |
| 162 innerNode, | 162 createVisibleSelection(pos))); |
| 163 createVisibleSelectionDeprecated(createVisiblePosition(pos)))); | |
| 164 if (selectionInUserSelectAll.isRange()) { | 163 if (selectionInUserSelectAll.isRange()) { |
| 165 if (selectionInUserSelectAll.start().compareTo(newSelection.start()) < 0) | 164 if (selectionInUserSelectAll.start().compareTo(newSelection.start()) < 0) |
| 166 pos = selectionInUserSelectAll.start(); | 165 pos = selectionInUserSelectAll.start(); |
| 167 else if (newSelection.end().compareTo(selectionInUserSelectAll.end()) < 0) | 166 else if (newSelection.end().compareTo(selectionInUserSelectAll.end()) < 0) |
| 168 pos = selectionInUserSelectAll.end(); | 167 pos = selectionInUserSelectAll.end(); |
| 169 } | 168 } |
| 170 | 169 |
| 171 if (!m_frame->editor().behavior().shouldConsiderSelectionAsDirectional()) { | 170 if (!m_frame->editor().behavior().shouldConsiderSelectionAsDirectional()) { |
| 172 if (pos.isNotNull()) { | 171 if (pos.isNotNull()) { |
| 173 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click | 172 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click |
| 174 // deselects when selection was created right-to-left | 173 // deselects when selection was created right-to-left |
| 175 const PositionInFlatTree start = newSelection.start(); | 174 const PositionInFlatTree start = newSelection.start(); |
| 176 const PositionInFlatTree end = newSelection.end(); | 175 const PositionInFlatTree end = newSelection.end(); |
| 177 int distanceToStart = textDistance(start, pos); | 176 int distanceToStart = textDistance(start, pos); |
| 178 int distanceToEnd = textDistance(pos, end); | 177 int distanceToEnd = textDistance(pos, end); |
| 179 if (distanceToStart <= distanceToEnd) | 178 if (distanceToStart <= distanceToEnd) |
| 180 newSelection = createVisibleSelectionDeprecated(end, pos); | 179 newSelection = createVisibleSelection(end, pos); |
| 181 else | 180 else |
| 182 newSelection = createVisibleSelectionDeprecated(start, pos); | 181 newSelection = createVisibleSelection(start, pos); |
| 183 } | 182 } |
| 184 } else { | 183 } else { |
| 185 newSelection.setExtent(pos); | 184 newSelection.setExtent(pos); |
| 186 } | 185 } |
| 187 | 186 |
| 188 if (selection().granularity() != CharacterGranularity) { | 187 if (selection().granularity() != CharacterGranularity) { |
| 189 granularity = selection().granularity(); | 188 granularity = selection().granularity(); |
| 190 newSelection.expandUsingGranularity(selection().granularity()); | 189 newSelection.expandUsingGranularity(selection().granularity()); |
| 191 } | 190 } |
| 192 } else if (m_selectionState != SelectionState::ExtendedSelection) { | 191 } else if (m_selectionState != SelectionState::ExtendedSelection) { |
| 193 newSelection = expandSelectionToRespectUserSelectAll( | 192 newSelection = expandSelectionToRespectUserSelectAll( |
| 194 innerNode, createVisibleSelectionDeprecated(visiblePos)); | 193 innerNode, createVisibleSelection(visiblePos)); |
| 195 } | 194 } |
| 196 | 195 |
| 197 // Updating the selection is considered side-effect of the event and so it doe
sn't impact the handled state. | 196 // Updating the selection is considered side-effect of the event and so it doe
sn't impact the handled state. |
| 198 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, | 197 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, |
| 199 granularity); | 198 granularity); |
| 200 return false; | 199 return false; |
| 201 } | 200 } |
| 202 | 201 |
| 203 void SelectionController::updateSelectionForMouseDrag( | 202 void SelectionController::updateSelectionForMouseDrag( |
| 204 const HitTestResult& hitTestResult, | 203 const HitTestResult& hitTestResult, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 dispatchSelectStart(target) != DispatchEventResult::NotCanceled) | 246 dispatchSelectStart(target) != DispatchEventResult::NotCanceled) |
| 248 return; | 247 return; |
| 249 | 248 |
| 250 // TODO(yosin) We should check |mousePressNode|, |targetPosition|, and | 249 // TODO(yosin) We should check |mousePressNode|, |targetPosition|, and |
| 251 // |newSelection| are valid for |m_frame->document()|. | 250 // |newSelection| are valid for |m_frame->document()|. |
| 252 // |dispatchSelectStart()| can change them by "selectstart" event handler. | 251 // |dispatchSelectStart()| can change them by "selectstart" event handler. |
| 253 | 252 |
| 254 if (m_selectionState != SelectionState::ExtendedSelection) { | 253 if (m_selectionState != SelectionState::ExtendedSelection) { |
| 255 // Always extend selection here because it's caused by a mouse drag | 254 // Always extend selection here because it's caused by a mouse drag |
| 256 m_selectionState = SelectionState::ExtendedSelection; | 255 m_selectionState = SelectionState::ExtendedSelection; |
| 257 newSelection = createVisibleSelectionDeprecated(targetPosition); | 256 newSelection = createVisibleSelection(targetPosition); |
| 258 } | 257 } |
| 259 | 258 |
| 260 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { | 259 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { |
| 261 // TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|? | 260 // TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|? |
| 262 Node* const rootUserSelectAllForMousePressNode = | 261 Node* const rootUserSelectAllForMousePressNode = |
| 263 EditingInFlatTreeStrategy::rootUserSelectAllForNode(mousePressNode); | 262 EditingInFlatTreeStrategy::rootUserSelectAllForNode(mousePressNode); |
| 264 Node* const rootUserSelectAllForTarget = | 263 Node* const rootUserSelectAllForTarget = |
| 265 EditingInFlatTreeStrategy::rootUserSelectAllForNode(target); | 264 EditingInFlatTreeStrategy::rootUserSelectAllForNode(target); |
| 266 if (rootUserSelectAllForMousePressNode && | 265 if (rootUserSelectAllForMousePressNode && |
| 267 rootUserSelectAllForMousePressNode == rootUserSelectAllForTarget) { | 266 rootUserSelectAllForMousePressNode == rootUserSelectAllForTarget) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 // mid-point of the the image (which was intended for mouse-drag selection | 363 // mid-point of the the image (which was intended for mouse-drag selection |
| 365 // and isn't desirable for touch). | 364 // and isn't desirable for touch). |
| 366 HitTestResult adjustedHitTestResult = result; | 365 HitTestResult adjustedHitTestResult = result; |
| 367 if (selectInputEventType == SelectInputEventType::Touch && result.image()) | 366 if (selectInputEventType == SelectInputEventType::Touch && result.image()) |
| 368 adjustedHitTestResult.setNodeAndPosition(result.innerNode(), | 367 adjustedHitTestResult.setNodeAndPosition(result.innerNode(), |
| 369 LayoutPoint(0, 0)); | 368 LayoutPoint(0, 0)); |
| 370 | 369 |
| 371 const VisiblePositionInFlatTree& pos = | 370 const VisiblePositionInFlatTree& pos = |
| 372 visiblePositionOfHitTestResult(adjustedHitTestResult); | 371 visiblePositionOfHitTestResult(adjustedHitTestResult); |
| 373 if (pos.isNotNull()) { | 372 if (pos.isNotNull()) { |
| 374 newSelection = createVisibleSelectionDeprecated(pos); | 373 newSelection = createVisibleSelection(pos); |
| 375 newSelection.expandUsingGranularity(WordGranularity); | 374 newSelection.expandUsingGranularity(WordGranularity); |
| 376 } | 375 } |
| 377 | 376 |
| 378 if (selectInputEventType == SelectInputEventType::Touch) { | 377 if (selectInputEventType == SelectInputEventType::Touch) { |
| 379 // If node doesn't have text except space, tab or line break, do not | 378 // If node doesn't have text except space, tab or line break, do not |
| 380 // select that 'empty' area. | 379 // select that 'empty' area. |
| 381 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); | 380 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); |
| 382 const String& str = | 381 const String& str = |
| 383 plainText(range, hasEditableStyle(*innerNode) | 382 plainText(range, hasEditableStyle(*innerNode) |
| 384 ? TextIteratorEmitsObjectReplacementCharacter | 383 ? TextIteratorEmitsObjectReplacementCharacter |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 const PositionInFlatTree& markerPosition = | 416 const PositionInFlatTree& markerPosition = |
| 418 pos.deepEquivalent().parentAnchoredEquivalent(); | 417 pos.deepEquivalent().parentAnchoredEquivalent(); |
| 419 DocumentMarkerVector markers = | 418 DocumentMarkerVector markers = |
| 420 innerNode->document().markers().markersInRange( | 419 innerNode->document().markers().markersInRange( |
| 421 EphemeralRange(toPositionInDOMTree(markerPosition)), | 420 EphemeralRange(toPositionInDOMTree(markerPosition)), |
| 422 DocumentMarker::MisspellingMarkers()); | 421 DocumentMarker::MisspellingMarkers()); |
| 423 if (markers.size() == 1) { | 422 if (markers.size() == 1) { |
| 424 Node* containerNode = markerPosition.computeContainerNode(); | 423 Node* containerNode = markerPosition.computeContainerNode(); |
| 425 const PositionInFlatTree start(containerNode, markers[0]->startOffset()); | 424 const PositionInFlatTree start(containerNode, markers[0]->startOffset()); |
| 426 const PositionInFlatTree end(containerNode, markers[0]->endOffset()); | 425 const PositionInFlatTree end(containerNode, markers[0]->endOffset()); |
| 427 newSelection = createVisibleSelectionDeprecated(start, end); | 426 newSelection = createVisibleSelection(start, end); |
| 428 } | 427 } |
| 429 } | 428 } |
| 430 | 429 |
| 431 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && | 430 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && |
| 432 newSelection.isRange()) | 431 newSelection.isRange()) |
| 433 newSelection.appendTrailingWhitespace(); | 432 newSelection.appendTrailingWhitespace(); |
| 434 | 433 |
| 435 updateSelectionForMouseDownDispatchingSelectStart( | 434 updateSelectionForMouseDownDispatchingSelectStart( |
| 436 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 435 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 437 WordGranularity); | 436 WordGranularity); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 return false; | 538 return false; |
| 540 | 539 |
| 541 Node* innerNode = event.innerNode(); | 540 Node* innerNode = event.innerNode(); |
| 542 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) | 541 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) |
| 543 return false; | 542 return false; |
| 544 | 543 |
| 545 VisibleSelectionInFlatTree newSelection; | 544 VisibleSelectionInFlatTree newSelection; |
| 546 const VisiblePositionInFlatTree& pos = | 545 const VisiblePositionInFlatTree& pos = |
| 547 visiblePositionOfHitTestResult(event.hitTestResult()); | 546 visiblePositionOfHitTestResult(event.hitTestResult()); |
| 548 if (pos.isNotNull()) { | 547 if (pos.isNotNull()) { |
| 549 newSelection = createVisibleSelectionDeprecated(pos); | 548 newSelection = createVisibleSelection(pos); |
| 550 newSelection.expandUsingGranularity(ParagraphGranularity); | 549 newSelection.expandUsingGranularity(ParagraphGranularity); |
| 551 } | 550 } |
| 552 | 551 |
| 553 return updateSelectionForMouseDownDispatchingSelectStart( | 552 return updateSelectionForMouseDownDispatchingSelectStart( |
| 554 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), | 553 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| 555 ParagraphGranularity); | 554 ParagraphGranularity); |
| 556 } | 555 } |
| 557 | 556 |
| 558 void SelectionController::handleMousePressEvent( | 557 void SelectionController::handleMousePressEvent( |
| 559 const MouseEventWithHitTestResults& event) { | 558 const MouseEventWithHitTestResults& event) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 636 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 638 | 637 |
| 639 VisibleSelectionInFlatTree newSelection; | 638 VisibleSelectionInFlatTree newSelection; |
| 640 Node* node = event.innerNode(); | 639 Node* node = event.innerNode(); |
| 641 bool caretBrowsing = | 640 bool caretBrowsing = |
| 642 m_frame->settings() && m_frame->settings()->caretBrowsingEnabled(); | 641 m_frame->settings() && m_frame->settings()->caretBrowsingEnabled(); |
| 643 if (node && node->layoutObject() && | 642 if (node && node->layoutObject() && |
| 644 (caretBrowsing || hasEditableStyle(*node))) { | 643 (caretBrowsing || hasEditableStyle(*node))) { |
| 645 const VisiblePositionInFlatTree pos = | 644 const VisiblePositionInFlatTree pos = |
| 646 visiblePositionOfHitTestResult(event.hitTestResult()); | 645 visiblePositionOfHitTestResult(event.hitTestResult()); |
| 647 newSelection = createVisibleSelectionDeprecated(pos); | 646 newSelection = createVisibleSelection(pos); |
| 648 } | 647 } |
| 649 | 648 |
| 650 setSelectionIfNeeded(selection(), newSelection); | 649 setSelectionIfNeeded(selection(), newSelection); |
| 651 | 650 |
| 652 handled = true; | 651 handled = true; |
| 653 } | 652 } |
| 654 | 653 |
| 655 selection().notifyLayoutObjectOfSelectionChange(UserTriggered); | 654 selection().notifyLayoutObjectOfSelectionChange(UserTriggered); |
| 656 | 655 |
| 657 selection().selectFrameElementInParentIfFullySelected(); | 656 selection().selectFrameElementInParentIfFullySelected(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position()); | 776 IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position()); |
| 778 if (!selection().contains(p)) | 777 if (!selection().contains(p)) |
| 779 return; | 778 return; |
| 780 | 779 |
| 781 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 780 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 782 // needs to be audited. See http://crbug.com/590369 for more details. | 781 // needs to be audited. See http://crbug.com/590369 for more details. |
| 783 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 782 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 784 | 783 |
| 785 const VisiblePositionInFlatTree& visiblePos = | 784 const VisiblePositionInFlatTree& visiblePos = |
| 786 visiblePositionOfHitTestResult(mev.hitTestResult()); | 785 visiblePositionOfHitTestResult(mev.hitTestResult()); |
| 787 VisibleSelectionInFlatTree newSelection = | 786 VisibleSelectionInFlatTree newSelection = createVisibleSelection(visiblePos); |
| 788 createVisibleSelectionDeprecated(visiblePos); | |
| 789 selection().setSelection(newSelection); | 787 selection().setSelection(newSelection); |
| 790 } | 788 } |
| 791 | 789 |
| 792 void SelectionController::initializeSelectionState() { | 790 void SelectionController::initializeSelectionState() { |
| 793 m_selectionState = SelectionState::HaveNotStartedSelection; | 791 m_selectionState = SelectionState::HaveNotStartedSelection; |
| 794 } | 792 } |
| 795 | 793 |
| 796 void SelectionController::setMouseDownMayStartSelect(bool mayStartSelect) { | 794 void SelectionController::setMouseDownMayStartSelect(bool mayStartSelect) { |
| 797 m_mouseDownMayStartSelect = mayStartSelect; | 795 m_mouseDownMayStartSelect = mayStartSelect; |
| 798 } | 796 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 822 return event.event().altKey() && event.isOverLink(); | 820 return event.event().altKey() && event.isOverLink(); |
| 823 } | 821 } |
| 824 | 822 |
| 825 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { | 823 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 826 bool isMouseDownOnLinkOrImage = | 824 bool isMouseDownOnLinkOrImage = |
| 827 event.isOverLink() || event.hitTestResult().image(); | 825 event.isOverLink() || event.hitTestResult().image(); |
| 828 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; | 826 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; |
| 829 } | 827 } |
| 830 | 828 |
| 831 } // namespace blink | 829 } // namespace blink |
| OLD | NEW |