Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 10677009: Move command handling and updating off Browser and onto a helper object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 // - If the |browser_| is not for an app, and the |accelerator| is associated 1227 // - If the |browser_| is not for an app, and the |accelerator| is associated
1225 // with the browser, and it is not a reserved one, do nothing. 1228 // with the browser, and it is not a reserved one, do nothing.
1226 1229
1227 if (browser_->is_app()) { 1230 if (browser_->is_app()) {
1228 // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app 1231 // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app
1229 // might not be able to see a subsequent Char event. See OnHandleInputEvent 1232 // might not be able to see a subsequent Char event. See OnHandleInputEvent
1230 // in content/renderer/render_widget.cc for details. 1233 // in content/renderer/render_widget.cc for details.
1231 return false; 1234 return false;
1232 } 1235 }
1233 1236
1237 chrome::BrowserCommandController* controller = browser_->command_controller();
1238
1234 // Here we need to retrieve the command id (if any) associated to the 1239 // Here we need to retrieve the command id (if any) associated to the
1235 // keyboard event. Instead of looking up the command id in the 1240 // keyboard event. Instead of looking up the command id in the
1236 // |accelerator_table_| by ourselves, we block the command execution of 1241 // |accelerator_table_| by ourselves, we block the command execution of
1237 // the |browser_| object then send the keyboard event to the 1242 // the |browser_| object then send the keyboard event to the
1238 // |focus_manager| as if we are activating an accelerator key. 1243 // |focus_manager| as if we are activating an accelerator key.
1239 // Then we can retrieve the command id from the |browser_| object. 1244 // Then we can retrieve the command id from the |browser_| object.
1240 browser_->SetBlockCommandExecution(true); 1245 controller->SetBlockCommandExecution(true);
1241 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the 1246 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the
1242 // command execution cannot be blocked and true is returned. However, it is 1247 // command execution cannot be blocked and true is returned. However, it is
1243 // okay as long as is_app() is false. See comments in this function. 1248 // okay as long as is_app() is false. See comments in this function.
1244 const bool processed = focus_manager->ProcessAccelerator(accelerator); 1249 const bool processed = focus_manager->ProcessAccelerator(accelerator);
1245 const int id = browser_->GetLastBlockedCommand(NULL); 1250 const int id = controller->GetLastBlockedCommand(NULL);
1246 browser_->SetBlockCommandExecution(false); 1251 controller->SetBlockCommandExecution(false);
1247 1252
1248 // Executing the command may cause |this| object to be destroyed. 1253 // Executing the command may cause |this| object to be destroyed.
1249 if (browser_->IsReservedCommandOrKey(id, event)) { 1254 if (controller->IsReservedCommandOrKey(id, event)) {
1250 UpdateAcceleratorMetrics(accelerator, id); 1255 UpdateAcceleratorMetrics(accelerator, id);
1251 return browser_->ExecuteCommandIfEnabled(id); 1256 return chrome::ExecuteCommand(browser_.get(), id);
1252 } 1257 }
1253 1258
1254 if (id != -1) { 1259 if (id != -1) {
1255 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+t). 1260 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+t).
1256 if (event.type == WebKit::WebInputEvent::RawKeyDown) 1261 if (event.type == WebKit::WebInputEvent::RawKeyDown)
1257 *is_keyboard_shortcut = true; 1262 *is_keyboard_shortcut = true;
1258 } else if (processed) { 1263 } else if (processed) {
1259 // |accelerator| is a non-browser shortcut (e.g. F5-F10 on Ash). 1264 // |accelerator| is a non-browser shortcut (e.g. F5-F10 on Ash).
1260 return true; 1265 return true;
1261 } 1266 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 ((command_id & sc_mask) == SC_MAXIMIZE)) 1520 ((command_id & sc_mask) == SC_MAXIMIZE))
1516 return true; 1521 return true;
1517 } 1522 }
1518 #endif 1523 #endif
1519 // Translate WM_APPCOMMAND command ids into a command id that the browser 1524 // Translate WM_APPCOMMAND command ids into a command id that the browser
1520 // knows how to handle. 1525 // knows how to handle.
1521 int command_id_from_app_command = GetCommandIDForAppCommandID(command_id); 1526 int command_id_from_app_command = GetCommandIDForAppCommandID(command_id);
1522 if (command_id_from_app_command != -1) 1527 if (command_id_from_app_command != -1)
1523 command_id = command_id_from_app_command; 1528 command_id = command_id_from_app_command;
1524 1529
1525 return browser_->ExecuteCommandIfEnabled(command_id); 1530 return chrome::ExecuteCommand(browser_.get(), command_id);
1526 } 1531 }
1527 1532
1528 std::string BrowserView::GetWindowName() const { 1533 std::string BrowserView::GetWindowName() const {
1529 return chrome::GetWindowPlacementKey(browser_.get()); 1534 return chrome::GetWindowPlacementKey(browser_.get());
1530 } 1535 }
1531 1536
1532 void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds, 1537 void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds,
1533 ui::WindowShowState show_state) { 1538 ui::WindowShowState show_state) {
1534 // If IsFullscreen() is true, we've just changed into fullscreen mode, and 1539 // If IsFullscreen() is true, we've just changed into fullscreen mode, and
1535 // we're catching the going-into-fullscreen sizing and positioning calls, 1540 // we're catching the going-into-fullscreen sizing and positioning calls,
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 bubble->Show(); 2517 bubble->Show();
2513 } 2518 }
2514 2519
2515 void BrowserView::RestackLocationBarContainer() { 2520 void BrowserView::RestackLocationBarContainer() {
2516 #if defined(USE_AURA) 2521 #if defined(USE_AURA)
2517 if (search_view_controller_.get()) 2522 if (search_view_controller_.get())
2518 search_view_controller_->StackAtTop(); 2523 search_view_controller_->StackAtTop();
2519 #endif 2524 #endif
2520 toolbar_->location_bar_container()->StackAtTop(); 2525 toolbar_->location_bar_container()->StackAtTop();
2521 } 2526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698