| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 #include "components/app_modal/app_modal_dialog_queue.h" | 106 #include "components/app_modal/app_modal_dialog_queue.h" |
| 107 #include "components/app_modal/native_app_modal_dialog.h" | 107 #include "components/app_modal/native_app_modal_dialog.h" |
| 108 #include "components/omnibox/browser/omnibox_popup_model.h" | 108 #include "components/omnibox/browser/omnibox_popup_model.h" |
| 109 #include "components/omnibox/browser/omnibox_popup_view.h" | 109 #include "components/omnibox/browser/omnibox_popup_view.h" |
| 110 #include "components/omnibox/browser/omnibox_view.h" | 110 #include "components/omnibox/browser/omnibox_view.h" |
| 111 #include "components/prefs/pref_service.h" | 111 #include "components/prefs/pref_service.h" |
| 112 #include "components/sessions/core/tab_restore_service.h" | 112 #include "components/sessions/core/tab_restore_service.h" |
| 113 #include "components/signin/core/common/profile_management_switches.h" | 113 #include "components/signin/core/common/profile_management_switches.h" |
| 114 #include "components/translate/core/browser/language_state.h" | 114 #include "components/translate/core/browser/language_state.h" |
| 115 #include "content/public/browser/download_manager.h" | 115 #include "content/public/browser/download_manager.h" |
| 116 #include "content/public/browser/keyboard_event_processing_result.h" |
| 116 #include "content/public/browser/notification_service.h" | 117 #include "content/public/browser/notification_service.h" |
| 117 #include "content/public/browser/render_frame_host.h" | 118 #include "content/public/browser/render_frame_host.h" |
| 118 #include "content/public/browser/render_view_host.h" | 119 #include "content/public/browser/render_view_host.h" |
| 119 #include "content/public/browser/render_widget_host_view.h" | 120 #include "content/public/browser/render_widget_host_view.h" |
| 120 #include "content/public/browser/user_metrics.h" | 121 #include "content/public/browser/user_metrics.h" |
| 121 #include "content/public/browser/web_contents.h" | 122 #include "content/public/browser/web_contents.h" |
| 122 #include "content/public/common/content_switches.h" | 123 #include "content/public/common/content_switches.h" |
| 123 #include "ui/accessibility/ax_node_data.h" | 124 #include "ui/accessibility/ax_node_data.h" |
| 124 #include "ui/base/accelerators/accelerator.h" | 125 #include "ui/base/accelerators/accelerator.h" |
| 125 #include "ui/base/hit_test.h" | 126 #include "ui/base/hit_test.h" |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 return; | 1300 return; |
| 1300 | 1301 |
| 1301 // Keep the top-of-window views revealed as long as the app menu is visible. | 1302 // Keep the top-of-window views revealed as long as the app menu is visible. |
| 1302 std::unique_ptr<ImmersiveRevealedLock> revealed_lock( | 1303 std::unique_ptr<ImmersiveRevealedLock> revealed_lock( |
| 1303 immersive_mode_controller_->GetRevealedLock( | 1304 immersive_mode_controller_->GetRevealedLock( |
| 1304 ImmersiveModeController::ANIMATE_REVEAL_NO)); | 1305 ImmersiveModeController::ANIMATE_REVEAL_NO)); |
| 1305 | 1306 |
| 1306 toolbar_->app_menu_button()->Activate(nullptr); | 1307 toolbar_->app_menu_button()->Activate(nullptr); |
| 1307 } | 1308 } |
| 1308 | 1309 |
| 1309 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 1310 content::KeyboardEventProcessingResult BrowserView::PreHandleKeyboardEvent( |
| 1310 bool* is_keyboard_shortcut) { | 1311 const NativeWebKeyboardEvent& event) { |
| 1311 *is_keyboard_shortcut = false; | |
| 1312 | |
| 1313 if ((event.type() != blink::WebInputEvent::RawKeyDown) && | 1312 if ((event.type() != blink::WebInputEvent::RawKeyDown) && |
| 1314 (event.type() != blink::WebInputEvent::KeyUp)) { | 1313 (event.type() != blink::WebInputEvent::KeyUp)) { |
| 1315 return false; | 1314 return content::KeyboardEventProcessingResult::NOT_HANDLED; |
| 1316 } | 1315 } |
| 1317 | 1316 |
| 1318 views::FocusManager* focus_manager = GetFocusManager(); | 1317 views::FocusManager* focus_manager = GetFocusManager(); |
| 1319 DCHECK(focus_manager); | 1318 DCHECK(focus_manager); |
| 1320 | 1319 |
| 1321 if (focus_manager->shortcut_handling_suspended()) | 1320 if (focus_manager->shortcut_handling_suspended()) |
| 1322 return false; | 1321 return content::KeyboardEventProcessingResult::NOT_HANDLED; |
| 1323 | 1322 |
| 1324 ui::Accelerator accelerator = | 1323 ui::Accelerator accelerator = |
| 1325 ui::GetAcceleratorFromNativeWebKeyboardEvent(event); | 1324 ui::GetAcceleratorFromNativeWebKeyboardEvent(event); |
| 1326 | 1325 |
| 1327 // What we have to do here is as follows: | 1326 // What we have to do here is as follows: |
| 1328 // - If the |browser_| is for an app, do nothing. | 1327 // - If the |browser_| is for an app, do nothing. |
| 1329 // - On CrOS if |accelerator| is deprecated, we allow web contents to consume | 1328 // - On CrOS if |accelerator| is deprecated, we allow web contents to consume |
| 1330 // it if needed. | 1329 // it if needed. |
| 1331 // - If the |browser_| is not for an app, and the |accelerator| is not | 1330 // - If the |browser_| is not for an app, and the |accelerator| is not |
| 1332 // associated with the browser (e.g. an Ash shortcut), process it. | 1331 // associated with the browser (e.g. an Ash shortcut), process it. |
| 1333 // - If the |browser_| is not for an app, and the |accelerator| is associated | 1332 // - If the |browser_| is not for an app, and the |accelerator| is associated |
| 1334 // with the browser, and it is a reserved one (e.g. Ctrl+w), process it. | 1333 // with the browser, and it is a reserved one (e.g. Ctrl+w), process it. |
| 1335 // - If the |browser_| is not for an app, and the |accelerator| is associated | 1334 // - If the |browser_| is not for an app, and the |accelerator| is associated |
| 1336 // with the browser, and it is not a reserved one, do nothing. | 1335 // with the browser, and it is not a reserved one, do nothing. |
| 1337 | 1336 |
| 1338 if (browser_->is_app()) { | 1337 if (browser_->is_app()) { |
| 1339 // Let all keys fall through to a v1 app's web content, even accelerators. | 1338 // Let all keys fall through to a v1 app's web content, even accelerators. |
| 1340 // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app | 1339 // We don't use NOT_HANDLED_IS_SHORTCUT here. If we do that, the app |
| 1341 // might not be able to see a subsequent Char event. See OnHandleInputEvent | 1340 // might not be able to see a subsequent Char event. See OnHandleInputEvent |
| 1342 // in content/renderer/render_widget.cc for details. | 1341 // in content/renderer/render_widget.cc for details. |
| 1343 return false; | 1342 return content::KeyboardEventProcessingResult::NOT_HANDLED; |
| 1344 } | 1343 } |
| 1345 | 1344 |
| 1346 #if defined(OS_CHROMEOS) | 1345 #if defined(OS_CHROMEOS) |
| 1347 if (ash_util::IsAcceleratorDeprecated(accelerator)) { | 1346 if (ash_util::IsAcceleratorDeprecated(accelerator)) { |
| 1348 if (event.type() == blink::WebInputEvent::RawKeyDown) | 1347 return (event.type() == blink::WebInputEvent::RawKeyDown) |
| 1349 *is_keyboard_shortcut = true; | 1348 ? content::KeyboardEventProcessingResult::NOT_HANDLED_IS_SHORTCUT |
| 1350 return false; | 1349 : content::KeyboardEventProcessingResult::NOT_HANDLED; |
| 1351 } | 1350 } |
| 1352 #endif // defined(OS_CHROMEOS) | 1351 #endif // defined(OS_CHROMEOS) |
| 1353 | 1352 |
| 1354 if (frame_->PreHandleKeyboardEvent(event)) | 1353 if (frame_->PreHandleKeyboardEvent(event)) |
| 1355 return true; | 1354 return content::KeyboardEventProcessingResult::HANDLED; |
| 1356 | 1355 |
| 1357 chrome::BrowserCommandController* controller = browser_->command_controller(); | 1356 chrome::BrowserCommandController* controller = browser_->command_controller(); |
| 1358 | 1357 |
| 1359 // Here we need to retrieve the command id (if any) associated to the | 1358 // Here we need to retrieve the command id (if any) associated to the |
| 1360 // keyboard event. Instead of looking up the command id in the | 1359 // keyboard event. Instead of looking up the command id in the |
| 1361 // |accelerator_table_| by ourselves, we block the command execution of | 1360 // |accelerator_table_| by ourselves, we block the command execution of |
| 1362 // the |browser_| object then send the keyboard event to the | 1361 // the |browser_| object then send the keyboard event to the |
| 1363 // |focus_manager| as if we are activating an accelerator key. | 1362 // |focus_manager| as if we are activating an accelerator key. |
| 1364 // Then we can retrieve the command id from the |browser_| object. | 1363 // Then we can retrieve the command id from the |browser_| object. |
| 1365 bool original_block_command_state = controller->block_command_execution(); | 1364 bool original_block_command_state = controller->block_command_execution(); |
| 1366 controller->SetBlockCommandExecution(true); | 1365 controller->SetBlockCommandExecution(true); |
| 1367 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the | 1366 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the |
| 1368 // command execution cannot be blocked and true is returned. However, it is | 1367 // command execution cannot be blocked and true is returned. However, it is |
| 1369 // okay as long as is_app() is false. See comments in this function. | 1368 // okay as long as is_app() is false. See comments in this function. |
| 1370 const bool processed = focus_manager->ProcessAccelerator(accelerator); | 1369 const bool processed = focus_manager->ProcessAccelerator(accelerator); |
| 1371 const int id = controller->GetLastBlockedCommand(nullptr); | 1370 const int id = controller->GetLastBlockedCommand(nullptr); |
| 1372 controller->SetBlockCommandExecution(original_block_command_state); | 1371 controller->SetBlockCommandExecution(original_block_command_state); |
| 1373 | 1372 |
| 1374 // Executing the command may cause |this| object to be destroyed. | 1373 // Executing the command may cause |this| object to be destroyed. |
| 1375 if (controller->IsReservedCommandOrKey(id, event)) { | 1374 if (controller->IsReservedCommandOrKey(id, event)) { |
| 1376 UpdateAcceleratorMetrics(accelerator, id); | 1375 UpdateAcceleratorMetrics(accelerator, id); |
| 1377 return chrome::ExecuteCommand(browser_.get(), id); | 1376 return chrome::ExecuteCommand(browser_.get(), id) |
| 1377 ? content::KeyboardEventProcessingResult::HANDLED |
| 1378 : content::KeyboardEventProcessingResult::NOT_HANDLED; |
| 1378 } | 1379 } |
| 1379 | 1380 |
| 1380 if (id != -1) { | 1381 if (id != -1) { |
| 1381 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+f). | 1382 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+f). |
| 1382 if (event.type() == blink::WebInputEvent::RawKeyDown) | 1383 return (event.type() == blink::WebInputEvent::RawKeyDown) |
| 1383 *is_keyboard_shortcut = true; | 1384 ? content::KeyboardEventProcessingResult::NOT_HANDLED_IS_SHORTCUT |
| 1384 } else if (processed) { | 1385 : content::KeyboardEventProcessingResult::NOT_HANDLED; |
| 1386 } |
| 1387 |
| 1388 if (processed) { |
| 1385 // |accelerator| is a non-browser shortcut (e.g. F4-F10 on Ash). Report | 1389 // |accelerator| is a non-browser shortcut (e.g. F4-F10 on Ash). Report |
| 1386 // that we handled it. | 1390 // that we handled it. |
| 1387 return true; | 1391 return content::KeyboardEventProcessingResult::HANDLED; |
| 1388 } | 1392 } |
| 1389 | 1393 |
| 1390 return false; | 1394 return content::KeyboardEventProcessingResult::NOT_HANDLED; |
| 1391 } | 1395 } |
| 1392 | 1396 |
| 1393 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 1397 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 1394 if (frame_->HandleKeyboardEvent(event)) | 1398 if (frame_->HandleKeyboardEvent(event)) |
| 1395 return; | 1399 return; |
| 1396 | 1400 |
| 1397 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 1401 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 1398 GetFocusManager()); | 1402 GetFocusManager()); |
| 1399 } | 1403 } |
| 1400 | 1404 |
| (...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2672 } | 2676 } |
| 2673 | 2677 |
| 2674 extensions::ActiveTabPermissionGranter* | 2678 extensions::ActiveTabPermissionGranter* |
| 2675 BrowserView::GetActiveTabPermissionGranter() { | 2679 BrowserView::GetActiveTabPermissionGranter() { |
| 2676 content::WebContents* web_contents = GetActiveWebContents(); | 2680 content::WebContents* web_contents = GetActiveWebContents(); |
| 2677 if (!web_contents) | 2681 if (!web_contents) |
| 2678 return nullptr; | 2682 return nullptr; |
| 2679 return extensions::TabHelper::FromWebContents(web_contents) | 2683 return extensions::TabHelper::FromWebContents(web_contents) |
| 2680 ->active_tab_permission_granter(); | 2684 ->active_tab_permission_granter(); |
| 2681 } | 2685 } |
| OLD | NEW |