Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Google Inc. | 3 * Copyright (C) 2008 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 DCHECK(dragData); | 449 DCHECK(dragData); |
| 450 Document* doc = m_page->deprecatedLocalMainFrame()->documentAtPoint( | 450 Document* doc = m_page->deprecatedLocalMainFrame()->documentAtPoint( |
| 451 dragData->clientPosition()); | 451 dragData->clientPosition()); |
| 452 | 452 |
| 453 if (doc && | 453 if (doc && |
| 454 (m_didInitiateDrag || doc->isPluginDocument() || hasEditableStyle(*doc))) | 454 (m_didInitiateDrag || doc->isPluginDocument() || hasEditableStyle(*doc))) |
| 455 return DragOperationNone; | 455 return DragOperationNone; |
| 456 return dragOperation(dragData); | 456 return dragOperation(dragData); |
| 457 } | 457 } |
| 458 | 458 |
| 459 // Returns true if node at |point| is editable with populating |dragCaret| and | |
| 460 // |range|, otherwise returns false. | |
| 461 // TODO(yosin): We should return |VisibleSelection| rather than three values. | |
| 459 static bool setSelectionToDragCaret(LocalFrame* frame, | 462 static bool setSelectionToDragCaret(LocalFrame* frame, |
| 460 VisibleSelection& dragCaret, | 463 VisibleSelection& dragCaret, |
| 461 Range*& range, | 464 Range*& range, |
| 462 const IntPoint& point) { | 465 const IntPoint& point) { |
| 463 frame->selection().setSelection(dragCaret); | 466 frame->selection().setSelection(dragCaret); |
| 464 if (frame->selection().isNone()) { | 467 if (frame->selection().isNone()) { |
| 465 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 468 // TODO(editing-dev): The use of |
| 469 // updateStyleAndLayoutIgnorePendingStylesheets | |
| 466 // needs to be audited. See http://crbug.com/590369 for more details. | 470 // needs to be audited. See http://crbug.com/590369 for more details. |
| 471 // |LocalFrame::positinForPoint()| requires clean layout. | |
| 467 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 472 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 473 const PositionWithAffinity& position = frame->positionForPoint(point); | |
| 474 if (!position.isConnected()) | |
|
tkent
2016/10/20 08:05:19
In the old code, what happened if !frame->position
yosin_UTC9
2016/10/20 08:34:00
It makes empty selection since visible position ca
tkent
2016/10/21 01:06:27
Because this code is in |if (frame-selection().isN
yosin_UTC9
2016/10/21 01:23:40
Yes, since we attempt to set selection to none on
| |
| 475 return false; | |
| 468 | 476 |
| 469 dragCaret = createVisibleSelection(frame->positionForPoint(point)); | 477 frame->selection().setSelection( |
| 470 frame->selection().setSelection(dragCaret); | 478 SelectionInDOMTree::Builder().collapse(position).build()); |
| 479 dragCaret = frame->selection().selection(); | |
| 471 range = createRange(dragCaret.toNormalizedEphemeralRange()); | 480 range = createRange(dragCaret.toNormalizedEphemeralRange()); |
| 472 } | 481 } |
| 473 return !frame->selection().isNone() && frame->selection().isContentEditable(); | 482 return !frame->selection().isNone() && frame->selection().isContentEditable(); |
| 474 } | 483 } |
| 475 | 484 |
| 476 DispatchEventResult DragController::dispatchTextInputEventFor( | 485 DispatchEventResult DragController::dispatchTextInputEventFor( |
| 477 LocalFrame* innerFrame, | 486 LocalFrame* innerFrame, |
| 478 DragData* dragData) { | 487 DragData* dragData) { |
| 479 // Layout should be clean due to a hit test performed in |elementUnderMouse|. | 488 // Layout should be clean due to a hit test performed in |elementUnderMouse|. |
| 480 DCHECK(!innerFrame->document()->needsLayoutTreeUpdate()); | 489 DCHECK(!innerFrame->document()->needsLayoutTreeUpdate()); |
| 481 DCHECK(m_page->dragCaretController().hasCaret()); | 490 DCHECK(m_page->dragCaretController().hasCaret()); |
| 482 String text = m_page->dragCaretController().isContentRichlyEditable() | 491 String text = m_page->dragCaretController().isContentRichlyEditable() |
| 483 ? "" | 492 ? "" |
| 484 : dragData->asPlainText(); | 493 : dragData->asPlainText(); |
| 485 Element* target = innerFrame->editor().findEventTargetFrom( | 494 const PositionWithAffinity& caretPosition = |
| 486 createVisibleSelection(m_page->dragCaretController().caretPosition())); | 495 m_page->dragCaretController().caretPosition(); |
| 496 DCHECK(caretPosition.isConnected()) << caretPosition; | |
| 497 Element* target = | |
| 498 innerFrame->editor().findEventTargetFrom(createVisibleSelection( | |
| 499 SelectionInDOMTree::Builder().collapse(caretPosition).build())); | |
| 487 return target->dispatchEvent( | 500 return target->dispatchEvent( |
| 488 TextEvent::createForDrop(innerFrame->domWindow(), text)); | 501 TextEvent::createForDrop(innerFrame->domWindow(), text)); |
| 489 } | 502 } |
| 490 | 503 |
| 491 bool DragController::concludeEditDrag(DragData* dragData) { | 504 bool DragController::concludeEditDrag(DragData* dragData) { |
| 492 DCHECK(dragData); | 505 DCHECK(dragData); |
| 493 | 506 |
| 494 HTMLInputElement* fileInput = m_fileInputElementUnderMouse; | 507 HTMLInputElement* fileInput = m_fileInputElementUnderMouse; |
| 495 if (m_fileInputElementUnderMouse) { | 508 if (m_fileInputElementUnderMouse) { |
| 496 m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false); | 509 m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 if (m_page->dragCaretController().hasCaret()) { | 545 if (m_page->dragCaretController().hasCaret()) { |
| 533 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 546 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 534 // needs to be audited. See http://crbug.com/590369 for more details. | 547 // needs to be audited. See http://crbug.com/590369 for more details. |
| 535 m_page->dragCaretController() | 548 m_page->dragCaretController() |
| 536 .caretPosition() | 549 .caretPosition() |
| 537 .position() | 550 .position() |
| 538 .document() | 551 .document() |
| 539 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 552 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 540 } | 553 } |
| 541 | 554 |
| 542 VisibleSelection dragCaret = | 555 const PositionWithAffinity& caretPosition = |
| 543 createVisibleSelection(m_page->dragCaretController().caretPosition()); | 556 m_page->dragCaretController().caretPosition(); |
| 557 if (!caretPosition.isConnected()) { | |
| 558 // "editing/pasteboard/drop-text-events-sideeffect-crash.html" and | |
| 559 // "editing/pasteboard/drop-text-events-sideeffect.html" reach here. | |
| 560 m_page->dragCaretController().clear(); | |
| 561 return false; | |
| 562 } | |
| 563 VisibleSelection dragCaret = createVisibleSelection( | |
| 564 SelectionInDOMTree::Builder().collapse(caretPosition).build()); | |
| 544 m_page->dragCaretController().clear(); | 565 m_page->dragCaretController().clear(); |
| 545 // |innerFrame| can be removed by event handler called by | 566 // |innerFrame| can be removed by event handler called by |
| 546 // |dispatchTextInputEventFor()|. | 567 // |dispatchTextInputEventFor()|. |
| 547 if (!innerFrame->selection().isAvailable()) { | 568 if (!innerFrame->selection().isAvailable()) { |
| 548 // "editing/pasteboard/drop-text-events-sideeffect-crash.html" reaches | 569 // "editing/pasteboard/drop-text-events-sideeffect-crash.html" reaches |
| 549 // here. | 570 // here. |
| 550 return false; | 571 return false; |
| 551 } | 572 } |
| 552 Range* range = createRange(dragCaret.toNormalizedEphemeralRange()); | 573 Range* range = createRange(dragCaret.toNormalizedEphemeralRange()); |
| 553 Element* rootEditableElement = innerFrame->selection().rootEditableElement(); | 574 Element* rootEditableElement = innerFrame->selection().rootEditableElement(); |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1187 } | 1208 } |
| 1188 | 1209 |
| 1189 DEFINE_TRACE(DragController) { | 1210 DEFINE_TRACE(DragController) { |
| 1190 visitor->trace(m_page); | 1211 visitor->trace(m_page); |
| 1191 visitor->trace(m_documentUnderMouse); | 1212 visitor->trace(m_documentUnderMouse); |
| 1192 visitor->trace(m_dragInitiator); | 1213 visitor->trace(m_dragInitiator); |
| 1193 visitor->trace(m_fileInputElementUnderMouse); | 1214 visitor->trace(m_fileInputElementUnderMouse); |
| 1194 } | 1215 } |
| 1195 | 1216 |
| 1196 } // namespace blink | 1217 } // namespace blink |
| OLD | NEW |