diff options
Diffstat (limited to 'webkit/port/platform/chromium')
-rw-r--r-- | webkit/port/platform/chromium/ChromiumBridge.h | 17 | ||||
-rw-r--r-- | webkit/port/platform/chromium/ClipboardChromium.cpp | 60 | ||||
-rw-r--r-- | webkit/port/platform/chromium/ClipboardChromium.h | 52 | ||||
-rw-r--r-- | webkit/port/platform/chromium/ClipboardUtilitiesChromium.cpp | 66 | ||||
-rw-r--r-- | webkit/port/platform/chromium/ClipboardUtilitiesChromium.h | 40 | ||||
-rw-r--r-- | webkit/port/platform/chromium/PasteboardChromium.cpp | 152 | ||||
-rw-r--r-- | webkit/port/platform/chromium/PasteboardLinux.cpp | 60 | ||||
-rw-r--r-- | webkit/port/platform/chromium/PasteboardPrivate.h | 10 |
8 files changed, 322 insertions, 135 deletions
diff --git a/webkit/port/platform/chromium/ChromiumBridge.h b/webkit/port/platform/chromium/ChromiumBridge.h index 2777c22..9e1e575 100644 --- a/webkit/port/platform/chromium/ChromiumBridge.h +++ b/webkit/port/platform/chromium/ChromiumBridge.h @@ -30,10 +30,15 @@ #ifndef ChromiumBridge_h #define ChromiumBridge_h +#include "PasteboardPrivate.h" +#include "PlatformString.h" + +class NativeImageSkia; + namespace WebCore { class Cursor; - class KURL; class IntRect; + class KURL; class String; class Widget; @@ -42,6 +47,16 @@ namespace WebCore { class ChromiumBridge { public: + // Clipboard ---------------------------------------------------------- + static bool clipboardIsFormatAvailable(PasteboardPrivate::ClipboardFormat); + + static String clipboardReadPlainText(); + static void clipboardReadHTML(String*, KURL*); + + static void clipboardWriteSelection(const String&, const KURL&, const String&, bool); + static void clipboardWriteURL(const KURL&, const String&); + static void clipboardWriteImage(const NativeImageSkia* bitmap, const KURL&, const String&); + // Cookies ------------------------------------------------------------ static void setCookies(const KURL& url, const KURL& policyURL, const String& value); static String cookies(const KURL& url, const KURL& policyURL); diff --git a/webkit/port/platform/chromium/ClipboardChromium.cpp b/webkit/port/platform/chromium/ClipboardChromium.cpp index c080eea..663a341 100644 --- a/webkit/port/platform/chromium/ClipboardChromium.cpp +++ b/webkit/port/platform/chromium/ClipboardChromium.cpp @@ -27,8 +27,10 @@ #pragma warning(push, 0) #include "CachedImage.h" +#include "ChromiumBridge.h" #include "ChromiumDataObject.h" #include "ClipboardChromium.h" +#include "ClipboardUtilitiesChromium.h" #include "CSSHelper.h" #include "CString.h" #include "Document.h" @@ -53,13 +55,6 @@ #include <wtf/RefPtr.h> #pragma warning(pop) -// TODO(tc): Once the clipboard methods get moved to the bridge, -// we can get rid of our dependency on webkit_glue and base. -#undef LOG -#include "base/string_util.h" -#include "webkit/glue/glue_util.h" -#include "webkit/glue/webkit_glue.h" - namespace WebCore { using namespace HTMLNames; @@ -82,23 +77,6 @@ static ClipboardDataType clipboardTypeFromMIMEType(const String& type) return ClipboardDataTypeNone; } -#if PLATFORM(WIN_OS) -static void replaceNewlinesWithWindowsStyleNewlines(String& str) -{ - static const UChar Newline = '\n'; - static const char* const WindowsNewline("\r\n"); - str.replace(Newline, WindowsNewline); -} -#endif - -static void replaceNBSPWithSpace(String& str) -{ - static const UChar NonBreakingSpaceCharacter = 0xA0; - static const UChar SpaceCharacter = ' '; - str.replace(NonBreakingSpaceCharacter, SpaceCharacter); -} - - ClipboardChromium::ClipboardChromium(bool isForDragging, ChromiumDataObject* dataObject, ClipboardAccessPolicy policy) @@ -145,38 +123,27 @@ String ClipboardChromium::getData(const String& type, bool& success) const } ClipboardDataType dataType = clipboardTypeFromMIMEType(type); + String text; if (dataType == ClipboardDataTypeText) { - String text; if (!isForDragging()) { -#if PLATFORM(WIN_OS) // If this isn't for a drag, it's for a cut/paste event handler. - // In this case, we need to use our glue methods to access the - // clipboard contents. - std::wstring wideStr; - // TODO(tc): Once the clipboard methods get moved to the bridge, - // we can get rid of our dependency on webkit_glue. - webkit_glue::ClipboardReadText(&wideStr); - if (wideStr.empty()) { - std::string asciiText; - webkit_glue::ClipboardReadAsciiText(&asciiText); - wideStr = ASCIIToWide(asciiText); - } - success = !wideStr.empty(); - text = webkit_glue::StdWStringToString(wideStr); -#endif + // In this case, we need to check the clipboard. + text = ChromiumBridge::clipboardReadPlainText(); + success = !text.isEmpty(); } else if (!m_dataObject->plain_text.isEmpty()) { success = true; text = m_dataObject->plain_text; } - return text; } else if (dataType == ClipboardDataTypeURL) { + // TODO(tc): Handle the cut/paste event. This requires adding + // a new IPC message to get the URL from the clipboard directly. if (!m_dataObject->url.isEmpty()) { success = true; - return m_dataObject->url.string(); + text = m_dataObject->url.string(); } } - return ""; + return text; } bool ClipboardChromium::setData(const String& type, const String& data) @@ -363,12 +330,7 @@ void ClipboardChromium::writeURL(const KURL& url, const String& title, Frame*) m_dataObject->plain_text = url.string(); // The URL can also be used as an HTML fragment. - String markup("<a href=\""); - markup.append(url.string()); - markup.append("\">"); - markup.append(title); - markup.append("</a>"); - m_dataObject->text_html = markup; + m_dataObject->text_html = urlToMarkup(url, title); } void ClipboardChromium::writeRange(Range* selectedRange, Frame* frame) diff --git a/webkit/port/platform/chromium/ClipboardChromium.h b/webkit/port/platform/chromium/ClipboardChromium.h index 9585988..81f2851 100644 --- a/webkit/port/platform/chromium/ClipboardChromium.h +++ b/webkit/port/platform/chromium/ClipboardChromium.h @@ -1,27 +1,31 @@ -/* - * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +// Copyright (c) 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ClipboardChromium_h #define ClipboardChromium_h diff --git a/webkit/port/platform/chromium/ClipboardUtilitiesChromium.cpp b/webkit/port/platform/chromium/ClipboardUtilitiesChromium.cpp new file mode 100644 index 0000000..37910c1 --- /dev/null +++ b/webkit/port/platform/chromium/ClipboardUtilitiesChromium.cpp @@ -0,0 +1,66 @@ +// Copyright (c) 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "config.h" +#include "ClipboardUtilitiesChromium.h" + +#include "KURL.h" +#include "PlatformString.h" + +namespace WebCore { + +#if PLATFORM(WIN_OS) +void replaceNewlinesWithWindowsStyleNewlines(String& str) +{ + static const UChar Newline = '\n'; + static const char* const WindowsNewline("\r\n"); + str.replace(Newline, WindowsNewline); +} +#endif + +void replaceNBSPWithSpace(String& str) +{ + static const UChar NonBreakingSpaceCharacter = 0xA0; + static const UChar SpaceCharacter = ' '; + str.replace(NonBreakingSpaceCharacter, SpaceCharacter); +} + +String urlToMarkup(const KURL& url, const String& title) +{ + String markup("<a href=\""); + markup.append(url.string()); + markup.append("\">"); + // TODO(tc): HTML escape this, possibly by moving into the glue layer so we + // can use net/base/escape.h. + markup.append(title); + markup.append("</a>"); + return markup; +} + +} diff --git a/webkit/port/platform/chromium/ClipboardUtilitiesChromium.h b/webkit/port/platform/chromium/ClipboardUtilitiesChromium.h new file mode 100644 index 0000000..4bccc13 --- /dev/null +++ b/webkit/port/platform/chromium/ClipboardUtilitiesChromium.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +namespace WebCore { + +class KURL; +class String; + +#if PLATFORM(WIN_OS) +void replaceNewlinesWithWindowsStyleNewlines(String&); +#endif +void replaceNBSPWithSpace(String&); + +String urlToMarkup(const KURL&, const String&); + +} diff --git a/webkit/port/platform/chromium/PasteboardChromium.cpp b/webkit/port/platform/chromium/PasteboardChromium.cpp new file mode 100644 index 0000000..01e8861 --- /dev/null +++ b/webkit/port/platform/chromium/PasteboardChromium.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "Pasteboard.h" + +#include "ChromiumBridge.h" +#include "ClipboardUtilitiesChromium.h" +#include "CString.h" +#include "DocumentFragment.h" +#include "Document.h" +#include "Element.h" +#include "Frame.h" +#include "HitTestResult.h" +#include "Image.h" +#include "KURL.h" +#include "NativeImageSkia.h" +#include "NotImplemented.h" +#include "Page.h" +#include "Range.h" +#include "RenderImage.h" +#include "TextEncoding.h" +#include "markup.h" + +namespace WebCore { + +Pasteboard* Pasteboard::generalPasteboard() +{ + static Pasteboard* pasteboard = new Pasteboard; + return pasteboard; +} + +Pasteboard::Pasteboard() +{ +} + +void Pasteboard::clear() +{ + // The ScopedClipboardWriter class takes care of clearing the clipboard's + // previous contents. +} + +void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) +{ + String html = createMarkup(selectedRange, 0, AnnotateForInterchange); + ExceptionCode ec = 0; + KURL url = selectedRange->startContainer(ec)->document()->url(); + String plainText = frame->selectedText(); +#if PLATFORM(WIN_OS) + replaceNewlinesWithWindowsStyleNewlines(plainText); +#endif + replaceNBSPWithSpace(plainText); + + ChromiumBridge::clipboardWriteSelection(html, url, plainText, + canSmartCopyOrDelete); +} + +void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) +{ + ASSERT(!url.isEmpty()); + + String title(titleStr); + if (title.isEmpty()) { + title = url.lastPathComponent(); + if (title.isEmpty()) + title = url.host(); + } + + ChromiumBridge::clipboardWriteURL(url, title); +} + +void Pasteboard::writeImage(Node* node, const KURL& url, const String& title) +{ + ASSERT(node && node->renderer() && node->renderer()->isImage()); + RenderImage* renderer = static_cast<RenderImage*>(node->renderer()); + CachedImage* cachedImage = static_cast<CachedImage*>(renderer->cachedImage()); + ASSERT(cachedImage); + Image* image = cachedImage->image(); + ASSERT(image); + + NativeImageSkia* bitmap = 0; +#if !PLATFORM(CG) + bitmap = image->nativeImageForCurrentFrame(); +#endif + ChromiumBridge::clipboardWriteImage(bitmap, url, title); +} + +bool Pasteboard::canSmartReplace() +{ + return ChromiumBridge::clipboardIsFormatAvailable( + PasteboardPrivate::WebSmartPasteFormat); +} + +String Pasteboard::plainText(Frame* frame) +{ + return ChromiumBridge::clipboardReadPlainText(); +} + +PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) +{ + chosePlainText = false; + + if (ChromiumBridge::clipboardIsFormatAvailable( + PasteboardPrivate::HTMLFormat)) { + String markup; + KURL src_url; + ChromiumBridge::clipboardReadHTML(&markup, &src_url); + + RefPtr<DocumentFragment> fragment = + createFragmentFromMarkup(frame->document(), markup, src_url); + + if (fragment) + return fragment.release(); + } + + if (allowPlainText) { + String markup = ChromiumBridge::clipboardReadPlainText(); + if (!markup.isEmpty()) { + chosePlainText = true; + RefPtr<DocumentFragment> fragment = + createFragmentFromText(context.get(), markup); + if (fragment) + return fragment.release(); + } + } + + return 0; +} + +} // namespace WebCore diff --git a/webkit/port/platform/chromium/PasteboardLinux.cpp b/webkit/port/platform/chromium/PasteboardLinux.cpp deleted file mode 100644 index 7abc6f6..0000000 --- a/webkit/port/platform/chromium/PasteboardLinux.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "config.h" -#import "Pasteboard.h" - -#import "DocumentFragment.h" -#import "NotImplemented.h" - -/* - A stub for a X11 pasteboard - */ -namespace WebCore { - -Pasteboard* Pasteboard::generalPasteboard() -{ - notImplemented(); - return 0; -} - -void Pasteboard::clear() -{ - notImplemented(); -} - -void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) -{ - notImplemented(); -} - -void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) -{ - notImplemented(); -} - -void Pasteboard::writeImage(Node* node, const KURL& url, const String& title) -{ - notImplemented(); -} - -bool Pasteboard::canSmartReplace() -{ - notImplemented(); - return false; -} - -String Pasteboard::plainText(Frame* frame) -{ - notImplemented(); - return String(); -} - -PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) -{ - notImplemented(); - return 0; -} - -} diff --git a/webkit/port/platform/chromium/PasteboardPrivate.h b/webkit/port/platform/chromium/PasteboardPrivate.h index 5a5390c..014e66f 100644 --- a/webkit/port/platform/chromium/PasteboardPrivate.h +++ b/webkit/port/platform/chromium/PasteboardPrivate.h @@ -32,7 +32,15 @@ namespace WebCore { -struct PasteboardPrivate {}; + class PasteboardPrivate + { + public: + enum ClipboardFormat { + HTMLFormat, + BookmarkFormat, + WebSmartPasteFormat, + }; + }; } |