diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-05 01:34:30 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-05 01:34:30 +0000 |
commit | 3ee3ffd1d79a0c1544f3bfd70c7de7606df9482f (patch) | |
tree | 0943a0925f5974478463e5d00886be29109858e6 /webkit | |
parent | 38733063b7e1cf0b6e67c0b590773ff4f1aaa18d (diff) | |
download | chromium_src-3ee3ffd1d79a0c1544f3bfd70c7de7606df9482f.zip chromium_src-3ee3ffd1d79a0c1544f3bfd70c7de7606df9482f.tar.gz chromium_src-3ee3ffd1d79a0c1544f3bfd70c7de7606df9482f.tar.bz2 |
Rewrote the clipboard API to be more concurrent. Added a helper class to make it more foolproof. Updated all clients and unittests. Mac port by jeremy@chromium.org
Review URL: http://codereview.chromium.org/9154
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4719 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/build/glue/glue.vcproj | 4 | ||||
-rw-r--r-- | webkit/glue/scoped_clipboard_writer_glue.h | 29 | ||||
-rw-r--r-- | webkit/glue/simple_clipboard_impl.cc | 41 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.h | 22 | ||||
-rw-r--r-- | webkit/port/platform/win/PasteboardWin.cpp | 41 |
5 files changed, 70 insertions, 67 deletions
diff --git a/webkit/build/glue/glue.vcproj b/webkit/build/glue/glue.vcproj index 784de66..28fe820 100644 --- a/webkit/build/glue/glue.vcproj +++ b/webkit/build/glue/glue.vcproj @@ -481,6 +481,10 @@ > </File> <File + RelativePath="..\..\glue\scoped_clipboard_writer_glue.h" + > + </File> + <File RelativePath="..\..\glue\searchable_form_data.cc" > </File> diff --git a/webkit/glue/scoped_clipboard_writer_glue.h b/webkit/glue/scoped_clipboard_writer_glue.h new file mode 100644 index 0000000..5a3ecb5 --- /dev/null +++ b/webkit/glue/scoped_clipboard_writer_glue.h @@ -0,0 +1,29 @@ +// Copyright (c) 2006-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. + +#ifndef SCOPED_CLIPBOARD_WRITER_GLUE_H__ +#define SCOPED_CLIPBOARD_WRITER_GLUE_H__ + +#include "base/clipboard.h" +#include "base/scoped_clipboard_writer.h" + +class ScopedClipboardWriterGlue : public ScopedClipboardWriter { + public: + ScopedClipboardWriterGlue(Clipboard* clipboard) + : ScopedClipboardWriter(clipboard), + shared_buf_(NULL) { + } + + ~ScopedClipboardWriterGlue(); + +#if defined(OS_WIN) + void ScopedClipboardWriterGlue::WriteBitmap(const SkBitmap& bitmap); +#endif + + private: + SharedMemory* shared_buf_; + DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriterGlue); +}; + +#endif // SCOPED_CLIPBOARD_WRITER_GLUE_H__ diff --git a/webkit/glue/simple_clipboard_impl.cc b/webkit/glue/simple_clipboard_impl.cc index e332a47..b60a36808 100644 --- a/webkit/glue/simple_clipboard_impl.cc +++ b/webkit/glue/simple_clipboard_impl.cc @@ -7,46 +7,32 @@ #include <string> #include "base/clipboard.h" +#include "webkit/glue/scoped_clipboard_writer_glue.h" #include "googleurl/src/gurl.h" #include "SkBitmap.h" // Clipboard glue -// Basically just proxy the calls off to the clipboard -namespace webkit_glue { - -Clipboard clipboard; - -void ClipboardClear() { - clipboard.Clear(); -} - -void ClipboardWriteText(const std::wstring& text) { - clipboard.WriteText(text); +#if defined(OS_WIN) +// The call is being made within the current process. +void ScopedClipboardWriterGlue::WriteBitmap(const SkBitmap& bitmap) { + SkAutoLockPixels bitmap_lock(bitmap); + WriteBitmapFromPixels(bitmap.getPixels(), gfx::Size(bitmap.width(), + bitmap.height())); } +#endif // defined(OS_WIN) -void ClipboardWriteHTML(const std::wstring& html, - const GURL& url) { - clipboard.WriteHTML(html, url.spec()); +ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() { } -void ClipboardWriteBookmark(const std::wstring& title, - const GURL& url) { - clipboard.WriteBookmark(title, url.spec()); -} +namespace webkit_glue { -#if defined(OS_WIN) -void ClipboardWriteBitmap(const SkBitmap& bitmap) { - SkAutoLockPixels bitmap_lock(bitmap); - clipboard.WriteBitmap(bitmap.getPixels(), - gfx::Size(bitmap.width(), bitmap.height())); -} +Clipboard clipboard; -void ClipboardWriteWebSmartPaste() { - clipboard.WriteWebSmartPaste(); +Clipboard* ClipboardGetClipboard() { + return &clipboard; } -#endif bool ClipboardIsFormatAvailable(Clipboard::FormatType format) { return clipboard.IsFormatAvailable(format); @@ -68,4 +54,3 @@ void ClipboardReadHTML(std::wstring* markup, GURL* url) { } } // namespace webkit_glue - diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index b8b2156..2691b25 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -42,6 +42,7 @@ class Frame; } class SkBitmap; +class Clipboard; #if defined(OS_MACOSX) typedef struct CGImage* CGImageRef; @@ -194,25 +195,8 @@ HCURSOR LoadCursor(int cursor_id); // Glue to access the clipboard. -// Clear the clipboard. It is usually a good idea to clear the clipboard -// before writing content to the clipboard. -void ClipboardClear(); - -// Adds UNICODE and ASCII text to the clipboard. -void ClipboardWriteText(const std::wstring& text); - -// Adds HTML to the clipboard. The url parameter is optional, but especially -// useful if the HTML fragment contains relative links -void ClipboardWriteHTML(const std::wstring& html, const GURL& url); - -// Adds a bookmark to the clipboard -void ClipboardWriteBookmark(const std::wstring& title, const GURL& url); - -// Adds a bitmap to the clipboard -void ClipboardWriteBitmap(const SkBitmap& bitmap); - -// Used by WebKit to determine whether WebKit wrote the clipboard last -void ClipboardWriteWebSmartPaste(); +// Get a clipboard that can be used to construct a ScopedClipboardWriterGlue. +Clipboard* ClipboardGetClipboard(); // Tests whether the clipboard contains a certain format bool ClipboardIsFormatAvailable(unsigned int format); diff --git a/webkit/port/platform/win/PasteboardWin.cpp b/webkit/port/platform/win/PasteboardWin.cpp index f22b85f..3063dc9 100644 --- a/webkit/port/platform/win/PasteboardWin.cpp +++ b/webkit/port/platform/win/PasteboardWin.cpp @@ -45,6 +45,7 @@ #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 { @@ -70,36 +71,35 @@ Pasteboard::Pasteboard() void Pasteboard::clear() { - webkit_glue::ClipboardClear(); + // The ScopedClipboardWriter class takes care of clearing the clipboard's + // previous contents. } void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) { - clear(); + ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); ExceptionCode ec = 0; - webkit_glue::ClipboardWriteHTML( + scw.WriteHTML( webkit_glue::StringToStdWString( createMarkup(selectedRange, 0, AnnotateForInterchange)), GURL(webkit_glue::StringToStdWString( - selectedRange->startContainer(ec)->document()->url()))); + 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); - webkit_glue::ClipboardWriteText(webkit_glue::StringToStdWString(str)); + scw.WriteText(webkit_glue::StringToStdWString(str)); if (canSmartCopyOrDelete) - webkit_glue::ClipboardWriteWebSmartPaste(); + scw.WriteWebSmartPaste(); } void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) { ASSERT(!url.isEmpty()); - clear(); - String title(titleStr); if (title.isEmpty()) { title = url.lastPathComponent(); @@ -107,17 +107,19 @@ void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) 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 - webkit_glue::ClipboardWriteBookmark(webkit_glue::StringToStdWString(titleStr), - webkit_glue::KURLToGURL(url)); + 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))); - webkit_glue::ClipboardWriteHTML(link, GURL()); + scw.WriteHTML(link, GURL().spec()); // bare-bones CF_UNICODETEXT support std::wstring spec(webkit_glue::StringToStdWString(url)); - webkit_glue::ClipboardWriteText(spec); + scw.WriteText(spec); } void Pasteboard::writeImage(Node* node, const KURL& url, const String& title) @@ -129,24 +131,23 @@ void Pasteboard::writeImage(Node* node, const KURL& url, const String& title) Image* image = cachedImage->image(); ASSERT(image); - clear(); NativeImageSkia* bitmap = image->nativeImageForCurrentFrame(); + ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); + if (bitmap) - webkit_glue::ClipboardWriteBitmap(*bitmap); + scw.WriteBitmap(*bitmap); if (!url.isEmpty()) { - webkit_glue::ClipboardWriteBookmark(webkit_glue::StringToStdWString(title), - webkit_glue::KURLToGURL(url)); // write to clipboard in format com.apple.safari.bookmarkdata to be able to paste into the bookmarks view with appropriate title - webkit_glue::ClipboardWriteBookmark(webkit_glue::StringToStdWString(title), - webkit_glue::KURLToGURL(url)); + 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))); - webkit_glue::ClipboardWriteHTML(markup, GURL()); + scw.WriteHTML(markup, GURL().spec()); // bare-bones CF_UNICODETEXT support std::wstring spec(webkit_glue::StringToStdWString(url.string())); - webkit_glue::ClipboardWriteText(spec); + scw.WriteText(spec); } } |