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

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

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

Powered by Google App Engine
This is Rietveld 408576698