summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/browser_window_gtk.cc
diff options
context:
space:
mode:
authorsuzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-25 04:46:23 +0000
committersuzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-25 04:46:23 +0000
commit20012dd4bc52c78aca5b0a17dec2150617c76f30 (patch)
tree135577e5684a210f0ac36801e208606b58b3706b /chrome/browser/gtk/browser_window_gtk.cc
parent9e6069029b7a63c2a0235c92df22c811520fd47c (diff)
downloadchromium_src-20012dd4bc52c78aca5b0a17dec2150617c76f30.zip
chromium_src-20012dd4bc52c78aca5b0a17dec2150617c76f30.tar.gz
chromium_src-20012dd4bc52c78aca5b0a17dec2150617c76f30.tar.bz2
[Linux]Implement Cut, Copy and Paste from page menu.
BUG=18030 TEST=The Cut, Copy and Paste commands in page menu should work in both web content and location bar. Review URL: http://codereview.chromium.org/552125 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36989 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/browser_window_gtk.cc')
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 1e2a448..440639a 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -68,6 +68,7 @@
#include "chrome/browser/gtk/toolbar_star_toggle_gtk.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/page_info_window.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
@@ -296,6 +297,26 @@ bool ShouldExecuteReservedCommandImmediately(
return true;
}
+// Performs Cut/Copy/Paste operation on the |window|.
+// If the current render view is focused, then just call the specified |method|
+// against the current render view host, otherwise emit the specified |signal|
+// against the focused widget.
+// TODO(suzhe): This approach does not work for plugins.
+void DoCutCopyPaste(BrowserWindowGtk* window, void (RenderViewHost::*method)(),
+ const char* signal) {
+ TabContents* current_tab_contents =
+ window->browser()->tabstrip_model()->GetSelectedTabContents();
+ if (current_tab_contents && current_tab_contents->GetContentNativeView() &&
+ gtk_widget_is_focus(current_tab_contents->GetContentNativeView())) {
+ (current_tab_contents->render_view_host()->*method)();
+ } else {
+ GtkWidget* widget = gtk_window_get_focus(window->window());
+ guint id;
+ if (widget && (id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0)
+ g_signal_emit(widget, id, 0);
+ }
+}
+
} // namespace
std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_;
@@ -1002,6 +1023,18 @@ void BrowserWindowGtk::ShowCreateShortcutsDialog(TabContents* tab_contents) {
bitmap);
}
+void BrowserWindowGtk::Cut() {
+ DoCutCopyPaste(this, &RenderViewHost::Cut, "cut-clipboard");
+}
+
+void BrowserWindowGtk::Copy() {
+ DoCutCopyPaste(this, &RenderViewHost::Copy, "copy-clipboard");
+}
+
+void BrowserWindowGtk::Paste() {
+ DoCutCopyPaste(this, &RenderViewHost::Paste, "paste-clipboard");
+}
+
void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() {
new DownloadInProgressDialogGtk(browser());
}