Commit 01b054ac authored by jam@chromium.org's avatar jam@chromium.org

Fix clipboard operations through the wrench menu not working in the find bar or devtools.

The previous approach to fix the omnibox was specific to it and that's why it didn't handle other widgets. To fix this, generalize looking for the widget by asking the FocusManager for the focused views::Textfield. I had to add a special case for devtools since the way it worked before is that it gets the synthesized keyboard shortcut and in the renderer it translates it to a clipboard operation.

BUG=164235
Review URL: https://codereview.chromium.org/11734015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175409 0039d316-1c4b-4281-b951-d872f2087c98
parent 089f8e48
...@@ -112,6 +112,7 @@ ...@@ -112,6 +112,7 @@
#include "ui/gfx/safe_integer_conversions.h" #include "ui/gfx/safe_integer_conversions.h"
#include "ui/gfx/sys_color_change_listener.h" #include "ui/gfx/sys_color_change_listener.h"
#include "ui/views/controls/single_split_view.h" #include "ui/views/controls/single_split_view.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#include "ui/views/focus/external_focus_tracker.h" #include "ui/views/focus/external_focus_tracker.h"
#include "ui/views/focus/view_storage.h" #include "ui/views/focus/view_storage.h"
...@@ -1507,63 +1508,27 @@ void BrowserView::Cut() { ...@@ -1507,63 +1508,27 @@ void BrowserView::Cut() {
// Omnibox is focused, send a Ctrl+x key event to Chrome. Using RWH interface // Omnibox is focused, send a Ctrl+x key event to Chrome. Using RWH interface
// rather than the fake key event for a WebContent is important since the fake // rather than the fake key event for a WebContent is important since the fake
// event might be consumed by the web content (crbug.com/137908). // event might be consumed by the web content (crbug.com/137908).
if (DoCutCopyPaste(&content::RenderWidgetHost::Cut)) DoCutCopyPaste(&content::RenderWidgetHost::Cut,
return; #if defined(OS_WIN)
WM_CUT,
OmniboxView* omnibox_view = GetLocationBarView()->GetLocationEntry();
if (!omnibox_view->model()->has_focus())
return;
#if defined(OS_WIN) && !defined(USE_AURA)
OmniboxViewWin* omnibox_win = GetOmniboxViewWin(omnibox_view);
if (omnibox_win) {
::SendMessage(omnibox_win->GetNativeView(), WM_CUT, 0, 0);
return;
}
#endif #endif
IDS_APP_CUT);
OmniboxViewViews* omnibox_views = GetOmniboxViewViews(omnibox_view);
omnibox_views->ExecuteCommandOnTextField(IDS_APP_CUT);
} }
void BrowserView::Copy() { void BrowserView::Copy() {
if (DoCutCopyPaste(&content::RenderWidgetHost::Copy)) DoCutCopyPaste(&content::RenderWidgetHost::Copy,
return; #if defined(OS_WIN)
WM_COPY,
OmniboxView* omnibox_view = GetLocationBarView()->GetLocationEntry();
if (!omnibox_view->model()->has_focus())
return;
#if defined(OS_WIN) && !defined(USE_AURA)
OmniboxViewWin* omnibox_win = GetOmniboxViewWin(omnibox_view);
if (omnibox_win) {
::SendMessage(omnibox_win->GetNativeView(), WM_COPY, 0, 0);
return;
}
#endif #endif
IDS_APP_COPY);
OmniboxViewViews* omnibox_views = GetOmniboxViewViews(omnibox_view);
omnibox_views->ExecuteCommandOnTextField(IDS_APP_COPY);
} }
void BrowserView::Paste() { void BrowserView::Paste() {
if (DoCutCopyPaste(&content::RenderWidgetHost::Paste)) DoCutCopyPaste(&content::RenderWidgetHost::Paste,
return; #if defined(OS_WIN)
WM_PASTE,
OmniboxView* omnibox_view = GetLocationBarView()->GetLocationEntry();
if (!omnibox_view->model()->has_focus())
return;
#if defined(OS_WIN) && !defined(USE_AURA)
OmniboxViewWin* omnibox_win = GetOmniboxViewWin(omnibox_view);
if (omnibox_win) {
::SendMessage(omnibox_win->GetNativeView(), WM_PASTE, 0, 0);
return;
}
#endif #endif
IDS_APP_PASTE);
OmniboxViewViews* omnibox_views = GetOmniboxViewViews(omnibox_view);
omnibox_views->ExecuteCommandOnTextField(IDS_APP_PASTE);
} }
gfx::Rect BrowserView::GetInstantBounds() { gfx::Rect BrowserView::GetInstantBounds() {
...@@ -2785,10 +2750,44 @@ void BrowserView::ShowPasswordGenerationBubble( ...@@ -2785,10 +2750,44 @@ void BrowserView::ShowPasswordGenerationBubble(
bubble->Show(); bubble->Show();
} }
bool BrowserView::DoCutCopyPaste(void (content::RenderWidgetHost::*method)()) { void BrowserView::DoCutCopyPaste(void (content::RenderWidgetHost::*method)(),
#if defined(OS_WIN)
int windows_msg_id,
#endif
int command_id) {
WebContents* contents = chrome::GetActiveWebContents(browser_.get()); WebContents* contents = chrome::GetActiveWebContents(browser_.get());
if (!contents) if (!contents)
return false; return;
if (DoCutCopyPasteForWebContents(contents, method))
return;
DevToolsWindow* devtools_window =
DevToolsWindow::GetDockedInstanceForInspectedTab(contents);
if (devtools_window &&
DoCutCopyPasteForWebContents(devtools_window->web_contents(), method)) {
return;
}
views::FocusManager* focus_manager = GetFocusManager();
views::View* focused = focus_manager->GetFocusedView();
if (focused->GetClassName() == views::Textfield::kViewClassName) {
views::Textfield* textfield = static_cast<views::Textfield*>(focused);
textfield->ExecuteCommand(command_id);
return;
}
#if defined(OS_WIN) && !defined(USE_AURA)
OmniboxView* omnibox_view = GetLocationBarView()->GetLocationEntry();
if (omnibox_view->model()->has_focus()) {
OmniboxViewWin* omnibox_win = GetOmniboxViewWin(omnibox_view);
::SendMessage(omnibox_win->GetNativeView(), windows_msg_id, 0, 0);
}
#endif
}
bool BrowserView::DoCutCopyPasteForWebContents(
WebContents* contents,
void (content::RenderWidgetHost::*method)()) {
gfx::NativeView native_view = contents->GetContentNativeView(); gfx::NativeView native_view = contents->GetContentNativeView();
if (!native_view) if (!native_view)
return false; return false;
......
...@@ -570,9 +570,22 @@ class BrowserView : public BrowserWindow, ...@@ -570,9 +570,22 @@ class BrowserView : public BrowserWindow,
// Create an icon for this window in the launcher (currently only for Ash). // Create an icon for this window in the launcher (currently only for Ash).
void CreateLauncherIcon(); void CreateLauncherIcon();
// Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste // Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste,
// and returns true if the focus is currently on a WebContent. // first trying the content WebContents, then the devtools WebContents, and
bool DoCutCopyPaste(void (content::RenderWidgetHost::*method)()); // lastly the Views::Textfield if one is focused.
// |windows_msg_id| is temporary until Win Aura is the default on Windows,
// since until then the omnibox doesn't use Views::Textfield.
void DoCutCopyPaste(void (content::RenderWidgetHost::*method)(),
#if defined(OS_WIN)
int windows_msg_id,
#endif
int command_id);
// Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste on
// the given WebContents, returning true if it consumed the event.
bool DoCutCopyPasteForWebContents(
content::WebContents* contents,
void (content::RenderWidgetHost::*method)());
// Shows the next app-modal dialog box, if there is one to be shown, or moves // Shows the next app-modal dialog box, if there is one to be shown, or moves
// an existing showing one to the front. // an existing showing one to the front.
......
...@@ -420,10 +420,6 @@ bool OmniboxViewViews::IsLocationEntryFocusableInRootView() const { ...@@ -420,10 +420,6 @@ bool OmniboxViewViews::IsLocationEntryFocusableInRootView() const {
return textfield_->IsFocusable(); return textfield_->IsFocusable();
} }
void OmniboxViewViews::ExecuteCommandOnTextField(int command_id) {
return textfield_->ExecuteCommand(command_id);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// OmniboxViewViews, views::View implementation: // OmniboxViewViews, views::View implementation:
void OmniboxViewViews::Layout() { void OmniboxViewViews::Layout() {
......
...@@ -85,9 +85,6 @@ class OmniboxViewViews ...@@ -85,9 +85,6 @@ class OmniboxViewViews
// the root view. // the root view.
bool IsLocationEntryFocusableInRootView() const; bool IsLocationEntryFocusableInRootView() const;
// Executes the given command on the text field.
void ExecuteCommandOnTextField(int command_id);
// Implements views::View // Implements views::View
virtual void Layout() OVERRIDE; virtual void Layout() OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment