summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-01 21:03:08 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-01 21:03:08 +0000
commit8bbe7efe110336916c819fdc7f5566afa3a97495 (patch)
tree6d473efd35ca0f48584dd3254e8b4e5ebd708fbb /webkit/tools/test_shell
parentd294668d4c62e94c342cff58b1096af8106113ef (diff)
downloadchromium_src-8bbe7efe110336916c819fdc7f5566afa3a97495.zip
chromium_src-8bbe7efe110336916c819fdc7f5566afa3a97495.tar.gz
chromium_src-8bbe7efe110336916c819fdc7f5566afa3a97495.tar.bz2
Enable the X selection clipboard for copying html and text out of a linux test shell.
I implemented it in the webview delegate, so when we switch to the multiprocess architecture, we will need to find out if the clipboard callback can be async (the current method would require a sync call from browser to renderer to get the selected text). Review URL: http://codereview.chromium.org/12700 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/test_shell')
-rw-r--r--webkit/tools/test_shell/mac/test_webview_delegate.mm4
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.cc3
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.h3
-rw-r--r--webkit/tools/test_shell/test_webview_delegate_gtk.cc56
-rw-r--r--webkit/tools/test_shell/test_webview_delegate_win.cc4
5 files changed, 68 insertions, 2 deletions
diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm
index 3672f05..ee23e80 100644
--- a/webkit/tools/test_shell/mac/test_webview_delegate.mm
+++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm
@@ -127,6 +127,10 @@ void TestWebViewDelegate::RunModal(WebWidget* webwidget) {
NOTIMPLEMENTED();
}
+void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) {
+ // No selection clipboard on mac, do nothing.
+}
+
// Private methods -----------------------------------------------------------
void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc
index e6166b4..905b9be 100644
--- a/webkit/tools/test_shell/test_webview_delegate.cc
+++ b/webkit/tools/test_shell/test_webview_delegate.cc
@@ -552,11 +552,12 @@ void TestWebViewDelegate::DidBeginEditing() {
}
}
-void TestWebViewDelegate::DidChangeSelection() {
+void TestWebViewDelegate::DidChangeSelection(bool is_empty_selection) {
if (shell_->ShouldDumpEditingCallbacks()) {
printf("EDITING DELEGATE: "
"webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n");
}
+ UpdateSelectionClipboard(is_empty_selection);
}
void TestWebViewDelegate::DidChangeContents() {
diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h
index df214bd..bc8d226 100644
--- a/webkit/tools/test_shell/test_webview_delegate.h
+++ b/webkit/tools/test_shell/test_webview_delegate.h
@@ -176,7 +176,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>,
std::wstring range);
virtual bool SmartInsertDeleteEnabled();
virtual void DidBeginEditing();
- virtual void DidChangeSelection();
+ virtual void DidChangeSelection(bool is_empty_selection);
virtual void DidChangeContents();
virtual void DidEndEditing();
@@ -269,6 +269,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>,
void UpdateForCommittedLoad(WebFrame* webframe, bool is_new_navigation);
void UpdateURL(WebFrame* frame);
void UpdateSessionHistory(WebFrame* frame);
+ void UpdateSelectionClipboard(bool is_empty_selection);
// Get a string suitable for dumping a frame to the console.
std::wstring GetFrameDescription(WebFrame* webframe);
diff --git a/webkit/tools/test_shell/test_webview_delegate_gtk.cc b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
index 0874429..3866e3d 100644
--- a/webkit/tools/test_shell/test_webview_delegate_gtk.cc
+++ b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
@@ -26,6 +26,42 @@
#include "webkit/tools/test_shell/test_navigation_controller.h"
#include "webkit/tools/test_shell/test_shell.h"
+namespace {
+
+
+enum SelectionClipboardType {
+ TEXT_HTML,
+ PLAIN_TEXT,
+};
+
+GdkAtom GetTextHtmlAtom() {
+ GdkAtom kTextHtmlGdkAtom = gdk_atom_intern_static_string("text/html");
+ return kTextHtmlGdkAtom;
+}
+
+void SelectionClipboardGetContents(GtkClipboard* clipboard,
+ GtkSelectionData* selection_data, guint info, gpointer data) {
+ // Ignore formats that we don't know about.
+ if (info != TEXT_HTML && info != PLAIN_TEXT)
+ return;
+
+ WebView* webview = static_cast<WebView*>(data);
+ WebFrame* frame = webview->GetFocusedFrame();
+ std::string selection = frame->GetSelection(TEXT_HTML == info);
+ if (TEXT_HTML == info) {
+ gtk_selection_data_set(selection_data,
+ GetTextHtmlAtom(),
+ 8 /* bits per data unit, ie, char */,
+ reinterpret_cast<const guchar*>(selection.data()),
+ selection.length());
+ } else {
+ gtk_selection_data_set_text(selection_data, selection.data(),
+ selection.length());
+ }
+}
+
+} // namespace
+
// WebViewDelegate -----------------------------------------------------------
TestWebViewDelegate::~TestWebViewDelegate() {
@@ -150,6 +186,26 @@ void TestWebViewDelegate::RunModal(WebWidget* webwidget) {
NOTIMPLEMENTED();
}
+void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) {
+ if (is_empty_selection)
+ return;
+
+ GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+ // Put data on the X clipboard. This doesn't actually grab the text from
+ // the HTML, it just registers a callback for when someone tries to paste.
+ GtkTargetList* target_list = gtk_target_list_new(NULL, 0);
+ gtk_target_list_add(target_list, GetTextHtmlAtom(), 0, TEXT_HTML);
+ gtk_target_list_add_text_targets(target_list, PLAIN_TEXT);
+
+ gint num_targets = 0;
+ GtkTargetEntry* targets = gtk_target_table_new_from_list(target_list,
+ &num_targets);
+ gtk_clipboard_set_with_data(clipboard, targets, num_targets,
+ SelectionClipboardGetContents, NULL,
+ shell_->webView());
+ gtk_target_table_free(targets, num_targets);
+}
+
// Private methods -----------------------------------------------------------
void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {
diff --git a/webkit/tools/test_shell/test_webview_delegate_win.cc b/webkit/tools/test_shell/test_webview_delegate_win.cc
index db51893..64b1e17 100644
--- a/webkit/tools/test_shell/test_webview_delegate_win.cc
+++ b/webkit/tools/test_shell/test_webview_delegate_win.cc
@@ -154,6 +154,10 @@ void TestWebViewDelegate::RunModal(WebWidget* webwidget) {
EnableWindow(*i, TRUE);
}
+void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) {
+ // No selection clipboard on windows, do nothing.
+}
+
// Private methods -----------------------------------------------------------
void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {