Upstream 3 files into WebCore/platform/blackberry
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Dec 2011 05:22:47 +0000 (05:22 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Dec 2011 05:22:47 +0000 (05:22 +0000)
ClipboardBlackBerry.cpp/h, PasteboardBlackBerry.cpp
https://bugs.webkit.org/show_bug.cgi?id=74381

Patch by Mary Wu <mary.wu@torchmobile.com.cn> on 2011-12-13
Reviewed by Rob Buis.

Main contributor:
Mike Fenton <mifenton@rim.com>

Initial upstream, no new tests.

* platform/blackberry/ClipboardBlackBerry.cpp: Added.
* platform/blackberry/ClipboardBlackBerry.h: Added.
* platform/blackberry/PasteboardBlackBerry.cpp: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@102739 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/blackberry/ClipboardBlackBerry.cpp [new file with mode: 0644]
Source/WebCore/platform/blackberry/ClipboardBlackBerry.h [new file with mode: 0644]
Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp [new file with mode: 0644]

index 6754094..2a34d3a 100644 (file)
@@ -1,3 +1,20 @@
+2011-12-13  Mary Wu  <mary.wu@torchmobile.com.cn>
+
+        Upstream 3 files into WebCore/platform/blackberry
+        ClipboardBlackBerry.cpp/h, PasteboardBlackBerry.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=74381
+
+        Reviewed by Rob Buis.
+
+        Main contributor:
+        Mike Fenton <mifenton@rim.com>
+
+        Initial upstream, no new tests.
+
+        * platform/blackberry/ClipboardBlackBerry.cpp: Added.
+        * platform/blackberry/ClipboardBlackBerry.h: Added.
+        * platform/blackberry/PasteboardBlackBerry.cpp: Added.
+
 2011-12-13  James Robinson  <jamesr@chromium.org>
 
         Unreviewed, rolling out r102726.
diff --git a/Source/WebCore/platform/blackberry/ClipboardBlackBerry.cpp b/Source/WebCore/platform/blackberry/ClipboardBlackBerry.cpp
new file mode 100644 (file)
index 0000000..1612737
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "ClipboardBlackBerry.h"
+
+#include "FileList.h"
+#include "NotImplemented.h"
+
+#include <BlackBerryPlatformClipboard.h>
+
+namespace WebCore {
+
+PassRefPtr<ClipboardBlackBerry> ClipboardBlackBerry::create(ClipboardAccessPolicy policy, ClipboardType clipboardType)
+{
+    return adoptRef(new ClipboardBlackBerry(policy, clipboardType));
+}
+
+PassRefPtr<Clipboard> Clipboard::create(ClipboardAccessPolicy policy, DragData*, Frame*)
+{
+    return ClipboardBlackBerry::create(policy, DragAndDrop);
+}
+
+ClipboardBlackBerry::ClipboardBlackBerry(ClipboardAccessPolicy policy, ClipboardType type)
+: Clipboard(policy, type)
+{
+}
+
+ClipboardBlackBerry::~ClipboardBlackBerry()
+{
+}
+
+void ClipboardBlackBerry::clearData(const String& type)
+{
+    BlackBerry::Platform::Clipboard::clearClipboardByType(type.utf8().data());
+}
+
+void ClipboardBlackBerry::clearAllData()
+{
+    BlackBerry::Platform::Clipboard::clearClipboard();
+}
+
+String ClipboardBlackBerry::getData(const String& type, bool& success) const
+{
+    success = true;
+    return String::fromUTF8(BlackBerry::Platform::Clipboard::readClipboardByType(type.utf8().data()).c_str());
+}
+
+bool ClipboardBlackBerry::setData(const String& type, const String& text)
+{
+    if (type == "text/plain")
+        BlackBerry::Platform::Clipboard::writePlainText(text.utf8().data());
+    else if (type == "text/html")
+        BlackBerry::Platform::Clipboard::writeHTML(text.utf8().data());
+    else if (type == "text/url")
+        BlackBerry::Platform::Clipboard::writeURL(text.utf8().data());
+    return true;
+}
+
+HashSet<String> ClipboardBlackBerry::types() const
+{
+    // We use hardcoded list here since there seems to be no API to get the list.
+    HashSet<String> ret;
+    ret.add("text/plain");
+    ret.add("text/html");
+    ret.add("text/url");
+    return ret;
+}
+
+PassRefPtr<FileList> ClipboardBlackBerry::files() const
+{
+    notImplemented();
+    return 0;
+}
+
+DragImageRef ClipboardBlackBerry::createDragImage(IntPoint&) const
+{
+    notImplemented();
+    return 0;
+}
+
+void ClipboardBlackBerry::declareAndWriteDragImage(Element*, const KURL&, const String&, Frame*)
+{
+    notImplemented();
+}
+
+void ClipboardBlackBerry::writeURL(const KURL& url, const String&, Frame*)
+{
+    ASSERT(!url.isEmpty());
+    BlackBerry::Platform::Clipboard::writeURL(url.string().utf8().data());
+}
+
+void ClipboardBlackBerry::writeRange(Range*, Frame*)
+{
+    notImplemented();
+}
+
+void ClipboardBlackBerry::writePlainText(const String& text)
+{
+    BlackBerry::Platform::Clipboard::writePlainText(text.utf8().data());
+}
+
+bool ClipboardBlackBerry::hasData()
+{
+    return BlackBerry::Platform::Clipboard::hasPlainText() || BlackBerry::Platform::Clipboard::hasHTML()
+        || BlackBerry::Platform::Clipboard::hasURL();
+}
+
+void ClipboardBlackBerry::setDragImage(CachedImage*, const IntPoint&)
+{
+    notImplemented();
+}
+
+void ClipboardBlackBerry::setDragImageElement(Node*, const IntPoint&)
+{
+    notImplemented();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/blackberry/ClipboardBlackBerry.h b/Source/WebCore/platform/blackberry/ClipboardBlackBerry.h
new file mode 100644 (file)
index 0000000..2f39f46
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2010 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef ClipboardBlackBerry_h
+#define ClipboardBlackBerry_h
+
+#include "CachedResourceClient.h"
+#include "Clipboard.h"
+
+namespace WebCore {
+
+class ClipboardBlackBerry : public Clipboard, public CachedResourceClient {
+WTF_MAKE_FAST_ALLOCATED;
+public:
+    static PassRefPtr<ClipboardBlackBerry> create(ClipboardAccessPolicy, ClipboardType = CopyAndPaste);
+    virtual ~ClipboardBlackBerry();
+
+    void clearData(const String& type);
+    void clearAllData();
+    String getData(const String& type, bool& success) const;
+    bool setData(const String& type, const String& data);
+
+    // extensions beyond IE's API
+    virtual HashSet<String> types() const;
+    virtual PassRefPtr<FileList> files() const;
+    virtual DragImageRef createDragImage(IntPoint&) const;
+    virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*);
+    virtual void writeURL(const KURL&, const String&, Frame*);
+    virtual void writeRange(Range*, Frame*);
+    virtual void writePlainText(const String&);
+
+    virtual bool hasData();
+
+    virtual void setDragImage(CachedImage*, const IntPoint&);
+    virtual void setDragImageElement(Node*, const IntPoint&);
+
+private:
+    ClipboardBlackBerry(ClipboardAccessPolicy, ClipboardType);
+};
+
+} // namespace WebCore
+
+#endif // ClipboardBlackBerry_h
diff --git a/Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp b/Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp
new file mode 100644 (file)
index 0000000..9365a6c
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2009, 2011 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "Pasteboard.h"
+
+#include "DocumentFragment.h"
+#include "Frame.h"
+#include "KURL.h"
+#include "NotImplemented.h"
+#include "Range.h"
+#include "markup.h"
+
+#include <BlackBerryPlatformClipboard.h>
+
+namespace WebCore {
+
+Pasteboard* Pasteboard::generalPasteboard()
+{
+    static Pasteboard* pasteboard = new Pasteboard();
+    return pasteboard;
+}
+
+Pasteboard::Pasteboard()
+{
+}
+
+bool Pasteboard::canSmartReplace()
+{
+    notImplemented();
+    return false;
+}
+
+void Pasteboard::clear()
+{
+    BlackBerry::Platform::Clipboard::clearClipboard();
+}
+
+void Pasteboard::writeImage(Node*, KURL const&, String const&)
+{
+    notImplemented();
+}
+
+void Pasteboard::writeSelection(Range* selectedRange, bool, Frame* frame)
+{
+    std::string text = frame->editor()->selectedText().utf8().data();
+    std::string html = createMarkup(selectedRange, 0, AnnotateForInterchange).utf8().data();
+    std::string url = frame->document()->url().string().utf8().data();
+
+    BlackBerry::Platform::Clipboard::write(text, html, url);
+}
+
+void Pasteboard::writeURL(KURL const& url, String const&, Frame*)
+{
+    ASSERT(!url.isEmpty());
+    BlackBerry::Platform::Clipboard::writeURL(url.string().utf8().data());
+}
+
+void Pasteboard::writePlainText(const String& text)
+{
+    BlackBerry::Platform::Clipboard::writePlainText(text.utf8().data());
+}
+
+String Pasteboard::plainText(Frame*)
+{
+    return String::fromUTF8(BlackBerry::Platform::Clipboard::readPlainText().c_str());
+}
+
+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 = String::fromUTF8(BlackBerry::Platform::Clipboard::readHTML().c_str());
+    RefPtr<DocumentFragment> fragment;
+    if (!html.isEmpty()) {
+        String url = String::fromUTF8(BlackBerry::Platform::Clipboard::readURL().c_str());
+        if (fragment = createFragmentFromMarkup(frame->document(), html, url, FragmentScriptingNotAllowed))
+            return fragment.release();
+    }
+
+    if (!allowPlainText)
+        return 0;
+
+    String text = String::fromUTF8(BlackBerry::Platform::Clipboard::readPlainText().c_str());
+    if (fragment = createFragmentFromText(context.get(), text)) {
+        chosePlainText = true;
+        return fragment.release();
+    }
+    return 0;
+}
+
+} // namespace WebCore