Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: third_party/WebKit/Source/core/editing/SelectionController.cpp

Issue 2664253002: Revert "Blink handle selection handle visibility" (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); 161 DCHECK(!m_frame->document()->needsLayoutTreeUpdate());
162 Node* innerNode = event.innerNode(); 162 Node* innerNode = event.innerNode();
163 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) 163 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect))
164 return false; 164 return false;
165 165
166 // Extend the selection if the Shift key is down, unless the click is in a 166 // Extend the selection if the Shift key is down, unless the click is in a
167 // link or image. 167 // link or image.
168 bool extendSelection = isExtendingSelection(event); 168 bool extendSelection = isExtendingSelection(event);
169 169
170 // Don't restart the selection when the mouse is pressed on an
171 // existing selection so we can allow for text dragging.
172 if (FrameView* view = m_frame->view()) {
173 LayoutPoint vPoint = view->rootFrameToContents(event.event().position());
174 if (!extendSelection && selection().contains(vPoint)) {
175 m_mouseDownWasSingleClickInSelection = true;
176 return false;
177 }
178 }
179
170 const VisiblePositionInFlatTree& visibleHitPos = 180 const VisiblePositionInFlatTree& visibleHitPos =
171 visiblePositionOfHitTestResult(event.hitTestResult()); 181 visiblePositionOfHitTestResult(event.hitTestResult());
172 const VisiblePositionInFlatTree& visiblePos = 182 const VisiblePositionInFlatTree& visiblePos =
173 visibleHitPos.isNull() 183 visibleHitPos.isNull()
174 ? createVisiblePosition( 184 ? createVisiblePosition(
175 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)) 185 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode))
176 : visibleHitPos; 186 : visibleHitPos;
177 const VisibleSelectionInFlatTree& selection = 187 const VisibleSelectionInFlatTree& selection =
178 this->selection().visibleSelection<EditingInFlatTreeStrategy>(); 188 this->selection().visibleSelection<EditingInFlatTreeStrategy>();
179 189
180 // Don't restart the selection when the mouse is pressed on an
181 // existing selection so we can allow for text dragging.
182 if (FrameView* view = m_frame->view()) {
183 const LayoutPoint vPoint =
184 view->rootFrameToContents(event.event().position());
185 if (!extendSelection && this->selection().contains(vPoint)) {
186 m_mouseDownWasSingleClickInSelection = true;
187 if (!event.event().fromTouch())
188 return false;
189
190 if (!this->selection().isHandleVisible()) {
191 updateSelectionForMouseDownDispatchingSelectStart(
192 innerNode, selection, CharacterGranularity,
193 HandleVisibility::Visible);
194 return false;
195 }
196 }
197 }
198
199 if (extendSelection && !selection.isNone()) { 190 if (extendSelection && !selection.isNone()) {
200 // Note: "fast/events/shift-click-user-select-none.html" makes 191 // Note: "fast/events/shift-click-user-select-none.html" makes
201 // |pos.isNull()| true. 192 // |pos.isNull()| true.
202 const PositionInFlatTree& pos = adjustPositionRespectUserSelectAll( 193 const PositionInFlatTree& pos = adjustPositionRespectUserSelectAll(
203 innerNode, selection.start(), selection.end(), 194 innerNode, selection.start(), selection.end(),
204 visiblePos.deepEquivalent()); 195 visiblePos.deepEquivalent());
205 SelectionInFlatTree::Builder builder; 196 SelectionInFlatTree::Builder builder;
206 builder.setGranularity(this->selection().granularity()); 197 builder.setGranularity(this->selection().granularity());
207 if (m_frame->editor().behavior().shouldConsiderSelectionAsDirectional()) { 198 if (m_frame->editor().behavior().shouldConsiderSelectionAsDirectional()) {
208 builder.setBaseAndExtent(selection.base(), pos); 199 builder.setBaseAndExtent(selection.base(), pos);
209 } else if (pos.isNull()) { 200 } else if (pos.isNull()) {
210 builder.setBaseAndExtent(selection.base(), selection.extent()); 201 builder.setBaseAndExtent(selection.base(), selection.extent());
211 } else { 202 } else {
212 // Shift+Click deselects when selection was created right-to-left 203 // Shift+Click deselects when selection was created right-to-left
213 const PositionInFlatTree& start = selection.start(); 204 const PositionInFlatTree& start = selection.start();
214 const PositionInFlatTree& end = selection.end(); 205 const PositionInFlatTree& end = selection.end();
215 const int distanceToStart = textDistance(start, pos); 206 const int distanceToStart = textDistance(start, pos);
216 const int distanceToEnd = textDistance(pos, end); 207 const int distanceToEnd = textDistance(pos, end);
217 builder.setBaseAndExtent(distanceToStart <= distanceToEnd ? end : start, 208 builder.setBaseAndExtent(distanceToStart <= distanceToEnd ? end : start,
218 pos); 209 pos);
219 } 210 }
220 211
221 updateSelectionForMouseDownDispatchingSelectStart( 212 updateSelectionForMouseDownDispatchingSelectStart(
222 innerNode, createVisibleSelection(builder.build()), 213 innerNode, createVisibleSelection(builder.build()),
223 this->selection().granularity(), HandleVisibility::NotVisible); 214 this->selection().granularity());
224 return false; 215 return false;
225 } 216 }
226 217
227 if (m_selectionState == SelectionState::ExtendedSelection) { 218 if (m_selectionState == SelectionState::ExtendedSelection) {
228 updateSelectionForMouseDownDispatchingSelectStart( 219 updateSelectionForMouseDownDispatchingSelectStart(innerNode, selection,
229 innerNode, selection, CharacterGranularity, 220 CharacterGranularity);
230 HandleVisibility::NotVisible);
231 return false; 221 return false;
232 } 222 }
233 223
234 if (visiblePos.isNull()) { 224 if (visiblePos.isNull()) {
235 updateSelectionForMouseDownDispatchingSelectStart( 225 updateSelectionForMouseDownDispatchingSelectStart(
236 innerNode, VisibleSelectionInFlatTree(), CharacterGranularity, 226 innerNode, VisibleSelectionInFlatTree(), CharacterGranularity);
237 HandleVisibility::NotVisible);
238 return false; 227 return false;
239 } 228 }
240 229
241 bool isHandleVisible = false;
242 if (hasEditableStyle(*innerNode)) {
243 const bool isTextBoxEmpty =
244 createVisibleSelection(SelectionInFlatTree::Builder()
245 .selectAllChildren(*innerNode)
246 .build())
247 .isCaret();
248 const bool notLeftClick = event.event().pointerProperties().button !=
249 WebPointerProperties::Button::Left;
250 if (!isTextBoxEmpty || notLeftClick)
251 isHandleVisible = event.event().fromTouch();
252 }
253
254 updateSelectionForMouseDownDispatchingSelectStart( 230 updateSelectionForMouseDownDispatchingSelectStart(
255 innerNode, 231 innerNode,
256 expandSelectionToRespectUserSelectAll( 232 expandSelectionToRespectUserSelectAll(
257 innerNode, createVisibleSelection( 233 innerNode, createVisibleSelection(
258 SelectionInFlatTree::Builder() 234 SelectionInFlatTree::Builder()
259 .collapse(visiblePos.toPositionWithAffinity()) 235 .collapse(visiblePos.toPositionWithAffinity())
260 .build())), 236 .build())),
261 CharacterGranularity, isHandleVisible ? HandleVisibility::Visible 237 CharacterGranularity);
262 : HandleVisibility::NotVisible);
263 return false; 238 return false;
264 } 239 }
265 240
266 void SelectionController::updateSelectionForMouseDrag( 241 void SelectionController::updateSelectionForMouseDrag(
267 const HitTestResult& hitTestResult, 242 const HitTestResult& hitTestResult,
268 Node* mousePressNode, 243 Node* mousePressNode,
269 const LayoutPoint& dragStartPos, 244 const LayoutPoint& dragStartPos,
270 const IntPoint& lastKnownMousePosition) { 245 const IntPoint& lastKnownMousePosition) {
271 if (!m_mouseDownMayStartSelect) 246 if (!m_mouseDownMayStartSelect)
272 return; 247 return;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // |newSelection|. 357 // |newSelection|.
383 if (selection().granularity() != CharacterGranularity) { 358 if (selection().granularity() != CharacterGranularity) {
384 newSelection = createVisibleSelection( 359 newSelection = createVisibleSelection(
385 SelectionInFlatTree::Builder() 360 SelectionInFlatTree::Builder()
386 .setBaseAndExtent(newSelection.base(), newSelection.extent()) 361 .setBaseAndExtent(newSelection.base(), newSelection.extent())
387 .setGranularity(selection().granularity()) 362 .setGranularity(selection().granularity())
388 .build()); 363 .build());
389 } 364 }
390 365
391 setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(), 366 setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(),
392 AdjustEndpointsAtBidiBoundary, 367 AdjustEndpointsAtBidiBoundary);
393 HandleVisibility::NotVisible);
394 } 368 }
395 369
396 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( 370 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(
397 Node* targetNode, 371 Node* targetNode,
398 const VisibleSelectionInFlatTree& selection, 372 const VisibleSelectionInFlatTree& selection,
399 TextGranularity granularity, 373 TextGranularity granularity) {
400 HandleVisibility handleVisibility) {
401 if (targetNode && targetNode->layoutObject() && 374 if (targetNode && targetNode->layoutObject() &&
402 !targetNode->layoutObject()->isSelectable()) 375 !targetNode->layoutObject()->isSelectable())
403 return false; 376 return false;
404 377
405 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled) 378 if (dispatchSelectStart(targetNode) != DispatchEventResult::NotCanceled)
406 return false; 379 return false;
407 380
408 // |dispatchSelectStart()| can change document hosted by |m_frame|. 381 // |dispatchSelectStart()| can change document hosted by |m_frame|.
409 if (!this->selection().isAvailable()) 382 if (!this->selection().isAvailable())
410 return false; 383 return false;
411 384
412 if (!selection.isValidFor(this->selection().document())) 385 if (!selection.isValidFor(this->selection().document()))
413 return false; 386 return false;
414 387
415 if (selection.isRange()) { 388 if (selection.isRange()) {
416 m_selectionState = SelectionState::ExtendedSelection; 389 m_selectionState = SelectionState::ExtendedSelection;
417 } else { 390 } else {
418 granularity = CharacterGranularity; 391 granularity = CharacterGranularity;
419 m_selectionState = SelectionState::PlacedCaret; 392 m_selectionState = SelectionState::PlacedCaret;
420 } 393 }
421 394
422 setNonDirectionalSelectionIfNeeded(selection, granularity, 395 setNonDirectionalSelectionIfNeeded(selection, granularity,
423 DoNotAdjustEndpoints, handleVisibility); 396 DoNotAdjustEndpoints);
424 397
425 return true; 398 return true;
426 } 399 }
427 400
428 bool SelectionController::selectClosestWordFromHitTestResult( 401 bool SelectionController::selectClosestWordFromHitTestResult(
429 const HitTestResult& result, 402 const HitTestResult& result,
430 AppendTrailingWhitespace appendTrailingWhitespace, 403 AppendTrailingWhitespace appendTrailingWhitespace,
431 SelectInputEventType selectInputEventType) { 404 SelectInputEventType selectInputEventType) {
432 Node* innerNode = result.innerNode(); 405 Node* innerNode = result.innerNode();
433 VisibleSelectionInFlatTree newSelection; 406 VisibleSelectionInFlatTree newSelection;
(...skipping 13 matching lines...) Expand all
447 const VisiblePositionInFlatTree& pos = 420 const VisiblePositionInFlatTree& pos =
448 visiblePositionOfHitTestResult(adjustedHitTestResult); 421 visiblePositionOfHitTestResult(adjustedHitTestResult);
449 if (pos.isNotNull()) { 422 if (pos.isNotNull()) {
450 newSelection = 423 newSelection =
451 createVisibleSelection(SelectionInFlatTree::Builder() 424 createVisibleSelection(SelectionInFlatTree::Builder()
452 .collapse(pos.toPositionWithAffinity()) 425 .collapse(pos.toPositionWithAffinity())
453 .setGranularity(WordGranularity) 426 .setGranularity(WordGranularity)
454 .build()); 427 .build());
455 } 428 }
456 429
457 HandleVisibility visibility = HandleVisibility::NotVisible;
458 if (selectInputEventType == SelectInputEventType::Touch) { 430 if (selectInputEventType == SelectInputEventType::Touch) {
459 // If node doesn't have text except space, tab or line break, do not 431 // If node doesn't have text except space, tab or line break, do not
460 // select that 'empty' area. 432 // select that 'empty' area.
461 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end()); 433 EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end());
462 const String& str = 434 const String& str =
463 plainText(range, hasEditableStyle(*innerNode) 435 plainText(range, hasEditableStyle(*innerNode)
464 ? TextIteratorEmitsObjectReplacementCharacter 436 ? TextIteratorEmitsObjectReplacementCharacter
465 : TextIteratorDefaultBehavior); 437 : TextIteratorDefaultBehavior);
466 if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace()) 438 if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace())
467 return false; 439 return false;
468 440
469 if (newSelection.rootEditableElement() && 441 if (newSelection.rootEditableElement() &&
470 pos.deepEquivalent() == 442 pos.deepEquivalent() ==
471 VisiblePositionInFlatTree::lastPositionInNode( 443 VisiblePositionInFlatTree::lastPositionInNode(
472 newSelection.rootEditableElement()) 444 newSelection.rootEditableElement())
473 .deepEquivalent()) 445 .deepEquivalent())
474 return false; 446 return false;
475
476 visibility = HandleVisibility::Visible;
477 } 447 }
478 448
479 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend) 449 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend)
480 newSelection.appendTrailingWhitespace(); 450 newSelection.appendTrailingWhitespace();
481 451
482 return updateSelectionForMouseDownDispatchingSelectStart( 452 return updateSelectionForMouseDownDispatchingSelectStart(
483 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), 453 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
484 WordGranularity, visibility); 454 WordGranularity);
485 } 455 }
486 456
487 void SelectionController::selectClosestMisspellingFromHitTestResult( 457 void SelectionController::selectClosestMisspellingFromHitTestResult(
488 const HitTestResult& result, 458 const HitTestResult& result,
489 AppendTrailingWhitespace appendTrailingWhitespace) { 459 AppendTrailingWhitespace appendTrailingWhitespace) {
490 Node* innerNode = result.innerNode(); 460 Node* innerNode = result.innerNode();
491 VisibleSelectionInFlatTree newSelection; 461 VisibleSelectionInFlatTree newSelection;
492 462
493 if (!innerNode || !innerNode->layoutObject()) 463 if (!innerNode || !innerNode->layoutObject())
494 return; 464 return;
(...skipping 13 matching lines...) Expand all
508 newSelection = createVisibleSelection( 478 newSelection = createVisibleSelection(
509 SelectionInFlatTree::Builder().collapse(start).extend(end).build()); 479 SelectionInFlatTree::Builder().collapse(start).extend(end).build());
510 } 480 }
511 } 481 }
512 482
513 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend) 483 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend)
514 newSelection.appendTrailingWhitespace(); 484 newSelection.appendTrailingWhitespace();
515 485
516 updateSelectionForMouseDownDispatchingSelectStart( 486 updateSelectionForMouseDownDispatchingSelectStart(
517 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), 487 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
518 WordGranularity, HandleVisibility::NotVisible); 488 WordGranularity);
519 } 489 }
520 490
521 void SelectionController::selectClosestWordFromMouseEvent( 491 void SelectionController::selectClosestWordFromMouseEvent(
522 const MouseEventWithHitTestResults& result) { 492 const MouseEventWithHitTestResults& result) {
523 if (!m_mouseDownMayStartSelect) 493 if (!m_mouseDownMayStartSelect)
524 return; 494 return;
525 495
526 AppendTrailingWhitespace appendTrailingWhitespace = 496 AppendTrailingWhitespace appendTrailingWhitespace =
527 (result.event().clickCount() == 2 && 497 (result.event().clickCount() == 2 &&
528 m_frame->editor().isSelectTrailingWhitespaceEnabled()) 498 m_frame->editor().isSelectTrailingWhitespaceEnabled())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 const VisiblePositionInFlatTree pos = 535 const VisiblePositionInFlatTree pos =
566 visiblePositionOfHitTestResult(result.hitTestResult()); 536 visiblePositionOfHitTestResult(result.hitTestResult());
567 if (pos.isNotNull() && 537 if (pos.isNotNull() &&
568 pos.deepEquivalent().anchorNode()->isDescendantOf(URLElement)) { 538 pos.deepEquivalent().anchorNode()->isDescendantOf(URLElement)) {
569 newSelection = createVisibleSelection( 539 newSelection = createVisibleSelection(
570 SelectionInFlatTree::Builder().selectAllChildren(*URLElement).build()); 540 SelectionInFlatTree::Builder().selectAllChildren(*URLElement).build());
571 } 541 }
572 542
573 updateSelectionForMouseDownDispatchingSelectStart( 543 updateSelectionForMouseDownDispatchingSelectStart(
574 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), 544 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
575 WordGranularity, HandleVisibility::NotVisible); 545 WordGranularity);
576 } 546 }
577 547
578 // TODO(xiaochengh): We should not use reference to return value. 548 // TODO(xiaochengh): We should not use reference to return value.
579 static void adjustEndpointsAtBidiBoundary( 549 static void adjustEndpointsAtBidiBoundary(
580 VisiblePositionInFlatTree& visibleBase, 550 VisiblePositionInFlatTree& visibleBase,
581 VisiblePositionInFlatTree& visibleExtent) { 551 VisiblePositionInFlatTree& visibleExtent) {
582 DCHECK(visibleBase.isValid()); 552 DCHECK(visibleBase.isValid());
583 DCHECK(visibleExtent.isValid()); 553 DCHECK(visibleExtent.isValid());
584 554
585 RenderedPosition base(visibleBase); 555 RenderedPosition base(visibleBase);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 base.rightBoundaryOfBidiRun(extent.bidiLevelOnLeft()))) { 593 base.rightBoundaryOfBidiRun(extent.bidiLevelOnLeft()))) {
624 visibleExtent = createVisiblePosition( 594 visibleExtent = createVisiblePosition(
625 toPositionInFlatTree(extent.positionAtRightBoundaryOfBiDiRun())); 595 toPositionInFlatTree(extent.positionAtRightBoundaryOfBiDiRun()));
626 return; 596 return;
627 } 597 }
628 } 598 }
629 599
630 void SelectionController::setNonDirectionalSelectionIfNeeded( 600 void SelectionController::setNonDirectionalSelectionIfNeeded(
631 const VisibleSelectionInFlatTree& passedNewSelection, 601 const VisibleSelectionInFlatTree& passedNewSelection,
632 TextGranularity granularity, 602 TextGranularity granularity,
633 EndPointsAdjustmentMode endpointsAdjustmentMode, 603 EndPointsAdjustmentMode endpointsAdjustmentMode) {
634 HandleVisibility handleVisibility) {
635 VisibleSelectionInFlatTree newSelection = passedNewSelection; 604 VisibleSelectionInFlatTree newSelection = passedNewSelection;
636 bool isDirectional = 605 bool isDirectional =
637 m_frame->editor().behavior().shouldConsiderSelectionAsDirectional() || 606 m_frame->editor().behavior().shouldConsiderSelectionAsDirectional() ||
638 newSelection.isDirectional(); 607 newSelection.isDirectional();
639 608
640 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 609 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
641 // needs to be audited. See http://crbug.com/590369 for more details. 610 // needs to be audited. See http://crbug.com/590369 for more details.
642 document().updateStyleAndLayoutIgnorePendingStylesheets(); 611 document().updateStyleAndLayoutIgnorePendingStylesheets();
643 612
644 const PositionInFlatTree& basePosition = 613 const PositionInFlatTree& basePosition =
(...skipping 19 matching lines...) Expand all
664 newSelection.setExtent(newExtent); 633 newSelection.setExtent(newExtent);
665 } else if (originalBase.isNotNull()) { 634 } else if (originalBase.isNotNull()) {
666 if (selection().visibleSelection<EditingInFlatTreeStrategy>().base() == 635 if (selection().visibleSelection<EditingInFlatTreeStrategy>().base() ==
667 newSelection.base()) 636 newSelection.base())
668 newSelection.setBase(originalBase); 637 newSelection.setBase(originalBase);
669 m_originalBaseInFlatTree = VisiblePositionInFlatTree(); 638 m_originalBaseInFlatTree = VisiblePositionInFlatTree();
670 } 639 }
671 640
672 // Adjusting base and extent will make newSelection always directional 641 // Adjusting base and extent will make newSelection always directional
673 newSelection.setIsDirectional(isDirectional); 642 newSelection.setIsDirectional(isDirectional);
674 const bool isHandleVisible = handleVisibility == HandleVisibility::Visible; 643 if (selection().visibleSelection<EditingInFlatTreeStrategy>() == newSelection)
675 if (selection().visibleSelection<EditingInFlatTreeStrategy>() ==
676 newSelection &&
677 selection().isHandleVisible() == isHandleVisible)
678 return; 644 return;
679 645
680 const FrameSelection::SetSelectionOptions options = 646 const FrameSelection::SetSelectionOptions options =
681 isHandleVisible 647 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle;
682 ? FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
683 FrameSelection::HandleVisible
684 : FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle;
685
686 selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, 648 selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded,
687 granularity); 649 granularity);
688 } 650 }
689 651
690 void SelectionController::setCaretAtHitTestResult( 652 void SelectionController::setCaretAtHitTestResult(
691 const HitTestResult& hitTestResult) { 653 const HitTestResult& hitTestResult) {
692 Node* innerNode = hitTestResult.innerNode(); 654 Node* innerNode = hitTestResult.innerNode();
693 const VisiblePositionInFlatTree& visibleHitPos = 655 const VisiblePositionInFlatTree& visibleHitPos =
694 visiblePositionOfHitTestResult(hitTestResult); 656 visiblePositionOfHitTestResult(hitTestResult);
695 const VisiblePositionInFlatTree& visiblePos = 657 const VisiblePositionInFlatTree& visiblePos =
696 visibleHitPos.isNull() 658 visibleHitPos.isNull()
697 ? createVisiblePosition( 659 ? createVisiblePosition(
698 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)) 660 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode))
699 : visibleHitPos; 661 : visibleHitPos;
700 662
701 updateSelectionForMouseDownDispatchingSelectStart( 663 updateSelectionForMouseDownDispatchingSelectStart(
702 innerNode, 664 innerNode,
703 expandSelectionToRespectUserSelectAll( 665 expandSelectionToRespectUserSelectAll(
704 innerNode, createVisibleSelection( 666 innerNode, createVisibleSelection(
705 SelectionInFlatTree::Builder() 667 SelectionInFlatTree::Builder()
706 .collapse(visiblePos.toPositionWithAffinity()) 668 .collapse(visiblePos.toPositionWithAffinity())
707 .build())), 669 .build())),
708 CharacterGranularity, HandleVisibility::Visible); 670 CharacterGranularity);
709 } 671 }
710 672
711 bool SelectionController::handleMousePressEventDoubleClick( 673 bool SelectionController::handleMousePressEventDoubleClick(
712 const MouseEventWithHitTestResults& event) { 674 const MouseEventWithHitTestResults& event) {
713 TRACE_EVENT0("blink", 675 TRACE_EVENT0("blink",
714 "SelectionController::handleMousePressEventDoubleClick"); 676 "SelectionController::handleMousePressEventDoubleClick");
715 677
716 if (!selection().isAvailable()) 678 if (!selection().isAvailable())
717 return false; 679 return false;
718 680
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 const VisiblePositionInFlatTree& pos = 723 const VisiblePositionInFlatTree& pos =
762 visiblePositionOfHitTestResult(event.hitTestResult()); 724 visiblePositionOfHitTestResult(event.hitTestResult());
763 if (pos.isNotNull()) { 725 if (pos.isNotNull()) {
764 newSelection = 726 newSelection =
765 createVisibleSelection(SelectionInFlatTree::Builder() 727 createVisibleSelection(SelectionInFlatTree::Builder()
766 .collapse(pos.toPositionWithAffinity()) 728 .collapse(pos.toPositionWithAffinity())
767 .setGranularity(ParagraphGranularity) 729 .setGranularity(ParagraphGranularity)
768 .build()); 730 .build());
769 } 731 }
770 732
771 const bool isHandleVisible =
772 event.event().fromTouch() && newSelection.isRange();
773
774 return updateSelectionForMouseDownDispatchingSelectStart( 733 return updateSelectionForMouseDownDispatchingSelectStart(
775 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), 734 innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
776 ParagraphGranularity, isHandleVisible ? HandleVisibility::Visible 735 ParagraphGranularity);
777 : HandleVisibility::NotVisible);
778 } 736 }
779 737
780 void SelectionController::handleMousePressEvent( 738 void SelectionController::handleMousePressEvent(
781 const MouseEventWithHitTestResults& event) { 739 const MouseEventWithHitTestResults& event) {
782 // If we got the event back, that must mean it wasn't prevented, 740 // If we got the event back, that must mean it wasn't prevented,
783 // so it's allowed to start a drag or selection if it wasn't in a scrollbar. 741 // so it's allowed to start a drag or selection if it wasn't in a scrollbar.
784 m_mouseDownMayStartSelect = 742 m_mouseDownMayStartSelect =
785 (canMouseDownStartSelect(event.innerNode()) || isLinkSelection(event)) && 743 (canMouseDownStartSelect(event.innerNode()) || isLinkSelection(event)) &&
786 !event.scrollbar(); 744 !event.scrollbar();
787 m_mouseDownWasSingleClickInSelection = false; 745 m_mouseDownWasSingleClickInSelection = false;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 return event.event().altKey() && event.isOverLink(); 1018 return event.event().altKey() && event.isOverLink();
1061 } 1019 }
1062 1020
1063 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { 1021 bool isExtendingSelection(const MouseEventWithHitTestResults& event) {
1064 bool isMouseDownOnLinkOrImage = 1022 bool isMouseDownOnLinkOrImage =
1065 event.isOverLink() || event.hitTestResult().image(); 1023 event.isOverLink() || event.hitTestResult().image();
1066 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; 1024 return event.event().shiftKey() && !isMouseDownOnLinkOrImage;
1067 } 1025 }
1068 1026
1069 } // namespace blink 1027 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698