diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-26 02:37:52 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-26 02:37:52 +0000 |
commit | 331fdb258d70ff5d78b08006a8506691cca65432 (patch) | |
tree | 32cc4f80237c5e6492a01e938243aa6413f87baa /chrome | |
parent | 2f60f4aaaf70bbb5ee35a42ee216eed74e2ad3c2 (diff) | |
download | chromium_src-331fdb258d70ff5d78b08006a8506691cca65432.zip chromium_src-331fdb258d70ff5d78b08006a8506691cca65432.tar.gz chromium_src-331fdb258d70ff5d78b08006a8506691cca65432.tar.bz2 |
Add NativeWidgetDelegate/Widget::OnKeyEvent post-IME handling.
Refactor XEvent code and InputMethodGtk::DispatchKeyEvent.
Nix WidgetWin::GetFocusedViewRootView, rename RootView::OnKeyEvent.
Cleanup headers and refactor code in extension_input_api.cc.
Rename WidgetGtk::OnEventKey to avoid overloading Widget::OnEventKey.
BUG=72040
TEST=Key event handling in win/linux_views/touch; extension input API SendKeyboardEventInputFunction use.
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=82713
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=82751
Review URL: http://codereview.chromium.org/6823055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82983 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/login/screen_locker.cc | 47 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_input_api.cc | 42 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_input_api.h | 6 |
3 files changed, 40 insertions, 55 deletions
diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index bb3c860..2e79b6f 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -82,7 +82,7 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, // NotificationObserver overrides: virtual void Observe(NotificationType type, const NotificationSource& source, - const NotificationDetails& details) { + const NotificationDetails& details) OVERRIDE { if (type == NotificationType::LOGIN_USER_CHANGED) { // Register Screen Lock after login screen to make sure // we don't show the screen lock on top of the login screen by accident. @@ -91,18 +91,18 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, } } - virtual void LockScreen(chromeos::ScreenLockLibrary* obj) { + virtual void LockScreen(chromeos::ScreenLockLibrary* obj) OVERRIDE { VLOG(1) << "In: ScreenLockObserver::LockScreen"; SetupInputMethodsForScreenLocker(); chromeos::ScreenLocker::Show(); } - virtual void UnlockScreen(chromeos::ScreenLockLibrary* obj) { + virtual void UnlockScreen(chromeos::ScreenLockLibrary* obj) OVERRIDE { RestoreInputMethods(); chromeos::ScreenLocker::Hide(); } - virtual void UnlockScreenFailed(chromeos::ScreenLockLibrary* obj) { + virtual void UnlockScreenFailed(chromeos::ScreenLockLibrary* obj) OVERRIDE { chromeos::ScreenLocker::UnlockScreenFailed(); } @@ -206,17 +206,17 @@ class LockWindow : public views::WidgetGtk { // GTK propagates key events from parents to children. // Make sure LockWindow will never handle key events. - virtual gboolean OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { + virtual gboolean OnEventKey(GtkWidget* widget, GdkEventKey* event) OVERRIDE { // Don't handle key event in the lock window. return false; } - virtual void OnDestroy(GtkWidget* object) { + virtual void OnDestroy(GtkWidget* object) OVERRIDE { VLOG(1) << "OnDestroy: LockWindow destroyed"; views::WidgetGtk::OnDestroy(object); } - virtual void ClearNativeFocus() { + virtual void ClearNativeFocus() OVERRIDE { DCHECK(toplevel_focus_widget_); gtk_widget_grab_focus(toplevel_focus_widget_); } @@ -254,14 +254,14 @@ class GrabWidgetRootView } // views::View implementation. - virtual void Layout() { + virtual void Layout() OVERRIDE { gfx::Size size = screen_lock_view_->GetPreferredSize(); screen_lock_view_->SetBounds(0, 0, size.width(), size.height()); shutdown_button_->LayoutIn(this); } // ScreenLocker::ScreenLockViewContainer implementation: - void SetScreenLockView(views::View* screen_lock_view) { + void SetScreenLockView(views::View* screen_lock_view) OVERRIDE { if (screen_lock_view_) { RemoveChildView(screen_lock_view_); } @@ -294,7 +294,7 @@ class GrabWidget : public views::WidgetGtk { shutdown_(NULL) { } - virtual void Show() { + virtual void Show() OVERRIDE { views::WidgetGtk::Show(); signout_link_ = screen_locker_->GetViewByID(VIEW_ID_SCREEN_LOCKER_SIGNOUT_LINK); @@ -317,7 +317,7 @@ class GrabWidget : public views::WidgetGtk { gtk_grab_remove(current_grab_window); } - virtual gboolean OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { + virtual gboolean OnEventKey(GtkWidget* widget, GdkEventKey* event) OVERRIDE { views::KeyEvent key_event(reinterpret_cast<GdkEvent*>(event)); // This is a hack to workaround the issue crosbug.com/10655 due to // the limitation that a focus manager cannot handle views in @@ -338,10 +338,11 @@ class GrabWidget : public views::WidgetGtk { return true; } } - return views::WidgetGtk::OnKeyEvent(widget, event); + return views::WidgetGtk::OnEventKey(widget, event); } - virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event) { + virtual gboolean OnButtonPress(GtkWidget* widget, + GdkEventButton* event) OVERRIDE { WidgetGtk::OnButtonPress(widget, event); // Never propagate event to parent. return true; @@ -357,7 +358,7 @@ class GrabWidget : public views::WidgetGtk { void TryUngrabOtherClients(); private: - virtual void HandleGtkGrabBroke() { + virtual void HandleGtkGrabBroke() OVERRIDE { // Input should never be stolen from ScreenLocker once it's // grabbed. If this happens, it's a bug and has to be fixed. We // let chrome crash to get a crash report and dump, and @@ -483,11 +484,11 @@ class ScreenLockerBackgroundView screen_lock_view_(screen_lock_view) { } - virtual ScreenMode GetScreenMode() const { + virtual ScreenMode GetScreenMode() const OVERRIDE { return kScreenLockerMode; } - virtual void Layout() { + virtual void Layout() OVERRIDE { chromeos::BackgroundView::Layout(); gfx::Rect screen = bounds(); if (screen_lock_view_) { @@ -504,7 +505,7 @@ class ScreenLockerBackgroundView } // ScreenLocker::ScreenLockViewContainer implementation: - void SetScreenLockView(views::View* screen_lock_view) { + virtual void SetScreenLockView(views::View* screen_lock_view) OVERRIDE { screen_lock_view_ = screen_lock_view; Layout(); } @@ -536,9 +537,9 @@ class MouseEventRelay : public MessageLoopForUI::Observer { DCHECK(dest_); } - virtual void WillProcessEvent(GdkEvent* event) {} + virtual void WillProcessEvent(GdkEvent* event) OVERRIDE {} - virtual void DidProcessEvent(GdkEvent* event) { + virtual void DidProcessEvent(GdkEvent* event) OVERRIDE { if (event->any.window != src_) return; if (!initialized_) { @@ -595,7 +596,7 @@ class InputEventObserver : public MessageLoopForUI::Observer { activated_(false) { } - virtual void WillProcessEvent(GdkEvent* event) { + virtual void WillProcessEvent(GdkEvent* event) OVERRIDE { if ((event->type == GDK_KEY_PRESS || event->type == GDK_BUTTON_PRESS || event->type == GDK_MOTION_NOTIFY) && @@ -610,7 +611,7 @@ class InputEventObserver : public MessageLoopForUI::Observer { } } - virtual void DidProcessEvent(GdkEvent* event) { + virtual void DidProcessEvent(GdkEvent* event) OVERRIDE { } private: @@ -633,7 +634,7 @@ class LockerInputEventObserver : public MessageLoopForUI::Observer { &LockerInputEventObserver::StartScreenSaver)) { } - virtual void WillProcessEvent(GdkEvent* event) { + virtual void WillProcessEvent(GdkEvent* event) OVERRIDE { if ((event->type == GDK_KEY_PRESS || event->type == GDK_BUTTON_PRESS || event->type == GDK_MOTION_NOTIFY)) { @@ -642,7 +643,7 @@ class LockerInputEventObserver : public MessageLoopForUI::Observer { } } - virtual void DidProcessEvent(GdkEvent* event) { + virtual void DidProcessEvent(GdkEvent* event) OVERRIDE { } private: diff --git a/chrome/browser/extensions/extension_input_api.cc b/chrome/browser/extensions/extension_input_api.cc index b3b8473..ffcd659 100644 --- a/chrome/browser/extensions/extension_input_api.cc +++ b/chrome/browser/extensions/extension_input_api.cc @@ -8,17 +8,12 @@ #include "base/string_util.h" #include "base/values.h" -#include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/key_identifier_conversion_views.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/views/frame/browser_view.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/common/native_web_keyboard_event.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "views/events/event.h" #include "views/ime/input_method.h" -#include "views/widget/root_view.h" #include "views/widget/widget.h" namespace { @@ -56,7 +51,7 @@ void InputFunction::Run() { SendResponse(RunImpl()); } -views::RootView* SendKeyboardEventInputFunction::GetRootView() { +views::Widget* SendKeyboardEventInputFunction::GetTopLevelWidget() { Browser* browser = GetCurrentBrowser(); if (!browser) return NULL; @@ -67,10 +62,7 @@ views::RootView* SendKeyboardEventInputFunction::GetRootView() { BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( window->GetNativeHandle()); - if (!browser_view) - return NULL; - - return browser_view->GetRootView(); + return browser_view ? browser_view->GetWidget() : NULL; } bool SendKeyboardEventInputFunction::RunImpl() { @@ -96,36 +88,28 @@ bool SendKeyboardEventInputFunction::RunImpl() { return false; } + bool flag = false; int flags = prototype_event.flags(); - bool alt = false; - if (args->GetBoolean(kAlt, &alt)) - flags |= alt ? ui::EF_ALT_DOWN : 0; - bool ctrl = false; - if (args->GetBoolean(kCtrl, &ctrl)) - flags |= ctrl ? ui::EF_CONTROL_DOWN : 0; - bool shift = false; - if (args->GetBoolean(kShift, &shift)) - flags |= shift ? ui::EF_SHIFT_DOWN : 0; - bool meta = false; - if (args->GetBoolean(kMeta, &meta)) { + flags |= (args->GetBoolean(kAlt, &flag) && flag) ? ui::EF_ALT_DOWN : 0; + flags |= (args->GetBoolean(kCtrl, &flag) && flag) ? ui::EF_CONTROL_DOWN : 0; + flags |= (args->GetBoolean(kShift, &flag) && flag) ? ui::EF_SHIFT_DOWN : 0; + if (args->GetBoolean(kMeta, &flag) && flag) { // Views does not have a Meta event flag, so return an error for now. - if (meta) { - error_ = kUnsupportedModifier; - return false; - } + error_ = kUnsupportedModifier; + return false; } - views::RootView* root_view = GetRootView(); - if (!root_view) { + views::Widget* widget = GetTopLevelWidget(); + if (!widget) { error_ = kNoValidRecipientError; return false; } views::KeyEvent event(type, prototype_event.key_code(), flags); - views::InputMethod* ime = root_view->GetWidget()->GetInputMethod(); + views::InputMethod* ime = widget->GetInputMethod(); if (ime) { ime->DispatchKeyEvent(event); - } else if (!root_view->ProcessKeyEvent(event)) { + } else if (!widget->OnKeyEvent(event)) { error_ = kKeyEventUnprocessedError; return false; } diff --git a/chrome/browser/extensions/extension_input_api.h b/chrome/browser/extensions/extension_input_api.h index 3000211..39a8161 100644 --- a/chrome/browser/extensions/extension_input_api.h +++ b/chrome/browser/extensions/extension_input_api.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,7 @@ #include "chrome/browser/extensions/extension_function.h" namespace views { - class RootView; +class Widget; } // namespace views // Base class for input APIs. @@ -30,7 +30,7 @@ class SendKeyboardEventInputFunction : public InputFunction { DECLARE_EXTENSION_FUNCTION_NAME("experimental.input.sendKeyboardEvent"); private: - views::RootView* GetRootView(); + views::Widget* GetTopLevelWidget(); }; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INPUT_API_H_ |