1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "config.h"
  27 #include "Frame.h"
  28 #include "DragData.h"
  29 #include "Range.h"
  30 
  31 #include "DataObjectJava.h"
  32 #include "DataTransfer.h"
  33 #include "DocumentFragment.h"
  34 #include "URL.h"
  35 #include "markup.h"
  36 #include "NotImplemented.h"
  37 
  38 #include <wtf/text/WTFString.h>
  39 
  40 namespace WebCore {
  41 
  42 bool DragData::containsURL(FilenameConversionPolicy /*= ConvertFilenames*/) const
  43 {
  44     /* utaTODO: extent the functionality
  45     */
  46     return m_platformDragData->containsURL();
  47 }
  48 
  49 String DragData::asURL(FilenameConversionPolicy, String* title) const
  50 {
  51     /* utaTODO: extent the functionality
  52     String url;
  53     if (m_platformDragData->hasValidURL())
  54         url = m_platformDragData->getURL().string();
  55     else if (filenamePolicy == ConvertFilenames && !m_platformDragData->filenames.isEmpty()) {
  56         String fileName = m_platformDragData->filenames[0];
  57         fileName = ChromiumBridge::getAbsolutePath(fileName);
  58         url = ChromiumBridge::filePathToURL(fileName).string();
  59     }
  60     */
  61     return m_platformDragData->asURL(title);
  62 }
  63 
  64 bool DragData::containsFiles() const
  65 {
  66     return m_platformDragData->containsFiles();
  67 }
  68 
  69 Vector<String> DragData::asFilenames() const
  70 {
  71     return m_platformDragData->asFilenames();
  72 }
  73 
  74 bool DragData::containsPlainText() const
  75 {
  76     return m_platformDragData->containsPlainText();
  77 }
  78 
  79 String DragData::asPlainText() const
  80 {
  81     return m_platformDragData->asPlainText();
  82 }
  83 
  84 bool DragData::canSmartReplace() const
  85 {
  86     // Mimic the situations in which mac allows drag&drop to do a smart replace.
  87     // This is allowed whenever the drag data contains a 'range' (ie.,
  88     // ClipboardWin::writeRange is called).  For example, dragging a link
  89     // should not result in a space being added.
  90     /*
  91     return containsPlainText()
  92         && containsURL();
  93     */
  94     return false;
  95 }
  96 
  97 bool DragData::containsCompatibleContent(DraggingPurpose) const
  98 {
  99     return containsPlainText()
 100         || containsURL()
 101         || m_platformDragData->containsHTML()
 102         || containsColor();
 103 }
 104 
 105 //XXX: WebCore::DragController::createFragmentFromDragData): Move DragData::asFragment() implementation here.
 106 //XXX: WebCore::DragController::createFragmentFromDragData) moved to editor
 107 // PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, Range&, bool, bool&) const
 108 // {
 109 //     /*
 110 //      * Order is richest format first. On OSX this is:
 111 //      * * Web Archive
 112 //      * * Filenames
 113 //      * * HTML
 114 //      * * RTF
 115 //      * * TIFF
 116 //      * * PICT
 117 //      */
 118 
 119 //     if (containsFiles()) {
 120 //         // FIXME: Implement this.  Should be pretty simple to make some HTML
 121 //         // and call createFragmentFromMarkup.
 122 //         //if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
 123 //         //    ?, KURL()))
 124 //         //    return fragment;
 125 //     }
 126 
 127 //     if (m_platformDragData->containsHTML()) {
 128 //         bool ignoredSuccess;
 129 //         String sBase;
 130 //         String sHtml = m_platformDragData->asHTML(&sBase);
 131 //         RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(
 132 //             *frame->document(),
 133 //             sHtml,
 134 //             sBase,
 135 //             DisallowScriptingContent);
 136 //         return fragment.release();
 137 //     }
 138 
 139 //     return 0;
 140 // }
 141 bool DragData::containsColor() const
 142 {
 143     notImplemented();
 144     return false;
 145 }
 146 
 147 Color DragData::asColor() const
 148 {
 149     notImplemented();
 150     return Color();
 151 }
 152 
 153 unsigned DragData::numberOfFiles() const
 154 {
 155     return m_platformDragData->filenames().size();
 156 }
 157 
 158 } // namespace WebCore