summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser.cc
diff options
context:
space:
mode:
authorsuzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 06:01:48 +0000
committersuzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 06:01:48 +0000
commit867125a08f77a22b770f197d90519a8672af83aa (patch)
tree3d2ba6406f0932155b333af29bb2d9bff3e2d276 /chrome/browser/browser.cc
parent44d64924960f793fd92f964d1e349216757c1856 (diff)
downloadchromium_src-867125a08f77a22b770f197d90519a8672af83aa.zip
chromium_src-867125a08f77a22b770f197d90519a8672af83aa.tar.gz
chromium_src-867125a08f77a22b770f197d90519a8672af83aa.tar.bz2
Refactor the keyboard events handling code related to RenderViewHostDelegate::View and TabContentsDelegate interfaces.
Significant changes made by this CL: 1. The keyboard event handling code has been moved from TabContentsView implementation classes into BrowserWindow implementation classes. Please refer to this discussion thread: http://groups.google.com/group/chromium-dev/browse_thread/thread/e6e0b5cc105659b7/9953c4308bb0000c This change makes the keyboard event flow comply with the relationship between TabContents/TabContentsView and TabContentsDelegate/BrowserWindow. Besides it, the code is also simplified a lot, for example, the keyboard event handling code in chrome/browser/views/tab_contents/tab_contents_view_{gtk,win}.cc are now merged into one copy and moved into chrome/browser/views/frame/browser_view.cc. 2. A pre-handle phrase has been added into the keyboard event handling flow. A keyboard event will be first sent to the browser for pre-handling before being sent to the renderer. Then if the event was not handled by the renderer, it'll be sent to the browser again for post-handling. 3. The keyboard accelerator handling code of Windows and Linux ports have been optimized to get rid off extra command lookup. 4. The keyboard event message flow between the browser and the renderer is changed back to full async mode, all complex logics introduced by revision 29857 are removed. BUG=24479, 26054, 26131, 28839 TEST=See bug reports. Review URL: http://codereview.chromium.org/400012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34234 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser.cc')
-rw-r--r--chrome/browser/browser.cc66
1 files changed, 47 insertions, 19 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index cf1af8c..a52e157 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -140,7 +140,10 @@ Browser::Browser(Type type, Profile* profile)
is_attempting_to_close_browser_(false),
cancel_download_confirmation_state_(NOT_PROMPTED),
maximized_state_(MAXIMIZED_STATE_DEFAULT),
- method_factory_(this) {
+ method_factory_(this),
+ block_command_execution_(false),
+ last_blocked_command_id_(-1),
+ last_blocked_command_disposition_(CURRENT_TAB) {
tabstrip_model_.AddObserver(this);
registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED,
@@ -1402,6 +1405,16 @@ void Browser::ExecuteCommandWithDisposition(
DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command";
+ // If command execution is blocked then just record the command and return.
+ if (block_command_execution_) {
+ // We actually only allow no more than one blocked command, otherwise some
+ // commands maybe lost.
+ DCHECK(last_blocked_command_id_ == -1);
+ last_blocked_command_id_ = id;
+ last_blocked_command_disposition_ = disposition;
+ return;
+ }
+
// The order of commands in this switch statement must match the function
// declaration order in browser.h!
switch (id) {
@@ -1563,6 +1576,33 @@ void Browser::ExecuteCommandWithDisposition(
}
}
+bool Browser::IsReservedCommand(int command_id) {
+ return command_id == IDC_CLOSE_TAB ||
+ command_id == IDC_CLOSE_POPUPS ||
+ command_id == IDC_CLOSE_WINDOW ||
+ command_id == IDC_NEW_INCOGNITO_WINDOW ||
+ command_id == IDC_NEW_TAB ||
+ command_id == IDC_NEW_WINDOW ||
+ command_id == IDC_RESTORE_TAB ||
+ command_id == IDC_SELECT_NEXT_TAB ||
+ command_id == IDC_SELECT_PREVIOUS_TAB ||
+ command_id == IDC_EXIT;
+}
+
+void Browser::SetBlockCommandExecution(bool block) {
+ block_command_execution_ = block;
+ if (block) {
+ last_blocked_command_id_ = -1;
+ last_blocked_command_disposition_ = CURRENT_TAB;
+ }
+}
+
+int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) {
+ if (disposition)
+ *disposition = last_blocked_command_disposition_;
+ return last_blocked_command_id_;
+}
+
///////////////////////////////////////////////////////////////////////////////
// Browser, CommandUpdater::CommandUpdaterDelegate implementation:
@@ -2197,25 +2237,13 @@ void Browser::ShowPageInfo(Profile* profile,
window()->ShowPageInfo(profile, url, ssl, show_history);
}
-bool Browser::IsReservedAccelerator(const NativeWebKeyboardEvent& event) {
- // Other platforms don't send close-app keyboard shortcuts to apps first.
-#if defined(OS_WIN)
- if ((event.modifiers & NativeWebKeyboardEvent::AltKey) &&
- event.windowsKeyCode == VK_F4) {
- return true;
- }
-#endif
+bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
+ bool* is_keyboard_shortcut) {
+ return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
+}
- int command_id = window()->GetCommandId(event);
- return command_id == IDC_CLOSE_TAB ||
- command_id == IDC_CLOSE_POPUPS ||
- command_id == IDC_CLOSE_WINDOW ||
- command_id == IDC_NEW_INCOGNITO_WINDOW ||
- command_id == IDC_NEW_TAB ||
- command_id == IDC_NEW_WINDOW ||
- command_id == IDC_RESTORE_TAB ||
- command_id == IDC_SELECT_NEXT_TAB ||
- command_id == IDC_SELECT_PREVIOUS_TAB;
+void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
+ window()->HandleKeyboardEvent(event);
}
void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) {