summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 18:22:10 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 18:22:10 +0000
commit0c96668965e17a98f29b6862468783e5a04af0d7 (patch)
tree0386d0b802abcb6bc0c143648bdbfaaea6cdb154
parent134efc37e03e2d8da955f855533fbb5c7c6177f1 (diff)
downloadchromium_src-0c96668965e17a98f29b6862468783e5a04af0d7.zip
chromium_src-0c96668965e17a98f29b6862468783e5a04af0d7.tar.gz
chromium_src-0c96668965e17a98f29b6862468783e5a04af0d7.tar.bz2
Nix GetFocusManagerForNativeView|Window.
Use Widget|View::GetFocusManager instead. Use Widget::Get[TopLevel]WidgetForNativeView|Window as necessary. BUG=88718 TEST=none Review URL: http://codereview.chromium.org/7532015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95111 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/testing_automation_provider_views.cc10
-rw-r--r--chrome/browser/browser_focus_uitest.cc15
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_win.cc12
-rw-r--r--chrome/browser/ui/find_bar/find_bar_host_browsertest.cc7
-rw-r--r--chrome/browser/ui/views/dropdown_bar_host.cc3
-rw-r--r--chrome/browser/ui/views/tab_contents/tab_contents_view_touch.cc9
-rw-r--r--chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc10
-rw-r--r--chrome/test/base/ui_test_utils_linux.cc7
-rw-r--r--chrome/test/base/ui_test_utils_win.cc5
-rw-r--r--ui/views/focus/accelerator_handler_win.cc5
-rw-r--r--ui/views/focus/focus_manager.cc16
-rw-r--r--ui/views/focus/focus_manager.h8
-rw-r--r--views/controls/native/native_view_host_gtk.cc6
-rw-r--r--views/controls/native/native_view_host_gtk.h2
-rw-r--r--views/controls/native_control_gtk.cc6
-rw-r--r--views/controls/native_control_gtk.h2
-rw-r--r--views/focus/accelerator_handler_win.cc7
-rw-r--r--views/focus/focus_manager.cc19
-rw-r--r--views/focus/focus_manager.h8
-rw-r--r--views/focus/focus_manager_unittest.cc46
-rw-r--r--views/view_unittest.cc6
-rw-r--r--views/widget/gtk_views_window.cc8
22 files changed, 86 insertions, 131 deletions
diff --git a/chrome/browser/automation/testing_automation_provider_views.cc b/chrome/browser/automation/testing_automation_provider_views.cc
index 1cd7b89..d2d81e5 100644
--- a/chrome/browser/automation/testing_automation_provider_views.cc
+++ b/chrome/browser/automation/testing_automation_provider_views.cc
@@ -144,8 +144,9 @@ void TestingAutomationProvider::GetFocusedViewID(int handle, int* view_id) {
*view_id = -1;
if (window_tracker_->ContainsHandle(handle)) {
gfx::NativeWindow window = window_tracker_->GetResource(handle);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeWindow(window);
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
+ DCHECK(widget);
+ views::FocusManager* focus_manager = widget->GetFocusManager();
DCHECK(focus_manager);
views::View* focused_view = focus_manager->GetFocusedView();
if (focused_view)
@@ -158,8 +159,9 @@ void TestingAutomationProvider::WaitForFocusedViewIDToChange(
if (!window_tracker_->ContainsHandle(handle))
return;
gfx::NativeWindow window = window_tracker_->GetResource(handle);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeWindow(window);
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
+ DCHECK(widget);
+ views::FocusManager* focus_manager = widget->GetFocusManager();
// The waiter will respond to the IPC and delete itself when done.
new ViewFocusChangeWaiter(focus_manager,
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 303f5e8..cd23955 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -246,12 +246,13 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_BrowsersRememberFocus) {
browser2->window()->Show();
ui_test_utils::NavigateToURL(browser2, url);
- HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle());
+ gfx::NativeWindow window2 = browser2->window()->GetNativeHandle();
BrowserView* browser_view2 =
- BrowserView::GetBrowserViewForNativeWindow(hwnd2);
+ BrowserView::GetBrowserViewForNativeWindow(window2);
ASSERT_TRUE(browser_view2);
- views::FocusManager* focus_manager2 =
- views::FocusManager::GetFocusManagerForNativeView(hwnd2);
+ views::Widget* widget2 = views::Widget::GetWidgetForNativeWindow(window2);
+ ASSERT_TRUE(widget2);
+ views::FocusManager* focus_manager2 = widget2->GetFocusManager();
ASSERT_TRUE(focus_manager2);
EXPECT_EQ(browser_view2->GetTabContentsContainerView(),
focus_manager2->GetFocusedView());
@@ -264,9 +265,9 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_BrowsersRememberFocus) {
// Switch back to the second browser, focus should still be on the page.
browser2->window()->Activate();
- EXPECT_EQ(NULL,
- views::FocusManager::GetFocusManagerForNativeView(
- browser()->window()->GetNativeHandle())->GetFocusedView());
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
+ ASSERT_TRUE(widget);
+ EXPECT_EQ(NULL, widget->GetFocusManager()->GetFocusedView());
EXPECT_EQ(browser_view2->GetTabContentsContainerView(),
focus_manager2->GetFocusedView());
diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc
index 64d6c0f..e9cf419 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_win.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc
@@ -497,11 +497,13 @@ void RenderWidgetHostViewWin::Focus() {
}
void RenderWidgetHostViewWin::Blur() {
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(m_hWnd);
- // We don't have a FocusManager if we are hidden.
- if (focus_manager)
- focus_manager->ClearFocus();
+ views::Widget* widget = views::Widget::GetTopLevelWidgetForNativeView(m_hWnd);
+ if (widget) {
+ views::FocusManager* focus_manager = widget->GetFocusManager();
+ // We don't have a FocusManager if we are hidden.
+ if (focus_manager)
+ focus_manager->ClearFocus();
+ }
}
bool RenderWidgetHostViewWin::HasFocus() {
diff --git a/chrome/browser/ui/find_bar/find_bar_host_browsertest.cc b/chrome/browser/ui/find_bar/find_bar_host_browsertest.cc
index ee2e26d..5445484 100644
--- a/chrome/browser/ui/find_bar/find_bar_host_browsertest.cc
+++ b/chrome/browser/ui/find_bar/find_bar_host_browsertest.cc
@@ -27,6 +27,7 @@
#if defined(TOOLKIT_VIEWS)
#include "chrome/browser/ui/views/find_bar_host.h"
#include "views/focus/focus_manager.h"
+#include "views/widget/widget.h"
#elif defined(TOOLKIT_GTK)
#include "chrome/browser/ui/gtk/slide_animator_gtk.h"
#elif defined(OS_MACOSX)
@@ -751,9 +752,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
GURL url = test_server()->GetURL(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeWindow(
- browser()->window()->GetNativeHandle());
+ gfx::NativeWindow window = browser()->window()->GetNativeHandle();
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
+ views::FocusManager* focus_manager = widget->GetFocusManager();
// See where Escape is registered.
views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false);
diff --git a/chrome/browser/ui/views/dropdown_bar_host.cc b/chrome/browser/ui/views/dropdown_bar_host.cc
index 190b25c..80fa513 100644
--- a/chrome/browser/ui/views/dropdown_bar_host.cc
+++ b/chrome/browser/ui/views/dropdown_bar_host.cc
@@ -70,8 +70,7 @@ void DropdownBarHost::Init(views::View* view,
// Start listening to focus changes, so we can register and unregister our
// own handler for Escape.
- focus_manager_ =
- views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView());
+ focus_manager_ = host_->GetFocusManager();
if (focus_manager_) {
focus_manager_->AddFocusChangeListener(this);
} else {
diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_touch.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_touch.cc
index 26f2102..7449112 100644
--- a/chrome/browser/ui/views/tab_contents/tab_contents_view_touch.cc
+++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_touch.cc
@@ -190,8 +190,7 @@ void TabContentsViewTouch::StoreFocus() {
if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
view_storage->RemoveView(last_focused_view_storage_id_);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
+ views::FocusManager* focus_manager = GetFocusManager();
if (focus_manager) {
// |focus_manager| can be NULL if the tab has been detached but still
// exists.
@@ -208,8 +207,7 @@ void TabContentsViewTouch::RestoreFocus() {
if (!last_focused_view) {
SetInitialFocus();
} else {
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
+ views::FocusManager* focus_manager = GetFocusManager();
// If you hit this DCHECK, please report it to Jay (jcampan).
DCHECK(focus_manager != NULL) << "No focus manager when restoring focus.";
@@ -318,8 +316,7 @@ void TabContentsViewTouch::TakeFocus(bool reverse) {
if (tab_contents_->delegate() &&
!tab_contents_->delegate()->TakeFocus(reverse)) {
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
+ views::FocusManager* focus_manager = GetFocusManager();
// We may not have a focus manager if the tab has been switched before this
// message arrived.
diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
index b607ed1..428a078 100644
--- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
+++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
@@ -186,8 +186,7 @@ void TabContentsViewViews::StoreFocus() {
if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
view_storage->RemoveView(last_focused_view_storage_id_);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
+ views::FocusManager* focus_manager = GetFocusManager();
if (focus_manager) {
// |focus_manager| can be NULL if the tab has been detached but still
// exists.
@@ -205,9 +204,7 @@ void TabContentsViewViews::RestoreFocus() {
if (!last_focused_view) {
SetInitialFocus();
} else {
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
-
+ views::FocusManager* focus_manager = GetFocusManager();
// If you hit this DCHECK, please report it to Jay (jcampan).
DCHECK(focus_manager != NULL) << "No focus manager when restoring focus.";
@@ -264,8 +261,7 @@ void TabContentsViewViews::GotFocus() {
void TabContentsViewViews::TakeFocus(bool reverse) {
if (!tab_contents_->delegate()->TakeFocus(reverse)) {
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
+ views::FocusManager* focus_manager = GetFocusManager();
// We may not have a focus manager if the tab has been switched before this
// message arrived.
diff --git a/chrome/test/base/ui_test_utils_linux.cc b/chrome/test/base/ui_test_utils_linux.cc
index 55af9d3..f890d7d 100644
--- a/chrome/test/base/ui_test_utils_linux.cc
+++ b/chrome/test/base/ui_test_utils_linux.cc
@@ -47,10 +47,9 @@ bool IsViewFocused(const Browser* browser, ViewID vid) {
DCHECK(browser_window);
#if defined(TOOLKIT_VIEWS)
gfx::NativeWindow window = browser_window->GetNativeHandle();
- DCHECK(window);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(
- GTK_WIDGET(window));
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
+ DCHECK(widget);
+ views::FocusManager* focus_manager = widget->GetFocusManager();
DCHECK(focus_manager);
return focus_manager->GetFocusedView() &&
focus_manager->GetFocusedView()->id() == vid;
diff --git a/chrome/test/base/ui_test_utils_win.cc b/chrome/test/base/ui_test_utils_win.cc
index 5244a7e..e7abb26 100644
--- a/chrome/test/base/ui_test_utils_win.cc
+++ b/chrome/test/base/ui_test_utils_win.cc
@@ -19,8 +19,9 @@ bool IsViewFocused(const Browser* browser, ViewID vid) {
DCHECK(browser_window);
gfx::NativeWindow window = browser_window->GetNativeHandle();
DCHECK(window);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(window);
+ views::Widget* widget = views::Widget::GetTopLevelWidgetForNativeView(window);
+ DCHECK(widget);
+ views::FocusManager* focus_manager = widget->GetFocusManager();
DCHECK(focus_manager);
return focus_manager->GetFocusedView()->id() == vid;
}
diff --git a/ui/views/focus/accelerator_handler_win.cc b/ui/views/focus/accelerator_handler_win.cc
index 5efdab8..ab059ec 100644
--- a/ui/views/focus/accelerator_handler_win.cc
+++ b/ui/views/focus/accelerator_handler_win.cc
@@ -8,6 +8,7 @@
#include "ui/base/keycodes/keyboard_code_conversion_win.h"
#include "ui/views/events/event.h"
#include "ui/views/focus/focus_manager.h"
+#include "ui/views/widget/widget.h"
namespace ui {
@@ -18,8 +19,8 @@ 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);
+ Widget* widget = Widget::GetTopLevelWidgetForNativeView(msg.hwnd);
+ FocusManager* focus_manager = widget ? widget->GetFocusManager() : NULL;
if (focus_manager) {
switch (msg.message) {
case WM_KEYDOWN:
diff --git a/ui/views/focus/focus_manager.cc b/ui/views/focus/focus_manager.cc
index 6e1e953..efe65b1 100644
--- a/ui/views/focus/focus_manager.cc
+++ b/ui/views/focus/focus_manager.cc
@@ -326,22 +326,6 @@ bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) {
!key_event.IsControlDown();
}
-// static
-FocusManager* FocusManager::GetFocusManagerForNativeView(
- gfx::NativeView native_view) {
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeView(native_view);
- return native_widget ? native_widget->GetWidget()->GetFocusManager() : NULL;
-}
-
-// static
-FocusManager* FocusManager::GetFocusManagerForNativeWindow(
- gfx::NativeWindow native_window) {
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeWindow(native_window);
- return native_widget ? native_widget->GetWidget()->GetFocusManager() : NULL;
-}
-
////////////////////////////////////////////////////////////////////////////////
// FocusManager, private:
diff --git a/ui/views/focus/focus_manager.h b/ui/views/focus/focus_manager.h
index a132ccc..2236619 100644
--- a/ui/views/focus/focus_manager.h
+++ b/ui/views/focus/focus_manager.h
@@ -251,14 +251,6 @@ class FocusManager {
// pressed).
static bool IsTabTraversalKeyEvent(const KeyEvent& key_event);
- // Retrieves the FocusManager associated with the passed native view.
- static FocusManager* GetFocusManagerForNativeView(
- gfx::NativeView native_view);
-
- // Retrieves the FocusManager associated with the passed native view.
- static FocusManager* GetFocusManagerForNativeWindow(
- gfx::NativeWindow native_window);
-
private:
// Returns the next focusable view.
View* GetNextFocusableView(View* starting_view,
diff --git a/views/controls/native/native_view_host_gtk.cc b/views/controls/native/native_view_host_gtk.cc
index 3284344..adc21d5 100644
--- a/views/controls/native/native_view_host_gtk.cc
+++ b/views/controls/native/native_view_host_gtk.cc
@@ -382,11 +382,11 @@ void NativeViewHostGtk::CallDestroy(GtkObject* object,
}
// static
-gboolean NativeViewHostGtk::CallFocusIn(GtkWidget* widget,
+gboolean NativeViewHostGtk::CallFocusIn(GtkWidget* gtk_widget,
GdkEventFocus* event,
NativeViewHostGtk* host) {
- FocusManager* focus_manager =
- FocusManager::GetFocusManagerForNativeView(widget);
+ Widget* widget = Widget::GetWidgetForNativeView(gtk_widget);
+ FocusManager* focus_manager = widget ? widget->GetFocusManager() : NULL;
if (!focus_manager) {
// TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the
// options page is only based on views.
diff --git a/views/controls/native/native_view_host_gtk.h b/views/controls/native/native_view_host_gtk.h
index 84b0a36..1a903ef 100644
--- a/views/controls/native/native_view_host_gtk.h
+++ b/views/controls/native/native_view_host_gtk.h
@@ -64,7 +64,7 @@ class NativeViewHostGtk : public NativeViewHostWrapper {
static void CallDestroy(GtkObject* object, NativeViewHostGtk* host);
// Invoked from the 'focus-in-event' signal.
- static gboolean CallFocusIn(GtkWidget* widget,
+ static gboolean CallFocusIn(GtkWidget* gtk_widget,
GdkEventFocus* event,
NativeViewHostGtk* button);
diff --git a/views/controls/native_control_gtk.cc b/views/controls/native_control_gtk.cc
index 0c21a9e..965d347 100644
--- a/views/controls/native_control_gtk.cc
+++ b/views/controls/native_control_gtk.cc
@@ -232,11 +232,11 @@ void NativeControlGtk::NativeControlCreated(GtkWidget* native_control) {
}
// static
-gboolean NativeControlGtk::CallFocusIn(GtkWidget* widget,
+gboolean NativeControlGtk::CallFocusIn(GtkWidget* gtk_widget,
GdkEventFocus* event,
NativeControlGtk* control) {
- FocusManager* focus_manager =
- FocusManager::GetFocusManagerForNativeView(widget);
+ Widget* widget = Widget::GetTopLevelWidgetForNativeView(gtk_widget);
+ FocusManager* focus_manager = widget ? widget->GetFocusManager() : NULL;
if (!focus_manager) {
// TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the
// options page is only based on views.
diff --git a/views/controls/native_control_gtk.h b/views/controls/native_control_gtk.h
index 05582fb..0333e36 100644
--- a/views/controls/native_control_gtk.h
+++ b/views/controls/native_control_gtk.h
@@ -47,7 +47,7 @@ class NativeControlGtk : public NativeViewHost {
virtual void NativeControlCreated(GtkWidget* widget);
private:
- static gboolean CallFocusIn(GtkWidget* widget,
+ static gboolean CallFocusIn(GtkWidget* gtk_widget,
GdkEventFocus* event,
NativeControlGtk* button);
diff --git a/views/focus/accelerator_handler_win.cc b/views/focus/accelerator_handler_win.cc
index ad401f3..8f2c8e8 100644
--- a/views/focus/accelerator_handler_win.cc
+++ b/views/focus/accelerator_handler_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 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.
@@ -8,6 +8,7 @@
#include "ui/base/keycodes/keyboard_code_conversion_win.h"
#include "views/events/event.h"
#include "views/focus/focus_manager.h"
+#include "views/widget/widget.h"
namespace views {
@@ -18,8 +19,8 @@ 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);
+ Widget* widget = Widget::GetTopLevelWidgetForNativeView(msg.hwnd);
+ FocusManager* focus_manager = widget ? widget->GetFocusManager() : NULL;
if (focus_manager) {
switch (msg.message) {
case WM_KEYDOWN:
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc
index e2942a6..2dff171f 100644
--- a/views/focus/focus_manager.cc
+++ b/views/focus/focus_manager.cc
@@ -463,25 +463,6 @@ 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 018a4f2..ca31752 100644
--- a/views/focus/focus_manager.h
+++ b/views/focus/focus_manager.h
@@ -280,14 +280,6 @@ class VIEWS_API FocusManager {
// pressed).
static bool IsTabTraversalKeyEvent(const KeyEvent& key_event);
- // Retrieves the FocusManager associated with the passed native view.
- static FocusManager* GetFocusManagerForNativeView(
- gfx::NativeView native_view);
-
- // Retrieves the FocusManager associated with the passed native view.
- static FocusManager* GetFocusManagerForNativeWindow(
- gfx::NativeWindow native_window);
-
private:
// Returns the next focusable view.
View* GetNextFocusableView(View* starting_view, bool reverse, bool dont_loop);
diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc
index cec153c..8c4c29a 100644
--- a/views/focus/focus_manager_unittest.cc
+++ b/views/focus/focus_manager_unittest.cc
@@ -1601,32 +1601,38 @@ TEST_F(FocusManagerTest, CreationForNativeRoot) {
// Get the focus manager directly from the first window. Should exist
// because the first window is the root widget.
- views::FocusManager* focus_manager_member1 = widget1->GetFocusManager();
- EXPECT_TRUE(focus_manager_member1);
+ views::FocusManager* focus_manager1 = widget1->GetFocusManager();
+ EXPECT_TRUE(focus_manager1);
// Create another view window parented to the first view window.
scoped_ptr<Widget> widget2(new Widget);
params.parent = widget1->GetNativeView();
widget2->Init(params);
- // Get the focus manager directly from the second window. Should return the
- // first window's focus manager.
- views::FocusManager* focus_manager_member2 = widget2->GetFocusManager();
- EXPECT_EQ(focus_manager_member2, focus_manager_member1);
-
- // Get the focus manager indirectly using the first window handle. Should
- // return the first window's focus manager.
- views::FocusManager* focus_manager_indirect =
- views::FocusManager::GetFocusManagerForNativeView(
- widget1->GetNativeView());
- EXPECT_EQ(focus_manager_indirect, focus_manager_member1);
-
- // Get the focus manager indirectly using the second window handle. Should
- // return the first window's focus manager.
- focus_manager_indirect =
- views::FocusManager::GetFocusManagerForNativeView(
- widget2->GetNativeView());
- EXPECT_EQ(focus_manager_indirect, focus_manager_member1);
+ // Access the shared focus manager directly from the second window.
+ views::FocusManager* focus_manager2 = widget2->GetFocusManager();
+ EXPECT_EQ(focus_manager2, focus_manager1);
+
+ // Access the shared focus manager indirectly from the first window handle.
+ gfx::NativeWindow native_window = widget1->GetNativeWindow();
+ views::Widget* widget =
+ views::Widget::GetWidgetForNativeWindow(native_window);
+ EXPECT_EQ(widget->GetFocusManager(), focus_manager1);
+
+ // Access the shared focus manager indirectly from the second window handle.
+ native_window = widget2->GetNativeWindow();
+ widget = views::Widget::GetWidgetForNativeWindow(native_window);
+ EXPECT_EQ(widget->GetFocusManager(), focus_manager1);
+
+ // Access the shared focus manager indirectly from the first view handle.
+ gfx::NativeView native_view = widget1->GetNativeView();
+ widget = views::Widget::GetTopLevelWidgetForNativeView(native_view);
+ EXPECT_EQ(widget->GetFocusManager(), focus_manager1);
+
+ // Access the shared focus manager indirectly from the second view handle.
+ native_view = widget2->GetNativeView();
+ widget = views::Widget::GetTopLevelWidgetForNativeView(native_view);
+ EXPECT_EQ(widget->GetFocusManager(), focus_manager1);
DestroyWindow(hwnd);
}
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index e4ed9e5..f2309108 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -840,8 +840,7 @@ TEST_F(ViewTest, ActivateAccelerator) {
root->AddChildView(view);
// Get the focus manager.
- FocusManager* focus_manager = FocusManager::GetFocusManagerForNativeView(
- widget->GetNativeView());
+ FocusManager* focus_manager = widget->GetFocusManager();
ASSERT_TRUE(focus_manager);
// Hit the return key and see if it takes effect.
@@ -904,8 +903,7 @@ TEST_F(ViewTest, HiddenViewWithAccelerator) {
View* root = widget->GetRootView();
root->AddChildView(view);
- FocusManager* focus_manager = FocusManager::GetFocusManagerForNativeView(
- widget->GetNativeView());
+ FocusManager* focus_manager = widget->GetFocusManager();
ASSERT_TRUE(focus_manager);
view->SetVisible(false);
diff --git a/views/widget/gtk_views_window.cc b/views/widget/gtk_views_window.cc
index 7da1490..dbb526a 100644
--- a/views/widget/gtk_views_window.cc
+++ b/views/widget/gtk_views_window.cc
@@ -1,11 +1,12 @@
-// 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.
#include <gtk/gtk.h>
#include "views/events/event.h"
-#include "views/widget/gtk_views_window.h"
#include "views/focus/focus_manager.h"
+#include "views/widget/gtk_views_window.h"
+#include "views/widget/widget.h"
G_BEGIN_DECLS
@@ -13,8 +14,9 @@ G_DEFINE_TYPE(GtkViewsWindow, gtk_views_window, GTK_TYPE_WINDOW)
static void gtk_views_window_move_focus(GtkWindow* window,
GtkDirectionType dir) {
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeWindow(window);
+ widget ? widget->GetFocusManager() : NULL;
if (focus_manager) {
GdkEvent* key = gtk_get_current_event();
if (key && key->type == GDK_KEY_PRESS) {