diff options
author | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-14 08:03:30 +0000 |
---|---|---|
committer | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-14 08:03:30 +0000 |
commit | 5c320965fef19421538290eb27ea1819a2a04b87 (patch) | |
tree | d401109162be9ead524ef4bad37747f0884665cb /views | |
parent | 7606b72dae9664f9da19f8f39e3d6f9c86a4092c (diff) | |
download | chromium_src-5c320965fef19421538290eb27ea1819a2a04b87.zip chromium_src-5c320965fef19421538290eb27ea1819a2a04b87.tar.gz chromium_src-5c320965fef19421538290eb27ea1819a2a04b87.tar.bz2 |
Clean up FocusManager
Use Widget API to get FocusManager for native_view/window.
Move FocusNatieView to native widget impl.
This is necessary for NativeWidgetX
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7351008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92497 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/focus/focus_manager.cc | 23 | ||||
-rw-r--r-- | views/focus/focus_manager.h | 10 | ||||
-rw-r--r-- | views/focus/focus_manager_gtk.cc | 45 | ||||
-rw-r--r-- | views/focus/focus_manager_win.cc | 33 | ||||
-rw-r--r-- | views/views.gyp | 2 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 5 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_private.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 4 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 6 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 1 | ||||
-rw-r--r-- | views/widget/widget.cc | 4 | ||||
-rw-r--r-- | views/widget/widget.h | 3 |
14 files changed, 54 insertions, 85 deletions
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc index 87610d7..e2942a6 100644 --- a/views/focus/focus_manager.cc +++ b/views/focus/focus_manager.cc @@ -454,11 +454,34 @@ AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator( return map_iter->second.front(); } +void FocusManager::FocusNativeView(gfx::NativeView native_view) { + widget_->FocusNativeView(native_view); +} + // static bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) { return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown(); } +// static +FocusManager* FocusManager::GetFocusManagerForNativeView( + gfx::NativeView native_view) { + // TODO(beng): This method probably isn't necessary. + Widget* widget = Widget::GetTopLevelWidgetForNativeView(native_view); + return widget ? widget->GetFocusManager() : NULL; +} + +// static +FocusManager* FocusManager::GetFocusManagerForNativeWindow( + gfx::NativeWindow native_window) { + // TODO(beng): This method probably isn't necessary. + Widget* widget = Widget::GetWidgetForNativeWindow(native_window); + if (!widget) + return NULL; + widget = widget->GetTopLevelWidget(); + return widget ? widget->GetFocusManager() : NULL; +} + void FocusManager::ViewRemoved(View* removed) { // If the view being removed contains (or is) the focused view, // clear the focus. However, it's not safe to call ClearFocus() diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h index 70c38e56..a75f79a 100644 --- a/views/focus/focus_manager.h +++ b/views/focus/focus_manager.h @@ -269,17 +269,17 @@ class FocusManager { AcceleratorTarget* GetCurrentTargetForAccelerator( const Accelerator& accelertor) const; - // Convenience method that returns true if the passed |key_event| should - // trigger tab traversal (if it is a TAB key press with or without SHIFT - // pressed). - static bool IsTabTraversalKeyEvent(const KeyEvent& key_event); - // Sets the focus to the specified native view. virtual void FocusNativeView(gfx::NativeView native_view); // Clears the native view having the focus. virtual void ClearNativeFocus(); + // Convenience method that returns true if the passed |key_event| should + // trigger tab traversal (if it is a TAB key press with or without SHIFT + // pressed). + static bool IsTabTraversalKeyEvent(const KeyEvent& key_event); + // Retrieves the FocusManager associated with the passed native view. static FocusManager* GetFocusManagerForNativeView( gfx::NativeView native_view); diff --git a/views/focus/focus_manager_gtk.cc b/views/focus/focus_manager_gtk.cc deleted file mode 100644 index e0fa90a..0000000 --- a/views/focus/focus_manager_gtk.cc +++ /dev/null @@ -1,45 +0,0 @@ -// 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. - -#include <gtk/gtk.h> - -#include "views/focus/focus_manager.h" - -#include "base/logging.h" -#include "views/widget/native_widget_gtk.h" - -namespace views { - -void FocusManager::FocusNativeView(gfx::NativeView native_view) { - if (native_view && !gtk_widget_is_focus(native_view)) - gtk_widget_grab_focus(native_view); -} - -// static -FocusManager* FocusManager::GetFocusManagerForNativeView( - gfx::NativeView native_view) { - GtkWidget* root = gtk_widget_get_toplevel(native_view); - if (!root || !GTK_WIDGET_TOPLEVEL(root)) - return NULL; - - Widget* widget = Widget::GetWidgetForNativeView(root); - if (!widget) { - // TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the - // options page is only based on views. - // NOTREACHED(); - NOTIMPLEMENTED(); - return NULL; - } - FocusManager* focus_manager = widget->GetFocusManager(); - DCHECK(focus_manager) << "no FocusManager for top level Widget"; - return focus_manager; -} - -// static -FocusManager* FocusManager::GetFocusManagerForNativeWindow( - gfx::NativeWindow native_window) { - return GetFocusManagerForNativeView(GTK_WIDGET(native_window)); -} - -} // namespace views diff --git a/views/focus/focus_manager_win.cc b/views/focus/focus_manager_win.cc deleted file mode 100644 index 17517a9..0000000 --- a/views/focus/focus_manager_win.cc +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -#include "views/focus/focus_manager.h" - -#include "views/view.h" -#include "views/widget/native_widget.h" -#include "views/widget/widget.h" - -namespace views { - -void FocusManager::FocusNativeView(gfx::NativeView native_view) { - // Only reset focus if hwnd is not already focused. - if (native_view && ::GetFocus() != native_view) - ::SetFocus(native_view); -} - -// static -FocusManager* FocusManager::GetFocusManagerForNativeView( - gfx::NativeView native_view) { - // TODO(beng): This method probably isn't necessary. - Widget* widget = Widget::GetTopLevelWidgetForNativeView(native_view); - return widget ? widget->GetFocusManager() : NULL; -} - -// static -FocusManager* FocusManager::GetFocusManagerForNativeWindow( - gfx::NativeWindow native_window) { - return GetFocusManagerForNativeView(native_window); -} - -} // namespace views diff --git a/views/views.gyp b/views/views.gyp index 5177013..8441f37 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -255,8 +255,6 @@ 'focus/accelerator_handler_win.cc', 'focus/external_focus_tracker.cc', 'focus/external_focus_tracker.h', - 'focus/focus_manager_gtk.cc', - 'focus/focus_manager_win.cc', 'focus/focus_manager.cc', 'focus/focus_manager.h', 'focus/focus_search.cc', diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index 7fbe649..d9dd8d2 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -1326,6 +1326,11 @@ void NativeWidgetGtk::ClearNativeFocus() { gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); } +void NativeWidgetGtk::FocusNativeView(gfx::NativeView native_view) { + if (native_view && !gtk_widget_is_focus(native_view)) + gtk_widget_grab_focus(native_view); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetGtk, protected: diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index 82f8f13..7c99e94 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -221,6 +221,7 @@ class NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; virtual void ClearNativeFocus() OVERRIDE; + virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; protected: // Modifies event coordinates to the targeted widget contained by this widget. diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h index 874612e..e1b6955 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -212,6 +212,7 @@ class NativeWidgetPrivate : public NativeWidget { virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0; virtual void SetCursor(gfx::NativeCursor cursor) = 0; virtual void ClearNativeFocus() = 0; + virtual void FocusNativeView(gfx::NativeView native_view) = 0; // Overridden from NativeWidget: virtual internal::NativeWidgetPrivate* AsNativeWidgetPrivate() OVERRIDE; diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index 47bb1a7..a69169b 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -459,6 +459,10 @@ void NativeWidgetViews::ClearNativeFocus() { GetParentNativeWidget()->ClearNativeFocus(); } +void NativeWidgetViews::FocusNativeView(gfx::NativeView native_view) { + GetParentNativeWidget()->FocusNativeView(native_view); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetViews, private: diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index 30567db..f1acf63 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -121,6 +121,7 @@ class NativeWidgetViews : public internal::NativeWidgetPrivate, virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; virtual void ClearNativeFocus() OVERRIDE; + virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; // Overridden from internal::InputMethodDelegate virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 17b28e9..da00f33 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -1088,6 +1088,12 @@ void NativeWidgetWin::ClearNativeFocus() { ::SetFocus(GetNativeView()); } +void NativeWidgetWin::FocusNativeView(gfx::NativeView native_view) { + // Only reset focus if hwnd is not already focused. + if (native_view && ::GetFocus() != native_view) + ::SetFocus(native_view); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetWin, MessageLoop::Observer implementation: diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index a6dd942..4d668d9 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -268,6 +268,7 @@ class NativeWidgetWin : public ui::WindowImpl, virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; virtual void ClearNativeFocus() OVERRIDE; + virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; protected: // Information saved before going into fullscreen mode, used to restore the diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 69386a6..d26937f 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -633,6 +633,10 @@ void Widget::ClearNativeFocus() { native_widget_->ClearNativeFocus(); } +void Widget::FocusNativeView(gfx::NativeView native_view) { + native_widget_->FocusNativeView(native_view); +} + void Widget::UpdateFrameAfterFrameChange() { native_widget_->UpdateFrameAfterFrameChange(); } diff --git a/views/widget/widget.h b/views/widget/widget.h index af9a899..aea6ff9 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -437,6 +437,9 @@ class Widget : public internal::NativeWidgetDelegate, // Clear native focus set to the Widget's NativeWidget. void ClearNativeFocus(); + // Sets the focus to |native_view|. + void FocusNativeView(gfx::NativeView native_view); + // Updates the frame after an event caused it to be changed. virtual void UpdateFrameAfterFrameChange(); |