Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: ui/views/focus/focus_manager_unittest.cc

Issue 10951033: Plumb ClearNativeFocus to DesktopRootWindowHostWin. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: get rid of FocusNativeView Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/views/widget/desktop_native_widget_aura.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "ui/base/accelerators/accelerator.h" 9 #include "ui/base/accelerators/accelerator.h"
10 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
11 #include "ui/views/controls/button/text_button.h" 11 #include "ui/views/controls/button/text_button.h"
12 #include "ui/views/controls/textfield/textfield.h" 12 #include "ui/views/controls/textfield/textfield.h"
13 #include "ui/views/focus/accelerator_handler.h" 13 #include "ui/views/focus/accelerator_handler.h"
14 #include "ui/views/focus/focus_manager_factory.h" 14 #include "ui/views/focus/focus_manager_factory.h"
15 #include "ui/views/focus/focus_manager_test.h" 15 #include "ui/views/focus/focus_manager_test.h"
16 #include "ui/views/focus/widget_focus_manager.h" 16 #include "ui/views/focus/widget_focus_manager.h"
17 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 18
19 #if !defined(USE_AURA) 19 #if defined(USE_AURA)
20 #include "ui/aura/focus_manager.h"
21 #include "ui/aura/window.h"
22 #else
20 #include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h" 23 #include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
21 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" 24 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
22 #endif 25 #endif
23 26
24 namespace views { 27 namespace views {
25 28
29 void FocusNativeView(gfx::NativeView view) {
30 #if defined(USE_AURA)
31 view->GetFocusManager()->SetFocusedWindow(view, NULL);
32 #elif defined(OS_WIN)
33 SetFocus(view);
34 #else
35 #error
36 #endif
37 }
38
26 enum FocusTestEventType { 39 enum FocusTestEventType {
27 ON_FOCUS = 0, 40 ON_FOCUS = 0,
28 ON_BLUR 41 ON_BLUR
29 }; 42 };
30 43
31 struct FocusTestEvent { 44 struct FocusTestEvent {
32 FocusTestEvent(FocusTestEventType type, int view_id) 45 FocusTestEvent(FocusTestEventType type, int view_id)
33 : type(type), 46 : type(type),
34 view_id(view_id) { 47 view_id(view_id) {
35 } 48 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 scoped_ptr<Widget> widget1(new Widget); 145 scoped_ptr<Widget> widget1(new Widget);
133 widget1->Init(params); 146 widget1->Init(params);
134 widget1->Show(); 147 widget1->Show();
135 148
136 scoped_ptr<Widget> widget2(new Widget); 149 scoped_ptr<Widget> widget2(new Widget);
137 widget2->Init(params); 150 widget2->Init(params);
138 widget2->Show(); 151 widget2->Show();
139 152
140 widget_listener.ClearFocusChanges(); 153 widget_listener.ClearFocusChanges();
141 gfx::NativeView native_view1 = widget1->GetNativeView(); 154 gfx::NativeView native_view1 = widget1->GetNativeView();
142 GetWidget()->FocusNativeView(native_view1); 155 FocusNativeView(native_view1);
143 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size())); 156 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size()));
144 EXPECT_EQ(native_view1, widget_listener.focus_changes()[0].second); 157 EXPECT_EQ(native_view1, widget_listener.focus_changes()[0].second);
145 EXPECT_EQ(native_view1, widget_listener.focus_changes()[1].second); 158 EXPECT_EQ(native_view1, widget_listener.focus_changes()[1].second);
146 159
147 widget_listener.ClearFocusChanges(); 160 widget_listener.ClearFocusChanges();
148 gfx::NativeView native_view2 = widget2->GetNativeView(); 161 gfx::NativeView native_view2 = widget2->GetNativeView();
149 GetWidget()->FocusNativeView(native_view2); 162 FocusNativeView(native_view2);
150 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size())); 163 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size()));
151 EXPECT_EQ(NativeViewPair(native_view1, native_view2), 164 EXPECT_EQ(NativeViewPair(native_view1, native_view2),
152 widget_listener.focus_changes()[0]); 165 widget_listener.focus_changes()[0]);
153 EXPECT_EQ(NativeViewPair(native_view1, native_view2), 166 EXPECT_EQ(NativeViewPair(native_view1, native_view2),
154 widget_listener.focus_changes()[1]); 167 widget_listener.focus_changes()[1]);
155 } 168 }
156 169
157 #if !defined(USE_AURA) 170 #if !defined(USE_AURA)
158 class TestTextfield : public Textfield { 171 class TestTextfield : public Textfield {
159 public: 172 public:
(...skipping 18 matching lines...) Expand all
178 TestTabbedPane* tabbed_pane = new TestTabbedPane(); 191 TestTabbedPane* tabbed_pane = new TestTabbedPane();
179 tabbed_pane->set_use_native_win_control(true); 192 tabbed_pane->set_use_native_win_control(true);
180 TestTextfield* textfield2 = new TestTextfield(); 193 TestTextfield* textfield2 = new TestTextfield();
181 194
182 GetContentsView()->AddChildView(textfield); 195 GetContentsView()->AddChildView(textfield);
183 GetContentsView()->AddChildView(tabbed_pane); 196 GetContentsView()->AddChildView(tabbed_pane);
184 197
185 tabbed_pane->AddTab(ASCIIToUTF16("Awesome textfield"), textfield2); 198 tabbed_pane->AddTab(ASCIIToUTF16("Awesome textfield"), textfield2);
186 199
187 // Simulate the native view getting the native focus (such as by user click). 200 // Simulate the native view getting the native focus (such as by user click).
188 GetWidget()->FocusNativeView(textfield->TestGetNativeControlView()); 201 FocusNativeView(textfield->TestGetNativeControlView());
189 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); 202 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView());
190 203
191 GetWidget()->FocusNativeView(tabbed_pane->TestGetNativeControlView()); 204 FocusNativeView(tabbed_pane->TestGetNativeControlView());
192 EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView()); 205 EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView());
193 206
194 GetWidget()->FocusNativeView(textfield2->TestGetNativeControlView()); 207 FocusNativeView(textfield2->TestGetNativeControlView());
195 EXPECT_EQ(textfield2, GetFocusManager()->GetFocusedView()); 208 EXPECT_EQ(textfield2, GetFocusManager()->GetFocusedView());
196 } 209 }
197 #endif 210 #endif
198 211
199 // There is no tabbed pane in Aura. 212 // There is no tabbed pane in Aura.
200 #if !defined(USE_AURA) 213 #if !defined(USE_AURA)
201 TEST_F(FocusManagerTest, ContainsView) { 214 TEST_F(FocusManagerTest, ContainsView) {
202 View* view = new View(); 215 View* view = new View();
203 scoped_ptr<View> detached_view(new View()); 216 scoped_ptr<View> detached_view(new View());
204 TabbedPane* tabbed_pane = new TabbedPane(); 217 TabbedPane* tabbed_pane = new TabbedPane();
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 654
642 // Test window, button and focus manager should all be destructed. 655 // Test window, button and focus manager should all be destructed.
643 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); 656 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size()));
644 657
645 // Focus manager should be the last one to destruct. 658 // Focus manager should be the last one to destruct.
646 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); 659 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str());
647 } 660 }
648 #endif 661 #endif
649 662
650 } // namespace views 663 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/desktop_native_widget_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698