| 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 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/profiles/avatar_menu_model.h" | 26 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/profiles/profile_info_cache.h" | 28 #include "chrome/browser/profiles/profile_info_cache.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
| 30 #include "chrome/browser/sessions/tab_restore_service.h" | 30 #include "chrome/browser/sessions/tab_restore_service.h" |
| 31 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 31 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 32 #include "chrome/browser/speech/extension_api/tts_extension_api.h" | 32 #include "chrome/browser/speech/extension_api/tts_extension_api.h" |
| 33 #include "chrome/browser/themes/theme_service.h" | 33 #include "chrome/browser/themes/theme_service.h" |
| 34 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 34 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
| 35 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/browser_command_controller.h" |
| 37 #include "chrome/browser/ui/browser_commands.h" |
| 36 #include "chrome/browser/ui/browser_dialogs.h" | 38 #include "chrome/browser/ui/browser_dialogs.h" |
| 37 #include "chrome/browser/ui/browser_list.h" | 39 #include "chrome/browser/ui/browser_list.h" |
| 38 #include "chrome/browser/ui/browser_window_state.h" | 40 #include "chrome/browser/ui/browser_window_state.h" |
| 39 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 41 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 40 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" | 42 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" |
| 41 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 43 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 42 #include "chrome/browser/ui/search/search.h" | 44 #include "chrome/browser/ui/search/search.h" |
| 43 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 45 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 44 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 46 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 47 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 ExtensionTtsController::GetInstance()->Stop(); | 470 ExtensionTtsController::GetInstance()->Stop(); |
| 469 return false; | 471 return false; |
| 470 } | 472 } |
| 471 #endif | 473 #endif |
| 472 | 474 |
| 473 std::map<ui::Accelerator, int>::const_iterator iter = | 475 std::map<ui::Accelerator, int>::const_iterator iter = |
| 474 accelerator_table_.find(accelerator); | 476 accelerator_table_.find(accelerator); |
| 475 DCHECK(iter != accelerator_table_.end()); | 477 DCHECK(iter != accelerator_table_.end()); |
| 476 int command_id = iter->second; | 478 int command_id = iter->second; |
| 477 | 479 |
| 478 if (!browser_->block_command_execution()) | 480 chrome::BrowserCommandController* controller = browser_->command_controller(); |
| 481 if (!controller->block_command_execution()) |
| 479 UpdateAcceleratorMetrics(accelerator, command_id); | 482 UpdateAcceleratorMetrics(accelerator, command_id); |
| 480 return browser_->ExecuteCommandIfEnabled(command_id); | 483 return chrome::ExecuteCommand(browser_.get(), command_id); |
| 481 } | 484 } |
| 482 | 485 |
| 483 bool BrowserView::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { | 486 bool BrowserView::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { |
| 484 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators | 487 // 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. | 488 // anywhere so we need to check for them explicitly here. |
| 486 switch (cmd_id) { | 489 switch (cmd_id) { |
| 487 case IDC_CUT: | 490 case IDC_CUT: |
| 488 *accelerator = ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN); | 491 *accelerator = ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN); |
| 489 return true; | 492 return true; |
| 490 case IDC_COPY: | 493 case IDC_COPY: |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 // - If the |browser_| is not for an app, and the |accelerator| is associated | 1226 // - If the |browser_| is not for an app, and the |accelerator| is associated |
| 1224 // with the browser, and it is not a reserved one, do nothing. | 1227 // with the browser, and it is not a reserved one, do nothing. |
| 1225 | 1228 |
| 1226 if (browser_->is_app()) { | 1229 if (browser_->is_app()) { |
| 1227 // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app | 1230 // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app |
| 1228 // might not be able to see a subsequent Char event. See OnHandleInputEvent | 1231 // might not be able to see a subsequent Char event. See OnHandleInputEvent |
| 1229 // in content/renderer/render_widget.cc for details. | 1232 // in content/renderer/render_widget.cc for details. |
| 1230 return false; | 1233 return false; |
| 1231 } | 1234 } |
| 1232 | 1235 |
| 1236 chrome::BrowserCommandController* controller = browser_->command_controller(); |
| 1237 |
| 1233 // Here we need to retrieve the command id (if any) associated to the | 1238 // Here we need to retrieve the command id (if any) associated to the |
| 1234 // keyboard event. Instead of looking up the command id in the | 1239 // keyboard event. Instead of looking up the command id in the |
| 1235 // |accelerator_table_| by ourselves, we block the command execution of | 1240 // |accelerator_table_| by ourselves, we block the command execution of |
| 1236 // the |browser_| object then send the keyboard event to the | 1241 // the |browser_| object then send the keyboard event to the |
| 1237 // |focus_manager| as if we are activating an accelerator key. | 1242 // |focus_manager| as if we are activating an accelerator key. |
| 1238 // Then we can retrieve the command id from the |browser_| object. | 1243 // Then we can retrieve the command id from the |browser_| object. |
| 1239 browser_->SetBlockCommandExecution(true); | 1244 controller->SetBlockCommandExecution(true); |
| 1240 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the | 1245 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the |
| 1241 // command execution cannot be blocked and true is returned. However, it is | 1246 // command execution cannot be blocked and true is returned. However, it is |
| 1242 // okay as long as is_app() is false. See comments in this function. | 1247 // okay as long as is_app() is false. See comments in this function. |
| 1243 const bool processed = focus_manager->ProcessAccelerator(accelerator); | 1248 const bool processed = focus_manager->ProcessAccelerator(accelerator); |
| 1244 const int id = browser_->GetLastBlockedCommand(NULL); | 1249 const int id = controller->GetLastBlockedCommand(NULL); |
| 1245 browser_->SetBlockCommandExecution(false); | 1250 controller->SetBlockCommandExecution(false); |
| 1246 | 1251 |
| 1247 // Executing the command may cause |this| object to be destroyed. | 1252 // Executing the command may cause |this| object to be destroyed. |
| 1248 if (browser_->IsReservedCommandOrKey(id, event)) { | 1253 if (controller->IsReservedCommandOrKey(id, event)) { |
| 1249 UpdateAcceleratorMetrics(accelerator, id); | 1254 UpdateAcceleratorMetrics(accelerator, id); |
| 1250 return browser_->ExecuteCommandIfEnabled(id); | 1255 return chrome::ExecuteCommand(browser_.get(), id); |
| 1251 } | 1256 } |
| 1252 | 1257 |
| 1253 if (id != -1) { | 1258 if (id != -1) { |
| 1254 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+t). | 1259 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+t). |
| 1255 if (event.type == WebKit::WebInputEvent::RawKeyDown) | 1260 if (event.type == WebKit::WebInputEvent::RawKeyDown) |
| 1256 *is_keyboard_shortcut = true; | 1261 *is_keyboard_shortcut = true; |
| 1257 } else if (processed) { | 1262 } else if (processed) { |
| 1258 // |accelerator| is a non-browser shortcut (e.g. F5-F10 on Ash). | 1263 // |accelerator| is a non-browser shortcut (e.g. F5-F10 on Ash). |
| 1259 return true; | 1264 return true; |
| 1260 } | 1265 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 ((command_id & sc_mask) == SC_MAXIMIZE)) | 1519 ((command_id & sc_mask) == SC_MAXIMIZE)) |
| 1515 return true; | 1520 return true; |
| 1516 } | 1521 } |
| 1517 #endif | 1522 #endif |
| 1518 // Translate WM_APPCOMMAND command ids into a command id that the browser | 1523 // Translate WM_APPCOMMAND command ids into a command id that the browser |
| 1519 // knows how to handle. | 1524 // knows how to handle. |
| 1520 int command_id_from_app_command = GetCommandIDForAppCommandID(command_id); | 1525 int command_id_from_app_command = GetCommandIDForAppCommandID(command_id); |
| 1521 if (command_id_from_app_command != -1) | 1526 if (command_id_from_app_command != -1) |
| 1522 command_id = command_id_from_app_command; | 1527 command_id = command_id_from_app_command; |
| 1523 | 1528 |
| 1524 return browser_->ExecuteCommandIfEnabled(command_id); | 1529 return chrome::ExecuteCommand(browser_.get(), command_id); |
| 1525 } | 1530 } |
| 1526 | 1531 |
| 1527 std::string BrowserView::GetWindowName() const { | 1532 std::string BrowserView::GetWindowName() const { |
| 1528 return chrome::GetWindowPlacementKey(browser_.get()); | 1533 return chrome::GetWindowPlacementKey(browser_.get()); |
| 1529 } | 1534 } |
| 1530 | 1535 |
| 1531 void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds, | 1536 void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds, |
| 1532 ui::WindowShowState show_state) { | 1537 ui::WindowShowState show_state) { |
| 1533 // If IsFullscreen() is true, we've just changed into fullscreen mode, and | 1538 // If IsFullscreen() is true, we've just changed into fullscreen mode, and |
| 1534 // we're catching the going-into-fullscreen sizing and positioning calls, | 1539 // we're catching the going-into-fullscreen sizing and positioning calls, |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2510 bubble->Show(); | 2515 bubble->Show(); |
| 2511 } | 2516 } |
| 2512 | 2517 |
| 2513 void BrowserView::RestackLocationBarContainer() { | 2518 void BrowserView::RestackLocationBarContainer() { |
| 2514 #if defined(USE_AURA) | 2519 #if defined(USE_AURA) |
| 2515 if (search_view_controller_.get()) | 2520 if (search_view_controller_.get()) |
| 2516 search_view_controller_->StackAtTop(); | 2521 search_view_controller_->StackAtTop(); |
| 2517 #endif | 2522 #endif |
| 2518 toolbar_->location_bar_container()->StackAtTop(); | 2523 toolbar_->location_bar_container()->StackAtTop(); |
| 2519 } | 2524 } |
| OLD | NEW |