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

Side by Side Diff: ui/views/focus/focus_manager_test.h

Issue 10562025: aura: Fix WidgetFocusChangeListener::OnNativeFocusChange(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge again Created 8 years, 6 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_ 5 #ifndef UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_
6 #define UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_ 6 #define UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_
7 7
8 #include "ui/views/focus/focus_manager.h" 8 #include "ui/views/focus/focus_manager.h"
9 #include "ui/views/focus/widget_focus_manager.h"
9 #include "ui/views/test/views_test_base.h" 10 #include "ui/views/test/views_test_base.h"
10 #include "ui/views/widget/widget_delegate.h" 11 #include "ui/views/widget/widget_delegate.h"
11 12
12 namespace views { 13 namespace views {
13 14
14 class FocusChangeListener; 15 class FocusChangeListener;
15 16
16 class FocusManagerTest : public ViewsTestBase, 17 class FocusManagerTest : public ViewsTestBase,
17 public WidgetDelegate { 18 public WidgetDelegate {
18 public: 19 public:
(...skipping 11 matching lines...) Expand all
30 virtual View* GetContentsView() OVERRIDE; 31 virtual View* GetContentsView() OVERRIDE;
31 virtual Widget* GetWidget() OVERRIDE; 32 virtual Widget* GetWidget() OVERRIDE;
32 virtual const Widget* GetWidget() const OVERRIDE; 33 virtual const Widget* GetWidget() const OVERRIDE;
33 34
34 protected: 35 protected:
35 // Called after the Widget is initialized and the content view is added. 36 // Called after the Widget is initialized and the content view is added.
36 // Override to add controls to the layout. 37 // Override to add controls to the layout.
37 virtual void InitContentView(); 38 virtual void InitContentView();
38 39
39 void AddFocusChangeListener(FocusChangeListener* listener); 40 void AddFocusChangeListener(FocusChangeListener* listener);
41 void AddWidgetFocusChangeListener(WidgetFocusChangeListener* listener);
40 42
41 #if defined(OS_WIN) && !defined(USE_AURA) 43 #if defined(OS_WIN) && !defined(USE_AURA)
42 // Mocks activating/deactivating the window. 44 // Mocks activating/deactivating the window.
43 void SimulateActivateWindow(); 45 void SimulateActivateWindow();
44 void SimulateDeactivateWindow(); 46 void SimulateDeactivateWindow();
45 47
46 void PostKeyDown(ui::KeyboardCode key_code); 48 void PostKeyDown(ui::KeyboardCode key_code);
47 void PostKeyUp(ui::KeyboardCode key_code); 49 void PostKeyUp(ui::KeyboardCode key_code);
48 #endif 50 #endif
49 51
50 private: 52 private:
51 View* contents_view_; 53 View* contents_view_;
52 FocusChangeListener* focus_change_listener_; 54 FocusChangeListener* focus_change_listener_;
55 WidgetFocusChangeListener* widget_focus_change_listener_;
53 56
54 DISALLOW_COPY_AND_ASSIGN(FocusManagerTest); 57 DISALLOW_COPY_AND_ASSIGN(FocusManagerTest);
55 }; 58 };
56 59
57 typedef std::pair<View*, View*> ViewPair; 60 typedef std::pair<View*, View*> ViewPair;
58 61
59 // Use to record focus change notifications. 62 // Use to record focus change notifications.
60 class TestFocusChangeListener : public FocusChangeListener { 63 class TestFocusChangeListener : public FocusChangeListener {
61 public: 64 public:
62 TestFocusChangeListener(); 65 TestFocusChangeListener();
63 virtual ~TestFocusChangeListener(); 66 virtual ~TestFocusChangeListener();
64 67
65 const std::vector<ViewPair>& focus_changes() const { return focus_changes_; } 68 const std::vector<ViewPair>& focus_changes() const { return focus_changes_; }
66 void ClearFocusChanges(); 69 void ClearFocusChanges();
67 70
68 // Overridden from FocusChangeListener: 71 // Overridden from FocusChangeListener:
69 virtual void OnWillChangeFocus(View* focused_before, 72 virtual void OnWillChangeFocus(View* focused_before,
70 View* focused_now) OVERRIDE; 73 View* focused_now) OVERRIDE;
71 virtual void OnDidChangeFocus(View* focused_before, 74 virtual void OnDidChangeFocus(View* focused_before,
72 View* focused_now) OVERRIDE; 75 View* focused_now) OVERRIDE;
73 76
74 private: 77 private:
75 // A vector of which views lost/gained focus. 78 // A vector of which views lost/gained focus.
76 std::vector<ViewPair> focus_changes_; 79 std::vector<ViewPair> focus_changes_;
77 80
78 DISALLOW_COPY_AND_ASSIGN(TestFocusChangeListener); 81 DISALLOW_COPY_AND_ASSIGN(TestFocusChangeListener);
79 }; 82 };
80 83
84 typedef std::pair<gfx::NativeView, gfx::NativeView> NativeViewPair;
85
86 // Use to record widget focus change notifications.
87 class TestWidgetFocusChangeListener : public WidgetFocusChangeListener {
88 public:
89 TestWidgetFocusChangeListener();
90 virtual ~TestWidgetFocusChangeListener();
91
92 const std::vector<NativeViewPair>& focus_changes() const {
93 return focus_changes_;
94 }
95 void ClearFocusChanges();
96
97 // Overridden from WidgetFocusChangeListener:
98 virtual void OnNativeFocusChange(gfx::NativeView focused_before,
99 gfx::NativeView focused_now) OVERRIDE;
100
101 private:
102 // Pairs of (focused_before, focused_now) parameters we've received via calls
103 // to OnNativeFocusChange(), in oldest-to-newest-received order.
104 std::vector<NativeViewPair> focus_changes_;
105
106 DISALLOW_COPY_AND_ASSIGN(TestWidgetFocusChangeListener);
107 };
108
81 } // namespace views 109 } // namespace views
82 110
83 #endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_ 111 #endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698