diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 22:25:59 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 22:25:59 +0000 |
commit | 3ccbdb9370f53c006b8d677ff90776df94da79a1 (patch) | |
tree | abac7727f520cf165fcc3bef57390c66005ad83e /webkit | |
parent | 80b54ab8f2ba05912a28acaa311336a3728619f1 (diff) | |
download | chromium_src-3ccbdb9370f53c006b8d677ff90776df94da79a1.zip chromium_src-3ccbdb9370f53c006b8d677ff90776df94da79a1.tar.gz chromium_src-3ccbdb9370f53c006b8d677ff90776df94da79a1.tar.bz2 |
* Remove windows-ism from pasteboard code and move to using
ChromiumBridge for clipboard methods. Also did some cleanup
of lingering webkit_glue code in ClipboardChromium.
Review URL: http://codereview.chromium.org/10285
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
21 files changed, 555 insertions, 1707 deletions
diff --git a/webkit/SConscript.port b/webkit/SConscript.port index 312a713..adb199f 100644 --- a/webkit/SConscript.port +++ b/webkit/SConscript.port @@ -46,6 +46,7 @@ input_files = [ '$PORT_DIR/platform/chromium/ChromiumDataObject.cpp', '$PORT_DIR/platform/chromium/ClipboardChromium.cpp', + '$PORT_DIR/platform/chromium/ClipboardUtilitiesChromium.cpp', '$PORT_DIR/platform/chromium/ContextMenuChromium.cpp', '$PORT_DIR/platform/chromium/ContextMenuItemChromium.cpp', '$PORT_DIR/platform/chromium/CursorChromium.cpp', @@ -57,6 +58,7 @@ input_files = [ '$PORT_DIR/platform/chromium/FramelessScrollView.cpp', '$PORT_DIR/platform/chromium/Language.cpp', '$PORT_DIR/platform/chromium/MimeTypeRegistryChromium.cpp', + '$PORT_DIR/platform/chromium/PasteboardChromium.cpp', '$PORT_DIR/platform/chromium/PlatformKeyboardEventChromium.cpp', '$PORT_DIR/platform/chromium/PlatformScreenChromium.cpp', '$PORT_DIR/platform/chromium/PopupMenuChromium.cpp', @@ -125,7 +127,6 @@ if env['PLATFORM'] == 'posix': # Linux specific implementations input_files.extend([ '$PORT_DIR/platform/chromium/IconLinux.cpp', - '$PORT_DIR/platform/chromium/PasteboardLinux.cpp', '$PORT_DIR/platform/chromium/ScreenLinux.cpp', '$PORT_DIR/platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp', '$PORT_DIR/platform/graphics/skia/GdkSkia.cc', @@ -153,8 +154,6 @@ if env['PLATFORM'] == 'win32': '$PORT_DIR/platform/chromium/ScrollBarThemeChromiumWin.cpp', '$PORT_DIR/platform/UniscribeStateTextRun.cpp', '$PORT_DIR/platform/win/BString.cpp', - '$PORT_DIR/platform/win/ClipboardUtilitiesWin.cpp', - '$PORT_DIR/platform/win/PasteboardWin.cpp', '$PORT_DIR/platform/win/SoundWin.cpp', '$PORT_DIR/platform/graphics/FontCacheWin.cpp', '$PORT_DIR/platform/graphics/FontPlatformDataWin.cpp', @@ -186,10 +185,8 @@ if env['PLATFORM'] == 'darwin': '$PORT_DIR/page/WebCoreFrameBridge.mm', '$PORT_DIR/platform/GKURLMac.mm', '$PORT_DIR/platform/PluginStubsMac.cpp', - '$PORT_DIR/platform/mac/ClipboardMac.mm', '$PORT_DIR/platform/mac/DragDataMac.mm', '$PORT_DIR/platform/mac/IntRectMac.mm', - '$PORT_DIR/platform/mac/PasteboardMac.mm', '$PORT_DIR/platform/mac/ScrollViewMac.mm', '$PORT_DIR/platform/graphics/mac/FontCacheMacPending.cpp', '$PORT_DIR/rendering/RenderThemeMac.mm', diff --git a/webkit/build/port/port.vcproj b/webkit/build/port/port.vcproj index 2259920..e2d6a31 100644 --- a/webkit/build/port/port.vcproj +++ b/webkit/build/port/port.vcproj @@ -695,22 +695,10 @@ > </File> <File - RelativePath="..\..\port\platform\win\ClipboardUtilitiesWin.cpp" - > - </File> - <File - RelativePath="..\..\port\platform\win\ClipboardUtilitiesWin.h" - > - </File> - <File RelativePath="..\..\port\platform\win\COMPtr.h" > </File> <File - RelativePath="..\..\port\platform\win\PasteboardWin.cpp" - > - </File> - <File RelativePath="..\..\port\platform\win\SoundWin.cpp" > </File> @@ -747,6 +735,14 @@ > </File> <File + RelativePath="..\..\port\platform\chromium\ClipboardUtilitiesChromium.cpp" + > + </File> + <File + RelativePath="..\..\port\platform\chromium\ClipboardUtilitiesChromium.h" + > + </File> + <File RelativePath="..\..\port\platform\chromium\CursorChromium.cpp" > </File> @@ -791,6 +787,10 @@ > </File> <File + RelativePath="..\..\port\platform\chromium\PasteboardChromium.cpp" + > + </File> + <File RelativePath="..\..\port\platform\chromium\PlatformKeyboardEventChromium.cpp" > </File> @@ -803,15 +803,15 @@ > </File> <File - RelativePath="..\..\port\platform\chromium\ScrollbarThemeChromiumWin.cpp" + RelativePath="..\..\port\platform\chromium\PopupMenuChromium.h" > </File> <File - RelativePath="..\..\port\platform\chromium\ScrollbarThemeChromiumWin.h" + RelativePath="..\..\port\platform\chromium\ScrollbarThemeChromiumWin.cpp" > </File> <File - RelativePath="..\..\port\platform\chromium\PopupMenuChromium.h" + RelativePath="..\..\port\platform\chromium\ScrollbarThemeChromiumWin.h" > </File> <File diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc index 0289f81..32f38a2 100644 --- a/webkit/glue/chromium_bridge_impl.cc +++ b/webkit/glue/chromium_bridge_impl.cc @@ -5,46 +5,175 @@ #include "config.h" #include "ChromiumBridge.h" +#include "ClipboardUtilitiesChromium.h" #include "Cursor.h" #include "Frame.h" #include "FrameView.h" #include "HostWindow.h" +#include "KURL.h" +#include "NativeImageSkia.h" #include "Page.h" +#include "PasteboardPrivate.h" +#include "PlatformString.h" #include "PlatformWidget.h" #include "ScrollView.h" #include "Widget.h" #undef LOG +#include "base/clipboard.h" +#include "base/string_util.h" #include "webkit/glue/chrome_client_impl.h" #include "webkit/glue/glue_util.h" +#include "webkit/glue/scoped_clipboard_writer_glue.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webview_impl.h" #include "webkit/glue/webview_delegate.h" -namespace WebCore { +namespace { -static PlatformWidget ToPlatform(Widget* widget) { +PlatformWidget ToPlatform(WebCore::Widget* widget) { return widget ? widget->root()->hostWindow()->platformWindow() : 0; } -static ChromeClientImpl* ToChromeClient(Widget* widget) { - FrameView* view; +ChromeClientImpl* ToChromeClient(WebCore::Widget* widget) { + WebCore::FrameView* view; if (widget->isFrameView()) { - view = static_cast<FrameView*>(widget); + view = static_cast<WebCore::FrameView*>(widget); } else if (widget->parent() && widget->parent()->isFrameView()) { - view = static_cast<FrameView*>(widget->parent()); + view = static_cast<WebCore::FrameView*>(widget->parent()); } else { return NULL; } - Page* page = view->frame() ? view->frame()->page() : NULL; + WebCore::Page* page = view->frame() ? view->frame()->page() : NULL; if (!page) return NULL; return static_cast<ChromeClientImpl*>(page->chrome()->client()); } +std::wstring UrlToImageMarkup(const WebCore::KURL& url, + const WebCore::String& alt_str) { + std::wstring markup(L"<img src=\""); + markup.append(webkit_glue::StringToStdWString(url.string())); + markup.append(L"\""); + if (!alt_str.isEmpty()) { + markup.append(L" alt=\""); + std::wstring alt_stdstr = webkit_glue::StringToStdWString(alt_str); + ReplaceSubstringsAfterOffset(&alt_stdstr, 0, L"\"", L"""); + markup.append(alt_stdstr); + markup.append(L"\""); + } + markup.append(L"/>"); + return markup; +} + +} // namespace + +namespace WebCore { + +bool ChromiumBridge::clipboardIsFormatAvailable( + PasteboardPrivate::ClipboardFormat format) { + switch (format) { + case PasteboardPrivate::HTMLFormat: + return webkit_glue::ClipboardIsFormatAvailable( + ::Clipboard::GetHtmlFormatType()); + + case PasteboardPrivate::BookmarkFormat: +#if defined(OS_WIN) || defined(OS_MACOSX) + return webkit_glue::ClipboardIsFormatAvailable( + ::Clipboard::GetUrlWFormatType()); +#endif + +#if defined(OS_WIN) + // TODO(tc): This should work for linux/mac too. + case PasteboardPrivate::WebSmartPasteFormat: + return webkit_glue::ClipboardIsFormatAvailable( + ::Clipboard::GetWebKitSmartPasteFormatType()); +#endif + + default: + NOTREACHED(); + return false; + } +} + +String ChromiumBridge::clipboardReadPlainText() { + if (webkit_glue::ClipboardIsFormatAvailable( + ::Clipboard::GetPlainTextWFormatType())) { + std::wstring text; + webkit_glue::ClipboardReadText(&text); + if (!text.empty()) + return webkit_glue::StdWStringToString(text); + } + + if (webkit_glue::ClipboardIsFormatAvailable( + ::Clipboard::GetPlainTextFormatType())) { + std::string text; + webkit_glue::ClipboardReadAsciiText(&text); + if (!text.empty()) + return webkit_glue::StdStringToString(text); + } + + return String(); +} + +void ChromiumBridge::clipboardReadHTML(String* html, KURL* url) { + std::wstring html_stdstr; + GURL gurl; + webkit_glue::ClipboardReadHTML(&html_stdstr, &gurl); + *html = webkit_glue::StdWStringToString(html_stdstr); + *url = webkit_glue::GURLToKURL(gurl); +} + +void ChromiumBridge::clipboardWriteSelection(const String& html, + const KURL& url, + const String& plain_text, + bool can_smart_copy_or_delete) { + ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); + scw.WriteHTML(webkit_glue::StringToStdWString(html), + webkit_glue::CStringToStdString(url.utf8String())); + scw.WriteText(webkit_glue::StringToStdWString(plain_text)); + +#if defined(OS_WIN) + if (can_smart_copy_or_delete) + scw.WriteWebSmartPaste(); +#endif +} + +void ChromiumBridge::clipboardWriteURL(const KURL& url, const String& title) { + ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); + + GURL gurl = webkit_glue::KURLToGURL(url); + scw.WriteBookmark(webkit_glue::StringToStdWString(title), gurl.spec()); + + std::wstring link(webkit_glue::StringToStdWString(urlToMarkup(url, title))); + scw.WriteHTML(link, ""); + + scw.WriteText(ASCIIToWide(gurl.spec())); +} + +void ChromiumBridge::clipboardWriteImage(const NativeImageSkia* bitmap, + const KURL& url, const String& title) { + ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); + +#if defined(OS_WIN) + if (bitmap) + scw.WriteBitmap(*bitmap); +#endif + if (!url.isEmpty()) { + GURL gurl = webkit_glue::KURLToGURL(url); + scw.WriteBookmark(webkit_glue::StringToStdWString(title), gurl.spec()); + + scw.WriteHTML(UrlToImageMarkup(url, title), ""); + + scw.WriteText(ASCIIToWide(gurl.spec())); + } +} + +// + // Cookies -------------------------------------------------------------------- void ChromiumBridge::setCookies( diff --git a/webkit/glue/clipboard_conversion.cc b/webkit/glue/clipboard_conversion.cc index 9df3f59..0c690c0 100644 --- a/webkit/glue/clipboard_conversion.cc +++ b/webkit/glue/clipboard_conversion.cc @@ -9,10 +9,10 @@ #include "build/build_config.h" #include "ChromiumDataObject.h" -#if defined(OS_WIN) -#include "ClipboardUtilitiesWin.h" -#endif +#include "ClipboardUtilitiesChromium.h" +#include "KURL.h" #include "SharedBuffer.h" +#include <wtf/Vector.h> #include "webkit/glue/glue_util.h" @@ -20,6 +20,66 @@ namespace { // TODO(tc): CF_HTML logic should move into the browser process since it only // makes sense on Windows. +#if defined(OS_WIN) +void append(WTF::Vector<char>& vector, const WebCore::CString& string) { + vector.append(string.data(), string.length()); +} +// Documentation for the CF_HTML format is available at +// http://msdn.microsoft.com/workshop/networking/clipboard/htmlclipboard.asp +void markupToCF_HTML(const WebCore::String& markup, + const WebCore::String& src_url, + WTF::Vector<char>& result) { + if (markup.isEmpty()) + return; + + #define MAX_DIGITS 10 + #define MAKE_NUMBER_FORMAT_1(digits) MAKE_NUMBER_FORMAT_2(digits) + #define MAKE_NUMBER_FORMAT_2(digits) "%0" #digits "u" + #define NUMBER_FORMAT MAKE_NUMBER_FORMAT_1(MAX_DIGITS) + + static const char* header = "Version:0.9\n" + "StartHTML:" NUMBER_FORMAT "\n" + "EndHTML:" NUMBER_FORMAT "\n" + "StartFragment:" NUMBER_FORMAT "\n" + "EndFragment:" NUMBER_FORMAT "\n"; + static const char* source_url_prefix = "SourceURL:"; + + static const char* start_markup = "<HTML>\n<BODY>\n<!--StartFragment-->\n"; + static const char* end_markup = "\n<!--EndFragment-->\n</BODY>\n</HTML>"; + + WebCore::CString source_url_utf8 = (src_url == WebCore::blankURL()) ? + "" : src_url.utf8(); + WebCore::CString markup_utf8 = markup.utf8(); + + // calculate offsets + size_t start_html_offset = strlen(header) - strlen(NUMBER_FORMAT) * 4 + + MAX_DIGITS * 4; + if (source_url_utf8.length()) { + start_html_offset += strlen(source_url_prefix) + + source_url_utf8.length() + 1; + } + size_t start_fragment_offset = start_html_offset + strlen(start_markup); + size_t end_fragment_offset = start_fragment_offset + markup_utf8.length(); + size_t end_html_offset = end_fragment_offset + strlen(end_markup); + + append(result, WebCore::String::format(header, start_html_offset, + end_html_offset, start_fragment_offset, end_fragment_offset).utf8()); + if (source_url_utf8.length()) { + append(result, source_url_prefix); + append(result, source_url_utf8); + result.append('\n'); + } + append(result, start_markup); + append(result, markup_utf8); + append(result, end_markup); + + #undef MAX_DIGITS + #undef MAKE_NUMBER_FORMAT_1 + #undef MAKE_NUMBER_FORMAT_2 + #undef NUMBER_FORMAT +} +#endif + std::wstring HTMLToCFHTML(const WebCore::String& html, const WebCore::KURL& url) { #if defined(OS_WIN) diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index 1d80e86..21754c5 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -14,6 +14,7 @@ #include <string> #include <vector> +#include "base/clipboard.h" #include "base/gfx/native_widget_types.h" #include "base/string16.h" #include "webkit/glue/screen_info.h" @@ -42,7 +43,6 @@ class Frame; } class SkBitmap; -class Clipboard; #if defined(OS_MACOSX) typedef struct CGImage* CGImageRef; @@ -196,11 +196,10 @@ HCURSOR LoadCursor(int cursor_id); // Glue to access the clipboard. // Get a clipboard that can be used to construct a ScopedClipboardWriterGlue. -// TODO(tc): Move base/clipboard.h into the base:: namespace. -::Clipboard* ClipboardGetClipboard(); +Clipboard* ClipboardGetClipboard(); // Tests whether the clipboard contains a certain format -bool ClipboardIsFormatAvailable(unsigned int format); +bool ClipboardIsFormatAvailable(Clipboard::FormatType format); // Reads UNICODE text from the clipboard, if available. void ClipboardReadText(std::wstring* result); 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, + }; + }; } diff --git a/webkit/port/platform/mac/ClipboardMac.mm b/webkit/port/platform/mac/ClipboardMac.mm deleted file mode 100644 index 74e5ef7..0000000 --- a/webkit/port/platform/mac/ClipboardMac.mm +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006 Apple Computer, 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. - */ - -#import "config.h" -#import "ClipboardMac.h" - -#import "CachedImage.h" -#import "Document.h" -#import "DragClient.h" -#import "DragController.h" -#import "Editor.h" -#import "EventHandler.h" -#import "FloatRect.h" -#import "FoundationExtras.h" -#import "Frame.h" -#import "HTMLImageElement.h" -#import "Image.h" -#import "Page.h" -#import "Pasteboard.h" -#import "Range.h" -#import "RenderImage.h" -#import "WebCoreSystemInterface.h" - -@class WebArchive; - -namespace WebCore { - -ClipboardMac::ClipboardMac(bool forDragging, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame *frame) - : Clipboard(policy, forDragging) - , m_pasteboard(pasteboard) - , m_frame(frame) -{ - m_changeCount = [m_pasteboard.get() changeCount]; -} - -ClipboardMac::~ClipboardMac() -{ -} - -bool ClipboardMac::hasData() -{ - return m_pasteboard && [m_pasteboard.get() types] && [[m_pasteboard.get() types] count] > 0; -} - -static NSString *cocoaTypeFromMIMEType(const String& type) -{ - String qType = type.stripWhiteSpace(); - - // two special cases for IE compatibility - if (qType == "Text") - return NSStringPboardType; - if (qType == "URL") - return NSURLPboardType; - - // Ignore any trailing charset - JS strings are Unicode, which encapsulates the charset issue - if (qType == "text/plain" || qType.startsWith("text/plain;")) - return NSStringPboardType; - if (qType == "text/uri-list") - // special case because UTI doesn't work with Cocoa's URL type - return NSURLPboardType; // note special case in getData to read NSFilenamesType - - // Try UTI now - NSString *mimeType = qType; - CFStringRef UTIType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mimeType, NULL); - if (UTIType) { - CFStringRef pbType = UTTypeCopyPreferredTagWithClass(UTIType, kUTTagClassNSPboardType); - CFRelease(UTIType); - if (pbType) - return HardAutorelease(pbType); - } - - // No mapping, just pass the whole string though - return qType; -} - -static String MIMETypeFromCocoaType(NSString *type) -{ - // UTI may not do these right, so make sure we get the right, predictable result - if ([type isEqualToString:NSStringPboardType]) - return "text/plain"; - if ([type isEqualToString:NSURLPboardType] || [type isEqualToString:NSFilenamesPboardType]) - return "text/uri-list"; - - // Now try the general UTI mechanism - CFStringRef UTIType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL); - if (UTIType) { - CFStringRef mimeType = UTTypeCopyPreferredTagWithClass(UTIType, kUTTagClassMIMEType); - CFRelease(UTIType); - if (mimeType) { - String result = mimeType; - CFRelease(mimeType); - return result; - } - } - - // No mapping, just pass the whole string though - return type; -} - -void ClipboardMac::clearData(const String& type) -{ - if (policy() != ClipboardWritable) - return; - - // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner - - NSString *cocoaType = cocoaTypeFromMIMEType(type); - if (cocoaType) { - [m_pasteboard.get() setString:@"" forType:cocoaType]; - } -} - -void ClipboardMac::clearAllData() -{ - if (policy() != ClipboardWritable) - return; - - // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner - - [m_pasteboard.get() declareTypes:[NSArray array] owner:nil]; -} - -String ClipboardMac::getData(const String& type, bool& success) const -{ - success = false; - if (policy() != ClipboardReadable) - return String(); - - NSString *cocoaType = cocoaTypeFromMIMEType(type); - NSString *cocoaValue = nil; - NSArray *availableTypes = [m_pasteboard.get() types]; - - // Fetch the data in different ways for the different Cocoa types - - if ([cocoaType isEqualToString:NSURLPboardType]) { - // When both URL and filenames are present, filenames is superior since it can contain a list. - // must check this or we get a printf from CF when there's no data of this type - if ([availableTypes containsObject:NSFilenamesPboardType]) { - NSArray *fileList = [m_pasteboard.get() propertyListForType:NSFilenamesPboardType]; - if (fileList && [fileList isKindOfClass:[NSArray class]]) { - unsigned count = [fileList count]; - if (count > 0) { - if (type != "text/uri-list") - count = 1; - NSMutableString *urls = [NSMutableString string]; - unsigned i; - for (i = 0; i < count; i++) { - if (i > 0) { - [urls appendString:@"\n"]; - } - NSString *string = [fileList objectAtIndex:i]; - if (![string isKindOfClass:[NSString class]]) - break; - NSURL *url = [NSURL fileURLWithPath:string]; - [urls appendString:[url absoluteString]]; - } - if (i == count) - cocoaValue = urls; - } - } - } - if (!cocoaValue) { - // must check this or we get a printf from CF when there's no data of this type - if ([availableTypes containsObject:NSURLPboardType]) { - NSURL *url = [NSURL URLFromPasteboard:m_pasteboard.get()]; - if (url) { - cocoaValue = [url absoluteString]; - } - } - } - } else if (cocoaType) { - cocoaValue = [m_pasteboard.get() stringForType:cocoaType]; - } - - // Enforce changeCount ourselves for security. We check after reading instead of before to be - // sure it doesn't change between our testing the change count and accessing the data. - if (cocoaValue && m_changeCount == [m_pasteboard.get() changeCount]) { - success = true; - return cocoaValue; - } - - return String(); -} - -bool ClipboardMac::setData(const String &type, const String &data) -{ - if (policy() != ClipboardWritable) - return false; - // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner - - NSString *cocoaType = cocoaTypeFromMIMEType(type); - NSString *cocoaData = data; - - if ([cocoaType isEqualToString:NSURLPboardType]) { - [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSURLPboardType] owner:nil]; - NSURL *url = [[NSURL alloc] initWithString:cocoaData]; - [url writeToPasteboard:m_pasteboard.get()]; - - if ([url isFileURL]) { - [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; - NSArray *fileList = [NSArray arrayWithObject:[url path]]; - [m_pasteboard.get() setPropertyList:fileList forType:NSFilenamesPboardType]; - } - - [url release]; - return true; - } - - if (cocoaType) { - // everything else we know of goes on the pboard as a string - [m_pasteboard.get() addTypes:[NSArray arrayWithObject:cocoaType] owner:nil]; - return [m_pasteboard.get() setString:cocoaData forType:cocoaType]; - } - - return false; -} - -HashSet<String> ClipboardMac::types() const -{ - if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable) - return HashSet<String>(); - - NSArray *types = [m_pasteboard.get() types]; - - // Enforce changeCount ourselves for security. We check after reading instead of before to be - // sure it doesn't change between our testing the change count and accessing the data. - if (m_changeCount != [m_pasteboard.get() changeCount]) - return HashSet<String>(); - - HashSet<String> result; - if (types) { - unsigned count = [types count]; - unsigned i; - for (i = 0; i < count; i++) { - NSString *pbType = [types objectAtIndex:i]; - if ([pbType isEqualToString:@"NeXT plain ascii pasteboard type"]) - continue; // skip this ancient type that gets auto-supplied by some system conversion - - String str = MIMETypeFromCocoaType(pbType); - if (!result.contains(str)) - result.add(str); - } - } - return result; -} - -// The rest of these getters don't really have any impact on security, so for now make no checks - -void ClipboardMac::setDragImage(CachedImage* img, const IntPoint &loc) -{ - setDragImage(img, 0, loc); -} - -void ClipboardMac::setDragImageElement(Node *node, const IntPoint &loc) -{ - setDragImage(0, node, loc); -} - -void ClipboardMac::setDragImage(CachedImage* image, Node *node, const IntPoint &loc) -{ - if (policy() == ClipboardImageWritable || policy() == ClipboardWritable) { - if (m_dragImage) - m_dragImage->removeClient(this); - m_dragImage = image; - if (m_dragImage) - m_dragImage->addClient(this); - - m_dragLoc = loc; - m_dragImageElement = node; - - if (dragStarted() && m_changeCount == [m_pasteboard.get() changeCount]) { - NSPoint cocoaLoc; - NSImage* cocoaImage = dragNSImage(cocoaLoc); - if (cocoaImage) { - // Dashboard wants to be able to set the drag image during dragging, but Cocoa does not allow this. - // Instead we must drop down to the CoreGraphics API. - wkSetDragImage(cocoaImage, cocoaLoc); - - // Hack: We must post an event to wake up the NSDragManager, which is sitting in a nextEvent call - // up the stack from us because the CoreFoundation drag manager does not use the run loop by itself. - // This is the most innocuous event to use, per Kristen Forster. - NSEvent* ev = [NSEvent mouseEventWithType:NSMouseMoved location:NSZeroPoint - modifierFlags:0 timestamp:0 windowNumber:0 context:nil eventNumber:0 clickCount:0 pressure:0]; - [NSApp postEvent:ev atStart:YES]; - } - } - // Else either 1) we haven't started dragging yet, so we rely on the part to install this drag image - // as part of getting the drag kicked off, or 2) Someone kept a ref to the clipboard and is trying to - // set the image way too late. - } -} - -void ClipboardMac::writeRange(Range* range, Frame* frame) -{ -#if 0 - ASSERT(range); - ASSERT(frame); - Pasteboard::writeSelection(m_pasteboard.get(), range, frame->editor()->smartInsertDeleteEnabled() && frame->selectionGranularity() == WordGranularity, frame); -#endif -} - -void ClipboardMac::writeURL(const KURL& url, const String& title, Frame* frame) -{ -#if 0 - ASSERT(frame); - ASSERT(m_pasteboard); - Pasteboard::writeURL(m_pasteboard.get(), nil, url, title, frame); -#endif -} - -void ClipboardMac::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame) -{ -#if 0 - // TODO(pinkerton): find a way to do without objc bindings, similar - // to how win32 does it - ASSERT(frame); - if (Page* page = frame->page()) - page->dragController()->client()->declareAndWriteDragImage(m_pasteboard.get(), [DOMElement _wrapElement:element], url.getNSURL(), title, frame); -#endif -} - -DragImageRef ClipboardMac::createDragImage(IntPoint& loc) const -{ - NSImage *result = nil; - if (m_dragImage) { - result = createDragImageFromImage(m_dragImage->image()); - - loc = m_dragLoc; - loc.setY([result size].height - loc.y()); - } - return result; -} - -NSImage *ClipboardMac::dragNSImage(NSPoint& loc) const -{ - return nil; -} - -} diff --git a/webkit/port/platform/mac/EditorMac.mm b/webkit/port/platform/mac/EditorMac.mm deleted file mode 100644 index 5ccab91..0000000 --- a/webkit/port/platform/mac/EditorMac.mm +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2006, 2007, 2008 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. - */ - -#import "config.h" -#import "Editor.h" - -#import "ClipboardMac.h" -#import "DocLoader.h" -#import "Frame.h" -#import "FrameView.h" - -namespace WebCore { - -extern "C" { - -// Kill ring calls. Would be better to use NSKillRing.h, but that's not available as API or SPI. - -void _NSInitializeKillRing(); -void _NSAppendToKillRing(NSString *); -void _NSPrependToKillRing(NSString *); -NSString *_NSYankFromKillRing(); -void _NSNewKillRingSequence(); -void _NSSetKillRingToYankedState(); - -} - -PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy) -{ - return ClipboardMac::create(false, [NSPasteboard generalPasteboard], policy, 0); -} - -static void initializeKillRingIfNeeded() -{ - static bool initializedKillRing = false; - if (!initializedKillRing) { - initializedKillRing = true; - _NSInitializeKillRing(); - } -} - -// TODO(port): WebCore's Editor.cpp provides these functions as stubs when -// PLATFORM(MAC) is not in effect. We no longer use PLATFORM(MAC) for the -// Chromium verison of WebKit, but we may want these implementations instead of -// the stubs in Editor.cpp. -#if 0 -void Editor::appendToKillRing(const String& string) -{ - initializeKillRingIfNeeded(); - _NSAppendToKillRing(string); -} - -void Editor::prependToKillRing(const String& string) -{ - initializeKillRingIfNeeded(); - _NSPrependToKillRing(string); -} - -String Editor::yankFromKillRing() -{ - initializeKillRingIfNeeded(); - return _NSYankFromKillRing(); -} - -void Editor::startNewKillRingSequence() -{ - initializeKillRingIfNeeded(); - _NSNewKillRingSequence(); -} - -void Editor::setKillRingToYankedState() -{ - initializeKillRingIfNeeded(); - _NSSetKillRingToYankedState(); -} -#endif - -void Editor::showFontPanel() -{ - [[NSFontManager sharedFontManager] orderFrontFontPanel:nil]; -} - -void Editor::showStylesPanel() -{ - [[NSFontManager sharedFontManager] orderFrontStylesPanel:nil]; -} - -void Editor::showColorPanel() -{ - [[NSApplication sharedApplication] orderFrontColorPanel:nil]; -} - -// FIXME: We want to use the platform-independent code instead. But when we last -// tried to do so it seemed that we first need to move more of the logic from -// -[WebHTMLView.cpp _documentFragmentFromPasteboard] into PasteboardMac. - -#if 0 -void Editor::paste() -{ - ASSERT(m_frame->document()); - FrameView* view = m_frame->view(); - if (!view) - return; - DocLoader* loader = m_frame->document()->docLoader(); - loader->setAllowStaleResources(true); - [view->documentView() tryToPerform:@selector(paste:) with:nil]; - loader->setAllowStaleResources(false); -} -#endif - -} // namespace WebCore diff --git a/webkit/port/platform/mac/PasteboardMac.mm b/webkit/port/platform/mac/PasteboardMac.mm deleted file mode 100644 index 249235b..0000000 --- a/webkit/port/platform/mac/PasteboardMac.mm +++ /dev/null @@ -1,422 +0,0 @@ -/* - * Copyright (C) 2006 Apple Computer, 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. - */ - -#import "config.h" -#import "Pasteboard.h" - -#import "CachedResource.h" -#import "CharacterNames.h" -#import "Document.h" -#import "DocumentFragment.h" -#import "Editor.h" -#import "EditorClient.h" -#import "Frame.h" -#import "HitTestResult.h" -#import "Image.h" -#import "KURL.h" -#import "LegacyWebArchive.h" -#import "LoaderNSURLExtras.h" -#import "MIMETypeRegistry.h" -#import "RenderImage.h" -#import "WebCoreNSStringExtras.h" -#import "WebCoreSystemInterface.h" -#import "markup.h" - -#import <wtf/RetainPtr.h> - -#include "webkit/glue/glue_util.h" -#include "webkit/glue/webkit_glue.h" - - -#if 0 -@interface NSAttributedString (AppKitSecretsIKnowAbout) -- (id)_initWithDOMRange:(DOMRange *)domRange; -@end -#endif - -namespace WebCore { - -// FIXME: It's not great to have these both here and in WebKit. -NSString *WebArchivePboardType = @"Apple Web Archive pasteboard type"; -NSString *WebSmartPastePboardType = @"NeXT smart paste pasteboard type"; -NSString *WebURLNamePboardType = @"public.url-name"; -NSString *WebURLPboardType = @"public.url"; -NSString *WebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType"; - -#ifndef BUILDING_ON_TIGER -static NSArray* selectionPasteboardTypes(bool canSmartCopyOrDelete, bool selectionContainsAttachments) -{ - if (selectionContainsAttachments) { - if (canSmartCopyOrDelete) - return [NSArray arrayWithObjects:WebSmartPastePboardType, WebArchivePboardType, NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, nil]; - else - return [NSArray arrayWithObjects:WebArchivePboardType, NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, nil]; - } else { // Don't write RTFD to the pasteboard when the copied attributed string has no attachments. - if (canSmartCopyOrDelete) - return [NSArray arrayWithObjects:WebSmartPastePboardType, WebArchivePboardType, NSRTFPboardType, NSStringPboardType, nil]; - else - return [NSArray arrayWithObjects:WebArchivePboardType, NSRTFPboardType, NSStringPboardType, nil]; - } -} -#endif - -static NSArray* writableTypesForURL() -{ - static RetainPtr<NSArray> types = nil; - if (!types) { - types = [[NSArray alloc] initWithObjects: - WebURLsWithTitlesPboardType, - NSURLPboardType, - WebURLPboardType, - WebURLNamePboardType, - NSStringPboardType, - nil]; - } - return types.get(); -} - -static NSArray* writableTypesForImage() -{ - static RetainPtr<NSMutableArray> types = nil; - if (!types) { - types = [[NSMutableArray alloc] initWithObjects:NSTIFFPboardType, nil]; - [types.get() addObjectsFromArray:writableTypesForURL()]; - [types.get() addObject:NSRTFDPboardType]; - } - return types.get(); -} - -Pasteboard* Pasteboard::generalPasteboard() -{ -#if 0 - static Pasteboard* pasteboard = new Pasteboard([NSPasteboard generalPasteboard]); - return pasteboard; -#endif - return nil; -} - -#if 0 -Pasteboard::Pasteboard(NSPasteboard* pboard) - : m_pasteboard(pboard) -{ -} -#endif - -void Pasteboard::clear() -{ -#if 0 - [m_pasteboard.get() declareTypes:[NSArray array] owner:nil]; -#endif -} - -static NSAttributedString *stripAttachmentCharacters(NSAttributedString *string) -{ - const unichar attachmentCharacter = NSAttachmentCharacter; - static RetainPtr<NSString> attachmentCharacterString = [NSString stringWithCharacters:&attachmentCharacter length:1]; - NSMutableAttributedString *result = [[string mutableCopy] autorelease]; - NSRange attachmentRange = [[result string] rangeOfString:attachmentCharacterString.get()]; - while (attachmentRange.location != NSNotFound) { - [result replaceCharactersInRange:attachmentRange withString:@""]; - attachmentRange = [[result string] rangeOfString:attachmentCharacterString.get()]; - } - return result; -} - -#if 0 -void Pasteboard::writeSelection(NSPasteboard* pasteboard, Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) -{ - -// TODO(pinkerton): We need to figure out how to get copy/paste info back -// to the main process and let it manage the pasteboard. One major problem is -// that we can't rely on -[NSAttributedString initWithHTML] since it calls -// the system WebKit and that wrecks havoc with ObjC's single-level -// namespace. That will cause some big problems getting rtf strings -// onto the pasteboard since we have no other way of creating that data -// ourselves. Punt for now. - - if (WebArchivePboardType == nil) - Pasteboard::generalPasteboard(); //Initialises pasteboard types - ASSERT(selectedRange); - - ExceptionCode ec = 0; - WebCore::String html = createMarkup(selectedRange, 0, AnnotateForInterchange); - - NSData* htmlData = [NSData dataWithBytes:reinterpret_cast<const void*>(html.characters()) length:html.length()]; - NSAttributedString *attributedString = - [[[NSAttributedString alloc] initWithHTML:htmlData documentAttributes:NULL] autorelease]; - -#ifdef BUILDING_ON_TIGER - // TODO(pinkerton): I don't think we need this, since we won't be used by the - // OS as a web view embedded in Mail or other apps. - // - // 4930197: Mail overrides [WebHTMLView pasteboardTypesForSelection] in order to add another type to the pasteboard - // after WebKit does. On Tiger we must call this function so that Mail code will be executed, meaning that - // we can't call WebCore::Pasteboard's method for setting types. - - NSArray *types = frame->editor()->client()->pasteboardTypesForSelection(frame); - // Don't write RTFD to the pasteboard when the copied attributed string has no attachments. - NSMutableArray *mutableTypes = nil; - if (![attributedString containsAttachments]) { - mutableTypes = [[types mutableCopy] autorelease]; - [mutableTypes removeObject:NSRTFDPboardType]; - types = mutableTypes; - } - [pasteboard declareTypes:types owner:nil]; -#else - NSArray *types = selectionPasteboardTypes(canSmartCopyOrDelete, [attributedString containsAttachments]); - [pasteboard declareTypes:types owner:nil]; - frame->editor()->client()->didSetSelectionTypesForPasteboard(); -#endif - - // Put HTML on the pasteboard. - if ([types containsObject:WebArchivePboardType]) { - RefPtr<LegacyWebArchive> archive = LegacyWebArchive::createFromSelection(frame); - RetainPtr<CFDataRef> data = archive ? archive->rawDataRepresentation() : 0; - [pasteboard setData:(NSData *)data.get() forType:WebArchivePboardType]; - } - - // Put the attributed string on the pasteboard (RTF/RTFD format). - if ([types containsObject:NSRTFDPboardType]) { - NSData *RTFDData = [attributedString RTFDFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil]; - [pasteboard setData:RTFDData forType:NSRTFDPboardType]; - } - if ([types containsObject:NSRTFPboardType]) { - if ([attributedString containsAttachments]) - attributedString = stripAttachmentCharacters(attributedString); - NSData *RTFData = [attributedString RTFFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil]; - [pasteboard setData:RTFData forType:NSRTFPboardType]; - } - - // Put plain string on the pasteboard. - if ([types containsObject:NSStringPboardType]) { - // Map to a plain old space because this is better for source code, other browsers do it, - // and because HTML forces you to do this any time you want two spaces in a row. - String text = selectedRange->text(); - text.replace('\\', frame->backslashAsCurrencySymbol()); - NSMutableString *s = [[[(NSString*)text copy] autorelease] mutableCopy]; - - NSString *NonBreakingSpaceString = [NSString stringWithCharacters:&noBreakSpace length:1]; - [s replaceOccurrencesOfString:NonBreakingSpaceString withString:@" " options:0 range:NSMakeRange(0, [s length])]; - [pasteboard setString:s forType:NSStringPboardType]; - [s release]; - } - - if ([types containsObject:WebSmartPastePboardType]) { - [pasteboard setData:nil forType:WebSmartPastePboardType]; - } -} -#endif - -void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) -{ -#if 0 - Pasteboard::writeSelection(m_pasteboard.get(), selectedRange, canSmartCopyOrDelete, frame); -#endif -} - -#if 0 -void Pasteboard::writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame) -{ - if (WebArchivePboardType == nil) - Pasteboard::generalPasteboard(); //Initialises pasteboard types - - if (types == nil) { - types = writableTypesForURL(); - [pasteboard declareTypes:types owner:nil]; - } - - ASSERT(!url.isEmpty()); - - NSURL *cocoaURL = url; - NSString *userVisibleString = frame->editor()->client()->userVisibleString(cocoaURL); - - NSString *title = (NSString*)titleStr; - if ([title length] == 0) { - title = [[cocoaURL path] lastPathComponent]; - if ([title length] == 0) - title = userVisibleString; - } - - if ([types containsObject:WebURLsWithTitlesPboardType]) - [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:userVisibleString], - [NSArray arrayWithObject:(NSString*)titleStr.stripWhiteSpace()], - nil] - forType:WebURLsWithTitlesPboardType]; - if ([types containsObject:NSURLPboardType]) - [cocoaURL writeToPasteboard:pasteboard]; - if ([types containsObject:WebURLPboardType]) - [pasteboard setString:userVisibleString forType:WebURLPboardType]; - if ([types containsObject:WebURLNamePboardType]) - [pasteboard setString:title forType:WebURLNamePboardType]; - if ([types containsObject:NSStringPboardType]) - [pasteboard setString:userVisibleString forType:NSStringPboardType]; -} -#endif - -void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) -{ -#if 0 - Pasteboard::writeURL(m_pasteboard.get(), nil, url, titleStr, frame); -#endif -} - -#if 0 -static NSFileWrapper* fileWrapperForImage(CachedResource* resource, NSURL *url) -{ - SharedBuffer* coreData = resource->data(); - NSData *data = [[[NSData alloc] initWithBytes:coreData->platformData() - length:coreData->platformDataSize()] autorelease]; - NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease]; - String coreMIMEType = resource->response().mimeType(); - NSString *MIMEType = nil; - if (!coreMIMEType.isNull()) - MIMEType = coreMIMEType; - [wrapper setPreferredFilename:suggestedFilenameWithMIMEType(url, MIMEType)]; - return wrapper; -} - -void Pasteboard::writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper) -{ - NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:wrapper]; - - NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attachment]; - [attachment release]; - - NSData *RTFDData = [string RTFDFromRange:NSMakeRange(0, [string length]) documentAttributes:nil]; - [m_pasteboard.get() setData:RTFDData forType:NSRTFDPboardType]; -} -#endif - -void Pasteboard::writeImage(Node* node, const KURL& url, const String& title) -{ -#if 0 - ASSERT(node); - Frame* frame = node->document()->frame(); - - NSURL *cocoaURL = url; - ASSERT(cocoaURL); - - NSArray* types = writableTypesForImage(); - [m_pasteboard.get() declareTypes:types owner:nil]; - writeURL(m_pasteboard.get(), types, cocoaURL, nsStringNilIfEmpty(title), frame); - - ASSERT(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); - - [m_pasteboard.get() setData:[image->getNSImage() TIFFRepresentation] forType:NSTIFFPboardType]; - - String MIMEType = cachedImage->response().mimeType(); - ASSERT(MIMETypeRegistry::isSupportedImageResourceMIMEType(MIMEType)); - - writeFileWrapperAsRTFDAttachment(fileWrapperForImage(cachedImage, cocoaURL)); -#endif -} - -bool Pasteboard::canSmartReplace() -{ -#if 0 - return [[m_pasteboard.get() types] containsObject:WebSmartPastePboardType]; -#endif - return false; -} - -String Pasteboard::plainText(Frame* frame) -{ -#if 0 - NSArray *types = [m_pasteboard.get() types]; - - if ([types containsObject:NSStringPboardType]) - return [m_pasteboard.get() stringForType:NSStringPboardType]; - - NSAttributedString *attributedString = nil; - NSString *string; - - if ([types containsObject:NSRTFDPboardType]) - attributedString = [[NSAttributedString alloc] initWithRTFD:[m_pasteboard.get() dataForType:NSRTFDPboardType] documentAttributes:NULL]; - if (attributedString == nil && [types containsObject:NSRTFPboardType]) - attributedString = [[NSAttributedString alloc] initWithRTF:[m_pasteboard.get() dataForType:NSRTFPboardType] documentAttributes:NULL]; - if (attributedString != nil) { - string = [[attributedString string] copy]; - [attributedString release]; - return [string autorelease]; - } - - if ([types containsObject:NSFilenamesPboardType]) { - string = [[m_pasteboard.get() propertyListForType:NSFilenamesPboardType] componentsJoinedByString:@"\n"]; - if (string != nil) - return string; - } - - - if (NSURL *url = [NSURL URLFromPasteboard:m_pasteboard.get()]) { - // FIXME: using the editorClient to call into webkit, for now, since - // calling _web_userVisibleString from WebCore involves migrating a sizable web of - // helper code that should either be done in a separate patch or figured out in another way. - string = frame->editor()->client()->userVisibleString(url); - if ([string length] > 0) - return string; - } - -#endif - return String(); -} - -PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) -{ -#if 0 - NSArray *types = [m_pasteboard.get() types]; - chosePlainText = false; - - if ([types containsObject:NSHTMLPboardType]) { - NSString *HTMLString = [m_pasteboard.get() stringForType:NSHTMLPboardType]; - // This is a hack to make Microsoft's HTML pasteboard data work. See 3778785. - if ([HTMLString hasPrefix:@"Version:"]) { - NSRange range = [HTMLString rangeOfString:@"<html" options:NSCaseInsensitiveSearch]; - if (range.location != NSNotFound) { - HTMLString = [HTMLString substringFromIndex:range.location]; - } - } - if ([HTMLString length] != 0) { - RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), HTMLString, ""); - if (fragment) - return fragment.release(); - } - } - - if (allowPlainText && [types containsObject:NSStringPboardType]) { - chosePlainText = true; - RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), [m_pasteboard.get() stringForType:NSStringPboardType]); - if (fragment) - return fragment.release(); - } -#endif - return 0; -} - -} diff --git a/webkit/port/platform/win/ClipboardUtilitiesWin.cpp b/webkit/port/platform/win/ClipboardUtilitiesWin.cpp deleted file mode 100644 index f23c2fe..0000000 --- a/webkit/port/platform/win/ClipboardUtilitiesWin.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright (C) 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 "ClipboardUtilitiesWin.h" - -#include "KURL.h" -#include "CString.h" -#include "DocumentFragment.h" -#include "markup.h" -#include "PlatformString.h" -#include "TextEncoding.h" -#include <shlobj.h> -#include <shlwapi.h> -#include <shellapi.h> -#include <wininet.h> // for INTERNET_MAX_URL_LENGTH - -#include "base/clipboard_util.h" - -namespace WebCore { - -FORMATETC* cfHDropFormat() -{ - static FORMATETC urlFormat = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -//Firefox text/html -static FORMATETC* texthtmlFormat() -{ - static UINT cf = RegisterClipboardFormat(L"text/html"); - static FORMATETC texthtmlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &texthtmlFormat; -} - -HGLOBAL createGlobalData(const KURL& url, const String& title) -{ - String mutableURL(url.string()); - String mutableTitle(title); - SIZE_T size = mutableURL.length() + mutableTitle.length() + 2; // +1 for "\n" and +1 for null terminator - HGLOBAL cbData = ::GlobalAlloc(GPTR, size * sizeof(UChar)); - - if (cbData) { - PWSTR buffer = (PWSTR)::GlobalLock(cbData); - swprintf_s(buffer, size, L"%s\n%s", mutableURL.charactersWithNullTermination(), mutableTitle.isNull() ? L"" : mutableTitle.charactersWithNullTermination()); - ::GlobalUnlock(cbData); - } - return cbData; -} - -HGLOBAL createGlobalData(const String& str) -{ - HGLOBAL globalData = ::GlobalAlloc(GPTR, (str.length() + 1) * sizeof(UChar)); - if (!globalData) - return 0; - UChar* buffer = static_cast<UChar*>(::GlobalLock(globalData)); - memcpy(buffer, str.characters(), str.length() * sizeof(UChar)); - buffer[str.length()] = 0; - ::GlobalUnlock(globalData); - return globalData; -} - -HGLOBAL createGlobalData(const Vector<char>& vector) -{ - HGLOBAL globalData = ::GlobalAlloc(GPTR, vector.size() + 1); - if (!globalData) - return 0; - char* buffer = static_cast<char*>(::GlobalLock(globalData)); - memcpy(buffer, vector.data(), vector.size()); - buffer[vector.size()] = 0; - ::GlobalUnlock(globalData); - return globalData; -} - -static void append(Vector<char>& vector, const char* string) -{ - vector.append(string, strlen(string)); -} - -static void append(Vector<char>& vector, const CString& string) -{ - vector.append(string.data(), string.length()); -} - -// Documentation for the CF_HTML format is available at http://msdn.microsoft.com/workshop/networking/clipboard/htmlclipboard.asp -void markupToCF_HTML(const String& markup, const String& srcURL, Vector<char>& result) -{ - if (markup.isEmpty()) - return; - - #define MAX_DIGITS 10 - #define MAKE_NUMBER_FORMAT_1(digits) MAKE_NUMBER_FORMAT_2(digits) - #define MAKE_NUMBER_FORMAT_2(digits) "%0" #digits "u" - #define NUMBER_FORMAT MAKE_NUMBER_FORMAT_1(MAX_DIGITS) - - const char* header = "Version:0.9\n" - "StartHTML:" NUMBER_FORMAT "\n" - "EndHTML:" NUMBER_FORMAT "\n" - "StartFragment:" NUMBER_FORMAT "\n" - "EndFragment:" NUMBER_FORMAT "\n"; - const char* sourceURLPrefix = "SourceURL:"; - - const char* startMarkup = "<HTML>\n<BODY>\n<!--StartFragment-->\n"; - const char* endMarkup = "\n<!--EndFragment-->\n</BODY>\n</HTML>"; - - CString sourceURLUTF8 = srcURL == blankURL() ? "" : srcURL.utf8(); - CString markupUTF8 = markup.utf8(); - - // calculate offsets - unsigned startHTMLOffset = strlen(header) - strlen(NUMBER_FORMAT) * 4 + MAX_DIGITS * 4; - if (sourceURLUTF8.length()) - startHTMLOffset += strlen(sourceURLPrefix) + sourceURLUTF8.length() + 1; - unsigned startFragmentOffset = startHTMLOffset + strlen(startMarkup); - unsigned endFragmentOffset = startFragmentOffset + markupUTF8.length(); - unsigned endHTMLOffset = endFragmentOffset + strlen(endMarkup); - - append(result, String::format(header, startHTMLOffset, endHTMLOffset, startFragmentOffset, endFragmentOffset).utf8()); - if (sourceURLUTF8.length()) { - append(result, sourceURLPrefix); - append(result, sourceURLUTF8); - result.append('\n'); - } - append(result, startMarkup); - append(result, markupUTF8); - append(result, endMarkup); - - #undef MAX_DIGITS - #undef MAKE_NUMBER_FORMAT_1 - #undef MAKE_NUMBER_FORMAT_2 - #undef NUMBER_FORMAT -} - -String urlToMarkup(const KURL& url, const String& title) -{ - String markup("<a href=\""); - markup.append(url.string()); - markup.append("\">"); - markup.append(title); - markup.append("</a>"); - return markup; -} - -String urlToImageMarkup(const KURL& url, const String& altStr) { - String markup("<img src=\""); - markup.append(url.string()); - markup.append("\""); - if (!altStr.isEmpty()) { - markup.append(" alt=\""); - // TODO(dglazkov): escape string - markup.append(altStr); - markup.append("\""); - } - markup.append("/>"); - return markup; -} - -void replaceNewlinesWithWindowsStyleNewlines(String& str) -{ - static const UChar Newline = '\n'; - static const char* const WindowsNewline("\r\n"); - str.replace(Newline, WindowsNewline); -} - -void replaceNBSPWithSpace(String& str) -{ - static const UChar NonBreakingSpaceCharacter = 0xA0; - static const UChar SpaceCharacter = ' '; - str.replace(NonBreakingSpaceCharacter, SpaceCharacter); -} - -FORMATETC* urlWFormat() -{ - static UINT cf = RegisterClipboardFormat(L"UniformResourceLocatorW"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -FORMATETC* urlFormat() -{ - static UINT cf = RegisterClipboardFormat(L"UniformResourceLocator"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -FORMATETC* plainTextFormat() -{ - static FORMATETC textFormat = {CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &textFormat; -} - -FORMATETC* plainTextWFormat() -{ - static FORMATETC textFormat = {CF_UNICODETEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &textFormat; -} - -FORMATETC* filenameWFormat() -{ - static UINT cf = RegisterClipboardFormat(L"FileNameW"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -FORMATETC* filenameFormat() -{ - static UINT cf = RegisterClipboardFormat(L"FileName"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -//MSIE HTML Format -FORMATETC* htmlFormat() -{ - static UINT cf = RegisterClipboardFormat(L"HTML Format"); - static FORMATETC htmlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &htmlFormat; -} - -FORMATETC* smartPasteFormat() -{ - static UINT cf = RegisterClipboardFormat(L"WebKit Smart Paste Format"); - static FORMATETC htmlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &htmlFormat; -} - -PassRefPtr<DocumentFragment> fragmentFromFilenames(Document*, const IDataObject*) -{ - //FIXME: We should be able to create fragments from files - return 0; -} - -bool containsFilenames(const IDataObject*) -{ - //FIXME: We'll want to update this once we can produce fragments from files - return false; -} - -//Convert a String containing CF_HTML formatted text to a DocumentFragment -PassRefPtr<DocumentFragment> fragmentFromCF_HTML(Document* doc, const String& cf_html) -{ - // obtain baseURL if present - String srcURLStr("sourceURL:"); - String srcURL; - unsigned lineStart = cf_html.find(srcURLStr, 0, false); - if (lineStart != -1) { - unsigned srcEnd = cf_html.find("\n", lineStart, false); - unsigned srcStart = lineStart+srcURLStr.length(); - String rawSrcURL = cf_html.substring(srcStart, srcEnd-srcStart); - replaceNBSPWithSpace(rawSrcURL); - srcURL = rawSrcURL.stripWhiteSpace(); - } - - // find the markup between "<!--StartFragment -->" and "<!--EndFragment -->", accounting for browser quirks - unsigned markupStart = cf_html.find("<html", 0, false); - unsigned tagStart = cf_html.find("startfragment", markupStart, false); - unsigned fragmentStart = cf_html.find('>', tagStart) + 1; - unsigned tagEnd = cf_html.find("endfragment", fragmentStart, false); - unsigned fragmentEnd = cf_html.reverseFind('<', tagEnd); - String markup = cf_html.substring(fragmentStart, fragmentEnd - fragmentStart).stripWhiteSpace(); - - return createFragmentFromMarkup(doc, markup, srcURL); -} - - -PassRefPtr<DocumentFragment> fragmentFromHTML(Document* doc, IDataObject* data) -{ - if (!doc || !data) - return 0; - - STGMEDIUM store; - String html; - String srcURL; - if (SUCCEEDED(data->GetData(ClipboardUtil::GetHtmlFormat(), &store))) { - //MS HTML Format parsing - char* data = (char*)GlobalLock(store.hGlobal); - SIZE_T dataSize = ::GlobalSize(store.hGlobal); - String cf_html(UTF8Encoding().decode(data, dataSize)); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - if (PassRefPtr<DocumentFragment> fragment = fragmentFromCF_HTML(doc, cf_html)) - return fragment; - } - if (SUCCEEDED(data->GetData(ClipboardUtil::GetTextHtmlFormat(), &store))) { - //raw html - UChar* data = (UChar*)GlobalLock(store.hGlobal); - html = String(data); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - return createFragmentFromMarkup(doc, html, srcURL); - } - - return 0; -} - -bool containsHTML(IDataObject* data) -{ - return SUCCEEDED(data->QueryGetData(ClipboardUtil::GetTextHtmlFormat())) || - SUCCEEDED(data->QueryGetData(ClipboardUtil::GetHtmlFormat())); -} - -} // namespace WebCore diff --git a/webkit/port/platform/win/ClipboardUtilitiesWin.h b/webkit/port/platform/win/ClipboardUtilitiesWin.h deleted file mode 100644 index a7669ad..0000000 --- a/webkit/port/platform/win/ClipboardUtilitiesWin.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 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. - */ - -#ifndef ClipboardUtilitiesWin_h -#define ClipboardUtilitiesWin_h - -#include "DocumentFragment.h" -#include <wtf/RefPtr.h> -#include <wtf/Vector.h> - -#include <windows.h> -#include <objidl.h> - -namespace WebCore { - -class Document; -class KURL; -class String; - -HGLOBAL createGlobalData(const String&); -HGLOBAL createGlobalData(const Vector<char>&); -HGLOBAL createGlobalData(const KURL& url, const String& title); - -FORMATETC* urlWFormat(); -FORMATETC* urlFormat(); -FORMATETC* plainTextWFormat(); -FORMATETC* plainTextFormat(); -FORMATETC* filenameWFormat(); -FORMATETC* filenameFormat(); -FORMATETC* htmlFormat(); -FORMATETC* cfHDropFormat(); -FORMATETC* smartPasteFormat(); - -void markupToCF_HTML(const String& markup, const String& srcURL, Vector<char>& result); -String urlToMarkup(const KURL& url, const String& title); -String urlToImageMarkup(const KURL& url, const String& altStr); - -void replaceNewlinesWithWindowsStyleNewlines(String& str); -void replaceNBSPWithSpace(String& str); - -bool containsFilenames(const IDataObject*); -bool containsHTML(IDataObject* data); - -PassRefPtr<DocumentFragment> fragmentFromFilenames(Document*, const IDataObject*); -PassRefPtr<DocumentFragment> fragmentFromHTML(Document* doc, IDataObject* data); -PassRefPtr<DocumentFragment> fragmentFromCF_HTML(Document* doc, const String& cf_html); - -} // namespace WebCore - -#endif // ClipboardUtilitiesWin_h diff --git a/webkit/port/platform/win/PasteboardWin.cpp b/webkit/port/platform/win/PasteboardWin.cpp deleted file mode 100644 index 3063dc9..0000000 --- a/webkit/port/platform/win/PasteboardWin.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 "ClipboardUtilitiesWin.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" - -#include "base/clipboard_util.h" -#include "webkit/glue/glue_util.h" -#include "webkit/glue/scoped_clipboard_writer_glue.h" -#include "webkit/glue/webkit_glue.h" - -namespace WebCore { - -static UINT HTMLClipboardFormat = 0; -static UINT BookmarkClipboardFormat = 0; -static UINT WebSmartPasteFormat = 0; - -Pasteboard* Pasteboard::generalPasteboard() -{ - static Pasteboard* pasteboard = new Pasteboard; - return pasteboard; -} - -Pasteboard::Pasteboard() -{ - HTMLClipboardFormat = ClipboardUtil::GetHtmlFormat()->cfFormat; - - BookmarkClipboardFormat = ClipboardUtil::GetUrlWFormat()->cfFormat; - - WebSmartPasteFormat = ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat; -} - -void Pasteboard::clear() -{ - // The ScopedClipboardWriter class takes care of clearing the clipboard's - // previous contents. -} - -void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) -{ - ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); - - ExceptionCode ec = 0; - scw.WriteHTML( - webkit_glue::StringToStdWString( - createMarkup(selectedRange, 0, AnnotateForInterchange)), - GURL(webkit_glue::StringToStdWString( - selectedRange->startContainer(ec)->document()->url())).spec()); - - // Put plain string on the pasteboard. CF_UNICODETEXT covers CF_TEXT as well - String str = frame->selectedText(); - replaceNewlinesWithWindowsStyleNewlines(str); - replaceNBSPWithSpace(str); - scw.WriteText(webkit_glue::StringToStdWString(str)); - - if (canSmartCopyOrDelete) - scw.WriteWebSmartPaste(); -} - -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(); - } - - ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); - - // write to clipboard in format com.apple.safari.bookmarkdata to be able to paste into the bookmarks view with appropriate title - scw.WriteBookmark(webkit_glue::StringToStdWString(titleStr), - webkit_glue::KURLToGURL(url).spec()); - - // write to clipboard in format CF_HTML to be able to paste into contenteditable areas as a link - std::wstring link(webkit_glue::StringToStdWString(urlToMarkup(url, title))); - scw.WriteHTML(link, GURL().spec()); - - // bare-bones CF_UNICODETEXT support - std::wstring spec(webkit_glue::StringToStdWString(url)); - scw.WriteText(spec); -} - -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 = image->nativeImageForCurrentFrame(); - ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); - - if (bitmap) - scw.WriteBitmap(*bitmap); - if (!url.isEmpty()) { - // write to clipboard in format com.apple.safari.bookmarkdata to be able to paste into the bookmarks view with appropriate title - scw.WriteBookmark(webkit_glue::StringToStdWString(title), - webkit_glue::KURLToGURL(url).spec()); - - // write to clipboard in format CF_HTML to be able to paste into contenteditable areas as a an image - std::wstring markup(webkit_glue::StringToStdWString(urlToImageMarkup(url, title))); - scw.WriteHTML(markup, GURL().spec()); - - // bare-bones CF_UNICODETEXT support - std::wstring spec(webkit_glue::StringToStdWString(url.string())); - scw.WriteText(spec); - } -} - -bool Pasteboard::canSmartReplace() -{ - return webkit_glue::ClipboardIsFormatAvailable(WebSmartPasteFormat); -} - -String Pasteboard::plainText(Frame* frame) -{ - if (webkit_glue::ClipboardIsFormatAvailable(CF_UNICODETEXT)) { - std::wstring text; - webkit_glue::ClipboardReadText(&text); - if (!text.empty()) - return webkit_glue::StdWStringToString(text); - } - - if (webkit_glue::ClipboardIsFormatAvailable(CF_TEXT)) { - std::string text; - webkit_glue::ClipboardReadAsciiText(&text); - if (!text.empty()) - return webkit_glue::StdStringToString(text); - } - - return String(); -} - -PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) -{ - chosePlainText = false; - - if (webkit_glue::ClipboardIsFormatAvailable(HTMLClipboardFormat)) { - std::wstring markup; - GURL src_url; - webkit_glue::ClipboardReadHTML(&markup, &src_url); - - PassRefPtr<DocumentFragment> fragment = - createFragmentFromMarkup(frame->document(), - webkit_glue::StdWStringToString(markup), - webkit_glue::StdStringToString(src_url.spec())); - - if (fragment) - return fragment; - } - - if (allowPlainText && - webkit_glue::ClipboardIsFormatAvailable(CF_UNICODETEXT)) { - - chosePlainText = true; - std::wstring markup; - webkit_glue::ClipboardReadText(&markup); - RefPtr<DocumentFragment> fragment = - createFragmentFromText(context.get(), - webkit_glue::StdWStringToString(markup)); - - if (fragment) - return fragment.release(); - } - - if (allowPlainText && webkit_glue::ClipboardIsFormatAvailable(CF_TEXT)) { - chosePlainText = true; - std::string markup; - webkit_glue::ClipboardReadAsciiText(&markup); - RefPtr<DocumentFragment> fragment = - createFragmentFromText(context.get(), - webkit_glue::StdStringToString(markup)); - if (fragment) - return fragment.release(); - } - - return 0; -} - -} // namespace WebCore diff --git a/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj b/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj index 7960119..d69447c 100644 --- a/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj +++ b/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 4DB7FA6F0E9BF33B00C66CE0 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DB7FA6E0E9BF33B00C66CE0 /* SystemConfiguration.framework */; }; 4DB7FEA40E9BF92100C66CE0 /* libwebcoresysteminterface.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DB7FE760E9BF6CB00C66CE0 /* libwebcoresysteminterface.a */; }; 4DB7FEA80E9BF98C00C66CE0 /* libWebKitSystemInterfaceLeopard.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DB7FEA70E9BF98C00C66CE0 /* libWebKitSystemInterfaceLeopard.a */; }; + 53E50D280ECA1B21001784B4 /* simple_clipboard_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 53E50D270ECA1B21001784B4 /* simple_clipboard_impl.cc */; }; 7B779D510E83001A00C2971E /* libevent.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B779D500E82FFAC00C2971E /* libevent.a */; }; 7BA363BD0E8C40C30023C8B9 /* libsdch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BA363BA0E8C409A0023C8B9 /* libsdch.a */; }; 82F372150E82AE0500DF5AFE /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82F372140E82AE0500DF5AFE /* Security.framework */; }; @@ -574,6 +575,7 @@ 4DB687CA0EAFE79200AB2128 /* libxslt.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libxslt.xcodeproj; path = third_party/libxslt/libxslt.xcodeproj; sourceTree = "<group>"; }; 4DB7FA6E0E9BF33B00C66CE0 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<group>"; }; 4DB7FEA70E9BF98C00C66CE0 /* libWebKitSystemInterfaceLeopard.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libWebKitSystemInterfaceLeopard.a; path = ../../../../third_party/WebKit/WebKitLibraries/libWebKitSystemInterfaceLeopard.a; sourceTree = SOURCE_ROOT; }; + 53E50D270ECA1B21001784B4 /* simple_clipboard_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = simple_clipboard_impl.cc; path = ../../../glue/simple_clipboard_impl.cc; sourceTree = SOURCE_ROOT; }; 7B42A4C40DE20F1700659DE0 /* v8.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = v8.xcodeproj; path = build/v8.xcodeproj; sourceTree = "<group>"; }; 7B779D4B0E82FFAC00C2971E /* libevent.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libevent.xcodeproj; path = third_party/libevent/libevent.xcodeproj; sourceTree = "<group>"; }; 7B8200950E76FDA1008F45CF /* common.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = common.xcconfig; sourceTree = "<group>"; }; @@ -1017,6 +1019,7 @@ AB8A77FE0DC54DD6005C27B8 /* layout_test_controller.h */, AB8A77FD0DC54DD6005C27B8 /* layout_test_controller.cc */, AB8A78540DC553BC005C27B8 /* node_leak_test.cc */, + 53E50D270ECA1B21001784B4 /* simple_clipboard_impl.cc */, E45629690E26B64D005E4685 /* simple_resource_loader_bridge.cc */, E45629680E26B64D005E4685 /* simple_resource_loader_bridge.h */, AB351E2E0DC7B290002F427A /* test_navigation_controller.cc */, @@ -1533,6 +1536,7 @@ E45629160E26B4FE005E4685 /* event_sending_controller.cc in Sources */, E45629170E26B4FE005E4685 /* layout_test_controller.cc in Sources */, E45629150E26B4FE005E4685 /* main.mm in Sources */, + 53E50D280ECA1B21001784B4 /* simple_clipboard_impl.cc in Sources */, E456296A0E26B64D005E4685 /* simple_resource_loader_bridge.cc in Sources */, E45629190E26B4FE005E4685 /* test_navigation_controller.cc in Sources */, E456291A0E26B4FE005E4685 /* test_shell_mac.mm in Sources */, diff --git a/webkit/webkit.xcodeproj/project.pbxproj b/webkit/webkit.xcodeproj/project.pbxproj index 1b8075a..2a4a624 100644 --- a/webkit/webkit.xcodeproj/project.pbxproj +++ b/webkit/webkit.xcodeproj/project.pbxproj @@ -164,6 +164,8 @@ 4DDC62B70EAD142D00FB5EBE /* MimeTypeArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DDC62B00EAD142D00FB5EBE /* MimeTypeArray.cpp */; }; 4DDC62B80EAD142D00FB5EBE /* Plugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DDC62B20EAD142D00FB5EBE /* Plugin.cpp */; }; 4DDC62B90EAD142D00FB5EBE /* PluginArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DDC62B40EAD142D00FB5EBE /* PluginArray.cpp */; }; + 532E35160ECA0EDE0097577C /* ClipboardUtilitiesChromium.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 532E35140ECA0EDE0097577C /* ClipboardUtilitiesChromium.cpp */; }; + 532E351C0ECA0F290097577C /* PasteboardChromium.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 532E351B0ECA0F290097577C /* PasteboardChromium.cpp */; }; 535EE0B60EC4CDEE00939D54 /* ClipboardChromium.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 535EE0B40EC4CDEE00939D54 /* ClipboardChromium.cpp */; }; 535EE0B80EC4CE0300939D54 /* EditorChromium.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 535EE0B70EC4CE0300939D54 /* EditorChromium.cpp */; }; 535EE0C00EC4D10E00939D54 /* clipboard_conversion.cc in Sources */ = {isa = PBXBuildFile; fileRef = 535EE0BE0EC4D10E00939D54 /* clipboard_conversion.cc */; }; @@ -888,10 +890,8 @@ E45624EA0E268E87005E4685 /* KURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E90CC0D7F3CC2001ECF42 /* KURL.cpp */; }; E45624EB0E268E87005E4685 /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E90D20D7F3CC2001ECF42 /* Logging.cpp */; }; E45624ED0E268E87005E4685 /* BlockExceptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E90D70D7F3CC2001ECF42 /* BlockExceptions.mm */; }; - E45624EE0E268E87005E4685 /* ClipboardMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E90D90D7F3CC2001ECF42 /* ClipboardMac.mm */; }; E45624FC0E268E87005E4685 /* LocalCurrentGraphicsContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E90E90D7F3CC2001ECF42 /* LocalCurrentGraphicsContext.mm */; }; E45624FE0E268E87005E4685 /* LoggingMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E90EB0D7F3CC2001ECF42 /* LoggingMac.mm */; }; - E45625000E268E87005E4685 /* PasteboardMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E90EE0D7F3CC2001ECF42 /* PasteboardMac.mm */; }; E456250F0E268E87005E4685 /* WebCoreKeyGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E91020D7F3CC2001ECF42 /* WebCoreKeyGenerator.m */; }; E45625100E268E87005E4685 /* WebCoreNSStringExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E91040D7F3CC2001ECF42 /* WebCoreNSStringExtras.mm */; }; E45625120E268E87005E4685 /* WebCoreSystemInterface.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B5E91080D7F3CC2001ECF42 /* WebCoreSystemInterface.mm */; }; @@ -1732,6 +1732,9 @@ 4DDC62B30EAD142D00FB5EBE /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Plugin.h; sourceTree = "<group>"; }; 4DDC62B40EAD142D00FB5EBE /* PluginArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginArray.cpp; sourceTree = "<group>"; }; 4DDC62B50EAD142D00FB5EBE /* PluginArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginArray.h; sourceTree = "<group>"; }; + 532E35140ECA0EDE0097577C /* ClipboardUtilitiesChromium.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClipboardUtilitiesChromium.cpp; sourceTree = "<group>"; }; + 532E35150ECA0EDE0097577C /* ClipboardUtilitiesChromium.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipboardUtilitiesChromium.h; sourceTree = "<group>"; }; + 532E351B0ECA0F290097577C /* PasteboardChromium.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PasteboardChromium.cpp; sourceTree = "<group>"; }; 535EE0B40EC4CDEE00939D54 /* ClipboardChromium.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClipboardChromium.cpp; sourceTree = "<group>"; }; 535EE0B50EC4CDEE00939D54 /* ClipboardChromium.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipboardChromium.h; sourceTree = "<group>"; }; 535EE0B70EC4CE0300939D54 /* EditorChromium.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EditorChromium.cpp; sourceTree = "<group>"; }; @@ -7775,6 +7778,8 @@ 53BECCC70EC4FF0500DC1DCD /* ChromiumDataObject.h */, 535EE0B40EC4CDEE00939D54 /* ClipboardChromium.cpp */, 535EE0B50EC4CDEE00939D54 /* ClipboardChromium.h */, + 532E35140ECA0EDE0097577C /* ClipboardUtilitiesChromium.cpp */, + 532E35150ECA0EDE0097577C /* ClipboardUtilitiesChromium.h */, E473F6320EADFF61006C2098 /* ContextMenuItemChromium.cpp */, E473F6330EADFF61006C2098 /* ContextMenuChromium.cpp */, E473F6360EADFF84006C2098 /* CursorChromium.cpp */, @@ -7792,6 +7797,7 @@ E473F64A0EADFFF8006C2098 /* Language.cpp */, E473F64D0EAE0005006C2098 /* MimeTypeRegistryChromium.cpp */, E473F6500EAE002F006C2098 /* PlatformKeyboardEventChromium.cpp */, + 532E351B0ECA0F290097577C /* PasteboardChromium.cpp */, E473F6510EAE002F006C2098 /* PasteboardPrivate.h */, E473F6520EAE002F006C2098 /* PlatformCursor.h */, E473F65D0EAE009A006C2098 /* PlatformWidget.h */, @@ -8493,7 +8499,6 @@ E45623B40E268E87005E4685 /* ClassNodeList.cpp in Sources */, E45623B50E268E87005E4685 /* Clipboard.cpp in Sources */, E45623B60E268E87005E4685 /* ClipboardEvent.cpp in Sources */, - E45624EE0E268E87005E4685 /* ClipboardMac.mm in Sources */, E45624C20E268E87005E4685 /* Color.cpp in Sources */, E45626820E268E87005E4685 /* ColorCG.cpp in Sources */, AB451D9D0EC21EDE0037A496 /* ColorSkia.cpp in Sources */, @@ -8813,7 +8818,6 @@ E45624200E268E87005E4685 /* PageCache.cpp in Sources */, 4DB7F2060E9BAE2900C66CE0 /* PageGroup.cpp in Sources */, E456247A0E268E87005E4685 /* PageURLRecord.cpp in Sources */, - E45625000E268E87005E4685 /* PasteboardMac.mm in Sources */, E45624E40E268E87005E4685 /* Path.cpp in Sources */, E456268C0E268E87005E4685 /* PathCG.cpp in Sources */, E45624E50E268E87005E4685 /* PathTraversalState.cpp in Sources */, @@ -9323,6 +9327,7 @@ E45627EE0E2694B8005E4685 /* CachedPage.cpp in Sources */, 53BECCC80EC4FF0500DC1DCD /* ChromiumDataObject.cpp in Sources */, 535EE0B60EC4CDEE00939D54 /* ClipboardChromium.cpp in Sources */, + 532E35160ECA0EDE0097577C /* ClipboardUtilitiesChromium.cpp in Sources */, E473F6350EADFF61006C2098 /* ContextMenuChromium.cpp in Sources */, E473F6340EADFF61006C2098 /* ContextMenuItemChromium.cpp in Sources */, 93BF8E9A0EA6B0EA0030F05C /* CookieJarChromium.cpp in Sources */, @@ -9355,6 +9360,7 @@ E473F64E0EAE0005006C2098 /* MimeTypeRegistryChromium.cpp in Sources */, E48A07280E3F95A000172919 /* NativeImageSkia.cpp in Sources */, 93BF8E9C0EA6B0F30030F05C /* NetworkStateNotifierChromium.cpp in Sources */, + 532E351C0ECA0F290097577C /* PasteboardChromium.cpp in Sources */, E4E4C8560E7832E2009A687C /* PlatformContextSkia.cpp in Sources */, E473F6530EAE002F006C2098 /* PlatformKeyboardEventChromium.cpp in Sources */, E40FB28F0EAFF0BC006F380A /* PlatformScreenMac.mm in Sources */, |