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 "Clipboard.h"
35 #include "ClipboardChromium.h"
36 #include "DocumentFragment.h"
37 #include "FileSystem.h"
40 #include "NotImplemented.h"
41 #include "PlatformString.h"
45 static bool containsHTML(const ChromiumDataObject* dropData)
47 return dropData->textHtml.length() > 0;
50 PassRefPtr<Clipboard> DragData::createClipboard(ClipboardAccessPolicy policy) const
52 RefPtr<ClipboardChromium> clipboard = ClipboardChromium::create(true,
53 m_platformDragData, policy);
55 return clipboard.release();
58 bool DragData::containsURL() const
60 return !asURL().isEmpty();
63 String DragData::asURL(String* title) const
66 if (m_platformDragData->url.isValid())
67 url = m_platformDragData->url.string();
68 else if (m_platformDragData->filenames.size() == 1) {
69 String fileName = m_platformDragData->filenames[0];
70 // FIXME: Add isDirectory to FileSystem so that we can check if it is not a directory.
71 if (fileExists(fileName))
75 // |title| can be NULL
77 *title = m_platformDragData->urlTitle;
81 bool DragData::containsFiles() const
83 return !m_platformDragData->filenames.isEmpty();
86 void DragData::asFilenames(Vector<String>& result) const
88 for (size_t i = 0; i < m_platformDragData->filenames.size(); ++i)
89 result.append(m_platformDragData->filenames[i]);
92 bool DragData::containsPlainText() const
94 return !m_platformDragData->plainText.isEmpty();
97 String DragData::asPlainText() const
99 return m_platformDragData->plainText;
102 bool DragData::containsColor() const
108 bool DragData::canSmartReplace() const
110 // Mimic the situations in which mac allows drag&drop to do a smart replace.
111 // This is allowed whenever the drag data contains a 'range' (ie.,
112 // ClipboardWin::writeRange is called). For example, dragging a link
113 // should not result in a space being added.
114 return !m_platformDragData->plainText.isEmpty()
115 && !m_platformDragData->url.isValid();
118 bool DragData::containsCompatibleContent() const
120 return containsPlainText()
122 || containsHTML(m_platformDragData)
127 PassRefPtr<DocumentFragment> DragData::asFragment(Document* doc) const
130 * Order is richest format first. On OSX this is:
139 if (containsFiles()) {
140 // FIXME: Implement this. Should be pretty simple to make some HTML
141 // and call createFragmentFromMarkup.
142 //if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
147 if (!m_platformDragData->textHtml.isEmpty()) {
148 RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
149 m_platformDragData->textHtml, m_platformDragData->htmlBaseUrl);
150 return fragment.release();
156 Color DragData::asColor() const
162 } // namespace WebCore