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(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 #include "grit/chromium_strings.h" | 86 #include "grit/chromium_strings.h" |
87 #include "grit/generated_resources.h" | 87 #include "grit/generated_resources.h" |
88 #include "grit/locale_settings.h" | 88 #include "grit/locale_settings.h" |
89 #include "grit/theme_resources.h" | 89 #include "grit/theme_resources.h" |
90 #include "grit/theme_resources_standard.h" | 90 #include "grit/theme_resources_standard.h" |
91 #include "grit/ui_resources.h" | 91 #include "grit/ui_resources.h" |
92 #include "grit/webkit_resources.h" | 92 #include "grit/webkit_resources.h" |
93 #include "ui/base/accessibility/accessible_view_state.h" | 93 #include "ui/base/accessibility/accessible_view_state.h" |
94 #include "ui/base/hit_test.h" | 94 #include "ui/base/hit_test.h" |
95 #include "ui/base/l10n/l10n_util.h" | 95 #include "ui/base/l10n/l10n_util.h" |
| 96 #include "ui/base/models/accelerator.h" |
96 #include "ui/base/resource/resource_bundle.h" | 97 #include "ui/base/resource/resource_bundle.h" |
97 #include "ui/gfx/canvas_skia.h" | 98 #include "ui/gfx/canvas_skia.h" |
98 #include "views/controls/single_split_view.h" | 99 #include "views/controls/single_split_view.h" |
99 #include "views/events/event.h" | 100 #include "views/events/event.h" |
100 #include "views/focus/external_focus_tracker.h" | 101 #include "views/focus/external_focus_tracker.h" |
101 #include "views/focus/view_storage.h" | 102 #include "views/focus/view_storage.h" |
102 #include "views/layout/grid_layout.h" | 103 #include "views/layout/grid_layout.h" |
103 #include "views/widget/native_widget.h" | 104 #include "views/widget/native_widget.h" |
104 #include "views/widget/root_view.h" | 105 #include "views/widget/root_view.h" |
105 #include "views/widget/widget.h" | 106 #include "views/widget/widget.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 ProfileInfoCache& cache = | 451 ProfileInfoCache& cache = |
451 g_browser_process->profile_manager()->GetProfileInfoCache(); | 452 g_browser_process->profile_manager()->GetProfileInfoCache(); |
452 if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) == | 453 if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) == |
453 std::string::npos) { | 454 std::string::npos) { |
454 return false; | 455 return false; |
455 } | 456 } |
456 | 457 |
457 return AvatarMenuModel::ShouldShowAvatarMenu(); | 458 return AvatarMenuModel::ShouldShowAvatarMenu(); |
458 } | 459 } |
459 | 460 |
460 bool BrowserView::AcceleratorPressed(const views::Accelerator& accelerator) { | 461 bool BrowserView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
461 #if defined(OS_CHROMEOS) | 462 #if defined(OS_CHROMEOS) |
462 // If accessibility is enabled, stop speech and return false so that key | 463 // If accessibility is enabled, stop speech and return false so that key |
463 // combinations involving Search can be used for extra accessibility | 464 // combinations involving Search can be used for extra accessibility |
464 // functionality. | 465 // functionality. |
465 if (accelerator.key_code() == ui::VKEY_LWIN && | 466 if (accelerator.key_code() == ui::VKEY_LWIN && |
466 g_browser_process->local_state()->GetBoolean( | 467 g_browser_process->local_state()->GetBoolean( |
467 prefs::kAccessibilityEnabled)) { | 468 prefs::kAccessibilityEnabled)) { |
468 ExtensionTtsController::GetInstance()->Stop(); | 469 ExtensionTtsController::GetInstance()->Stop(); |
469 return false; | 470 return false; |
470 } | 471 } |
471 #endif | 472 #endif |
472 | 473 |
473 std::map<views::Accelerator, int>::const_iterator iter = | 474 std::map<ui::Accelerator, int>::const_iterator iter = |
474 accelerator_table_.find(accelerator); | 475 accelerator_table_.find(accelerator); |
475 DCHECK(iter != accelerator_table_.end()); | 476 DCHECK(iter != accelerator_table_.end()); |
476 int command_id = iter->second; | 477 int command_id = iter->second; |
477 | 478 |
478 if (!browser_->block_command_execution()) | 479 if (!browser_->block_command_execution()) |
479 UpdateAcceleratorMetrics(accelerator, command_id); | 480 UpdateAcceleratorMetrics(accelerator, command_id); |
480 return browser_->ExecuteCommandIfEnabled(command_id); | 481 return browser_->ExecuteCommandIfEnabled(command_id); |
481 } | 482 } |
482 | 483 |
483 bool BrowserView::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { | 484 bool BrowserView::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { |
484 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators | 485 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators |
485 // anywhere so we need to check for them explicitly here. | 486 // anywhere so we need to check for them explicitly here. |
486 switch (cmd_id) { | 487 switch (cmd_id) { |
487 case IDC_CUT: | 488 case IDC_CUT: |
488 *accelerator = views::Accelerator(ui::VKEY_X, false, true, false); | 489 *accelerator = ui::Accelerator(ui::VKEY_X, false, true, false); |
489 return true; | 490 return true; |
490 case IDC_COPY: | 491 case IDC_COPY: |
491 *accelerator = views::Accelerator(ui::VKEY_C, false, true, false); | 492 *accelerator = ui::Accelerator(ui::VKEY_C, false, true, false); |
492 return true; | 493 return true; |
493 case IDC_PASTE: | 494 case IDC_PASTE: |
494 *accelerator = views::Accelerator(ui::VKEY_V, false, true, false); | 495 *accelerator = ui::Accelerator(ui::VKEY_V, false, true, false); |
495 return true; | 496 return true; |
496 } | 497 } |
497 // Else, we retrieve the accelerator information from the accelerator table. | 498 // Else, we retrieve the accelerator information from the accelerator table. |
498 std::map<views::Accelerator, int>::iterator it = | 499 std::map<ui::Accelerator, int>::iterator it = accelerator_table_.begin(); |
499 accelerator_table_.begin(); | |
500 for (; it != accelerator_table_.end(); ++it) { | 500 for (; it != accelerator_table_.end(); ++it) { |
501 if (it->second == cmd_id) { | 501 if (it->second == cmd_id) { |
502 *accelerator = it->first; | 502 *accelerator = it->first; |
503 return true; | 503 return true; |
504 } | 504 } |
505 } | 505 } |
506 return false; | 506 return false; |
507 } | 507 } |
508 | 508 |
509 bool BrowserView::ActivateAppModalDialog() const { | 509 bool BrowserView::ActivateAppModalDialog() const { |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 DCHECK(focus_manager); | 1169 DCHECK(focus_manager); |
1170 | 1170 |
1171 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 1171 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) |
1172 // Views and WebKit use different tables for GdkEventKey -> views::KeyEvent | 1172 // Views and WebKit use different tables for GdkEventKey -> views::KeyEvent |
1173 // conversion. We need to use View's conversion table here to keep consistent | 1173 // conversion. We need to use View's conversion table here to keep consistent |
1174 // behavior with views::FocusManager::OnKeyEvent() method. | 1174 // behavior with views::FocusManager::OnKeyEvent() method. |
1175 // TODO(suzhe): We need to check if Windows code also has this issue, and | 1175 // TODO(suzhe): We need to check if Windows code also has this issue, and |
1176 // it'll be best if we can unify these conversion tables. | 1176 // it'll be best if we can unify these conversion tables. |
1177 // See http://crbug.com/54315 | 1177 // See http://crbug.com/54315 |
1178 views::KeyEvent views_event(reinterpret_cast<GdkEvent*>(event.os_event)); | 1178 views::KeyEvent views_event(reinterpret_cast<GdkEvent*>(event.os_event)); |
1179 views::Accelerator accelerator(views_event.key_code(), | 1179 ui::Accelerator accelerator(views_event.key_code(), |
1180 views_event.IsShiftDown(), | 1180 views_event.IsShiftDown(), |
1181 views_event.IsControlDown(), | 1181 views_event.IsControlDown(), |
1182 views_event.IsAltDown()); | 1182 views_event.IsAltDown()); |
1183 #else | 1183 #else |
1184 views::Accelerator accelerator( | 1184 ui::Accelerator accelerator( |
1185 static_cast<ui::KeyboardCode>(event.windowsKeyCode), | 1185 static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
1186 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == | 1186 (event.modifiers & NativeWebKeyboardEvent::ShiftKey) == |
1187 NativeWebKeyboardEvent::ShiftKey, | 1187 NativeWebKeyboardEvent::ShiftKey, |
1188 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == | 1188 (event.modifiers & NativeWebKeyboardEvent::ControlKey) == |
1189 NativeWebKeyboardEvent::ControlKey, | 1189 NativeWebKeyboardEvent::ControlKey, |
1190 (event.modifiers & NativeWebKeyboardEvent::AltKey) == | 1190 (event.modifiers & NativeWebKeyboardEvent::AltKey) == |
1191 NativeWebKeyboardEvent::AltKey); | 1191 NativeWebKeyboardEvent::AltKey); |
1192 #endif | 1192 #endif |
1193 | 1193 |
1194 // We first find out the browser command associated to the |event|. | 1194 // We first find out the browser command associated to the |event|. |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2293 CopyAcceleratorTable(accelerator_table, accelerators, count); | 2293 CopyAcceleratorTable(accelerator_table, accelerators, count); |
2294 | 2294 |
2295 views::FocusManager* focus_manager = GetFocusManager(); | 2295 views::FocusManager* focus_manager = GetFocusManager(); |
2296 DCHECK(focus_manager); | 2296 DCHECK(focus_manager); |
2297 | 2297 |
2298 // Let's fill our own accelerator table. | 2298 // Let's fill our own accelerator table. |
2299 for (int i = 0; i < count; ++i) { | 2299 for (int i = 0; i < count; ++i) { |
2300 bool alt_down = (accelerators[i].fVirt & FALT) == FALT; | 2300 bool alt_down = (accelerators[i].fVirt & FALT) == FALT; |
2301 bool ctrl_down = (accelerators[i].fVirt & FCONTROL) == FCONTROL; | 2301 bool ctrl_down = (accelerators[i].fVirt & FCONTROL) == FCONTROL; |
2302 bool shift_down = (accelerators[i].fVirt & FSHIFT) == FSHIFT; | 2302 bool shift_down = (accelerators[i].fVirt & FSHIFT) == FSHIFT; |
2303 views::Accelerator accelerator( | 2303 ui::Accelerator accelerator( |
2304 static_cast<ui::KeyboardCode>(accelerators[i].key), | 2304 static_cast<ui::KeyboardCode>(accelerators[i].key), |
2305 shift_down, ctrl_down, alt_down); | 2305 shift_down, ctrl_down, alt_down); |
2306 accelerator_table_[accelerator] = accelerators[i].cmd; | 2306 accelerator_table_[accelerator] = accelerators[i].cmd; |
2307 | 2307 |
2308 // Also register with the focus manager. | 2308 // Also register with the focus manager. |
2309 focus_manager->RegisterAccelerator(accelerator, this); | 2309 focus_manager->RegisterAccelerator(accelerator, this); |
2310 } | 2310 } |
2311 | 2311 |
2312 // We don't need the Windows accelerator table anymore. | 2312 // We don't need the Windows accelerator table anymore. |
2313 free(accelerators); | 2313 free(accelerators); |
2314 #else | 2314 #else |
2315 views::FocusManager* focus_manager = GetFocusManager(); | 2315 views::FocusManager* focus_manager = GetFocusManager(); |
2316 DCHECK(focus_manager); | 2316 DCHECK(focus_manager); |
2317 // Let's fill our own accelerator table. | 2317 // Let's fill our own accelerator table. |
2318 for (size_t i = 0; i < browser::kAcceleratorMapLength; ++i) { | 2318 for (size_t i = 0; i < browser::kAcceleratorMapLength; ++i) { |
2319 views::Accelerator accelerator(browser::kAcceleratorMap[i].keycode, | 2319 ui::Accelerator accelerator(browser::kAcceleratorMap[i].keycode, |
2320 browser::kAcceleratorMap[i].shift_pressed, | 2320 browser::kAcceleratorMap[i].shift_pressed, |
2321 browser::kAcceleratorMap[i].ctrl_pressed, | 2321 browser::kAcceleratorMap[i].ctrl_pressed, |
2322 browser::kAcceleratorMap[i].alt_pressed); | 2322 browser::kAcceleratorMap[i].alt_pressed); |
2323 accelerator_table_[accelerator] = browser::kAcceleratorMap[i].command_id; | 2323 accelerator_table_[accelerator] = browser::kAcceleratorMap[i].command_id; |
2324 | 2324 |
2325 // Also register with the focus manager. | 2325 // Also register with the focus manager. |
2326 focus_manager->RegisterAccelerator(accelerator, this); | 2326 focus_manager->RegisterAccelerator(accelerator, this); |
2327 } | 2327 } |
2328 #endif | 2328 #endif |
2329 } | 2329 } |
2330 | 2330 |
2331 #if defined(OS_WIN) && !defined(USE_AURA) | 2331 #if defined(OS_WIN) && !defined(USE_AURA) |
2332 void BrowserView::BuildSystemMenuForBrowserWindow() { | 2332 void BrowserView::BuildSystemMenuForBrowserWindow() { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2442 | 2442 |
2443 pref_service->SetInteger(prefs::kPluginMessageResponseTimeout, | 2443 pref_service->SetInteger(prefs::kPluginMessageResponseTimeout, |
2444 plugin_message_response_timeout); | 2444 plugin_message_response_timeout); |
2445 pref_service->SetInteger(prefs::kHungPluginDetectFrequency, | 2445 pref_service->SetInteger(prefs::kHungPluginDetectFrequency, |
2446 hung_plugin_detect_freq); | 2446 hung_plugin_detect_freq); |
2447 } | 2447 } |
2448 #endif | 2448 #endif |
2449 } | 2449 } |
2450 | 2450 |
2451 void BrowserView::UpdateAcceleratorMetrics( | 2451 void BrowserView::UpdateAcceleratorMetrics( |
2452 const views::Accelerator& accelerator, int command_id) { | 2452 const ui::Accelerator& accelerator, int command_id) { |
2453 const ui::KeyboardCode key_code = accelerator.key_code(); | 2453 const ui::KeyboardCode key_code = accelerator.key_code(); |
2454 if (command_id == IDC_HELP_PAGE && key_code == ui::VKEY_F1) | 2454 if (command_id == IDC_HELP_PAGE && key_code == ui::VKEY_F1) |
2455 UserMetrics::RecordAction(UserMetricsAction("ShowHelpTabViaF1")); | 2455 UserMetrics::RecordAction(UserMetricsAction("ShowHelpTabViaF1")); |
2456 | 2456 |
2457 #if defined(OS_CHROMEOS) | 2457 #if defined(OS_CHROMEOS) |
2458 // Collect information about the relative popularity of various accelerators | 2458 // Collect information about the relative popularity of various accelerators |
2459 // on Chrome OS. | 2459 // on Chrome OS. |
2460 switch (command_id) { | 2460 switch (command_id) { |
2461 case IDC_BACK: | 2461 case IDC_BACK: |
2462 if (key_code == ui::VKEY_BACK) | 2462 if (key_code == ui::VKEY_BACK) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2599 Bubble::Show(this->GetWidget(), bounds, views::BubbleBorder::TOP_RIGHT, | 2599 Bubble::Show(this->GetWidget(), bounds, views::BubbleBorder::TOP_RIGHT, |
2600 views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, | 2600 views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, |
2601 bubble_view, bubble_view); | 2601 bubble_view, bubble_view); |
2602 } | 2602 } |
2603 | 2603 |
2604 void BrowserView::ShowAvatarBubbleFromAvatarButton() { | 2604 void BrowserView::ShowAvatarBubbleFromAvatarButton() { |
2605 AvatarMenuButton* button = frame_->GetAvatarMenuButton(); | 2605 AvatarMenuButton* button = frame_->GetAvatarMenuButton(); |
2606 if (button) | 2606 if (button) |
2607 button->ShowAvatarBubble(); | 2607 button->ShowAvatarBubble(); |
2608 } | 2608 } |
OLD | NEW |