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 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 const content::SSLStatus& ssl, | 1138 const content::SSLStatus& ssl, |
1139 bool show_history) { | 1139 bool show_history) { |
1140 } | 1140 } |
1141 | 1141 |
1142 void BrowserView::ShowAppMenu() { | 1142 void BrowserView::ShowAppMenu() { |
1143 toolbar_->app_menu()->Activate(); | 1143 toolbar_->app_menu()->Activate(); |
1144 } | 1144 } |
1145 | 1145 |
1146 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 1146 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
1147 bool* is_keyboard_shortcut) { | 1147 bool* is_keyboard_shortcut) { |
1148 if (event.type != WebKit::WebInputEvent::RawKeyDown) | 1148 *is_keyboard_shortcut = false; |
| 1149 |
| 1150 if ((event.type != WebKit::WebInputEvent::RawKeyDown) && |
| 1151 (event.type != WebKit::WebInputEvent::KeyUp)) { |
1149 return false; | 1152 return false; |
| 1153 } |
1150 | 1154 |
1151 #if defined(OS_WIN) && !defined(USE_AURA) | 1155 #if defined(OS_WIN) && !defined(USE_AURA) |
1152 // As Alt+F4 is the close-app keyboard shortcut, it needs processing | 1156 // As Alt+F4 is the close-app keyboard shortcut, it needs processing |
1153 // immediately. | 1157 // immediately. |
1154 if (event.windowsKeyCode == ui::VKEY_F4 && | 1158 if (event.windowsKeyCode == ui::VKEY_F4 && |
| 1159 event.type == WebKit::WebInputEvent::RawKeyDown && |
1155 event.modifiers == NativeWebKeyboardEvent::AltKey) { | 1160 event.modifiers == NativeWebKeyboardEvent::AltKey) { |
1156 DefWindowProc(event.os_event.hwnd, event.os_event.message, | 1161 DefWindowProc(event.os_event.hwnd, event.os_event.message, |
1157 event.os_event.wParam, event.os_event.lParam); | 1162 event.os_event.wParam, event.os_event.lParam); |
1158 return true; | 1163 return true; |
1159 } | 1164 } |
1160 #endif | 1165 #endif |
1161 | 1166 |
1162 views::FocusManager* focus_manager = GetFocusManager(); | 1167 views::FocusManager* focus_manager = GetFocusManager(); |
1163 DCHECK(focus_manager); | 1168 DCHECK(focus_manager); |
1164 | 1169 |
1165 ui::Accelerator accelerator( | 1170 ui::Accelerator accelerator( |
1166 static_cast<ui::KeyboardCode>(event.windowsKeyCode), | 1171 static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
1167 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == | 1172 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == |
1168 NativeWebKeyboardEvent::ShiftKey, | 1173 NativeWebKeyboardEvent::ShiftKey, |
1169 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == | 1174 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == |
1170 NativeWebKeyboardEvent::ControlKey, | 1175 NativeWebKeyboardEvent::ControlKey, |
1171 (event.modifiers & NativeWebKeyboardEvent::AltKey) == | 1176 (event.modifiers & NativeWebKeyboardEvent::AltKey) == |
1172 NativeWebKeyboardEvent::AltKey); | 1177 NativeWebKeyboardEvent::AltKey); |
| 1178 if (event.type == WebKit::WebInputEvent::KeyUp) |
| 1179 accelerator.set_type(ui::ET_KEY_RELEASED); |
1173 | 1180 |
1174 // We first find out the browser command associated to the |event|. | 1181 // What we have to do here is as follows: |
1175 // Then if the command is a reserved one, and should be processed | 1182 // - If the |browser_| is for an app, do nothing. |
1176 // immediately according to the |event|, the command will be executed | 1183 // - If the |browser_| is not for an app, and the |accelerator| is not |
1177 // immediately. Otherwise we just set |*is_keyboard_shortcut| properly and | 1184 // associated with the browser (e.g. an Ash shortcut), process it. |
1178 // return false. | 1185 // - If the |browser_| is not for an app, and the |accelerator| is associated |
| 1186 // with the browser, and it is a reserved one (e.g. Ctrl-t), process it. |
| 1187 // - If the |browser_| is not for an app, and the |accelerator| is associated |
| 1188 // with the browser, and it is not a reserved one, do nothing. |
1179 | 1189 |
1180 // This piece of code is based on the fact that accelerators registered | 1190 if (browser_->is_app()) { |
1181 // into the |focus_manager| may only trigger a browser command execution. | 1191 // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app |
1182 // | 1192 // might not be able to see a subsequent Char event. See OnHandleInputEvent |
| 1193 // in content/renderer/render_widget.cc for details. |
| 1194 return false; |
| 1195 } |
| 1196 |
1183 // Here we need to retrieve the command id (if any) associated to the | 1197 // Here we need to retrieve the command id (if any) associated to the |
1184 // keyboard event. Instead of looking up the command id in the | 1198 // keyboard event. Instead of looking up the command id in the |
1185 // |accelerator_table_| by ourselves, we block the command execution of | 1199 // |accelerator_table_| by ourselves, we block the command execution of |
1186 // the |browser_| object then send the keyboard event to the | 1200 // the |browser_| object then send the keyboard event to the |
1187 // |focus_manager| as if we are activating an accelerator key. | 1201 // |focus_manager| as if we are activating an accelerator key. |
1188 // Then we can retrieve the command id from the |browser_| object. | 1202 // Then we can retrieve the command id from the |browser_| object. |
1189 browser_->SetBlockCommandExecution(true); | 1203 browser_->SetBlockCommandExecution(true); |
1190 focus_manager->ProcessAccelerator(accelerator); | 1204 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the |
1191 int id = browser_->GetLastBlockedCommand(NULL); | 1205 // command execution cannot be blocked and true is returned. However, it is |
| 1206 // okay as long as is_app() is false. See comments in this function. |
| 1207 const bool processed = focus_manager->ProcessAccelerator(accelerator); |
| 1208 const int id = browser_->GetLastBlockedCommand(NULL); |
1192 browser_->SetBlockCommandExecution(false); | 1209 browser_->SetBlockCommandExecution(false); |
1193 | 1210 |
1194 if (id == -1) | |
1195 return false; | |
1196 | |
1197 // Executing the command may cause |this| object to be destroyed. | 1211 // Executing the command may cause |this| object to be destroyed. |
1198 if (browser_->IsReservedCommandOrKey(id, event)) { | 1212 if (browser_->IsReservedCommandOrKey(id, event)) { |
1199 UpdateAcceleratorMetrics(accelerator, id); | 1213 UpdateAcceleratorMetrics(accelerator, id); |
1200 return browser_->ExecuteCommandIfEnabled(id); | 1214 return browser_->ExecuteCommandIfEnabled(id); |
1201 } | 1215 } |
1202 | 1216 |
1203 DCHECK(is_keyboard_shortcut != NULL); | 1217 if (id != -1) { |
1204 *is_keyboard_shortcut = true; | 1218 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+t). |
| 1219 if (event.type == WebKit::WebInputEvent::RawKeyDown) |
| 1220 *is_keyboard_shortcut = true; |
| 1221 } else if (processed) { |
| 1222 // |accelerator| is a non-browser shortcut (e.g. F5-F10 on Ash). |
| 1223 return true; |
| 1224 } |
1205 | 1225 |
1206 return false; | 1226 return false; |
1207 } | 1227 } |
1208 | 1228 |
1209 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 1229 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
1210 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 1230 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
1211 GetFocusManager()); | 1231 GetFocusManager()); |
1212 } | 1232 } |
1213 | 1233 |
1214 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always | 1234 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2393 return; | 2413 return; |
2394 | 2414 |
2395 PasswordGenerationBubbleView* bubble = | 2415 PasswordGenerationBubbleView* bubble = |
2396 new PasswordGenerationBubbleView(bounds, | 2416 new PasswordGenerationBubbleView(bounds, |
2397 this, | 2417 this, |
2398 web_contents->GetRenderViewHost()); | 2418 web_contents->GetRenderViewHost()); |
2399 views::BubbleDelegateView::CreateBubble(bubble); | 2419 views::BubbleDelegateView::CreateBubble(bubble); |
2400 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 2420 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
2401 bubble->Show(); | 2421 bubble->Show(); |
2402 } | 2422 } |
OLD | NEW |