1 /* 2 * This library is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU Lesser General Public 4 * License as published by the Free Software Foundation; either 5 * version 2 of the License, or (at your option) any later version. 6 * 7 * This library is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 * Lesser General Public License for more details. 11 * 12 * You should have received a copy of the GNU Lesser General Public 13 * License along with this library; if not, write to the Free Software 14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 */ 16 17 #include "config.h" 18 #include "DragData.h" 19 20 #include "Clipboard.h" 21 #include "ClipboardGtk.h" 22 #include "Document.h" 23 #include "DocumentFragment.h" 24 #include "Frame.h" 25 #include "markup.h" 26 27 namespace WebCore { 28 29 bool DragData::canSmartReplace() const 30 { 31 return false; 32 } 33 34 bool DragData::containsColor() const 35 { 36 return false; 37 } 38 39 bool DragData::containsFiles() const 40 { 41 return m_platformDragData->hasFilenames(); 42 } 43 44 void DragData::asFilenames(Vector<String>& result) const 45 { 46 result = m_platformDragData->filenames(); 47 } 48 49 bool DragData::containsPlainText() const 50 { 51 return m_platformDragData->hasText(); 52 } 53 54 String DragData::asPlainText(Frame*) const 55 { 56 return m_platformDragData->text(); 57 } 58 59 Color DragData::asColor() const 60 { 61 return Color(); 62 } 63 64 bool DragData::containsCompatibleContent() const 65 { 66 return containsPlainText() || containsURL(0) || m_platformDragData->hasMarkup() || containsColor() || containsFiles(); 67 } 68 69 bool DragData::containsURL(Frame* frame, FilenameConversionPolicy filenamePolicy) const 70 { 71 return !asURL(frame, filenamePolicy).isEmpty(); 72 } 73 74 String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const 75 { 76 if (!m_platformDragData->hasURL()) 77 return String(); 78 if (filenamePolicy != ConvertFilenames) { 79 KURL url(KURL(), m_platformDragData->url()); 80 if (url.isLocalFile()) 81 return String(); 82 } 83 84 String url(m_platformDragData->url()); 85 if (title) 86 *title = m_platformDragData->urlLabel(); 87 return url; 88 } 89 90 91 PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range>, bool, bool&) const 92 { 93 if (!m_platformDragData->hasMarkup()) 94 return 0; 95 96 return createFragmentFromMarkup(frame->document(), m_platformDragData->markup(), ""); 97 } 98 99 } 100