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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 93 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
94 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 94 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
95 #include "chrome/common/chrome_switches.h" | 95 #include "chrome/common/chrome_switches.h" |
96 #include "chrome/common/pref_names.h" | 96 #include "chrome/common/pref_names.h" |
97 #include "chrome/common/profile_management_switches.h" | 97 #include "chrome/common/profile_management_switches.h" |
98 #include "chrome/common/url_constants.h" | 98 #include "chrome/common/url_constants.h" |
99 #include "components/password_manager/core/browser/password_manager.h" | 99 #include "components/password_manager/core/browser/password_manager.h" |
100 #include "content/public/browser/download_manager.h" | 100 #include "content/public/browser/download_manager.h" |
101 #include "content/public/browser/native_web_keyboard_event.h" | 101 #include "content/public/browser/native_web_keyboard_event.h" |
102 #include "content/public/browser/notification_service.h" | 102 #include "content/public/browser/notification_service.h" |
| 103 #include "content/public/browser/render_frame_host.h" |
103 #include "content/public/browser/render_view_host.h" | 104 #include "content/public/browser/render_view_host.h" |
104 #include "content/public/browser/render_widget_host.h" | |
105 #include "content/public/browser/user_metrics.h" | 105 #include "content/public/browser/user_metrics.h" |
106 #include "content/public/browser/web_contents.h" | 106 #include "content/public/browser/web_contents.h" |
107 #include "content/public/browser/web_contents_view.h" | 107 #include "content/public/browser/web_contents_view.h" |
108 #include "content/public/common/content_switches.h" | 108 #include "content/public/common/content_switches.h" |
109 #include "grit/chromium_strings.h" | 109 #include "grit/chromium_strings.h" |
110 #include "grit/generated_resources.h" | 110 #include "grit/generated_resources.h" |
111 #include "grit/locale_settings.h" | 111 #include "grit/locale_settings.h" |
112 #include "grit/theme_resources.h" | 112 #include "grit/theme_resources.h" |
113 #include "grit/ui_resources.h" | 113 #include "grit/ui_resources.h" |
114 #include "grit/ui_strings.h" | 114 #include "grit/ui_strings.h" |
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 } | 1412 } |
1413 | 1413 |
1414 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always | 1414 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always |
1415 // enabled in the page menu regardless of whether the command will do | 1415 // enabled in the page menu regardless of whether the command will do |
1416 // anything. When someone selects the menu item, we just act as if they hit | 1416 // anything. When someone selects the menu item, we just act as if they hit |
1417 // the keyboard shortcut for the command by sending the associated key press | 1417 // the keyboard shortcut for the command by sending the associated key press |
1418 // to windows. The real fix to this bug is to disable the commands when they | 1418 // to windows. The real fix to this bug is to disable the commands when they |
1419 // won't do anything. We'll need something like an overall clipboard command | 1419 // won't do anything. We'll need something like an overall clipboard command |
1420 // manager to do that. | 1420 // manager to do that. |
1421 void BrowserView::Cut() { | 1421 void BrowserView::Cut() { |
1422 // If a WebContent is focused, call RenderWidgetHost::Cut. Otherwise, e.g. if | 1422 // If a WebContent is focused, call RenderFrameHost::Cut. Otherwise, e.g. if |
1423 // Omnibox is focused, send a Ctrl+x key event to Chrome. Using RWH interface | 1423 // Omnibox is focused, send a Ctrl+x key event to Chrome. Using RWH interface |
1424 // rather than the fake key event for a WebContent is important since the fake | 1424 // rather than the fake key event for a WebContent is important since the fake |
1425 // event might be consumed by the web content (crbug.com/137908). | 1425 // event might be consumed by the web content (crbug.com/137908). |
1426 DoCutCopyPaste(&content::RenderWidgetHost::Cut, IDS_APP_CUT); | 1426 DoCutCopyPaste(&content::RenderFrameHost::Cut, IDS_APP_CUT); |
1427 } | 1427 } |
1428 | 1428 |
1429 void BrowserView::Copy() { | 1429 void BrowserView::Copy() { |
1430 DoCutCopyPaste(&content::RenderWidgetHost::Copy, IDS_APP_COPY); | 1430 DoCutCopyPaste(&content::RenderFrameHost::Copy, IDS_APP_COPY); |
1431 } | 1431 } |
1432 | 1432 |
1433 void BrowserView::Paste() { | 1433 void BrowserView::Paste() { |
1434 DoCutCopyPaste(&content::RenderWidgetHost::Paste, IDS_APP_PASTE); | 1434 DoCutCopyPaste(&content::RenderFrameHost::Paste, IDS_APP_PASTE); |
1435 } | 1435 } |
1436 | 1436 |
1437 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( | 1437 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( |
1438 const gfx::Rect& bounds) { | 1438 const gfx::Rect& bounds) { |
1439 #if defined(OS_WIN) | 1439 #if defined(OS_WIN) |
1440 // If we are in Win8's single window Metro mode, we can't allow popup windows. | 1440 // If we are in Win8's single window Metro mode, we can't allow popup windows. |
1441 return win8::IsSingleWindowMetroMode() ? NEW_BACKGROUND_TAB : NEW_POPUP; | 1441 return win8::IsSingleWindowMetroMode() ? NEW_BACKGROUND_TAB : NEW_POPUP; |
1442 #else | 1442 #else |
1443 return NEW_POPUP; | 1443 return NEW_POPUP; |
1444 #endif | 1444 #endif |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2501 void BrowserView::ShowPageActionPopup( | 2501 void BrowserView::ShowPageActionPopup( |
2502 const extensions::Extension* extension) { | 2502 const extensions::Extension* extension) { |
2503 toolbar_->ShowPageActionPopup(extension); | 2503 toolbar_->ShowPageActionPopup(extension); |
2504 } | 2504 } |
2505 | 2505 |
2506 void BrowserView::ShowBrowserActionPopup( | 2506 void BrowserView::ShowBrowserActionPopup( |
2507 const extensions::Extension* extension) { | 2507 const extensions::Extension* extension) { |
2508 toolbar_->ShowBrowserActionPopup(extension); | 2508 toolbar_->ShowBrowserActionPopup(extension); |
2509 } | 2509 } |
2510 | 2510 |
2511 void BrowserView::DoCutCopyPaste(void (content::RenderWidgetHost::*method)(), | 2511 void BrowserView::DoCutCopyPaste(void (content::RenderFrameHost::*method)(), |
2512 int command_id) { | 2512 int command_id) { |
2513 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); | 2513 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); |
2514 if (!contents) | 2514 if (!contents) |
2515 return; | 2515 return; |
2516 if (DoCutCopyPasteForWebContents(contents, method)) | 2516 if (DoCutCopyPasteForWebContents(contents, method)) |
2517 return; | 2517 return; |
2518 | 2518 |
2519 DevToolsWindow* devtools_window = | 2519 DevToolsWindow* devtools_window = |
2520 DevToolsWindow::GetDockedInstanceForInspectedTab(contents); | 2520 DevToolsWindow::GetDockedInstanceForInspectedTab(contents); |
2521 if (devtools_window && | 2521 if (devtools_window && |
2522 DoCutCopyPasteForWebContents(devtools_window->web_contents(), method)) { | 2522 DoCutCopyPasteForWebContents(devtools_window->web_contents(), method)) { |
2523 return; | 2523 return; |
2524 } | 2524 } |
2525 | 2525 |
2526 views::FocusManager* focus_manager = GetFocusManager(); | 2526 views::FocusManager* focus_manager = GetFocusManager(); |
2527 views::View* focused = focus_manager->GetFocusedView(); | 2527 views::View* focused = focus_manager->GetFocusedView(); |
2528 if (focused && | 2528 if (focused && |
2529 (!strcmp(focused->GetClassName(), views::Textfield::kViewClassName) || | 2529 (!strcmp(focused->GetClassName(), views::Textfield::kViewClassName) || |
2530 !strcmp(focused->GetClassName(), OmniboxViewViews::kViewClassName))) { | 2530 !strcmp(focused->GetClassName(), OmniboxViewViews::kViewClassName))) { |
2531 views::Textfield* textfield = static_cast<views::Textfield*>(focused); | 2531 views::Textfield* textfield = static_cast<views::Textfield*>(focused); |
2532 textfield->ExecuteCommand(command_id); | 2532 textfield->ExecuteCommand(command_id); |
2533 } | 2533 } |
2534 } | 2534 } |
2535 | 2535 |
2536 bool BrowserView::DoCutCopyPasteForWebContents( | 2536 bool BrowserView::DoCutCopyPasteForWebContents( |
2537 WebContents* contents, | 2537 WebContents* contents, |
2538 void (content::RenderWidgetHost::*method)()) { | 2538 void (content::RenderFrameHost::*method)()) { |
2539 gfx::NativeView native_view = contents->GetView()->GetContentNativeView(); | 2539 gfx::NativeView native_view = contents->GetView()->GetContentNativeView(); |
2540 if (!native_view) | 2540 if (!native_view) |
2541 return false; | 2541 return false; |
2542 #if defined(USE_AURA) | 2542 #if defined(USE_AURA) |
2543 if (native_view->HasFocus()) { | 2543 if (native_view->HasFocus()) { |
2544 #elif defined(OS_WIN) | 2544 #elif defined(OS_WIN) |
2545 if (native_view == ::GetFocus()) { | 2545 if (native_view == ::GetFocus()) { |
2546 #endif | 2546 #endif |
2547 (contents->GetRenderViewHost()->*method)(); | 2547 content::RenderFrameHost* frame = contents->GetFocusedFrame(); |
| 2548 if (frame) |
| 2549 (frame->*method)(); |
2548 return true; | 2550 return true; |
2549 } | 2551 } |
2550 | 2552 |
2551 return false; | 2553 return false; |
2552 } | 2554 } |
2553 | 2555 |
2554 void BrowserView::ActivateAppModalDialog() const { | 2556 void BrowserView::ActivateAppModalDialog() const { |
2555 // If another browser is app modal, flash and activate the modal browser. | 2557 // If another browser is app modal, flash and activate the modal browser. |
2556 AppModalDialog* active_dialog = | 2558 AppModalDialog* active_dialog = |
2557 AppModalDialogQueue::GetInstance()->active_dialog(); | 2559 AppModalDialogQueue::GetInstance()->active_dialog(); |
(...skipping 18 matching lines...) Expand all Loading... |
2576 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { | 2578 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { |
2577 gfx::Point icon_bottom( | 2579 gfx::Point icon_bottom( |
2578 toolbar_->location_bar()->GetLocationBarAnchorPoint()); | 2580 toolbar_->location_bar()->GetLocationBarAnchorPoint()); |
2579 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); | 2581 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); |
2580 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); | 2582 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); |
2581 ConvertPointToTarget(infobar_container_, this, &infobar_top); | 2583 ConvertPointToTarget(infobar_container_, this, &infobar_top); |
2582 top_arrow_height = infobar_top.y() - icon_bottom.y(); | 2584 top_arrow_height = infobar_top.y() - icon_bottom.y(); |
2583 } | 2585 } |
2584 return top_arrow_height; | 2586 return top_arrow_height; |
2585 } | 2587 } |
OLD | NEW |