| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 GetFocusManager()); | 1454 GetFocusManager()); |
| 1455 } | 1455 } |
| 1456 | 1456 |
| 1457 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always | 1457 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always |
| 1458 // enabled in the page menu regardless of whether the command will do | 1458 // enabled in the page menu regardless of whether the command will do |
| 1459 // anything. When someone selects the menu item, we just act as if they hit | 1459 // anything. When someone selects the menu item, we just act as if they hit |
| 1460 // the keyboard shortcut for the command by sending the associated key press | 1460 // the keyboard shortcut for the command by sending the associated key press |
| 1461 // to windows. The real fix to this bug is to disable the commands when they | 1461 // to windows. The real fix to this bug is to disable the commands when they |
| 1462 // won't do anything. We'll need something like an overall clipboard command | 1462 // won't do anything. We'll need something like an overall clipboard command |
| 1463 // manager to do that. | 1463 // manager to do that. |
| 1464 void BrowserView::Cut() { | 1464 void BrowserView::CutCopyPaste(int command_id) { |
| 1465 // If a WebContent is focused, call WebContents::Cut. Otherwise, e.g. if | 1465 // If a WebContents is focused, call its member method. |
| 1466 // Omnibox is focused, send a Ctrl+x key event to Chrome. Using RWH interface | 1466 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); |
| 1467 // rather than the fake key event for a WebContent is important since the fake | 1467 if (contents) { |
| 1468 // event might be consumed by the web content (crbug.com/137908). | 1468 void (WebContents::*method)(); |
| 1469 DoCutCopyPaste(&content::WebContents::Cut, IDS_APP_CUT); | 1469 if (command_id == IDC_CUT) |
| 1470 } | 1470 method = &content::WebContents::Cut; |
| 1471 else if (command_id == IDC_COPY) |
| 1472 method = &content::WebContents::Copy; |
| 1473 else |
| 1474 method = &content::WebContents::Paste; |
| 1475 if (DoCutCopyPasteForWebContents(contents, method)) |
| 1476 return; |
| 1471 | 1477 |
| 1472 void BrowserView::Copy() { | 1478 WebContents* devtools = |
| 1473 DoCutCopyPaste(&content::WebContents::Copy, IDS_APP_COPY); | 1479 DevToolsWindow::GetInTabWebContents(contents, nullptr); |
| 1474 } | 1480 if (devtools && DoCutCopyPasteForWebContents(devtools, method)) |
| 1481 return; |
| 1482 } |
| 1475 | 1483 |
| 1476 void BrowserView::Paste() { | 1484 // Execute the command on the focused view, if possible, by calling |
| 1477 DoCutCopyPaste(&content::WebContents::Paste, IDS_APP_PASTE); | 1485 // AcceleratorPressed(). Textfields override this to translate and execute |
| 1486 // the provided accelerator. |
| 1487 views::View* focused = GetFocusManager()->GetFocusedView(); |
| 1488 if (focused->CanHandleAccelerators()) { |
| 1489 ui::Accelerator accelerator; |
| 1490 GetAccelerator(command_id, &accelerator); |
| 1491 focused->AcceleratorPressed(accelerator); |
| 1492 } |
| 1478 } | 1493 } |
| 1479 | 1494 |
| 1480 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( | 1495 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( |
| 1481 const gfx::Rect& bounds) { | 1496 const gfx::Rect& bounds) { |
| 1482 return NEW_POPUP; | 1497 return NEW_POPUP; |
| 1483 } | 1498 } |
| 1484 | 1499 |
| 1485 FindBar* BrowserView::CreateFindBar() { | 1500 FindBar* BrowserView::CreateFindBar() { |
| 1486 return chrome::CreateFindBar(this); | 1501 return chrome::CreateFindBar(this); |
| 1487 } | 1502 } |
| (...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2507 void BrowserView::ExecuteExtensionCommand( | 2522 void BrowserView::ExecuteExtensionCommand( |
| 2508 const extensions::Extension* extension, | 2523 const extensions::Extension* extension, |
| 2509 const extensions::Command& command) { | 2524 const extensions::Command& command) { |
| 2510 toolbar_->ExecuteExtensionCommand(extension, command); | 2525 toolbar_->ExecuteExtensionCommand(extension, command); |
| 2511 } | 2526 } |
| 2512 | 2527 |
| 2513 ExclusiveAccessContext* BrowserView::GetExclusiveAccessContext() { | 2528 ExclusiveAccessContext* BrowserView::GetExclusiveAccessContext() { |
| 2514 return this; | 2529 return this; |
| 2515 } | 2530 } |
| 2516 | 2531 |
| 2517 void BrowserView::DoCutCopyPaste(void (WebContents::*method)(), | |
| 2518 int command_id) { | |
| 2519 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); | |
| 2520 if (!contents) | |
| 2521 return; | |
| 2522 if (DoCutCopyPasteForWebContents(contents, method)) | |
| 2523 return; | |
| 2524 | |
| 2525 WebContents* devtools = DevToolsWindow::GetInTabWebContents(contents, | |
| 2526 nullptr); | |
| 2527 if (devtools && DoCutCopyPasteForWebContents(devtools, method)) | |
| 2528 return; | |
| 2529 | |
| 2530 views::FocusManager* focus_manager = GetFocusManager(); | |
| 2531 views::View* focused = focus_manager->GetFocusedView(); | |
| 2532 if (focused && | |
| 2533 (!strcmp(focused->GetClassName(), views::Textfield::kViewClassName) || | |
| 2534 !strcmp(focused->GetClassName(), OmniboxViewViews::kViewClassName))) { | |
| 2535 views::Textfield* textfield = static_cast<views::Textfield*>(focused); | |
| 2536 textfield->ExecuteCommand(command_id); | |
| 2537 } | |
| 2538 } | |
| 2539 | |
| 2540 bool BrowserView::DoCutCopyPasteForWebContents( | 2532 bool BrowserView::DoCutCopyPasteForWebContents( |
| 2541 WebContents* contents, | 2533 WebContents* contents, |
| 2542 void (WebContents::*method)()) { | 2534 void (WebContents::*method)()) { |
| 2535 // Using RWH interface rather than a fake key event for a WebContent is |
| 2536 // important since a fake event might be consumed by the web content. |
| 2543 if (contents->GetRenderWidgetHostView()->HasFocus()) { | 2537 if (contents->GetRenderWidgetHostView()->HasFocus()) { |
| 2544 (contents->*method)(); | 2538 (contents->*method)(); |
| 2545 return true; | 2539 return true; |
| 2546 } | 2540 } |
| 2547 | 2541 |
| 2548 return false; | 2542 return false; |
| 2549 } | 2543 } |
| 2550 | 2544 |
| 2551 void BrowserView::ActivateAppModalDialog() const { | 2545 void BrowserView::ActivateAppModalDialog() const { |
| 2552 // If another browser is app modal, flash and activate the modal browser. | 2546 // If another browser is app modal, flash and activate the modal browser. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2612 return immersive_mode_controller()->IsEnabled(); | 2606 return immersive_mode_controller()->IsEnabled(); |
| 2613 } | 2607 } |
| 2614 | 2608 |
| 2615 views::Widget* BrowserView::GetBubbleAssociatedWidget() { | 2609 views::Widget* BrowserView::GetBubbleAssociatedWidget() { |
| 2616 return GetWidget(); | 2610 return GetWidget(); |
| 2617 } | 2611 } |
| 2618 | 2612 |
| 2619 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() { | 2613 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() { |
| 2620 return top_container_->GetBoundsInScreen(); | 2614 return top_container_->GetBoundsInScreen(); |
| 2621 } | 2615 } |
| OLD | NEW |