summaryrefslogtreecommitdiffstats
path: root/views/focus
diff options
context:
space:
mode:
Diffstat (limited to 'views/focus')
-rw-r--r--views/focus/focus_manager.cc19
-rw-r--r--views/focus/focus_manager.h20
-rw-r--r--views/focus/focus_manager_unittest.cc29
3 files changed, 39 insertions, 29 deletions
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc
index 046d6ea..ab67301 100644
--- a/views/focus/focus_manager.cc
+++ b/views/focus/focus_manager.cc
@@ -71,10 +71,6 @@ static LRESULT CALLBACK FocusWindowCallback(HWND window, UINT message,
// but that window may not have an associated FocusManager.
if (focus_manager) {
switch (message) {
- case WM_SETFOCUS:
- if (!focus_manager->OnSetFocus(window))
- return 0;
- break;
case WM_NCDESTROY:
if (!focus_manager->OnNCDestroy(window))
return 0;
@@ -189,21 +185,6 @@ FocusManager::~FocusManager() {
#if defined(OS_WIN)
// Message handlers.
-bool FocusManager::OnSetFocus(HWND window) {
- if (ignore_set_focus_msg_)
- return true;
-
- // Focus the view associated with that window.
- View* v = static_cast<View*>(GetProp(window, kViewKey));
- if (v && v->IsFocusable()) {
- v->GetRootView()->FocusView(v);
- } else {
- SetFocusedView(NULL);
- }
-
- return true;
-}
-
bool FocusManager::OnNCDestroy(HWND window) {
// Window is being destroyed, undo the subclassing.
FocusManager::UninstallFocusSubclass(window);
diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h
index 4c7f6ce..c5e2be9a 100644
--- a/views/focus/focus_manager.h
+++ b/views/focus/focus_manager.h
@@ -160,16 +160,6 @@ class FocusManager {
// The RootView specified should be the top RootView of the window.
// This also invokes InstallFocusSubclass.
static FocusManager* CreateFocusManager(HWND window, RootView* root_view);
-
- // Subclasses the specified window. The subclassed window procedure listens
- // for WM_SETFOCUS notification and keeps the FocusManager's focus owner
- // property in sync.
- // It's not necessary to explicitly invoke Uninstall, it's automatically done
- // when the window is destroyed and Uninstall wasn't invoked.
- static void InstallFocusSubclass(HWND window, View* view);
-
- // Uninstalls the window subclass installed by InstallFocusSubclass.
- static void UninstallFocusSubclass(HWND window);
#endif
static FocusManager* GetFocusManager(gfx::NativeView window);
@@ -294,6 +284,16 @@ class FocusManager {
private:
#if defined(OS_WIN)
explicit FocusManager(HWND root, RootView* root_view);
+
+ // Subclasses the specified window. The subclassed window procedure listens
+ // for WM_SETFOCUS notification and keeps the FocusManager's focus owner
+ // property in sync.
+ // It's not necessary to explicitly invoke Uninstall, it's automatically done
+ // when the window is destroyed and Uninstall wasn't invoked.
+ static void InstallFocusSubclass(HWND window, View* view);
+
+ // Uninstalls the window subclass installed by InstallFocusSubclass.
+ static void UninstallFocusSubclass(HWND window);
#endif
~FocusManager();
diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc
index 95257ec..f4142db 100644
--- a/views/focus/focus_manager_unittest.cc
+++ b/views/focus/focus_manager_unittest.cc
@@ -699,6 +699,24 @@ class TestNativeButton : public NativeButton {
}
};
+class TestCheckbox : public Checkbox {
+ public:
+ explicit TestCheckbox(const std::wstring& text) : Checkbox(text) {
+ };
+ virtual HWND TestGetNativeControlHWND() {
+ return native_wrapper_->GetTestingHandle();
+ }
+};
+
+class TestRadioButton : public RadioButton {
+ public:
+ explicit TestRadioButton(const std::wstring& text) : RadioButton(text, 1) {
+ };
+ virtual HWND TestGetNativeControlHWND() {
+ return native_wrapper_->GetTestingHandle();
+ }
+};
+
class TestTextfield : public Textfield {
public:
TestTextfield() { }
@@ -719,11 +737,15 @@ class TestTabbedPane : public TabbedPane {
// FocusManager.
TEST_F(FocusManagerTest, FocusNativeControls) {
TestNativeButton* button = new TestNativeButton(L"Press me");
+ TestCheckbox* checkbox = new TestCheckbox(L"Checkbox");
+ TestRadioButton* radio_button = new TestRadioButton(L"RadioButton");
TestTextfield* textfield = new TestTextfield();
TestTabbedPane* tabbed_pane = new TestTabbedPane();
TestNativeButton* tab_button = new TestNativeButton(L"tab button");
content_view_->AddChildView(button);
+ content_view_->AddChildView(checkbox);
+ content_view_->AddChildView(radio_button);
content_view_->AddChildView(textfield);
content_view_->AddChildView(tabbed_pane);
tabbed_pane->AddTab(L"Awesome tab", tab_button);
@@ -732,6 +754,13 @@ TEST_F(FocusManagerTest, FocusNativeControls) {
::SendMessage(button->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL);
EXPECT_EQ(button, GetFocusManager()->GetFocusedView());
+ ::SendMessage(checkbox->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL);
+ EXPECT_EQ(checkbox, GetFocusManager()->GetFocusedView());
+
+ ::SendMessage(radio_button->TestGetNativeControlHWND(), WM_SETFOCUS,
+ NULL, NULL);
+ EXPECT_EQ(radio_button, GetFocusManager()->GetFocusedView());
+
::SendMessage(textfield->TestGetNativeComponent(), WM_SETFOCUS, NULL, NULL);
EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView());