diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 00:57:10 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 00:57:10 +0000 |
commit | dbadbccda1ef5744aa78c4666434be9f7622a326 (patch) | |
tree | 37db95501bf557911f539b7522b30146e9152dda | |
parent | 3dce6d059ac9a69b85d2265f91a384554d27eaa7 (diff) | |
download | chromium_src-dbadbccda1ef5744aa78c4666434be9f7622a326.zip chromium_src-dbadbccda1ef5744aa78c4666434be9f7622a326.tar.gz chromium_src-dbadbccda1ef5744aa78c4666434be9f7622a326.tar.bz2 |
Copy text selection from renderer to browser every time it changes.
BUG=9848
Review URL: http://codereview.chromium.org/63145
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13396 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 10 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view.h | 5 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_gtk.cc | 77 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_gtk.h | 21 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 9 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 4 |
8 files changed, 12 insertions, 127 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 82b4622..ef6ea8d 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -789,7 +789,6 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFeedList, OnMsgUpdateFeedList) IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRequest, OnExtensionRequest) IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged) - IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectionText, OnMsgSetSelectionText) IPC_MESSAGE_HANDLER(ViewHostMsg_PasteFromSelectionClipboard, OnMsgPasteFromSelectionClipboard) // Have the super handle all other messages. @@ -1116,14 +1115,9 @@ void RenderViewHost::OnMsgSetTooltipText(const std::wstring& tooltip_text) { view()->SetTooltipText(tooltip_text); } -void RenderViewHost::OnMsgSelectionChanged() { +void RenderViewHost::OnMsgSelectionChanged(const std::string& text) { if (view()) - view()->SelectionChanged(); -} - -void RenderViewHost::OnMsgSetSelectionText(const std::string& text) { - if (view()) - view()->SetSelectionText(text); + view()->SelectionChanged(text); } void RenderViewHost::OnMsgPasteFromSelectionClipboard() { diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index ae7db54..8d82ba3 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -508,8 +508,7 @@ class RenderViewHost : public RenderWidgetHost { #endif void OnMsgGoToEntryAtOffset(int offset); void OnMsgSetTooltipText(const std::wstring& tooltip_text); - void OnMsgSelectionChanged(); - void OnMsgSetSelectionText(const std::string& text); + void OnMsgSelectionChanged(const std::string& text); void OnMsgPasteFromSelectionClipboard(); void OnMsgRunFileChooser(bool multiple_files, const std::wstring& title, diff --git a/chrome/browser/renderer_host/render_widget_host_view.h b/chrome/browser/renderer_host/render_widget_host_view.h index 1a9dead..d071b5a 100644 --- a/chrome/browser/renderer_host/render_widget_host_view.h +++ b/chrome/browser/renderer_host/render_widget_host_view.h @@ -113,10 +113,7 @@ class RenderWidgetHostView { virtual void SetTooltipText(const std::wstring& tooltip_text) = 0; // Notifies the View that the renderer text selection has changed. - virtual void SelectionChanged() { }; - - // Notifies the View what the current selection text is. - virtual void SetSelectionText(const std::string& text) { }; + virtual void SelectionChanged(const std::string& text) { }; // Tells the View to get the text from the selection clipboard and send it // back to the renderer asynchronously. diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index 3952e12..32135f9 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -68,25 +68,6 @@ class RenderWidgetHostViewGtkWidget { num_targets); gtk_target_list_unref(target_list); gtk_target_table_free(targets, num_targets); - - // When X requests the contents of the clipboard, GTK will emit the - // selection_request_event signal. The default handler would then - // synchronously emit the selection_get signal. However, we want to - // respond to the selection_request_event asynchronously, so we intercept - // the signal in OnSelectionRequest, request the selection text from the - // render view, and return TRUE so the default handler won't be called. Then - // when we get the selection text back from the renderer in - // SetSelectionText() we will call manually the selection_request_event - // default handler. - g_signal_connect(widget, "selection_request_event", - G_CALLBACK(OnSelectionRequest), host_view); - g_signal_connect(widget, "selection_get", - G_CALLBACK(OnSelectionGet), host_view); - - // In OnSelectionGet, we need to access |host_view| to get the selection - // text. - g_object_set_data(G_OBJECT(widget), "render-widget-host-view-gtk", - host_view); return widget; } @@ -157,40 +138,6 @@ class RenderWidgetHostViewGtkWidget { return FALSE; } - - static gboolean OnSelectionRequest(GtkWidget* widget, - GdkEventSelection* event) { - RenderWidgetHostViewGtk* host_view = - reinterpret_cast<RenderWidgetHostViewGtk*>( - g_object_get_data(G_OBJECT(widget), "render-widget-host-view-gtk")); - - // If we already know the selection text, return FALSE to let the default - // handler run. Also, don't try to handle two events simultaneously, - // because we might end up sending the wrong |event_selection_| back to GTK. - if (!host_view->selection_text_.empty() || - host_view->event_selection_active_) - return FALSE; - - host_view->event_selection_ = *event; - host_view->event_selection_active_ = true; - if (host_view->selection_text_.empty()) - host_view->RequestSelectionText(); - - return TRUE; - } - - static void OnSelectionGet(GtkWidget* widget, - GtkSelectionData* data, - guint info, guint time, - RenderWidgetHostViewGtk* host_view) { - DCHECK(!host_view->selection_text_.empty() || - host_view->event_selection_active_); - - gtk_selection_data_set(data, data->target, 8, - reinterpret_cast<const guchar*>(host_view->selection_text_.c_str()), - host_view->selection_text_.length()); - } - DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); }; @@ -212,8 +159,7 @@ RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host) parent_(NULL), popup_signal_id_(0), activatable_(true), - is_loading_(false), - event_selection_active_(false) { + is_loading_(false) { host_->set_view(this); } @@ -368,20 +314,9 @@ void RenderWidgetHostViewGtk::SetTooltipText(const std::wstring& tooltip_text) { } } -void RenderWidgetHostViewGtk::SelectionChanged() { - selection_text_.clear(); - - guint32 timestamp = gdk_x11_get_server_time(view_.get()->window); - gtk_selection_owner_set(view_.get(), GDK_SELECTION_PRIMARY, timestamp); -} - -void RenderWidgetHostViewGtk::SetSelectionText(const std::string& text) { - selection_text_ = text; - DCHECK(event_selection_active_); - event_selection_active_ = false; - // Resume normal handling of the active selection_request_event. - GtkWidgetClass* klass = GTK_WIDGET_CLASS(gtk_type_class(GTK_TYPE_WIDGET)); - klass->selection_request_event(view_.get(), &event_selection_); +void RenderWidgetHostViewGtk::SelectionChanged(const std::string& text) { + GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length()); } BackingStore* RenderWidgetHostViewGtk::AllocBackingStore( @@ -463,10 +398,6 @@ void RenderWidgetHostViewGtk::ShowCurrentCursor() { gdk_cursor_unref(gdk_cursor); } -void RenderWidgetHostViewGtk::RequestSelectionText() { - host_->Send(new ViewMsg_RequestSelectionText(host_->routing_id())); -} - void RenderWidgetHostViewGtk::ReceivedSelectionText(GtkClipboard* clipboard, const gchar* text, gpointer userdata) { // If there's nothing to paste (|text| is NULL), do nothing. diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.h b/chrome/browser/renderer_host/render_widget_host_view_gtk.h index 5d260a1..215549d 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.h +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.h @@ -61,8 +61,7 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { void RenderViewGone(); void Destroy(); void SetTooltipText(const std::wstring& tooltip_text); - void SelectionChanged(); - void SetSelectionText(const std::string& text); + void SelectionChanged(const std::string& text); void PasteFromSelectionClipboard(); BackingStore* AllocBackingStore(const gfx::Size& size); // --------------------------------------------------------------------------- @@ -74,16 +73,9 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { private: friend class RenderWidgetHostViewGtkWidget; - void set_event_selection(GdkEventSelection* event_selection) { - event_selection_ = *event_selection; - event_selection_active_ = true; - } - // Update the display cursor for the render view. void ShowCurrentCursor(); - void RequestSelectionText(); - // When we've requested the text from the X clipboard, GTK returns it to us // through this callback. static void ReceivedSelectionText(GtkClipboard* clipboard, @@ -115,17 +107,6 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { // The cursor for the page. This is passed up from the renderer. WebCursor current_cursor_; - - // We cache the text that is selected on the page. This is used for copying to - // the X clipboard. We update |selection_text_| whenever X asks us for it and - // the cache is empty. We invalidate it (set it to empty) whenever the - // renderer sends a SelectionChanged message. - std::string selection_text_; - - // A struct that keeps state for the XSelectionEvent we are handling (if any). - GdkEventSelection event_selection_; - // Tracks whether we are currently handling an XSelectionEvent. - bool event_selection_active_; }; #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_ diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 894a554..6e2b3eb 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -110,10 +110,6 @@ IPC_BEGIN_MESSAGES(View) // node. IPC_MESSAGE_ROUTED1(ViewMsg_SetInitialFocus, bool /* reverse */) - // Ask the renderer to send us the selection text via the SetSelectionText - // message. - IPC_MESSAGE_ROUTED0(ViewMsg_RequestSelectionText) - // Tells the renderer to perform the specified navigation, interrupting any // existing navigation. IPC_MESSAGE_ROUTED1(ViewMsg_Navigate, ViewMsg_Navigate_Params) @@ -927,10 +923,7 @@ IPC_BEGIN_MESSAGES(ViewHost) std::wstring /* tooltip text string */) // Notification that the text selection has changed. - IPC_MESSAGE_ROUTED0(ViewHostMsg_SelectionChanged) - - // Send the current text selection. - IPC_MESSAGE_ROUTED1(ViewHostMsg_SetSelectionText, + IPC_MESSAGE_ROUTED1(ViewHostMsg_SelectionChanged, std::string /* currently selected text */) // Asks the browser to display the file chooser. The result is returned in a diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index d0b8d28..6605f4e 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -440,7 +440,6 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamVolume, OnAudioStreamVolume) IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) - IPC_MESSAGE_HANDLER(ViewMsg_RequestSelectionText, OnRequestSelectionText) IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) // Have the super handle all other messages. @@ -471,10 +470,6 @@ void RenderView::SendThumbnail() { Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); } -void RenderView::OnRequestSelectionText() { - Send(new ViewHostMsg_SetSelectionText(routing_id_, selection_text_)); -} - void RenderView::PrintPage(const ViewMsg_PrintPage_Params& params, const gfx::Size& canvas_size, WebFrame* frame) { @@ -2477,9 +2472,8 @@ void RenderView::SetTooltipText(WebView* webview, void RenderView::DidChangeSelection(bool is_empty_selection) { #if defined(OS_LINUX) if (!is_empty_selection) { - // TODO(estade): find a way to incrementally update the selection text. - selection_text_ = webview()->GetMainFrame()->GetSelection(false); - Send(new ViewHostMsg_SelectionChanged(routing_id_)); + Send(new ViewHostMsg_SelectionChanged(routing_id_, + webview()->GetMainFrame()->GetSelection(false))); } #endif } diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 7e8e818..6dd2871 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -835,10 +835,6 @@ class RenderView : public RenderWidget, // Maps pending callback IDs to their frames. IDMap<WebFrame> pending_extension_callbacks_; - // The currently selected text. This is currently only updated on Linux, where - // it's for the selection clipboard. - std::string selection_text_; - DISALLOW_COPY_AND_ASSIGN(RenderView); }; |