2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/clipboard/Pasteboard.h"
34 #include "core/clipboard/DataObject.h"
35 #include "platform/clipboard/ClipboardUtilities.h"
36 #include "platform/graphics/Image.h"
37 #include "platform/graphics/skia/NativeImageSkia.h"
38 #include "platform/weborigin/KURL.h"
39 #include "public/platform/Platform.h"
40 #include "public/platform/WebDragData.h"
41 #include "public/platform/WebString.h"
42 #include "public/platform/WebURL.h"
43 #include "wtf/PassRefPtr.h"
44 #include "wtf/RefPtr.h"
48 Pasteboard* Pasteboard::generalPasteboard()
50 static Pasteboard* pasteboard = new Pasteboard;
54 Pasteboard::Pasteboard()
55 : m_buffer(blink::WebClipboard::BufferStandard)
59 bool Pasteboard::isSelectionMode() const
61 return m_buffer == blink::WebClipboard::BufferSelection;
64 void Pasteboard::setSelectionMode(bool selectionMode)
66 m_buffer = selectionMode ? blink::WebClipboard::BufferSelection : blink::WebClipboard::BufferStandard;
69 void Pasteboard::writePlainText(const String& text, SmartReplaceOption)
71 // FIXME: add support for smart replace
73 String plainText(text);
74 replaceNewlinesWithWindowsStyleNewlines(plainText);
75 blink::Platform::current()->clipboard()->writePlainText(plainText);
77 blink::Platform::current()->clipboard()->writePlainText(text);
81 void Pasteboard::writeImage(Image* image, const KURL& url, const String& title)
85 RefPtr<NativeImageSkia> bitmap = image->nativeImageForCurrentFrame();
89 blink::WebImage webImage = bitmap->bitmap();
90 blink::Platform::current()->clipboard()->writeImage(webImage, blink::WebURL(url), blink::WebString(title));
93 void Pasteboard::writeDataObject(PassRefPtr<DataObject> dataObject)
95 blink::Platform::current()->clipboard()->writeDataObject(dataObject);
98 bool Pasteboard::canSmartReplace()
100 return blink::Platform::current()->clipboard()->isFormatAvailable(blink::WebClipboard::FormatSmartPaste, m_buffer);
103 bool Pasteboard::isHTMLAvailable()
105 return blink::Platform::current()->clipboard()->isFormatAvailable(blink::WebClipboard::FormatHTML, m_buffer);
108 String Pasteboard::plainText()
110 return blink::Platform::current()->clipboard()->readPlainText(m_buffer);
113 String Pasteboard::readHTML(KURL& url, unsigned& fragmentStart, unsigned& fragmentEnd)
115 blink::WebURL webURL;
116 blink::WebString markup = blink::Platform::current()->clipboard()->readHTML(m_buffer, &webURL, &fragmentStart, &fragmentEnd);
117 if (!markup.isEmpty()) {
119 // fragmentStart and fragmentEnd are populated by WebClipboard::readHTML.
128 void Pasteboard::writeHTML(const String& markup, const KURL& documentURL, const String& plainText, bool canSmartCopyOrDelete)
130 String text = plainText;
132 replaceNewlinesWithWindowsStyleNewlines(text);
134 replaceNBSPWithSpace(text);
136 blink::Platform::current()->clipboard()->writeHTML(markup, documentURL, text, canSmartCopyOrDelete);
139 } // namespace WebCore