OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 if (!browser_->block_command_execution()) | 613 if (!browser_->block_command_execution()) |
614 UpdateAcceleratorMetrics(accelerator, command_id); | 614 UpdateAcceleratorMetrics(accelerator, command_id); |
615 return browser_->ExecuteCommandIfEnabled(command_id); | 615 return browser_->ExecuteCommandIfEnabled(command_id); |
616 } | 616 } |
617 | 617 |
618 bool BrowserView::GetAccelerator(int cmd_id, menus::Accelerator* accelerator) { | 618 bool BrowserView::GetAccelerator(int cmd_id, menus::Accelerator* accelerator) { |
619 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators | 619 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators |
620 // anywhere so we need to check for them explicitly here. | 620 // anywhere so we need to check for them explicitly here. |
621 switch (cmd_id) { | 621 switch (cmd_id) { |
622 case IDC_CUT: | 622 case IDC_CUT: |
623 *accelerator = views::Accelerator(app::VKEY_X, false, true, false); | 623 *accelerator = views::Accelerator(ui::VKEY_X, false, true, false); |
624 return true; | 624 return true; |
625 case IDC_COPY: | 625 case IDC_COPY: |
626 *accelerator = views::Accelerator(app::VKEY_C, false, true, false); | 626 *accelerator = views::Accelerator(ui::VKEY_C, false, true, false); |
627 return true; | 627 return true; |
628 case IDC_PASTE: | 628 case IDC_PASTE: |
629 *accelerator = views::Accelerator(app::VKEY_V, false, true, false); | 629 *accelerator = views::Accelerator(ui::VKEY_V, false, true, false); |
630 return true; | 630 return true; |
631 } | 631 } |
632 // Else, we retrieve the accelerator information from the accelerator table. | 632 // Else, we retrieve the accelerator information from the accelerator table. |
633 std::map<views::Accelerator, int>::iterator it = | 633 std::map<views::Accelerator, int>::iterator it = |
634 accelerator_table_.begin(); | 634 accelerator_table_.begin(); |
635 for (; it != accelerator_table_.end(); ++it) { | 635 for (; it != accelerator_table_.end(); ++it) { |
636 if (it->second == cmd_id) { | 636 if (it->second == cmd_id) { |
637 *accelerator = it->first; | 637 *accelerator = it->first; |
638 return true; | 638 return true; |
639 } | 639 } |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 } | 1206 } |
1207 | 1207 |
1208 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 1208 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
1209 bool* is_keyboard_shortcut) { | 1209 bool* is_keyboard_shortcut) { |
1210 if (event.type != WebKit::WebInputEvent::RawKeyDown) | 1210 if (event.type != WebKit::WebInputEvent::RawKeyDown) |
1211 return false; | 1211 return false; |
1212 | 1212 |
1213 #if defined(OS_WIN) | 1213 #if defined(OS_WIN) |
1214 // As Alt+F4 is the close-app keyboard shortcut, it needs processing | 1214 // As Alt+F4 is the close-app keyboard shortcut, it needs processing |
1215 // immediately. | 1215 // immediately. |
1216 if (event.windowsKeyCode == app::VKEY_F4 && | 1216 if (event.windowsKeyCode == ui::VKEY_F4 && |
1217 event.modifiers == NativeWebKeyboardEvent::AltKey) { | 1217 event.modifiers == NativeWebKeyboardEvent::AltKey) { |
1218 DefWindowProc(event.os_event.hwnd, event.os_event.message, | 1218 DefWindowProc(event.os_event.hwnd, event.os_event.message, |
1219 event.os_event.wParam, event.os_event.lParam); | 1219 event.os_event.wParam, event.os_event.lParam); |
1220 return true; | 1220 return true; |
1221 } | 1221 } |
1222 #endif | 1222 #endif |
1223 | 1223 |
1224 views::FocusManager* focus_manager = GetFocusManager(); | 1224 views::FocusManager* focus_manager = GetFocusManager(); |
1225 DCHECK(focus_manager); | 1225 DCHECK(focus_manager); |
1226 | 1226 |
1227 #if defined(OS_LINUX) && !defined(TOUCH_UI) | 1227 #if defined(OS_LINUX) && !defined(TOUCH_UI) |
1228 // Views and WebKit use different tables for GdkEventKey -> views::KeyEvent | 1228 // Views and WebKit use different tables for GdkEventKey -> views::KeyEvent |
1229 // conversion. We need to use View's conversion table here to keep consistent | 1229 // conversion. We need to use View's conversion table here to keep consistent |
1230 // behavior with views::FocusManager::OnKeyEvent() method. | 1230 // behavior with views::FocusManager::OnKeyEvent() method. |
1231 // TODO(suzhe): We need to check if Windows code also has this issue, and | 1231 // TODO(suzhe): We need to check if Windows code also has this issue, and |
1232 // it'll be best if we can unify these conversion tables. | 1232 // it'll be best if we can unify these conversion tables. |
1233 // See http://crbug.com/54315 | 1233 // See http://crbug.com/54315 |
1234 views::KeyEvent views_event(event.os_event); | 1234 views::KeyEvent views_event(event.os_event); |
1235 views::Accelerator accelerator(views_event.GetKeyCode(), | 1235 views::Accelerator accelerator(views_event.GetKeyCode(), |
1236 views_event.IsShiftDown(), | 1236 views_event.IsShiftDown(), |
1237 views_event.IsControlDown(), | 1237 views_event.IsControlDown(), |
1238 views_event.IsAltDown()); | 1238 views_event.IsAltDown()); |
1239 #else | 1239 #else |
1240 views::Accelerator accelerator( | 1240 views::Accelerator accelerator( |
1241 static_cast<app::KeyboardCode>(event.windowsKeyCode), | 1241 static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
1242 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == | 1242 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == |
1243 NativeWebKeyboardEvent::ShiftKey, | 1243 NativeWebKeyboardEvent::ShiftKey, |
1244 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == | 1244 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == |
1245 NativeWebKeyboardEvent::ControlKey, | 1245 NativeWebKeyboardEvent::ControlKey, |
1246 (event.modifiers & NativeWebKeyboardEvent::AltKey) == | 1246 (event.modifiers & NativeWebKeyboardEvent::AltKey) == |
1247 NativeWebKeyboardEvent::AltKey); | 1247 NativeWebKeyboardEvent::AltKey); |
1248 #endif | 1248 #endif |
1249 | 1249 |
1250 // We first find out the browser command associated to the |event|. | 1250 // We first find out the browser command associated to the |event|. |
1251 // Then if the command is a reserved one, and should be processed | 1251 // Then if the command is a reserved one, and should be processed |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 | 1299 |
1300 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always | 1300 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always |
1301 // enabled in the page menu regardless of whether the command will do | 1301 // enabled in the page menu regardless of whether the command will do |
1302 // anything. When someone selects the menu item, we just act as if they hit | 1302 // anything. When someone selects the menu item, we just act as if they hit |
1303 // the keyboard shortcut for the command by sending the associated key press | 1303 // the keyboard shortcut for the command by sending the associated key press |
1304 // to windows. The real fix to this bug is to disable the commands when they | 1304 // to windows. The real fix to this bug is to disable the commands when they |
1305 // won't do anything. We'll need something like an overall clipboard command | 1305 // won't do anything. We'll need something like an overall clipboard command |
1306 // manager to do that. | 1306 // manager to do that. |
1307 #if !defined(OS_MACOSX) | 1307 #if !defined(OS_MACOSX) |
1308 void BrowserView::Cut() { | 1308 void BrowserView::Cut() { |
1309 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_X, | 1309 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_X, |
1310 true, false, false, false); | 1310 true, false, false, false); |
1311 } | 1311 } |
1312 | 1312 |
1313 void BrowserView::Copy() { | 1313 void BrowserView::Copy() { |
1314 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_C, | 1314 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_C, |
1315 true, false, false, false); | 1315 true, false, false, false); |
1316 } | 1316 } |
1317 | 1317 |
1318 void BrowserView::Paste() { | 1318 void BrowserView::Paste() { |
1319 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_V, | 1319 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_V, |
1320 true, false, false, false); | 1320 true, false, false, false); |
1321 } | 1321 } |
1322 #else | 1322 #else |
1323 // Mac versions. Not tested by antyhing yet; | 1323 // Mac versions. Not tested by antyhing yet; |
1324 // don't assume written == works. | 1324 // don't assume written == works. |
1325 void BrowserView::Cut() { | 1325 void BrowserView::Cut() { |
1326 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_X, | 1326 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_X, |
1327 false, false, false, true); | 1327 false, false, false, true); |
1328 } | 1328 } |
1329 | 1329 |
1330 void BrowserView::Copy() { | 1330 void BrowserView::Copy() { |
1331 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_C, | 1331 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_C, |
1332 false, false, false, true); | 1332 false, false, false, true); |
1333 } | 1333 } |
1334 | 1334 |
1335 void BrowserView::Paste() { | 1335 void BrowserView::Paste() { |
1336 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_V, | 1336 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_V, |
1337 false, false, false, true); | 1337 false, false, false, true); |
1338 } | 1338 } |
1339 #endif | 1339 #endif |
1340 | 1340 |
1341 void BrowserView::ToggleTabStripMode() { | 1341 void BrowserView::ToggleTabStripMode() { |
1342 InitTabStrip(browser_->tabstrip_model()); | 1342 InitTabStrip(browser_->tabstrip_model()); |
1343 frame_->TabStripDisplayModeChanged(); | 1343 frame_->TabStripDisplayModeChanged(); |
1344 } | 1344 } |
1345 | 1345 |
1346 void BrowserView::PrepareForInstant() { | 1346 void BrowserView::PrepareForInstant() { |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2310 | 2310 |
2311 views::FocusManager* focus_manager = GetFocusManager(); | 2311 views::FocusManager* focus_manager = GetFocusManager(); |
2312 DCHECK(focus_manager); | 2312 DCHECK(focus_manager); |
2313 | 2313 |
2314 // Let's fill our own accelerator table. | 2314 // Let's fill our own accelerator table. |
2315 for (int i = 0; i < count; ++i) { | 2315 for (int i = 0; i < count; ++i) { |
2316 bool alt_down = (accelerators[i].fVirt & FALT) == FALT; | 2316 bool alt_down = (accelerators[i].fVirt & FALT) == FALT; |
2317 bool ctrl_down = (accelerators[i].fVirt & FCONTROL) == FCONTROL; | 2317 bool ctrl_down = (accelerators[i].fVirt & FCONTROL) == FCONTROL; |
2318 bool shift_down = (accelerators[i].fVirt & FSHIFT) == FSHIFT; | 2318 bool shift_down = (accelerators[i].fVirt & FSHIFT) == FSHIFT; |
2319 views::Accelerator accelerator( | 2319 views::Accelerator accelerator( |
2320 static_cast<app::KeyboardCode>(accelerators[i].key), | 2320 static_cast<ui::KeyboardCode>(accelerators[i].key), |
2321 shift_down, ctrl_down, alt_down); | 2321 shift_down, ctrl_down, alt_down); |
2322 accelerator_table_[accelerator] = accelerators[i].cmd; | 2322 accelerator_table_[accelerator] = accelerators[i].cmd; |
2323 | 2323 |
2324 // Also register with the focus manager. | 2324 // Also register with the focus manager. |
2325 focus_manager->RegisterAccelerator(accelerator, this); | 2325 focus_manager->RegisterAccelerator(accelerator, this); |
2326 } | 2326 } |
2327 | 2327 |
2328 // We don't need the Windows accelerator table anymore. | 2328 // We don't need the Windows accelerator table anymore. |
2329 free(accelerators); | 2329 free(accelerators); |
2330 #else | 2330 #else |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 hung_plugin_detect_freq); | 2469 hung_plugin_detect_freq); |
2470 } | 2470 } |
2471 #endif | 2471 #endif |
2472 } | 2472 } |
2473 | 2473 |
2474 void BrowserView::UpdateAcceleratorMetrics( | 2474 void BrowserView::UpdateAcceleratorMetrics( |
2475 const views::Accelerator& accelerator, int command_id) { | 2475 const views::Accelerator& accelerator, int command_id) { |
2476 #if defined(OS_CHROMEOS) | 2476 #if defined(OS_CHROMEOS) |
2477 // Collect information about the relative popularity of various accelerators | 2477 // Collect information about the relative popularity of various accelerators |
2478 // on Chrome OS. | 2478 // on Chrome OS. |
2479 const app::KeyboardCode key_code = accelerator.GetKeyCode(); | 2479 const ui::KeyboardCode key_code = accelerator.GetKeyCode(); |
2480 switch (command_id) { | 2480 switch (command_id) { |
2481 case IDC_BACK: | 2481 case IDC_BACK: |
2482 if (key_code == app::VKEY_BACK) | 2482 if (key_code == ui::VKEY_BACK) |
2483 UserMetrics::RecordAction(UserMetricsAction("Accel_Back_Backspace")); | 2483 UserMetrics::RecordAction(UserMetricsAction("Accel_Back_Backspace")); |
2484 else if (key_code == app::VKEY_F1) | 2484 else if (key_code == ui::VKEY_F1) |
2485 UserMetrics::RecordAction(UserMetricsAction("Accel_Back_F1")); | 2485 UserMetrics::RecordAction(UserMetricsAction("Accel_Back_F1")); |
2486 else if (key_code == app::VKEY_LEFT) | 2486 else if (key_code == ui::VKEY_LEFT) |
2487 UserMetrics::RecordAction(UserMetricsAction("Accel_Back_Left")); | 2487 UserMetrics::RecordAction(UserMetricsAction("Accel_Back_Left")); |
2488 break; | 2488 break; |
2489 case IDC_FORWARD: | 2489 case IDC_FORWARD: |
2490 if (key_code == app::VKEY_BACK) | 2490 if (key_code == ui::VKEY_BACK) |
2491 UserMetrics::RecordAction(UserMetricsAction("Accel_Forward_Backspace")); | 2491 UserMetrics::RecordAction(UserMetricsAction("Accel_Forward_Backspace")); |
2492 else if (key_code == app::VKEY_F2) | 2492 else if (key_code == ui::VKEY_F2) |
2493 UserMetrics::RecordAction(UserMetricsAction("Accel_Forward_F2")); | 2493 UserMetrics::RecordAction(UserMetricsAction("Accel_Forward_F2")); |
2494 else if (key_code == app::VKEY_LEFT) | 2494 else if (key_code == ui::VKEY_LEFT) |
2495 UserMetrics::RecordAction(UserMetricsAction("Accel_Forward_Right")); | 2495 UserMetrics::RecordAction(UserMetricsAction("Accel_Forward_Right")); |
2496 break; | 2496 break; |
2497 case IDC_RELOAD: | 2497 case IDC_RELOAD: |
2498 case IDC_RELOAD_IGNORING_CACHE: | 2498 case IDC_RELOAD_IGNORING_CACHE: |
2499 if (key_code == app::VKEY_R) | 2499 if (key_code == ui::VKEY_R) |
2500 UserMetrics::RecordAction(UserMetricsAction("Accel_Reload_R")); | 2500 UserMetrics::RecordAction(UserMetricsAction("Accel_Reload_R")); |
2501 else if (key_code == app::VKEY_F3) | 2501 else if (key_code == ui::VKEY_F3) |
2502 UserMetrics::RecordAction(UserMetricsAction("Accel_Reload_F3")); | 2502 UserMetrics::RecordAction(UserMetricsAction("Accel_Reload_F3")); |
2503 break; | 2503 break; |
2504 case IDC_FULLSCREEN: | 2504 case IDC_FULLSCREEN: |
2505 if (key_code == app::VKEY_F4) | 2505 if (key_code == ui::VKEY_F4) |
2506 UserMetrics::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); | 2506 UserMetrics::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); |
2507 break; | 2507 break; |
2508 case IDC_NEW_TAB: | 2508 case IDC_NEW_TAB: |
2509 if (key_code == app::VKEY_T) | 2509 if (key_code == ui::VKEY_T) |
2510 UserMetrics::RecordAction(UserMetricsAction("Accel_NewTab_T")); | 2510 UserMetrics::RecordAction(UserMetricsAction("Accel_NewTab_T")); |
2511 break; | 2511 break; |
2512 case IDC_SEARCH: | 2512 case IDC_SEARCH: |
2513 if (key_code == app::VKEY_LWIN) | 2513 if (key_code == ui::VKEY_LWIN) |
2514 UserMetrics::RecordAction(UserMetricsAction("Accel_Search_LWin")); | 2514 UserMetrics::RecordAction(UserMetricsAction("Accel_Search_LWin")); |
2515 break; | 2515 break; |
2516 case IDC_FOCUS_LOCATION: | 2516 case IDC_FOCUS_LOCATION: |
2517 if (key_code == app::VKEY_D) | 2517 if (key_code == ui::VKEY_D) |
2518 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusLocation_D")); | 2518 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusLocation_D")); |
2519 else if (key_code == app::VKEY_L) | 2519 else if (key_code == ui::VKEY_L) |
2520 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusLocation_L")); | 2520 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusLocation_L")); |
2521 break; | 2521 break; |
2522 case IDC_FOCUS_SEARCH: | 2522 case IDC_FOCUS_SEARCH: |
2523 if (key_code == app::VKEY_E) | 2523 if (key_code == ui::VKEY_E) |
2524 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusSearch_E")); | 2524 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusSearch_E")); |
2525 else if (key_code == app::VKEY_K) | 2525 else if (key_code == ui::VKEY_K) |
2526 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusSearch_K")); | 2526 UserMetrics::RecordAction(UserMetricsAction("Accel_FocusSearch_K")); |
2527 break; | 2527 break; |
2528 default: | 2528 default: |
2529 // Do nothing. | 2529 // Do nothing. |
2530 break; | 2530 break; |
2531 } | 2531 } |
2532 #endif | 2532 #endif |
2533 } | 2533 } |
2534 | 2534 |
2535 void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents, | 2535 void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2579 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 2579 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
2580 | 2580 |
2581 return view; | 2581 return view; |
2582 } | 2582 } |
2583 #endif | 2583 #endif |
2584 | 2584 |
2585 // static | 2585 // static |
2586 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 2586 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { |
2587 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 2587 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); |
2588 } | 2588 } |
OLD | NEW |