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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 return DragOperationNone; | 453 return DragOperationNone; |
454 return dragOperation(dragData); | 454 return dragOperation(dragData); |
455 } | 455 } |
456 | 456 |
457 static bool setSelectionToDragCaret(LocalFrame* frame, | 457 static bool setSelectionToDragCaret(LocalFrame* frame, |
458 VisibleSelection& dragCaret, | 458 VisibleSelection& dragCaret, |
459 Range*& range, | 459 Range*& range, |
460 const IntPoint& point) { | 460 const IntPoint& point) { |
461 frame->selection().setSelection(dragCaret); | 461 frame->selection().setSelection(dragCaret); |
462 if (frame->selection().isNone()) { | 462 if (frame->selection().isNone()) { |
463 dragCaret = | 463 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
464 createVisibleSelectionDeprecated(frame->positionForPoint(point)); | 464 // needs to be audited. See http://crbug.com/590369 for more details. |
| 465 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 466 |
| 467 dragCaret = createVisibleSelection(frame->positionForPoint(point)); |
465 frame->selection().setSelection(dragCaret); | 468 frame->selection().setSelection(dragCaret); |
466 range = createRange(dragCaret.toNormalizedEphemeralRange()); | 469 range = createRange(dragCaret.toNormalizedEphemeralRange()); |
467 } | 470 } |
468 return !frame->selection().isNone() && frame->selection().isContentEditable(); | 471 return !frame->selection().isNone() && frame->selection().isContentEditable(); |
469 } | 472 } |
470 | 473 |
471 DispatchEventResult DragController::dispatchTextInputEventFor( | 474 DispatchEventResult DragController::dispatchTextInputEventFor( |
472 LocalFrame* innerFrame, | 475 LocalFrame* innerFrame, |
473 DragData* dragData) { | 476 DragData* dragData) { |
| 477 // Layout should be clean due to a hit test performed in |elementUnderMouse|. |
| 478 DCHECK(!innerFrame->document()->needsLayoutTreeUpdate()); |
474 ASSERT(m_page->dragCaretController().hasCaret()); | 479 ASSERT(m_page->dragCaretController().hasCaret()); |
475 String text = m_page->dragCaretController().isContentRichlyEditable() | 480 String text = m_page->dragCaretController().isContentRichlyEditable() |
476 ? "" | 481 ? "" |
477 : dragData->asPlainText(); | 482 : dragData->asPlainText(); |
478 Element* target = | 483 Element* target = innerFrame->editor().findEventTargetFrom( |
479 innerFrame->editor().findEventTargetFrom(createVisibleSelectionDeprecated( | 484 createVisibleSelection(m_page->dragCaretController().caretPosition())); |
480 m_page->dragCaretController().caretPosition())); | |
481 return target->dispatchEvent( | 485 return target->dispatchEvent( |
482 TextEvent::createForDrop(innerFrame->domWindow(), text)); | 486 TextEvent::createForDrop(innerFrame->domWindow(), text)); |
483 } | 487 } |
484 | 488 |
485 bool DragController::concludeEditDrag(DragData* dragData) { | 489 bool DragController::concludeEditDrag(DragData* dragData) { |
486 ASSERT(dragData); | 490 ASSERT(dragData); |
487 | 491 |
488 HTMLInputElement* fileInput = m_fileInputElementUnderMouse; | 492 HTMLInputElement* fileInput = m_fileInputElementUnderMouse; |
489 if (m_fileInputElementUnderMouse) { | 493 if (m_fileInputElementUnderMouse) { |
490 m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false); | 494 m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false); |
(...skipping 24 matching lines...) Expand all Loading... |
515 return false; | 519 return false; |
516 | 520 |
517 return fileInput->receiveDroppedFiles(dragData); | 521 return fileInput->receiveDroppedFiles(dragData); |
518 } | 522 } |
519 | 523 |
520 if (!m_page->dragController().canProcessDrag(dragData)) { | 524 if (!m_page->dragController().canProcessDrag(dragData)) { |
521 m_page->dragCaretController().clear(); | 525 m_page->dragCaretController().clear(); |
522 return false; | 526 return false; |
523 } | 527 } |
524 | 528 |
525 VisibleSelection dragCaret = createVisibleSelectionDeprecated( | 529 if (m_page->dragCaretController().hasCaret()) { |
526 m_page->dragCaretController().caretPosition()); | 530 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 531 // needs to be audited. See http://crbug.com/590369 for more details. |
| 532 m_page->dragCaretController() |
| 533 .caretPosition() |
| 534 .position() |
| 535 .document() |
| 536 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 537 } |
| 538 |
| 539 VisibleSelection dragCaret = |
| 540 createVisibleSelection(m_page->dragCaretController().caretPosition()); |
527 m_page->dragCaretController().clear(); | 541 m_page->dragCaretController().clear(); |
528 // |innerFrame| can be removed by event handler called by | 542 // |innerFrame| can be removed by event handler called by |
529 // |dispatchTextInputEventFor()|. | 543 // |dispatchTextInputEventFor()|. |
530 if (!innerFrame->selection().isAvailable()) { | 544 if (!innerFrame->selection().isAvailable()) { |
531 // "editing/pasteboard/drop-text-events-sideeffect-crash.html" reaches | 545 // "editing/pasteboard/drop-text-events-sideeffect-crash.html" reaches |
532 // here. | 546 // here. |
533 return false; | 547 return false; |
534 } | 548 } |
535 Range* range = createRange(dragCaret.toNormalizedEphemeralRange()); | 549 Range* range = createRange(dragCaret.toNormalizedEphemeralRange()); |
536 Element* rootEditableElement = innerFrame->selection().rootEditableElement(); | 550 Element* rootEditableElement = innerFrame->selection().rootEditableElement(); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 DataTransfer* dataTransfer, | 794 DataTransfer* dataTransfer, |
781 Element* node, | 795 Element* node, |
782 const KURL& linkURL, | 796 const KURL& linkURL, |
783 const KURL& imageURL, | 797 const KURL& imageURL, |
784 const String& label) { | 798 const String& label) { |
785 node->document().updateStyleAndLayoutTree(); | 799 node->document().updateStyleAndLayoutTree(); |
786 if (hasRichlyEditableStyle(*node)) { | 800 if (hasRichlyEditableStyle(*node)) { |
787 Range* range = source->document()->createRange(); | 801 Range* range = source->document()->createRange(); |
788 range->selectNode(node, ASSERT_NO_EXCEPTION); | 802 range->selectNode(node, ASSERT_NO_EXCEPTION); |
789 source->selection().setSelection( | 803 source->selection().setSelection( |
790 createVisibleSelectionDeprecated(EphemeralRange(range))); | 804 createVisibleSelection(EphemeralRange(range))); |
791 } | 805 } |
792 dataTransfer->declareAndWriteDragImage( | 806 dataTransfer->declareAndWriteDragImage( |
793 node, !linkURL.isEmpty() ? linkURL : imageURL, label); | 807 node, !linkURL.isEmpty() ? linkURL : imageURL, label); |
794 } | 808 } |
795 | 809 |
796 bool DragController::populateDragDataTransfer(LocalFrame* src, | 810 bool DragController::populateDragDataTransfer(LocalFrame* src, |
797 const DragState& state, | 811 const DragState& state, |
798 const IntPoint& dragOrigin) { | 812 const IntPoint& dragOrigin) { |
799 ASSERT(dragTypeIsValid(state.m_dragType)); | 813 ASSERT(dragTypeIsValid(state.m_dragType)); |
800 ASSERT(src); | 814 ASSERT(src); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 } | 1131 } |
1118 | 1132 |
1119 DEFINE_TRACE(DragController) { | 1133 DEFINE_TRACE(DragController) { |
1120 visitor->trace(m_page); | 1134 visitor->trace(m_page); |
1121 visitor->trace(m_documentUnderMouse); | 1135 visitor->trace(m_documentUnderMouse); |
1122 visitor->trace(m_dragInitiator); | 1136 visitor->trace(m_dragInitiator); |
1123 visitor->trace(m_fileInputElementUnderMouse); | 1137 visitor->trace(m_fileInputElementUnderMouse); |
1124 } | 1138 } |
1125 | 1139 |
1126 } // namespace blink | 1140 } // namespace blink |
OLD | NEW |