PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; if (::IsClipboardFormatAvailable(HTMLClipboardFormat) && ::OpenClipboard(m_owner)) { // get data off of clipboard HANDLE cbData = ::GetClipboardData(HTMLClipboardFormat); if (cbData) { SIZE_T dataSize = ::GlobalSize(cbData); String cf_html(UTF8Encoding().decode((char*)GlobalLock(cbData), dataSize)); GlobalUnlock(cbData); CloseClipboard(); PassRefPtr<DocumentFragment> fragment = fragmentFromCF_HTML(frame->document(), cf_html); if (fragment) return fragment; } else CloseClipboard(); } if (allowPlainText && IsClipboardFormatAvailable(CF_UNICODETEXT)) { chosePlainText = true; if (OpenClipboard(m_owner)) { HANDLE cbData = GetClipboardData(CF_UNICODETEXT); if (cbData) { UChar* buffer = (UChar*)GlobalLock(cbData); String str(buffer); GlobalUnlock(cbData); CloseClipboard(); RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), str); if (fragment) return fragment.release(); } else CloseClipboard(); } } if (allowPlainText && ::IsClipboardFormatAvailable(CF_TEXT)) { chosePlainText = true; if (::OpenClipboard(m_owner)) { HANDLE cbData = ::GetClipboardData(CF_TEXT); if (cbData) { char* buffer = (char*)GlobalLock(cbData); String str(buffer); GlobalUnlock(cbData); CloseClipboard(); RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), str); if (fragment) return fragment.release(); } else CloseClipboard(); } } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { LOGD("documentFragment"); chosePlainText = false; String dataFormat = "HTML"; String imageFormat = "IMAGE"; String markup; KURL srcURL; markup = android::getHTML(); if(!markup.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), markup, srcURL, FragmentScriptingNotAllowed); if (fragment) return fragment.release(); } else if (allowPlainText) { WTF::String markup = android::getText();//ChromiumBridge::clipboardReadPlainText(buffer); if (!markup.isEmpty()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), markup); if (fragment) return fragment.release(); } } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { RefPtr<DocumentFragment> fragment = 0; if (wxTheClipboard->Open()) { #if wxCHECK_VERSION(2, 9, 4) if (wxTheClipboard->IsSupported(wxDF_HTML)) { wxHTMLDataObject data; wxTheClipboard->GetData(data); chosePlainText = false; fragment = createFragmentFromMarkup(frame->document(), data.GetHTML(), "", DisallowScriptingContent); } else #endif { if (allowPlainText && wxTheClipboard->IsSupported( wxDF_TEXT )) { wxTextDataObject data; wxTheClipboard->GetData( data ); chosePlainText = true; fragment = createFragmentFromText(context.get(), data.GetText()); } } wxTheClipboard->Close(); } if (fragment) return fragment.release(); return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { #ifndef QT_NO_CLIPBOARD const QMimeData* mimeData = QGuiApplication::clipboard()->mimeData( m_selectionMode ? QClipboard::Selection : QClipboard::Clipboard); chosePlainText = false; if (mimeData->hasHtml()) { QString html = mimeData->html(); if (!html.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "", DisallowScriptingAndPluginContentIfNeeded); if (fragment) return fragment.release(); } } if (allowPlainText && mimeData->hasText()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), mimeData->text()); if (fragment) return fragment.release(); } #endif return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { GtkClipboard* clipboard = PasteboardHelper::clipboardForFrame(frame); ASSERT(clipboard); DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); ASSERT(dataObject); PasteboardHelper::helper()->getClipboardContents(clipboard); if (dataObject->hasMarkup()) { chosePlainText = false; String markup(dataObject->markup()); if (!markup.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), markup, ""); if (fragment) return fragment.release(); } } if (!allowPlainText || !dataObject->hasText()) return 0; chosePlainText = true; String text(dataObject->text()); RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), text); if (fragment) return fragment.release(); return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { GdkAtom textHtml = gdk_atom_intern_static_string("text/html"); GtkClipboard* clipboard = m_helper->getCurrentTarget(frame); chosePlainText = false; if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, textHtml)) { ASSERT(data->data); String html = String::fromUTF8(reinterpret_cast<gchar*>(data->data), data->length * data->format / 8); gtk_selection_data_free(data); if (!html.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, ""); if (fragment) return fragment.release(); } } if (!allowPlainText) return 0; if (gchar* utf8 = gtk_clipboard_wait_for_text(clipboard)) { String text = String::fromUTF8(utf8); g_free(utf8); chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), text); if (fragment) return fragment.release(); } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; // Note: We are able to check if the format exists prior to reading but the check & the early return // path of get_clipboard_data are the exact same, so just use get_clipboard_data and validate the // return value to determine if the data was present. String html = BlackBerry::Platform::Clipboard::readHTML(); RefPtr<DocumentFragment> fragment; if (!html.isEmpty()) { String url = BlackBerry::Platform::Clipboard::readURL(); if (fragment = createFragmentFromMarkup(frame->document(), html, url, DisallowScriptingAndPluginContentIfNeeded)) return fragment.release(); } if (!allowPlainText) return 0; String text = BlackBerry::Platform::Clipboard::readPlainText(); if (fragment = createFragmentFromText(context.get(), text)) { chosePlainText = true; return fragment.release(); } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; WebKit::WebClipboard::Buffer buffer = m_selectionMode ? WebKit::WebClipboard::BufferSelection : WebKit::WebClipboard::BufferStandard; if (WebKit::Platform::current()->clipboard()->isFormatAvailable(WebKit::WebClipboard::FormatHTML, buffer)) { WebKit::WebString markup; unsigned fragmentStart = 0; unsigned fragmentEnd = 0; WebKit::WebURL url; markup = WebKit::Platform::current()->clipboard()->readHTML(buffer, &url, &fragmentStart, &fragmentEnd); if (!markup.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkupWithContext(frame->document(), markup, fragmentStart, fragmentEnd, KURL(url), DisallowScriptingContent); if (fragment) return fragment.release(); } } if (allowPlainText) { String markup = WebKit::Platform::current()->clipboard()->readPlainText(buffer); if (!markup.isEmpty()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), markup); if (fragment) return fragment.release(); } } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame& frame, Range& context, bool allowPlainText, bool& chosePlainText) { if (m_gtkClipboard) PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_gtkClipboard); chosePlainText = false; if (m_dataObject->hasMarkup()) { if (frame.document()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(*frame.document(), m_dataObject->markup(), emptyString(), DisallowScriptingAndPluginContent); if (fragment) return fragment.release(); } } if (!allowPlainText) return 0; if (m_dataObject->hasText()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context, m_dataObject->text()); if (fragment) return fragment.release(); } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; if (ChromiumBridge::clipboardIsFormatAvailable(PasteboardPrivate::HTMLFormat)) { String markup; KURL srcURL; ChromiumBridge::clipboardReadHTML(&markup, &srcURL); RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), markup, srcURL); if (fragment) return fragment.release(); } if (allowPlainText) { String markup = ChromiumBridge::clipboardReadPlainText(); if (!markup.isEmpty()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), markup); if (fragment) return fragment.release(); } } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; PasteboardPrivate::ClipboardBuffer buffer = m_selectionMode ? PasteboardPrivate::SelectionBuffer : PasteboardPrivate::StandardBuffer; if (ChromiumBridge::clipboardIsFormatAvailable(PasteboardPrivate::HTMLFormat, buffer)) { String markup; KURL srcURL; ChromiumBridge::clipboardReadHTML(buffer, &markup, &srcURL); RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), markup, srcURL, FragmentScriptingNotAllowed); if (fragment) return fragment.release(); } if (allowPlainText) { String markup = ChromiumBridge::clipboardReadPlainText(buffer); if (!markup.isEmpty()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), markup); if (fragment) return fragment.release(); } } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper(); GtkClipboard* clipboard = helper->getCurrentClipboard(frame); DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); helper->getClipboardContents(clipboard); chosePlainText = false; if (dataObject->hasMarkup()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), dataObject->markup(), "", FragmentScriptingNotAllowed); if (fragment) return fragment.release(); } if (!allowPlainText) return 0; if (dataObject->hasText()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), dataObject->text()); if (fragment) return fragment.release(); } return 0; }
static PassRefPtr<DocumentFragment> createFragmentFromPasteboardData(Pasteboard& pasteboard, Frame& frame, Range& range, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; Vector<String> types = pasteboard.types(); if (types.isEmpty()) return nullptr; if (types.contains("text/html;charset=utf-8") && frame.document()) { String markup = pasteboard.readString("text/html;charset=utf-8"); if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(*frame.document(), markup, emptyString(), DisallowScriptingAndPluginContent)) return fragment.release(); } if (!allowPlainText) return nullptr; if (types.contains("text/plain;charset=utf-8")) { chosePlainText = true; if (RefPtr<DocumentFragment> fragment = createFragmentFromText(range, pasteboard.readString("text/plain;charset=utf-8"))) return fragment.release(); } return nullptr; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; PasteboardPrivate::ClipboardBuffer buffer = m_selectionMode ? PasteboardPrivate::SelectionBuffer : PasteboardPrivate::StandardBuffer; if (PlatformSupport::clipboardIsFormatAvailable(PasteboardPrivate::HTMLFormat, buffer)) { String markup; KURL srcURL; unsigned fragmentStart = 0; unsigned fragmentEnd = 0; PlatformSupport::clipboardReadHTML(buffer, &markup, &srcURL, &fragmentStart, &fragmentEnd); if (!markup.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkupWithContext(frame->document(), markup, fragmentStart, fragmentEnd, srcURL, DisallowScriptingContent); if (fragment) return fragment.release(); } } if (allowPlainText) { String markup = PlatformSupport::clipboardReadPlainText(buffer); if (!markup.isEmpty()) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), markup); if (fragment) return fragment.release(); } } return 0; }
static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragData, RefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { ASSERT(dragData); chosePlainText = false; Document* document = context->ownerDocument(); ASSERT(document); if (document && dragData->containsCompatibleContent()) { if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(document)) return fragment; if (dragData->containsURL()) { String title; String url = dragData->asURL(&title); if (!url.isEmpty()) { RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(document); anchor->setHref(url); ExceptionCode ec; RefPtr<Node> anchorText = document->createTextNode(title); anchor->appendChild(anchorText, ec); RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); fragment->appendChild(anchor, ec); return fragment.get(); } } } if (allowPlainText && dragData->containsPlainText()) { chosePlainText = true; return createFragmentFromText(context.get(), dragData->asPlainText()).get(); } return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { RefPtr<DocumentFragment> fragment = 0; if (wxTheClipboard->Open()) { if (allowPlainText && wxTheClipboard->IsSupported( wxDF_TEXT )) { wxTextDataObject data; wxTheClipboard->GetData( data ); chosePlainText = true; fragment = createFragmentFromText(context.get(), data.GetText()); } wxTheClipboard->Close(); } if (fragment) return fragment.release(); return 0; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; AutoClipboardLocker locker(be_clipboard); if (!locker.isLocked()) return 0; BMessage* data = be_clipboard->Data(); if (!data) return 0; const char* buffer = 0; ssize_t bufferLength; if (data->FindData("text/html", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK) { RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plain", "UTF-8", true); String html = decoder->decode(buffer, bufferLength); html += decoder->flush(); if (!html.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "", DisallowScriptingContent); if (fragment) return fragment.release(); } } if (!allowPlainText) return 0; if (data->FindData("text/plain", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK) { BString plainText(buffer, bufferLength); chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), plainText); if (fragment) return fragment.release(); } return 0; }
static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragData, Frame* frame, RefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { ASSERT(dragData); chosePlainText = false; Document* document = context->ownerDocument(); ASSERT(document); if (document && dragData->containsCompatibleContent()) { if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(frame, context, allowPlainText, chosePlainText)) return fragment; if (dragData->containsURL(frame, DragData::DoNotConvertFilenames)) { String title; String url = dragData->asURL(frame, DragData::DoNotConvertFilenames, &title); if (!url.isEmpty()) { RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(document); anchor->setHref(url); if (title.isEmpty()) { // Try the plain text first because the url might be normalized or escaped. if (dragData->containsPlainText()) title = dragData->asPlainText(frame); if (title.isEmpty()) title = url; } RefPtr<Node> anchorText = document->createTextNode(title); ExceptionCode ec; anchor->appendChild(anchorText, ec); RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); fragment->appendChild(anchor, ec); return fragment.get(); } } } if (allowPlainText && dragData->containsPlainText()) { chosePlainText = true; return createFragmentFromText(context.get(), dragData->asPlainText(frame)).get(); } return 0; }
static RefPtr<DocumentFragment> createFragmentFromPasteboardData(Pasteboard& pasteboard, Frame& frame, Range& range, bool allowPlainText, bool& chosePlainText) { chosePlainText = false; if (!pasteboard.hasData()) return nullptr; DataObjectGtk* dataObject = pasteboard.dataObject(); if (dataObject->hasMarkup() && frame.document()) return createFragmentFromMarkup(*frame.document(), dataObject->markup(), emptyString(), DisallowScriptingAndPluginContent); if (!allowPlainText) return nullptr; if (dataObject->hasText()) { chosePlainText = true; return createFragmentFromText(range, dataObject->text()); } return nullptr; }
void SpellingCorrectionCommand::doApply() { m_corrected = plainText(m_rangeToBeCorrected.get()); if (!m_corrected.length()) return; if (!frame().selection().shouldChangeSelection(m_selectionToBeCorrected)) return; if (!m_rangeToBeCorrected) return; RefPtr<DocumentFragment> fragment = createFragmentFromText(*m_rangeToBeCorrected, m_correction); if (!fragment) return; applyCommandToComposite(SetSelectionCommand::create(m_selectionToBeCorrected, FrameSelection::defaultSetSelectionOptions() | FrameSelection::SpellCorrectionTriggered)); #if USE(AUTOCORRECTION_PANEL) applyCommandToComposite(SpellingCorrectionRecordUndoCommand::create(document(), m_corrected, m_correction)); #endif applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment.release(), ReplaceSelectionCommand::MatchStyle, EditActionPaste)); }
bool DragController::concludeEditDrag(DragData* dragData) { ASSERT(dragData); RefPtr<HTMLInputElement> fileInput = m_fileInputElementUnderMouse; if (m_fileInputElementUnderMouse) { m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false); m_fileInputElementUnderMouse = 0; } if (!m_documentUnderMouse) return false; IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->clientPosition()); Element* element = elementUnderMouse(m_documentUnderMouse.get(), point); if (!element) return false; Frame* innerFrame = element->ownerDocument()->frame(); ASSERT(innerFrame); if (m_page->dragCaretController()->hasCaret() && !dispatchTextInputEventFor(innerFrame, dragData)) return true; if (dragData->containsColor()) { Color color = dragData->asColor(); if (!color.isValid()) return false; RefPtr<Range> innerRange = innerFrame->selection()->toNormalizedRange(); RefPtr<StylePropertySet> style = StylePropertySet::create(); style->setProperty(CSSPropertyColor, color.serialized(), false); if (!innerFrame->editor()->shouldApplyStyle(style.get(), innerRange.get())) return false; m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); innerFrame->editor()->applyStyle(style.get(), EditActionSetColor); return true; } if (dragData->containsFiles() && fileInput) { // fileInput should be the element we hit tested for, unless it was made // display:none in a drop event handler. ASSERT(fileInput == element || !fileInput->renderer()); if (fileInput->disabled()) return false; Vector<String> filenames; dragData->asFilenames(filenames); if (filenames.isEmpty()) return false; fileInput->receiveDroppedFiles(filenames); m_client->willPerformDragDestinationAction(DragDestinationActionUpload, dragData); return true; } if (!m_page->dragController()->canProcessDrag(dragData)) { m_page->dragCaretController()->clear(); return false; } VisibleSelection dragCaret = m_page->dragCaretController()->caretPosition(); m_page->dragCaretController()->clear(); RefPtr<Range> range = dragCaret.toNormalizedRange(); RefPtr<Element> rootEditableElement = innerFrame->selection()->rootEditableElement(); // For range to be null a WebKit client must have done something bad while // manually controlling drag behaviour if (!range) return false; CachedResourceLoader* cachedResourceLoader = range->ownerDocument()->cachedResourceLoader(); ResourceCacheValidationSuppressor validationSuppressor(cachedResourceLoader); if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRichlyEditable()) { bool chosePlainText = false; RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, innerFrame, range, true, chosePlainText); if (!fragment || !innerFrame->editor()->shouldInsertFragment(fragment, range, EditorInsertActionDropped)) { return false; } m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); if (dragIsMove(innerFrame->selection(), dragData)) { // NSTextView behavior is to always smart delete on moving a selection, // but only to smart insert if the selection granularity is word granularity. bool smartDelete = innerFrame->editor()->smartInsertDeleteEnabled(); bool smartInsert = smartDelete && innerFrame->selection()->granularity() == WordGranularity && dragData->canSmartReplace(); applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert, smartDelete)); } else { if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting; if (dragData->canSmartReplace()) options |= ReplaceSelectionCommand::SmartReplace; if (chosePlainText) options |= ReplaceSelectionCommand::MatchStyle; applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), fragment, options)); } } } else { String text = dragData->asPlainText(innerFrame); if (text.isEmpty() || !innerFrame->editor()->shouldInsertText(text, range.get(), EditorInsertActionDropped)) { return false; } m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), createFragmentFromText(range.get(), text), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting)); } if (rootEditableElement) { if (Frame* frame = rootEditableElement->document()->frame()) frame->eventHandler()->updateDragStateAfterEditDragIfNeeded(rootEditableElement.get()); } return true; }
bool DragController::concludeEditDrag(DragData* dragData) { ASSERT(dragData); ASSERT(!m_isHandlingDrag); if (!m_documentUnderMouse) return false; IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->clientPosition()); Element* element = elementUnderMouse(m_documentUnderMouse, point); Frame* innerFrame = element->ownerDocument()->frame(); ASSERT(innerFrame); if (dragData->containsColor()) { Color color = dragData->asColor(); if (!color.isValid()) return false; if (!innerFrame) return false; RefPtr<Range> innerRange = innerFrame->selection()->toNormalizedRange(); RefPtr<CSSStyleDeclaration> style = m_documentUnderMouse->createCSSStyleDeclaration(); ExceptionCode ec; style->setProperty("color", color.name(), ec); if (!innerFrame->editor()->shouldApplyStyle(style.get(), innerRange.get())) return false; m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); innerFrame->editor()->applyStyle(style.get(), EditActionSetColor); return true; } if (!m_page->dragController()->canProcessDrag(dragData)) { m_page->dragCaretController()->clear(); return false; } if (HTMLInputElement* fileInput = asFileInput(element)) { if (!fileInput->isEnabledFormControl()) return false; if (!dragData->containsFiles()) return false; Vector<String> filenames; dragData->asFilenames(filenames); if (filenames.isEmpty()) return false; // Ugly. For security none of the APIs available to us can set the input value // on file inputs. Even forcing a change in HTMLInputElement doesn't work as // RenderFileUploadControl clears the file when doing updateFromElement(). RenderFileUploadControl* renderer = toRenderFileUploadControl(fileInput->renderer()); if (!renderer) return false; renderer->receiveDroppedFiles(filenames); return true; } VisibleSelection dragCaret(m_page->dragCaretController()->selection()); m_page->dragCaretController()->clear(); RefPtr<Range> range = dragCaret.toNormalizedRange(); // For range to be null a WebKit client must have done something bad while // manually controlling drag behaviour if (!range) return false; DocLoader* loader = range->ownerDocument()->docLoader(); loader->setAllowStaleResources(true); if (dragIsMove(innerFrame->selection()) || dragCaret.isContentRichlyEditable()) { bool chosePlainText = false; RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, range, true, chosePlainText); if (!fragment || !innerFrame->editor()->shouldInsertFragment(fragment, range, EditorInsertActionDropped)) { loader->setAllowStaleResources(false); return false; } m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); if (dragIsMove(innerFrame->selection())) { bool smartMove = innerFrame->selectionGranularity() == WordGranularity && innerFrame->editor()->smartInsertDeleteEnabled() && dragData->canSmartReplace(); applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartMove)); } else { if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, fragment, true, dragData->canSmartReplace(), chosePlainText)); } } else { String text = dragData->asPlainText(); if (text.isEmpty() || !innerFrame->editor()->shouldInsertText(text, range.get(), EditorInsertActionDropped)) { loader->setAllowStaleResources(false); return false; } m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, createFragmentFromText(range.get(), text), true, false, true)); } loader->setAllowStaleResources(false); return true; }