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 24 matching lines...) Expand all Loading... |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/DocumentFragment.h" | 36 #include "core/dom/DocumentFragment.h" |
37 #include "core/dom/Element.h" | 37 #include "core/dom/Element.h" |
38 #include "core/dom/Node.h" | 38 #include "core/dom/Node.h" |
39 #include "core/dom/Text.h" | 39 #include "core/dom/Text.h" |
40 #include "core/dom/shadow/ShadowRoot.h" | 40 #include "core/dom/shadow/ShadowRoot.h" |
41 #include "core/editing/DragCaretController.h" | 41 #include "core/editing/DragCaretController.h" |
42 #include "core/editing/EditingUtilities.h" | 42 #include "core/editing/EditingUtilities.h" |
43 #include "core/editing/Editor.h" | 43 #include "core/editing/Editor.h" |
44 #include "core/editing/FrameSelection.h" | 44 #include "core/editing/FrameSelection.h" |
45 #include "core/editing/commands/MoveSelectionCommand.h" | |
46 #include "core/editing/commands/ReplaceSelectionCommand.h" | |
47 #include "core/editing/serializers/Serialization.h" | 45 #include "core/editing/serializers/Serialization.h" |
48 #include "core/events/TextEvent.h" | 46 #include "core/events/TextEvent.h" |
49 #include "core/fetch/ImageResource.h" | 47 #include "core/fetch/ImageResource.h" |
50 #include "core/fetch/ResourceFetcher.h" | 48 #include "core/fetch/ResourceFetcher.h" |
51 #include "core/frame/FrameView.h" | 49 #include "core/frame/FrameView.h" |
52 #include "core/frame/LocalFrame.h" | 50 #include "core/frame/LocalFrame.h" |
53 #include "core/frame/Settings.h" | 51 #include "core/frame/Settings.h" |
54 #include "core/html/HTMLAnchorElement.h" | 52 #include "core/html/HTMLAnchorElement.h" |
55 #include "core/html/HTMLFormElement.h" | 53 #include "core/html/HTMLFormElement.h" |
56 #include "core/html/HTMLInputElement.h" | 54 #include "core/html/HTMLInputElement.h" |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 bool chosePlainText = false; | 494 bool chosePlainText = false; |
497 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag
Data(dragData, innerFrame.get(), range, true, chosePlainText); | 495 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag
Data(dragData, innerFrame.get(), range, true, chosePlainText); |
498 if (!fragment) | 496 if (!fragment) |
499 return false; | 497 return false; |
500 | 498 |
501 if (dragIsMove(innerFrame->selection(), dragData)) { | 499 if (dragIsMove(innerFrame->selection(), dragData)) { |
502 // NSTextView behavior is to always smart delete on moving a selecti
on, | 500 // NSTextView behavior is to always smart delete on moving a selecti
on, |
503 // but only to smart insert if the selection granularity is word gra
nularity. | 501 // but only to smart insert if the selection granularity is word gra
nularity. |
504 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); | 502 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); |
505 bool smartInsert = smartDelete && innerFrame->selection().granularit
y() == WordGranularity && dragData->canSmartReplace(); | 503 bool smartInsert = smartDelete && innerFrame->selection().granularit
y() == WordGranularity && dragData->canSmartReplace(); |
506 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert
, smartDelete)->apply(); | 504 innerFrame->editor().moveSelectionAfterDragging(fragment, dragCaret.
base(), smartInsert, smartDelete); |
507 } else { | 505 } else { |
508 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, poin
t)) { | 506 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, poin
t)) { |
509 ReplaceSelectionCommand::CommandOptions options = ReplaceSelecti
onCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting; | |
510 if (dragData->canSmartReplace()) | |
511 options |= ReplaceSelectionCommand::SmartReplace; | |
512 if (chosePlainText) | |
513 options |= ReplaceSelectionCommand::MatchStyle; | |
514 ASSERT(m_documentUnderMouse); | 507 ASSERT(m_documentUnderMouse); |
515 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), fra
gment, options, EditActionDrag)->apply(); | 508 m_documentUnderMouse->frame()->editor().replaceSelectionAfterDra
gging(fragment, dragData->canSmartReplace(), chosePlainText); |
516 } | 509 } |
517 } | 510 } |
518 } else { | 511 } else { |
519 String text = dragData->asPlainText(); | 512 String text = dragData->asPlainText(); |
520 if (text.isEmpty()) | 513 if (text.isEmpty()) |
521 return false; | 514 return false; |
522 | 515 |
523 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point))
{ | 516 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point))
{ |
| 517 const bool canSmartReplace = false; |
| 518 const bool chosePlainText = true; |
524 ASSERT(m_documentUnderMouse); | 519 ASSERT(m_documentUnderMouse); |
525 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), createF
ragmentFromText(EphemeralRange(range.get()), text), ReplaceSelectionCommand::Se
lectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand:
:PreventNesting, EditActionDrag)->apply(); | 520 m_documentUnderMouse->frame()->editor().replaceSelectionAfterDraggin
g(createFragmentFromText(EphemeralRange(range.get()), text), canSmartReplace, ch
osePlainText); |
526 } | 521 } |
527 } | 522 } |
528 | 523 |
529 if (rootEditableElement) { | 524 if (rootEditableElement) { |
530 if (LocalFrame* frame = rootEditableElement->document().frame()) | 525 if (LocalFrame* frame = rootEditableElement->document().frame()) |
531 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita
bleElement.get()); | 526 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita
bleElement.get()); |
532 } | 527 } |
533 | 528 |
534 return true; | 529 return true; |
535 } | 530 } |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 | 958 |
964 DEFINE_TRACE(DragController) | 959 DEFINE_TRACE(DragController) |
965 { | 960 { |
966 visitor->trace(m_page); | 961 visitor->trace(m_page); |
967 visitor->trace(m_documentUnderMouse); | 962 visitor->trace(m_documentUnderMouse); |
968 visitor->trace(m_dragInitiator); | 963 visitor->trace(m_dragInitiator); |
969 visitor->trace(m_fileInputElementUnderMouse); | 964 visitor->trace(m_fileInputElementUnderMouse); |
970 } | 965 } |
971 | 966 |
972 } // namespace blink | 967 } // namespace blink |
OLD | NEW |