Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(845)

Unified Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 1091703002: Eliminate faux-RTTI code from BrowserView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert to patch set 2 Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.h ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/frame/browser_view.cc
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 60877d74b81fa04d4ba840576f1f991d5cf34c58..b6db9162491692b96bb85026eb5b1971340b86c4 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -1461,20 +1461,35 @@ void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
// 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() {
- // If a WebContent is focused, call WebContents::Cut. Otherwise, e.g. if
- // 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
- // event might be consumed by the web content (crbug.com/137908).
- DoCutCopyPaste(&content::WebContents::Cut, IDS_APP_CUT);
-}
+void BrowserView::CutCopyPaste(int command_id) {
+ // If a WebContents is focused, call its member method.
+ WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
+ if (contents) {
+ void (WebContents::*method)();
+ if (command_id == IDC_CUT)
+ method = &content::WebContents::Cut;
+ else if (command_id == IDC_COPY)
+ method = &content::WebContents::Copy;
+ else
+ method = &content::WebContents::Paste;
+ if (DoCutCopyPasteForWebContents(contents, method))
+ return;
-void BrowserView::Copy() {
- DoCutCopyPaste(&content::WebContents::Copy, IDS_APP_COPY);
-}
+ WebContents* devtools =
+ DevToolsWindow::GetInTabWebContents(contents, nullptr);
+ if (devtools && DoCutCopyPasteForWebContents(devtools, method))
+ return;
+ }
-void BrowserView::Paste() {
- DoCutCopyPaste(&content::WebContents::Paste, IDS_APP_PASTE);
+ // Execute the command on the focused view, if possible, by calling
+ // AcceleratorPressed(). Textfields override this to translate and execute
+ // the provided accelerator.
+ views::View* focused = GetFocusManager()->GetFocusedView();
+ if (focused->CanHandleAccelerators()) {
+ ui::Accelerator accelerator;
+ GetAccelerator(command_id, &accelerator);
+ focused->AcceleratorPressed(accelerator);
+ }
}
WindowOpenDisposition BrowserView::GetDispositionForPopupBounds(
@@ -2514,32 +2529,11 @@ ExclusiveAccessContext* BrowserView::GetExclusiveAccessContext() {
return this;
}
-void BrowserView::DoCutCopyPaste(void (WebContents::*method)(),
- int command_id) {
- WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
- if (!contents)
- return;
- if (DoCutCopyPasteForWebContents(contents, method))
- return;
-
- WebContents* devtools = DevToolsWindow::GetInTabWebContents(contents,
- nullptr);
- if (devtools && DoCutCopyPasteForWebContents(devtools, method))
- return;
-
- views::FocusManager* focus_manager = GetFocusManager();
- views::View* focused = focus_manager->GetFocusedView();
- if (focused &&
- (!strcmp(focused->GetClassName(), views::Textfield::kViewClassName) ||
- !strcmp(focused->GetClassName(), OmniboxViewViews::kViewClassName))) {
- views::Textfield* textfield = static_cast<views::Textfield*>(focused);
- textfield->ExecuteCommand(command_id);
- }
-}
-
bool BrowserView::DoCutCopyPasteForWebContents(
WebContents* contents,
void (WebContents::*method)()) {
+ // Using RWH interface rather than a fake key event for a WebContent is
+ // important since a fake event might be consumed by the web content.
if (contents->GetRenderWidgetHostView()->HasFocus()) {
(contents->*method)();
return true;
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.h ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698