OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 DCHECK(focus_manager); | 1208 DCHECK(focus_manager); |
1209 | 1209 |
1210 ui::Accelerator accelerator( | 1210 ui::Accelerator accelerator( |
1211 static_cast<ui::KeyboardCode>(event.windowsKeyCode), | 1211 static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
1212 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == | 1212 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == |
1213 NativeWebKeyboardEvent::ShiftKey, | 1213 NativeWebKeyboardEvent::ShiftKey, |
1214 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == | 1214 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == |
1215 NativeWebKeyboardEvent::ControlKey, | 1215 NativeWebKeyboardEvent::ControlKey, |
1216 (event.modifiers & NativeWebKeyboardEvent::AltKey) == | 1216 (event.modifiers & NativeWebKeyboardEvent::AltKey) == |
1217 NativeWebKeyboardEvent::AltKey); | 1217 NativeWebKeyboardEvent::AltKey); |
1218 if (event.type == WebKit::WebInputEvent::KeyUp) | |
1219 accelerator.set_type(ui::ET_KEY_RELEASED); | |
1220 | |
1221 // If the current target of the |accelerator| is not |this| object, and the | |
1222 // browser is not for an app, the |accelerator| will be processed immediately. | |
1223 const ui::AcceleratorTarget* target = | |
1224 focus_manager->GetCurrentTargetForAccelerator(accelerator); | |
1225 if (!browser_->is_app() && target && target != this) { | |
1226 focus_manager->ProcessAccelerator(accelerator); | |
1227 return true; | |
1228 } | |
1218 | 1229 |
1219 // We first find out the browser command associated to the |event|. | 1230 // We first find out the browser command associated to the |event|. |
1220 // Then if the command is a reserved one, and should be processed | 1231 // Then if the command is a reserved one, and should be processed |
1221 // immediately according to the |event|, the command will be executed | 1232 // immediately according to the |event|, the command will be executed |
1222 // immediately. Otherwise we just set |*is_keyboard_shortcut| properly and | 1233 // immediately. Otherwise we just set |*is_keyboard_shortcut| properly and |
1223 // return false. | 1234 // return false. |
1224 | 1235 |
1225 // This piece of code is based on the fact that accelerators registered | 1236 // This piece of code is based on the fact that accelerators registered |
1226 // into the |focus_manager| may only trigger a browser command execution. | 1237 // into the |focus_manager| may only trigger a browser command execution if |
1238 // the current target of the |accelerator| is |this| object. | |
1227 // | 1239 // |
1228 // Here we need to retrieve the command id (if any) associated to the | 1240 // Here we need to retrieve the command id (if any) associated to the |
1229 // keyboard event. Instead of looking up the command id in the | 1241 // keyboard event. Instead of looking up the command id in the |
1230 // |accelerator_table_| by ourselves, we block the command execution of | 1242 // |accelerator_table_| by ourselves, we block the command execution of |
1231 // the |browser_| object then send the keyboard event to the | 1243 // the |browser_| object then send the keyboard event to the |
1232 // |focus_manager| as if we are activating an accelerator key. | 1244 // |focus_manager| as if we are activating an accelerator key. |
1233 // Then we can retrieve the command id from the |browser_| object. | 1245 // Then we can retrieve the command id from the |browser_| object. |
1234 browser_->SetBlockCommandExecution(true); | 1246 browser_->SetBlockCommandExecution(true); |
1235 focus_manager->ProcessAccelerator(accelerator); | 1247 if (target == this) |
Ben Goodger (Google)
2012/05/04 16:25:33
not sure if I understand the target checking. was
Yusuke Sato
2012/05/07 08:27:28
Done.
On 2012/05/04 16:25:33, Ben Goodger (Google
| |
1248 focus_manager->ProcessAccelerator(accelerator); | |
1236 int id = browser_->GetLastBlockedCommand(NULL); | 1249 int id = browser_->GetLastBlockedCommand(NULL); |
1237 browser_->SetBlockCommandExecution(false); | 1250 browser_->SetBlockCommandExecution(false); |
1238 | 1251 |
1239 if (id == -1) | 1252 if (id == -1) |
1240 return false; | 1253 return false; |
1241 | 1254 |
1242 // Executing the command may cause |this| object to be destroyed. | 1255 // Executing the command may cause |this| object to be destroyed. |
1243 if (browser_->IsReservedCommandOrKey(id, event)) { | 1256 if (browser_->IsReservedCommandOrKey(id, event)) { |
1244 UpdateAcceleratorMetrics(accelerator, id); | 1257 UpdateAcceleratorMetrics(accelerator, id); |
1245 return browser_->ExecuteCommandIfEnabled(id); | 1258 return browser_->ExecuteCommandIfEnabled(id); |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2470 return; | 2483 return; |
2471 | 2484 |
2472 PasswordGenerationBubbleView* bubble = | 2485 PasswordGenerationBubbleView* bubble = |
2473 new PasswordGenerationBubbleView(bounds, | 2486 new PasswordGenerationBubbleView(bounds, |
2474 this, | 2487 this, |
2475 web_contents->GetRenderViewHost()); | 2488 web_contents->GetRenderViewHost()); |
2476 views::BubbleDelegateView::CreateBubble(bubble); | 2489 views::BubbleDelegateView::CreateBubble(bubble); |
2477 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 2490 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
2478 bubble->Show(); | 2491 bubble->Show(); |
2479 } | 2492 } |
OLD | NEW |