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" |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/app/chrome_dll_resource.h" | 17 #include "chrome/app/chrome_dll_resource.h" |
18 #include "chrome/browser/app_mode/app_mode_utils.h" | 18 #include "chrome/browser/app_mode/app_mode_utils.h" |
19 #include "chrome/browser/bookmarks/bookmark_stats.h" | 19 #include "chrome/browser/bookmarks/bookmark_stats.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/extensions/extension_keybinding_registry.h" | |
22 #include "chrome/browser/extensions/extension_util.h" | 23 #include "chrome/browser/extensions/extension_util.h" |
23 #include "chrome/browser/extensions/tab_helper.h" | 24 #include "chrome/browser/extensions/tab_helper.h" |
24 #include "chrome/browser/infobars/infobar_service.h" | 25 #include "chrome/browser/infobars/infobar_service.h" |
25 #include "chrome/browser/native_window_notification_source.h" | 26 #include "chrome/browser/native_window_notification_source.h" |
26 #include "chrome/browser/profiles/avatar_menu.h" | 27 #include "chrome/browser/profiles/avatar_menu.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 29 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
29 #include "chrome/browser/profiles/profile_info_cache.h" | 30 #include "chrome/browser/profiles/profile_info_cache.h" |
30 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
31 #include "chrome/browser/profiles/profile_window.h" | 32 #include "chrome/browser/profiles/profile_window.h" |
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1368 | 1369 |
1369 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 1370 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
1370 bool* is_keyboard_shortcut) { | 1371 bool* is_keyboard_shortcut) { |
1371 *is_keyboard_shortcut = false; | 1372 *is_keyboard_shortcut = false; |
1372 | 1373 |
1373 if ((event.type != blink::WebInputEvent::RawKeyDown) && | 1374 if ((event.type != blink::WebInputEvent::RawKeyDown) && |
1374 (event.type != blink::WebInputEvent::KeyUp)) { | 1375 (event.type != blink::WebInputEvent::KeyUp)) { |
1375 return false; | 1376 return false; |
1376 } | 1377 } |
1377 | 1378 |
1378 views::FocusManager* focus_manager = GetFocusManager(); | 1379 if (extensions::ExtensionKeybindingRegistry::IsShortcutHandlingSuspended()) |
sky
2015/01/08 23:39:25
Could this be implemented by as a PreTargetHandler
Andre
2015/01/10 00:48:11
Thanks for the idea!
PTAL at patch #5, using Event
| |
1379 DCHECK(focus_manager); | |
1380 | |
1381 if (focus_manager->shortcut_handling_suspended()) | |
1382 return false; | 1380 return false; |
1383 | 1381 |
1384 ui::Accelerator accelerator = | 1382 ui::Accelerator accelerator = |
1385 ui::GetAcceleratorFromNativeWebKeyboardEvent(event); | 1383 ui::GetAcceleratorFromNativeWebKeyboardEvent(event); |
1386 | 1384 |
1387 // What we have to do here is as follows: | 1385 // What we have to do here is as follows: |
1388 // - If the |browser_| is for an app, do nothing. | 1386 // - If the |browser_| is for an app, do nothing. |
1389 // - If the |browser_| is not for an app, and the |accelerator| is not | 1387 // - If the |browser_| is not for an app, and the |accelerator| is not |
1390 // associated with the browser (e.g. an Ash shortcut), process it. | 1388 // associated with the browser (e.g. an Ash shortcut), process it. |
1391 // - If the |browser_| is not for an app, and the |accelerator| is associated | 1389 // - If the |browser_| is not for an app, and the |accelerator| is associated |
(...skipping 15 matching lines...) Expand all Loading... | |
1407 // keyboard event. Instead of looking up the command id in the | 1405 // keyboard event. Instead of looking up the command id in the |
1408 // |accelerator_table_| by ourselves, we block the command execution of | 1406 // |accelerator_table_| by ourselves, we block the command execution of |
1409 // the |browser_| object then send the keyboard event to the | 1407 // the |browser_| object then send the keyboard event to the |
1410 // |focus_manager| as if we are activating an accelerator key. | 1408 // |focus_manager| as if we are activating an accelerator key. |
1411 // Then we can retrieve the command id from the |browser_| object. | 1409 // Then we can retrieve the command id from the |browser_| object. |
1412 bool original_block_command_state = controller->block_command_execution(); | 1410 bool original_block_command_state = controller->block_command_execution(); |
1413 controller->SetBlockCommandExecution(true); | 1411 controller->SetBlockCommandExecution(true); |
1414 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the | 1412 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the |
1415 // command execution cannot be blocked and true is returned. However, it is | 1413 // command execution cannot be blocked and true is returned. However, it is |
1416 // okay as long as is_app() is false. See comments in this function. | 1414 // okay as long as is_app() is false. See comments in this function. |
1415 views::FocusManager* focus_manager = GetFocusManager(); | |
1416 DCHECK(focus_manager); | |
1417 const bool processed = focus_manager->ProcessAccelerator(accelerator); | 1417 const bool processed = focus_manager->ProcessAccelerator(accelerator); |
1418 const int id = controller->GetLastBlockedCommand(nullptr); | 1418 const int id = controller->GetLastBlockedCommand(nullptr); |
1419 controller->SetBlockCommandExecution(original_block_command_state); | 1419 controller->SetBlockCommandExecution(original_block_command_state); |
1420 | 1420 |
1421 // Executing the command may cause |this| object to be destroyed. | 1421 // Executing the command may cause |this| object to be destroyed. |
1422 if (controller->IsReservedCommandOrKey(id, event)) { | 1422 if (controller->IsReservedCommandOrKey(id, event)) { |
1423 UpdateAcceleratorMetrics(accelerator, id); | 1423 UpdateAcceleratorMetrics(accelerator, id); |
1424 return chrome::ExecuteCommand(browser_.get(), id); | 1424 return chrome::ExecuteCommand(browser_.get(), id); |
1425 } | 1425 } |
1426 | 1426 |
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2568 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { | 2568 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { |
2569 gfx::Point icon_bottom( | 2569 gfx::Point icon_bottom( |
2570 toolbar_->location_bar()->GetLocationBarAnchorPoint()); | 2570 toolbar_->location_bar()->GetLocationBarAnchorPoint()); |
2571 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); | 2571 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); |
2572 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(nullptr)); | 2572 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(nullptr)); |
2573 ConvertPointToTarget(infobar_container_, this, &infobar_top); | 2573 ConvertPointToTarget(infobar_container_, this, &infobar_top); |
2574 top_arrow_height = infobar_top.y() - icon_bottom.y(); | 2574 top_arrow_height = infobar_top.y() - icon_bottom.y(); |
2575 } | 2575 } |
2576 return top_arrow_height; | 2576 return top_arrow_height; |
2577 } | 2577 } |
OLD | NEW |