diff options
-rw-r--r-- | chrome/browser/browser.cc | 33 | ||||
-rw-r--r-- | chrome/browser/browser.h | 2 | ||||
-rw-r--r-- | chrome/browser/browser_window.h | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 33 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 23 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 3 |
7 files changed, 77 insertions, 28 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index fa5b781..d6d9122 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -83,7 +83,6 @@ #include <shellapi.h> #include "app/win_util.h" -#include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/browser_url_handler.h" #include "chrome/browser/cert_store.h" #include "chrome/browser/download/save_package.h" @@ -96,10 +95,6 @@ #include "chrome/common/child_process_host.h" #endif // OS_WIN -#if defined(OS_CHROMEOS) -#include "chrome/browser/automation/ui_controls.h" -#endif - #if !defined(OS_MACOSX) #include "chrome/browser/dock_info.h" #endif @@ -1109,38 +1104,22 @@ void Browser::OverrideEncoding(int encoding_id) { } } -#if defined(OS_WIN) || defined(OS_CHROMEOS) -// TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always -// enabled in the page menu regardless of whether the command will do -// anything. When someone selects the menu item, we just act as if they hit -// the keyboard shortcut for the command by sending the associated key press -// to windows. The real fix to this bug is to disable the commands when they -// won't do anything. We'll need something like an overall clipboard command -// manager to do that. - -// TODO(oshima): Enabling this for chromeos, but not for linux. It's safe -// to assume ctrl-x/c/v are cut, copy and paste on chromeos, but not on -// linux. See http://crbug.com/18030. We should switch to whatever linux/gtk -// will implement. - +#if !defined(OS_MACOSX) void Browser::Cut() { UserMetrics::RecordAction("Cut", profile_); - ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_X, true, - false, false); + window()->Cut(); } void Browser::Copy() { UserMetrics::RecordAction("Copy", profile_); - ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_C, true, - false, false); + window()->Copy(); } void Browser::Paste() { UserMetrics::RecordAction("Paste", profile_); - ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_V, true, - false, false); + window()->Paste(); } -#endif // #if defined(OS_WIN) || defined(OS_CHROMEOS) +#endif void Browser::Find() { UserMetrics::RecordAction("Find", profile_); @@ -1549,7 +1528,7 @@ void Browser::ExecuteCommandWithDisposition( case IDC_ENCODING_WINDOWS1255: case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break; -#if defined(OS_WIN) || defined(OS_CHROMEOS) +#if !defined(OS_MACOSX) // Clipboard commands case IDC_CUT: Cut(); break; case IDC_COPY: Copy(); break; diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 9c4af82..e43db31 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -383,7 +383,7 @@ class Browser : public TabStripModelDelegate, void ToggleEncodingAutoDetect(); void OverrideEncoding(int encoding_id); -#if defined(OS_WIN) || defined(OS_CHROMEOS) +#if !defined(OS_MACOSX) // Clipboard commands void Cut(); void Copy(); diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index be215cc..c3c2f48 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -287,6 +287,14 @@ class BrowserWindow { virtual void ToggleCompactNavigationBar() = 0; #endif +#if !defined(OS_MACOSX) + // Clipboard commands applied to the whole browser window. Only for Linux, + // Windows and ChromeOS ports. + virtual void Cut() {} + virtual void Copy() {} + virtual void Paste() {} +#endif + // Construct a BrowserWindow implementation for the specified |browser|. static BrowserWindow* CreateBrowserWindow(Browser* browser); 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()); } diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index d90dbaf..711c535 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -114,6 +114,9 @@ class BrowserWindowGtk : public BrowserWindow, bool* is_keyboard_shortcut); virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); virtual void ShowCreateShortcutsDialog(TabContents* tab_contents); + virtual void Cut(); + virtual void Copy(); + virtual void Paste(); // Overridden from NotificationObserver: virtual void Observe(NotificationType type, diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 9cc01a3..e02d3d5 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -20,6 +20,7 @@ #include "build/build_config.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/app_modal_dialog_queue.h" +#include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" @@ -1183,6 +1184,28 @@ void BrowserView::ToggleCompactNavigationBar() { } #endif +// TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always +// enabled in the page menu regardless of whether the command will do +// anything. When someone selects the menu item, we just act as if they hit +// the keyboard shortcut for the command by sending the associated key press +// to windows. The real fix to this bug is to disable the commands when they +// won't do anything. We'll need something like an overall clipboard command +// manager to do that. +void BrowserView::Cut() { + ui_controls::SendKeyPress(GetNativeHandle(), base::VKEY_X, true, + false, false); +} + +void BrowserView::Copy() { + ui_controls::SendKeyPress(GetNativeHandle(), base::VKEY_C, true, + false, false); +} + +void BrowserView::Paste() { + ui_controls::SendKeyPress(GetNativeHandle(), base::VKEY_V, true, + false, false); +} + /////////////////////////////////////////////////////////////////////////////// // BrowserView, BrowserWindowTesting implementation: diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 2ba812a..516e9bf 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -292,6 +292,9 @@ class BrowserView : public BrowserWindow, #if defined(OS_CHROMEOS) virtual void ToggleCompactNavigationBar(); #endif // defined(OS_CHROMEOS) + virtual void Cut(); + virtual void Copy(); + virtual void Paste(); // Overridden from BrowserWindowTesting: virtual BookmarkBarView* GetBookmarkBarView() const; |