summaryrefslogtreecommitdiffstats
path: root/views/focus
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 08:03:30 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 08:03:30 +0000
commit5c320965fef19421538290eb27ea1819a2a04b87 (patch)
treed401109162be9ead524ef4bad37747f0884665cb /views/focus
parent7606b72dae9664f9da19f8f39e3d6f9c86a4092c (diff)
downloadchromium_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/focus')
-rw-r--r--views/focus/focus_manager.cc23
-rw-r--r--views/focus/focus_manager.h10
-rw-r--r--views/focus/focus_manager_gtk.cc45
-rw-r--r--views/focus/focus_manager_win.cc33
4 files changed, 28 insertions, 83 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