OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/frame/browser_view.h" | 5 #include "chrome/browser/views/frame/browser_view.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 } | 1218 } |
1219 | 1219 |
1220 void BrowserView::ShowPageMenu() { | 1220 void BrowserView::ShowPageMenu() { |
1221 toolbar_->page_menu()->Activate(); | 1221 toolbar_->page_menu()->Activate(); |
1222 } | 1222 } |
1223 | 1223 |
1224 void BrowserView::ShowAppMenu() { | 1224 void BrowserView::ShowAppMenu() { |
1225 toolbar_->app_menu()->Activate(); | 1225 toolbar_->app_menu()->Activate(); |
1226 } | 1226 } |
1227 | 1227 |
1228 int BrowserView::GetCommandId(const NativeWebKeyboardEvent& event) { | 1228 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 1229 bool* is_keyboard_shortcut) { |
| 1230 if (event.type != WebKit::WebInputEvent::RawKeyDown) |
| 1231 return false; |
| 1232 |
| 1233 #if defined(OS_WIN) |
| 1234 // As Alt+F4 is the close-app keyboard shortcut, it needs processing |
| 1235 // immediately. |
| 1236 if (event.windowsKeyCode == base::VKEY_F4 && |
| 1237 event.modifiers == NativeWebKeyboardEvent::AltKey) { |
| 1238 DefWindowProc(event.os_event.hwnd, event.os_event.message, |
| 1239 event.os_event.wParam, event.os_event.lParam); |
| 1240 return true; |
| 1241 } |
| 1242 #endif |
| 1243 |
| 1244 views::FocusManager* focus_manager = GetFocusManager(); |
| 1245 DCHECK(focus_manager); |
| 1246 |
1229 views::Accelerator accelerator( | 1247 views::Accelerator accelerator( |
1230 static_cast<base::KeyboardCode>(event.windowsKeyCode), | 1248 static_cast<base::KeyboardCode>(event.windowsKeyCode), |
1231 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == | 1249 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == |
1232 NativeWebKeyboardEvent::ShiftKey, | 1250 NativeWebKeyboardEvent::ShiftKey, |
1233 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == | 1251 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == |
1234 NativeWebKeyboardEvent::ControlKey, | 1252 NativeWebKeyboardEvent::ControlKey, |
1235 (event.modifiers & NativeWebKeyboardEvent::AltKey) == | 1253 (event.modifiers & NativeWebKeyboardEvent::AltKey) == |
1236 NativeWebKeyboardEvent::AltKey); | 1254 NativeWebKeyboardEvent::AltKey); |
1237 | 1255 |
1238 std::map<views::Accelerator, int>::const_iterator iter = | 1256 // We first find out the browser command associated to the |event|. |
1239 accelerator_table_.find(accelerator); | 1257 // Then if the command is a reserved one, and should be processed |
1240 if (iter == accelerator_table_.end()) | 1258 // immediately according to the |event|, the command will be executed |
1241 return -1; | 1259 // immediately. Otherwise we just set |*is_keyboard_shortcut| properly and |
| 1260 // return false. |
1242 | 1261 |
1243 return iter->second; | 1262 // This piece of code is based on the fact that accelerators registered |
| 1263 // into the |focus_manager| may only trigger a browser command execution. |
| 1264 // |
| 1265 // Here we need to retrieve the command id (if any) associated to the |
| 1266 // keyboard event. Instead of looking up the command id in the |
| 1267 // |accelerator_table_| by ourselves, we block the command execution of |
| 1268 // the |browser_| object then send the keyboard event to the |
| 1269 // |focus_manager| as if we are activating an accelerator key. |
| 1270 // Then we can retrieve the command id from the |browser_| object. |
| 1271 browser_->SetBlockCommandExecution(true); |
| 1272 focus_manager->ProcessAccelerator(accelerator); |
| 1273 int id = browser_->GetLastBlockedCommand(NULL); |
| 1274 browser_->SetBlockCommandExecution(false); |
| 1275 |
| 1276 if (id == -1) |
| 1277 return false; |
| 1278 |
| 1279 if (browser_->IsReservedCommand(id)) { |
| 1280 // TODO(suzhe): For Linux, should we send things like Ctrl+w, Ctrl+n |
| 1281 // to the renderer first, just like what |
| 1282 // BrowserWindowGtk::HandleKeyboardEvent() does? |
| 1283 // Executing the command may cause |this| object to be destroyed. |
| 1284 browser_->ExecuteCommand(id); |
| 1285 return true; |
| 1286 } |
| 1287 |
| 1288 DCHECK(is_keyboard_shortcut != NULL); |
| 1289 *is_keyboard_shortcut = true; |
| 1290 |
| 1291 return false; |
| 1292 } |
| 1293 |
| 1294 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 1295 if (event.type == WebKit::WebInputEvent::RawKeyDown) { |
| 1296 views::FocusManager* focus_manager = GetFocusManager(); |
| 1297 DCHECK(focus_manager); |
| 1298 |
| 1299 views::Accelerator accelerator( |
| 1300 static_cast<base::KeyboardCode>(event.windowsKeyCode), |
| 1301 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == |
| 1302 NativeWebKeyboardEvent::ShiftKey, |
| 1303 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == |
| 1304 NativeWebKeyboardEvent::ControlKey, |
| 1305 (event.modifiers & NativeWebKeyboardEvent::AltKey) == |
| 1306 NativeWebKeyboardEvent::AltKey); |
| 1307 |
| 1308 if (focus_manager->ProcessAccelerator(accelerator)) |
| 1309 return; |
| 1310 } |
| 1311 |
| 1312 #if defined(OS_WIN) |
| 1313 // Any unhandled keyboard/character messages should be defproced. |
| 1314 // This allows stuff like F10, etc to work correctly. |
| 1315 DefWindowProc(event.os_event.hwnd, event.os_event.message, |
| 1316 event.os_event.wParam, event.os_event.lParam); |
| 1317 #endif |
1244 } | 1318 } |
1245 | 1319 |
1246 #if defined(TOOLKIT_VIEWS) | 1320 #if defined(TOOLKIT_VIEWS) |
1247 void BrowserView::ToggleCompactNavigationBar() { | 1321 void BrowserView::ToggleCompactNavigationBar() { |
1248 browser_extender_->ToggleCompactNavigationBar(); | 1322 browser_extender_->ToggleCompactNavigationBar(); |
1249 Layout(); | 1323 Layout(); |
1250 } | 1324 } |
1251 #endif | 1325 #endif |
1252 | 1326 |
1253 /////////////////////////////////////////////////////////////////////////////// | 1327 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 | 2383 |
2310 // static | 2384 // static |
2311 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 2385 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { |
2312 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 2386 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); |
2313 } | 2387 } |
2314 | 2388 |
2315 // static | 2389 // static |
2316 void BrowserList::AllBrowsersClosed() { | 2390 void BrowserList::AllBrowsersClosed() { |
2317 views::Window::CloseAllSecondaryWindows(); | 2391 views::Window::CloseAllSecondaryWindows(); |
2318 } | 2392 } |
OLD | NEW |