2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 // Modified from DragDataWin.cpp to not directly call any windows methods as
28 // they may not be available to us in the multiprocess
33 #include "ChromiumDataObject.h"
34 #include "ClipboardMimeTypes.h"
35 #include "DocumentFragment.h"
36 #include "FileSystem.h"
39 #include "NotImplemented.h"
40 #include "PlatformString.h"
41 #include "PlatformSupport.h"
46 static bool containsHTML(const ChromiumDataObject* dropData)
48 return dropData->types().contains(mimeTypeTextHTML);
51 bool DragData::containsURL(Frame*, FilenameConversionPolicy filenamePolicy) const
53 return m_platformDragData->types().contains(mimeTypeTextURIList)
54 || (filenamePolicy == ConvertFilenames && m_platformDragData->containsFilenames());
57 String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const
60 if (m_platformDragData->types().contains(mimeTypeTextURIList))
61 m_platformDragData->urlAndTitle(url, title);
62 else if (filenamePolicy == ConvertFilenames && containsFiles()) {
63 url = PlatformSupport::filePathToURL(PlatformSupport::getAbsolutePath(m_platformDragData->filenames()[0]));
68 bool DragData::containsFiles() const
70 return m_platformDragData->containsFilenames();
73 unsigned DragData::numberOfFiles() const
75 return m_platformDragData->filenames().size();
78 int DragData::modifierKeyState() const
80 return m_platformDragData->modifierKeyState();
83 void DragData::asFilenames(Vector<String>& result) const
85 const Vector<String>& filenames = m_platformDragData->filenames();
86 for (size_t i = 0; i < filenames.size(); ++i)
87 result.append(filenames[i]);
90 bool DragData::containsPlainText() const
92 return m_platformDragData->types().contains(mimeTypeTextPlain);
95 String DragData::asPlainText(Frame*) const
97 return m_platformDragData->getData(mimeTypeTextPlain);
100 bool DragData::containsColor() const
106 bool DragData::canSmartReplace() const
108 // Mimic the situations in which mac allows drag&drop to do a smart replace.
109 // This is allowed whenever the drag data contains a 'range' (ie.,
110 // ClipboardWin::writeRange is called). For example, dragging a link
111 // should not result in a space being added.
112 return m_platformDragData->types().contains(mimeTypeTextPlain)
113 && !m_platformDragData->types().contains(mimeTypeTextURIList);
116 bool DragData::containsCompatibleContent() const
118 return containsPlainText()
120 || containsHTML(m_platformDragData)
125 PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range>, bool, bool&) const
128 * Order is richest format first. On OSX this is:
137 if (containsFiles()) {
138 // FIXME: Implement this. Should be pretty simple to make some HTML
139 // and call createFragmentFromMarkup.
140 //if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
145 if (m_platformDragData->types().contains(mimeTypeTextHTML)) {
148 m_platformDragData->htmlAndBaseURL(html, baseURL);
149 RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, baseURL, FragmentScriptingNotAllowed);
150 return fragment.release();
156 Color DragData::asColor() const
162 } // namespace WebCore