| 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 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 const content::SSLStatus& ssl, | 1178 const content::SSLStatus& ssl, |
| 1179 bool show_history) { | 1179 bool show_history) { |
| 1180 } | 1180 } |
| 1181 | 1181 |
| 1182 void BrowserView::ShowAppMenu() { | 1182 void BrowserView::ShowAppMenu() { |
| 1183 toolbar_->app_menu()->Activate(); | 1183 toolbar_->app_menu()->Activate(); |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 1186 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 1187 bool* is_keyboard_shortcut) { | 1187 bool* is_keyboard_shortcut) { |
| 1188 if (event.type != WebKit::WebInputEvent::RawKeyDown) | 1188 if ((event.type != WebKit::WebInputEvent::RawKeyDown) && |
| 1189 (event.type != WebKit::WebInputEvent::KeyUp)) { |
| 1189 return false; | 1190 return false; |
| 1191 } |
| 1190 | 1192 |
| 1191 #if defined(OS_WIN) && !defined(USE_AURA) | 1193 #if defined(OS_WIN) && !defined(USE_AURA) |
| 1192 // As Alt+F4 is the close-app keyboard shortcut, it needs processing | 1194 // As Alt+F4 is the close-app keyboard shortcut, it needs processing |
| 1193 // immediately. | 1195 // immediately. |
| 1194 if (event.windowsKeyCode == ui::VKEY_F4 && | 1196 if (event.windowsKeyCode == ui::VKEY_F4 && |
| 1197 event.type == WebKit::WebInputEvent::RawKeyDown && |
| 1195 event.modifiers == NativeWebKeyboardEvent::AltKey) { | 1198 event.modifiers == NativeWebKeyboardEvent::AltKey) { |
| 1196 DefWindowProc(event.os_event.hwnd, event.os_event.message, | 1199 DefWindowProc(event.os_event.hwnd, event.os_event.message, |
| 1197 event.os_event.wParam, event.os_event.lParam); | 1200 event.os_event.wParam, event.os_event.lParam); |
| 1198 return true; | 1201 return true; |
| 1199 } | 1202 } |
| 1200 #endif | 1203 #endif |
| 1201 | 1204 |
| 1202 views::FocusManager* focus_manager = GetFocusManager(); | 1205 views::FocusManager* focus_manager = GetFocusManager(); |
| 1203 DCHECK(focus_manager); | 1206 DCHECK(focus_manager); |
| 1204 | 1207 |
| 1205 ui::Accelerator accelerator( | 1208 ui::Accelerator accelerator( |
| 1206 static_cast<ui::KeyboardCode>(event.windowsKeyCode), | 1209 static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
| 1207 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == | 1210 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == |
| 1208 NativeWebKeyboardEvent::ShiftKey, | 1211 NativeWebKeyboardEvent::ShiftKey, |
| 1209 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == | 1212 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == |
| 1210 NativeWebKeyboardEvent::ControlKey, | 1213 NativeWebKeyboardEvent::ControlKey, |
| 1211 (event.modifiers & NativeWebKeyboardEvent::AltKey) == | 1214 (event.modifiers & NativeWebKeyboardEvent::AltKey) == |
| 1212 NativeWebKeyboardEvent::AltKey); | 1215 NativeWebKeyboardEvent::AltKey); |
| 1216 if (event.type == WebKit::WebInputEvent::KeyUp) |
| 1217 accelerator.set_type(ui::ET_KEY_RELEASED); |
| 1213 | 1218 |
| 1214 // We first find out the browser command associated to the |event|. | 1219 // What we have to do here is as follows: |
| 1215 // Then if the command is a reserved one, and should be processed | 1220 // - If the |browser_| is for an app, do nothing. |
| 1216 // immediately according to the |event|, the command will be executed | 1221 // - If the |browser_| is not for an app, and the |accelerator| is not |
| 1217 // immediately. Otherwise we just set |*is_keyboard_shortcut| properly and | 1222 // associated with the browser (e.g. an Ash shortcut), process it. |
| 1218 // return false. | 1223 // - If the |browser_| is not for an app, and the |accelerator| is associated |
| 1224 // with the browser, and it is a reserved one (e.g. Ctrl-t), process it. |
| 1225 // - If the |browser_| is not for an app, and the |accelerator| is associated |
| 1226 // with the browser, and it is not a reserved one, do nothing. |
| 1219 | 1227 |
| 1220 // This piece of code is based on the fact that accelerators registered | 1228 const bool is_registered = |
| 1221 // into the |focus_manager| may only trigger a browser command execution. | 1229 (focus_manager->GetCurrentTargetForAccelerator(accelerator) != NULL); |
| 1222 // | 1230 if (browser_->is_app()) { |
| 1231 *is_keyboard_shortcut = is_registered; |
| 1232 return false; |
| 1233 } |
| 1234 |
| 1223 // Here we need to retrieve the command id (if any) associated to the | 1235 // Here we need to retrieve the command id (if any) associated to the |
| 1224 // keyboard event. Instead of looking up the command id in the | 1236 // keyboard event. Instead of looking up the command id in the |
| 1225 // |accelerator_table_| by ourselves, we block the command execution of | 1237 // |accelerator_table_| by ourselves, we block the command execution of |
| 1226 // the |browser_| object then send the keyboard event to the | 1238 // the |browser_| object then send the keyboard event to the |
| 1227 // |focus_manager| as if we are activating an accelerator key. | 1239 // |focus_manager| as if we are activating an accelerator key. |
| 1228 // Then we can retrieve the command id from the |browser_| object. | 1240 // Then we can retrieve the command id from the |browser_| object. |
| 1229 browser_->SetBlockCommandExecution(true); | 1241 browser_->SetBlockCommandExecution(true); |
| 1242 // If the |accelerator| is a non-browser shortcut, the command execution |
| 1243 // cannot be blocked. However, it is okay as long as is_app() is false. See |
| 1244 // comments in this function. |
| 1230 focus_manager->ProcessAccelerator(accelerator); | 1245 focus_manager->ProcessAccelerator(accelerator); |
| 1231 int id = browser_->GetLastBlockedCommand(NULL); | 1246 int id = browser_->GetLastBlockedCommand(NULL); |
| 1232 browser_->SetBlockCommandExecution(false); | 1247 browser_->SetBlockCommandExecution(false); |
| 1233 | 1248 |
| 1234 if (id == -1) | |
| 1235 return false; | |
| 1236 | |
| 1237 // Executing the command may cause |this| object to be destroyed. | 1249 // Executing the command may cause |this| object to be destroyed. |
| 1238 if (browser_->IsReservedCommandOrKey(id, event)) { | 1250 if (browser_->IsReservedCommandOrKey(id, event)) { |
| 1239 UpdateAcceleratorMetrics(accelerator, id); | 1251 UpdateAcceleratorMetrics(accelerator, id); |
| 1240 return browser_->ExecuteCommandIfEnabled(id); | 1252 return browser_->ExecuteCommandIfEnabled(id); |
| 1241 } | 1253 } |
| 1242 | 1254 |
| 1243 DCHECK(is_keyboard_shortcut != NULL); | 1255 if (is_registered) { |
| 1244 *is_keyboard_shortcut = true; | 1256 if (id == -1) { |
| 1257 // |accelerator| is a non-browser shortcut. |
| 1258 return true; |
| 1259 } else { |
| 1260 // |accelerator| is a non-reserved browser shortcut. |
| 1261 *is_keyboard_shortcut = true; |
| 1262 } |
| 1263 } |
| 1245 | 1264 |
| 1246 return false; | 1265 return false; |
| 1247 } | 1266 } |
| 1248 | 1267 |
| 1249 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 1268 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 1250 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 1269 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 1251 GetFocusManager()); | 1270 GetFocusManager()); |
| 1252 } | 1271 } |
| 1253 | 1272 |
| 1254 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always | 1273 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2444 return; | 2463 return; |
| 2445 | 2464 |
| 2446 PasswordGenerationBubbleView* bubble = | 2465 PasswordGenerationBubbleView* bubble = |
| 2447 new PasswordGenerationBubbleView(bounds, | 2466 new PasswordGenerationBubbleView(bounds, |
| 2448 this, | 2467 this, |
| 2449 web_contents->GetRenderViewHost()); | 2468 web_contents->GetRenderViewHost()); |
| 2450 views::BubbleDelegateView::CreateBubble(bubble); | 2469 views::BubbleDelegateView::CreateBubble(bubble); |
| 2451 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 2470 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 2452 bubble->Show(); | 2471 bubble->Show(); |
| 2453 } | 2472 } |
| OLD | NEW |