Index: chrome/browser/ui/gtk/gtk_util.cc |
=================================================================== |
--- chrome/browser/ui/gtk/gtk_util.cc (revision 151356) |
+++ chrome/browser/ui/gtk/gtk_util.cc (working copy) |
@@ -25,9 +25,12 @@ |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/gtk/browser_window_gtk.h" |
#include "chrome/browser/ui/gtk/gtk_theme_service.h" |
+#include "content/public/browser/render_view_host.h" |
+#include "content/public/browser/web_contents.h" |
#include "googleurl/src/gurl.h" |
#include "grit/theme_resources.h" |
#include "ui/base/gtk/gtk_compat.h" |
@@ -45,6 +48,9 @@ |
// These conflict with base/tracked_objects.h, so need to come last. |
#include <gdk/gdkx.h> // NOLINT |
+using content::RenderWidgetHost; |
+using content::WebContents; |
+ |
namespace { |
#if defined(GOOGLE_CHROME_BUILD) |
@@ -272,6 +278,16 @@ |
return TRUE; |
} |
+WebContents* GetBrowserWindowSelectedWebContents(BrowserWindow* window) { |
+ BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( |
+ window); |
+ return chrome::GetActiveWebContents(browser_window->browser()); |
+} |
+ |
+GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { |
+ return gtk_window_get_focus(window->GetNativeWindow()); |
+} |
+ |
} // namespace |
namespace gtk_util { |
@@ -992,4 +1008,38 @@ |
} |
} |
+// 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(BrowserWindow* window, |
+ void (RenderWidgetHost::*method)(), |
+ const char* signal) { |
+ GtkWidget* widget = GetBrowserWindowFocusedWidget(window); |
+ if (widget == NULL) |
+ return; // Do nothing if no focused widget. |
+ |
+ WebContents* current_tab = GetBrowserWindowSelectedWebContents(window); |
+ if (current_tab && widget == current_tab->GetContentNativeView()) { |
+ (current_tab->GetRenderViewHost()->*method)(); |
+ } else { |
+ guint id; |
+ if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0) |
+ g_signal_emit(widget, id, 0); |
+ } |
+} |
+ |
+void DoCut(BrowserWindow* window) { |
+ DoCutCopyPaste(window, &RenderWidgetHost::Cut, "cut-clipboard"); |
+} |
+ |
+void DoCopy(BrowserWindow* window) { |
+ DoCutCopyPaste(window, &RenderWidgetHost::Copy, "copy-clipboard"); |
+} |
+ |
+void DoPaste(BrowserWindow* window) { |
+ DoCutCopyPaste(window, &RenderWidgetHost::Paste, "paste-clipboard"); |
+} |
+ |
} // namespace gtk_util |