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

Unified Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 10134036: Let Chrome app handle Ash accelerators first if the app is launched as a window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/frame/browser_view.cc
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index da1f15abd35003c7314583e53a07b10e41ffaa90..f5f476db1fa4b9e1e38f9cc5aed81e50f353d52c 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -102,6 +102,7 @@
#include "ui/views/window/dialog_delegate.h"
#if defined(USE_ASH)
+#include "ash/accelerators/accelerator_controller.h"
#include "ash/launcher/launcher.h"
#include "ash/launcher/launcher_model.h"
#include "ash/shell.h"
@@ -117,6 +118,7 @@
#if defined(USE_AURA)
#include "chrome/browser/ui/views/accelerator_table.h"
+#include "ui/aura/event.h"
#include "ui/gfx/screen.h"
#endif
@@ -188,6 +190,52 @@ bool AdjustFrameForImmersiveMode(BrowserFrame* frame) {
}
#endif
+#if defined(USE_ASH)
+// Do not call this function directly.
+bool ProcessAshAcceleratorInternal(const NativeWebKeyboardEvent& event,
Ben Goodger (Google) 2012/05/01 16:00:37 Can we move this back to src/ash? I don't like ha
Yusuke Sato 2012/05/02 16:40:11 Thanks for the suggestion. Migrated to Ash-only so
+ bool check_only) {
+ ui::Accelerator accelerator(
+ static_cast<ui::KeyboardCode>(event.windowsKeyCode),
+ (event.modifiers & NativeWebKeyboardEvent::ShiftKey) ==
+ NativeWebKeyboardEvent::ShiftKey,
+ (event.modifiers & NativeWebKeyboardEvent::ControlKey) ==
+ NativeWebKeyboardEvent::ControlKey,
+ (event.modifiers & NativeWebKeyboardEvent::AltKey) ==
+ NativeWebKeyboardEvent::AltKey);
+
+ if (event.type == WebKit::WebInputEvent::KeyUp)
+ accelerator.set_type(ui::ET_KEY_RELEASED);
+ else if (event.type != WebKit::WebInputEvent::RawKeyDown)
+ return false;
+
+ const aura::KeyEvent* aura_event =
+ static_cast<const aura::KeyEvent*>(event.os_event);
+ ash::AcceleratorController* accelerator_controller =
+ ash::Shell::GetInstance()->accelerator_controller();
+
+ // |aura_event| could be NULL when the keyboard |event| is a fabricated one.
+ // See RenderWidgetHostViewAura::OnKeyEvent() for details.
+ if (!aura_event || !accelerator_controller)
+ return false;
+
+ if (check_only && accelerator_controller->IsAccelerator(accelerator))
+ return true;
+ if (!check_only && accelerator_controller->Process(accelerator))
+ return true;
+
+ return false;
+}
+
+bool ProcessAshAccelerator(const NativeWebKeyboardEvent& event) {
+ return ProcessAshAcceleratorInternal(event, false);
+}
+
+bool IsAshAccelerator(const NativeWebKeyboardEvent& event) {
+ return ProcessAshAcceleratorInternal(event, true);
+}
+
+#endif
+
} // namespace
// Returned from BrowserView::GetClassName.
@@ -1190,6 +1238,15 @@ void BrowserView::ShowAppMenu() {
bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) {
+#if defined(USE_ASH)
+ if (!browser_->is_app() && ProcessAshAccelerator(event))
+ return true;
+ if (browser_->is_app() && IsAshAccelerator(event)) {
+ *is_keyboard_shortcut = true;
+ return false;
+ }
+#endif
+
if (event.type != WebKit::WebInputEvent::RawKeyDown)
return false;
@@ -1252,6 +1309,10 @@ bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
}
void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
+#if defined(USE_ASH)
+ if (browser_->is_app() && ProcessAshAccelerator(event))
+ return;
+#endif
unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
GetFocusManager());
}
« ash/shell_delegate.h ('K') | « chrome/browser/ui/views/ash/chrome_shell_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698