diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-31 22:53:37 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-31 22:53:37 +0000 |
commit | 148d105e27c7c8c2cda0c81292690b9edafcae1f (patch) | |
tree | e278052fc84a6e5399aec5bd0d423162aecb6d16 /views/widget | |
parent | dc75d4823b598a9b9b313728a06f6b47d6a73929 (diff) | |
download | chromium_src-148d105e27c7c8c2cda0c81292690b9edafcae1f.zip chromium_src-148d105e27c7c8c2cda0c81292690b9edafcae1f.tar.gz chromium_src-148d105e27c7c8c2cda0c81292690b9edafcae1f.tar.bz2 |
This CL adds accelerators to the Linux toolkit views.
The MessageLoop had to be modified to support Dispatchers on Linux.
BUG=None
TEST=On Windows and Linux, make sure the accelerators still work as expected. On Linux toolkit views, build and run the unit-tests.
Review URL: http://codereview.chromium.org/159046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22210 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/accelerator_handler.cc | 41 | ||||
-rw-r--r-- | views/widget/accelerator_handler.h | 30 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 13 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 15 |
4 files changed, 23 insertions, 76 deletions
diff --git a/views/widget/accelerator_handler.cc b/views/widget/accelerator_handler.cc deleted file mode 100644 index 7d1f991..0000000 --- a/views/widget/accelerator_handler.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2006-2008 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. - -#include "views/widget/accelerator_handler.h" - -#include "views/focus/focus_manager.h" - -namespace views { - -AcceleratorHandler::AcceleratorHandler() { -} - -bool AcceleratorHandler::Dispatch(const MSG& msg) { - bool process_message = true; - - if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { - FocusManager* focus_manager = - FocusManager::GetFocusManagerForNativeView(msg.hwnd); - if (focus_manager) { - // FocusManager::OnKeyDown and OnKeyUp return false if this message has - // been consumed and should not be propagated further. - switch (msg.message) { - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - process_message = focus_manager->OnKeyDown(msg.hwnd, msg.message, - msg.wParam, msg.lParam); - break; - } - } - } - - if (process_message) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - return true; -} - -} // namespace views diff --git a/views/widget/accelerator_handler.h b/views/widget/accelerator_handler.h deleted file mode 100644 index 5ee896c..0000000 --- a/views/widget/accelerator_handler.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2006-2008 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. - -#ifndef VIEWS_WIDGET_ACCELERATOR_HANDLER_H_ -#define VIEWS_WIDGET_ACCELERATOR_HANDLER_H_ - -#include "base/message_loop.h" - -namespace views { - -// This class delegates WM_KEYDOWN and WM_SYSKEYDOWN messages to -// the associated FocusManager class for the window that is receiving -// these messages for accelerator processing. The BrowserProcess object -// holds a singleton instance of this class which can be used by other -// custom message loop dispatcher objects to implement default accelerator -// handling. -class AcceleratorHandler : public MessageLoopForUI::Dispatcher { - public: - AcceleratorHandler(); - // Dispatcher method. This returns true if an accelerator was - // processed by the focus manager - virtual bool Dispatch(const MSG& msg); - private: - DISALLOW_EVIL_CONSTRUCTORS(AcceleratorHandler); -}; - -} // namespace views - -#endif // VIEWS_WIDGET_ACCELERATOR_HANDLER_H_ diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index a77bd14..677e58c 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -70,6 +70,8 @@ WidgetGtk::WidgetGtk(Type type) ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), delete_on_destroy_(true), transparent_(false) { + if (type_ != TYPE_CHILD) + focus_manager_.reset(new FocusManager(this)); } WidgetGtk::~WidgetGtk() { @@ -398,9 +400,16 @@ ThemeProvider* WidgetGtk::GetThemeProvider() const { return default_theme_provider_.get(); } +FocusManager* WidgetGtk::GetFocusManager() { + return focus_manager_.get(); +} + //////////////////////////////////////////////////////////////////////////////// // WidgetGtk, MessageLoopForUI::Observer implementation: +void WidgetGtk::WillProcessEvent(GdkEvent* event) { +} + void WidgetGtk::DidProcessEvent(GdkEvent* event) { if (root_view_->NeedsPainting(true)) PaintNow(root_view_->GetScheduledPaintRect()); @@ -518,12 +527,12 @@ gboolean WidgetGtk::OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event) { } gboolean WidgetGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { - KeyEvent key_event(event); + KeyEvent key_event(event, false); return root_view_->ProcessKeyEvent(key_event); } gboolean WidgetGtk::OnKeyRelease(GtkWidget* widget, GdkEventKey* event) { - KeyEvent key_event(event); + KeyEvent key_event(event, false); return root_view_->ProcessKeyEvent(key_event); } diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 61a85d9..fbb6c0e 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -99,11 +99,15 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { virtual Window* GetWindow(); virtual const Window* GetWindow() const; virtual ThemeProvider* GetThemeProvider() const; + virtual FocusManager* GetFocusManager(); // MessageLoopForUI::Observer. - virtual void WillProcessEvent(GdkEvent* event) {} + virtual void WillProcessEvent(GdkEvent* event); virtual void DidProcessEvent(GdkEvent* event); + // Retrieves the WindowGtk associated with |widget|. + static WindowGtk* GetWindowForNative(GtkWidget* widget); + protected: virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation); virtual void OnPaint(GtkWidget* widget, GdkEventExpose* event); @@ -135,8 +139,7 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { // is true. virtual bool ReleaseCaptureOnMouseReleased() { return true; } - // Sets and retrieves the WidgetGtk in the userdata section of the widget. - static WindowGtk* GetWindowForNative(GtkWidget* widget); + // Sets the WindowGtk in the userdata section of the widget. static void SetWindowForNative(GtkWidget* widget, WindowGtk* window); // Are we a subclass of WindowGtk? @@ -215,6 +218,12 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { // must be destroyed AFTER root_view_. scoped_ptr<TooltipManagerGtk> tooltip_manager_; + // The focus manager keeping track of focus for this Widget and any of its + // children. NULL for non top-level widgets. + // WARNING: RootView's destructor calls into the FocusManager. As such, this + // must be destroyed AFTER root_view_. + scoped_ptr<FocusManager> focus_manager_; + // The root of the View hierarchy attached to this window. scoped_ptr<RootView> root_view_; |