summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/blackberry/ClipboardBlackBerry.cpp
blob: 2a31be862853a4bd595612cc58c04495bf751f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright (C) 2010, 2011, 2012 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<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)
{
    if (policy() != ClipboardWritable)
        return;

    BlackBerry::Platform::Clipboard::clearClipboardByType(type.utf8().data());
}

void ClipboardBlackBerry::clearAllData()
{
    if (policy() != ClipboardWritable)
        return;

    BlackBerry::Platform::Clipboard::clearClipboard();
}

String ClipboardBlackBerry::getData(const String& type) const
{
    if (policy() != ClipboardReadable)
        return String();

    return String::fromUTF8(BlackBerry::Platform::Clipboard::readClipboardByType(type.utf8().data()).c_str());
}

bool ClipboardBlackBerry::setData(const String& type, const String& text)
{
    if (policy() != ClipboardWritable)
        return false;

    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
{
    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
        return HashSet<String>();

    // 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